[Swfdec] problems to lookup AS object properties using SWFDEC API functions - cause found
Bernd Kischnick
kisch at ki.sch-co.de
Thu Jul 9 04:13:33 PDT 2009
Replying to my own mail:
> Neither
> swfdec_as_object_has_variable() nor swfdec_as_object_get_variable() nor
> swfdec_as_object_get_variable_and_flags() are able to find a property
> which definitely exists.
...whereas enumerating the properties shows them to exist.
This strange behaviour is caused by the properties-hash of AS objects
being a DIRECT hash as opposed to a STRING hash.
swfdec_as_object.c has this:
static void
swfdec_as_object_init (SwfdecAsObject *object)
{
object->properties = g_hash_table_new (g_direct_hash, g_direct_equal);
}
It should probably have g_str_hash and g_str_equal.
Direct hashing only works as long as the property names are guaranteed to
be the identical string constants (same address) as used when populating
the hash.
In my case I'm trying to look up a property using a fresh string constant
as the key; this will never be address-equal to any existing key in the
hash.
Changing swfdec_as_object_init() to use g_str_hash and g_str_euqal seems
to solve the lookup problem. Now I'm struggling to get AS function calls
to work.
Is there a reason why a direct hash was used in the first place?
I hope the change doesn't have bad side effects.
The lookup problem is probably masked by a backwards-compatibility mode
for ActionScript < v7. In swfdec_as_object_hash_lookup(), there's a
fallback to sequential case-insensitive property lookup when the direct
lookup fails --- but my test SWF are v7, so the fallback wasn't effective.
- kisch
More information about the Swfdec
mailing list