[Swfdec] 9 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_internal.h libswfdec/swfdec_as_interpret.c libswfdec/swfdec_movie.c libswfdec/swfdec_player.c libswfdec/swfdec_video_movie_as.c

Benjamin Otte company at kemper.freedesktop.org
Sat Sep 8 12:08:24 PDT 2007


 libswfdec/swfdec_as_context.c     |   19 ++-
 libswfdec/swfdec_as_internal.h    |    3 
 libswfdec/swfdec_as_interpret.c   |  209 ++++++++++++++++++++++----------------
 libswfdec/swfdec_movie.c          |    4 
 libswfdec/swfdec_player.c         |   20 +--
 libswfdec/swfdec_video_movie_as.c |    2 
 6 files changed, 150 insertions(+), 107 deletions(-)

New commits:
diff-tree f443e1a8281d0db546c00ec8ddb836ac9802862e (from parents)
Merge: 3641211119fdc27a91f84d33aaff656bd3dfec30 9fa2912e46463fbfc80bfeb37a78f1efb26e2b5e
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 21:08:17 2007 +0200

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec/swfdec
    
    Conflicts:
    
    	libswfdec/swfdec_player.c
    	libswfdec/swfdec_xml.c
    	libswfdec/swfdec_xml_node.c

diff --cc libswfdec/swfdec_as_context.c
index 64fbd0a,f6b3c3a..f2183f5
@@@ -1238,11 -1232,9 +1237,9 @@@
    swfdec_as_array_init_context (context, version);
    /* define the type objects */
    swfdec_as_string_init_context (context, version);
-   /* define the rest */
-   swfdec_as_math_init_context (context, version);
  
    /* run init script */
 -  swfdec_as_context_run_init_script (context, swfdec_as_initialize, sizeof (swfdec_as_initialize));
 +  swfdec_as_context_run_init_script (context, swfdec_as_initialize, sizeof (swfdec_as_initialize), 8);
  
    if (context->state == SWFDEC_AS_CONTEXT_NEW)
      context->state = SWFDEC_AS_CONTEXT_RUNNING;
diff --cc libswfdec/swfdec_as_interpret.c
index 2660c97,a94d3ca..71a5663
@@@ -409,25 -409,6 +409,25 @@@
    }
  }
  
- static SwfdecAsObject *
- super_special_movie_lookup_magic (SwfdecAsObject *movie, const char *name)
++static SwfdecMovie *
++super_special_movie_lookup_magic (SwfdecMovie *movie, const char *name)
 +{
 +  SwfdecAsValue val;
-   SwfdecAsObject *ret;
++  SwfdecMovie *ret;
 +
-   ret = SWFDEC_AS_OBJECT (swfdec_movie_get_by_name (SWFDEC_MOVIE (movie), name));
++  ret = swfdec_movie_get_by_name (movie, name);
 +  if (ret)
 +    return ret;
-   if (!swfdec_as_object_get_variable (movie, name, &val))
++  if (!swfdec_as_object_get_variable (SWFDEC_AS_OBJECT (movie), name, &val))
 +    return NULL;
 +  if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
 +    return NULL;
-   ret = SWFDEC_AS_VALUE_GET_OBJECT (&val);
++  ret = (SwfdecMovie *) SWFDEC_AS_VALUE_GET_OBJECT (&val);
 +  if (!SWFDEC_IS_MOVIE (ret))
 +    return NULL;
 +  return ret;
 +}
 +
  /**
   * swfdec_action_get_movie_by_path:
   * @cx: a #SwfdecAsContext
@@@ -445,9 -426,10 +445,26 @@@
  swfdec_action_get_movie_by_path (SwfdecAsContext *cx, const char *path, 
      SwfdecAsObject **object, const char **variable)
  {
--  SwfdecAsObject *movie;
--  const char *s;
-   gboolean was_slash = FALSE;
 -  SwfdecAsValue val;
 -  gboolean was_slash = FALSE;
++  SwfdecMovie *movie;
++  enum {
++    START,
++    IDENTIFIER,
++    BACK,
++    DOT,
++    COLON,
++    SLASH
++  } token = START;
++  enum {
++    STARTING = (1 << 0),
++    SLASHES = (1 << 1),
++    WAS_SLASH = (1 << 2),
++    DOTS = (1 << 3),
++    COLONS = (1 << 4),
++    DOUBLE = (1 << 5),
++    BACKS = (1 << 6)
++  } flags = STARTING;
++
++  g_assert (path != NULL);
  
    /* shortcut for the general case */
    if (strpbrk (path, ".:/") == NULL) {
@@@ -456,97 -438,98 +473,100 @@@
      return TRUE;
    }
  
--  /* in general, any combination of dot, colon and slash is allowed, but there
--   * is some weird stuff that is not allowed. WE check this first: */
--  /* if a slash is last, no colon or dot may be before it. */
--  s = strrchr (path, '/');
--  if (s != NULL) {
--    const char *dot = strrchr (path, '.');
--    const char *colon = strrchr (path, ':');
--    if (!(dot > s || colon > s) && 
--	(dot != NULL || colon != NULL))
--      return FALSE;
--  }
--  /* if a dot follows a slash, it must be the last seperator */
--  s = strchr (path, '/');
--  if (s) {
--    const char *dot = strchr (s, '.');
--    if (dot && strpbrk (dot + 1, ".:"))
--      return FALSE;
--  }
--  /* a colon at the beginning may not be the only separator */
--  if (path[0] == ':') {
--    if (strpbrk (path + 1, ".:/") == NULL)
--      return FALSE;
--    else
--      path++;
--  }
--
--  movie = cx->frame->target;
--  if (!SWFDEC_IS_MOVIE (movie)) {
++  *variable = NULL;
++  g_assert (cx->frame);
++  if (!SWFDEC_IS_MOVIE (cx->frame->target)) {
      SWFDEC_FIXME ("target is not a movie");
--  } else {
--    if (path[0] == '/') {
--      /* if path starts with a slash, start from the root movie */
--      while (SWFDEC_MOVIE (movie)->parent)
--	movie = SWFDEC_AS_OBJECT (SWFDEC_MOVIE (movie)->parent);
++    return FALSE;
++  }
++  movie = SWFDEC_MOVIE (cx->frame->target);
++  while (*path) {
++    /* parse next token */
++    if (path[0] == '.' && path[1] == '.') {
++      /* BACK */
++      if (token == DOT || token == BACK || token == IDENTIFIER)
++	return FALSE;
++      movie = movie->parent;
++      if (movie == NULL)
++	return FALSE;
++      path += 2;
++      flags &= ~DOUBLE;
++      flags |= BACKS;
++      token = BACK;
++    } else if (path[0] == '.') {
++      /* DOT */
++      if (token == DOT || token == START || 
++	  (flags & DOUBLE) ||
++	  ((flags & SLASHES) && !(flags | WAS_SLASH)) ||
++	  (flags & (SLASHES | DOTS)) == (SLASHES | DOTS))
++	return FALSE;
++      flags &= ~WAS_SLASH;
++      flags |= DOTS;
++      if (token != IDENTIFIER)
++	flags |= DOUBLE;
+       path++;
 -      was_slash = TRUE;
++      token = DOT;
++    } else if (path[0] == ':') {
++      /* COLON */
++      if ((flags & DOUBLE) ||
++	  (flags & (SLASHES | DOTS)) == (SLASHES | DOTS))
++	return FALSE;
++      flags &= ~WAS_SLASH;
++      if (token != IDENTIFIER && token != BACK)
++	flags |= DOUBLE;
++      if (token != START && token != COLON)
++	flags |= COLONS;
++      path++;
++      token = COLON;
++    } else if (path[0] == '/') {
++      /* SLASH */
++      if (token == DOT || token == SLASH || token == COLON ||
++	  (flags & DOTS))
++	return FALSE;
++      g_assert (!(flags & DOUBLE)); /* can't happen, we'd have returned above */
++      if (flags & STARTING) {
++	while (movie->parent)
++	  movie = movie->parent;
++      }
++      flags |= SLASHES | WAS_SLASH;
 +      path++;
-       was_slash = TRUE;
++      token = SLASH;
      } else {
--      /* if path starts with "..", move to parent */
--      while (path[0] == '.') {
--	if (path[1] != '.')
--	  return FALSE;
--	movie = SWFDEC_AS_OBJECT (SWFDEC_MOVIE (movie)->parent);
++      /* IDENTIFIER */
++      const char *s = strpbrk (path, ".:/");
++      g_assert (token != IDENTIFIER);
++      if (token == BACK)
++	return FALSE;
++      if (s) {
++	const char *var = swfdec_as_context_give_string (cx, g_strndup (path, s - path));
++	movie = super_special_movie_lookup_magic (movie, var);
  	if (movie == NULL)
  	  return FALSE;
--	path++;
--	if (path[0] == '/') {
--	  was_slash = TRUE;
--	  path++;
--	} else if (path[0] == ':' || path[0] == '.') {
--	  SWFDEC_FIXME ("what now?");
--	  path++;
--	  was_slash = FALSE;
--	  break;
++	path = s;
++      } else {
++	if (token == SLASH) {
++	  movie = super_special_movie_lookup_magic (movie, swfdec_as_context_get_string (cx, path));
++	  if (movie == NULL)
++	    return FALSE;
  	} else {
--	  return FALSE;
++	  *variable = path;
  	}
++	path = "\0";
        }
++      flags &= ~DOUBLE;
++      token = IDENTIFIER;
      }
++    flags &= ~STARTING;
    }
--  while ((s = strpbrk (path, ".:/"))) {
--    const char *var;
--    
--    if (s == path) {
--      if (*s == '/')
--	return FALSE;
--      was_slash = FALSE;
--      path++;
--      continue;
--    }
--    was_slash = *s == '/';
--    var = swfdec_as_context_give_string (cx, g_strndup (path, s - path));
-     movie = super_special_movie_lookup_magic (movie, var);
-     if (movie == NULL)
-       return FALSE;
-     path = s + 1;
-   }
-   if (was_slash) {
-     if (*path) {
-       const char *var = swfdec_as_context_get_string (cx, path);
-       movie = super_special_movie_lookup_magic (movie, var);
-       if (movie == NULL)
- 	return FALSE;
-     }
-     *object = movie;
-     *variable = NULL;
-     return TRUE;
-   } else {
-     *object = movie;
-     *variable = path;
-     return TRUE;
-   }
 -    if (!swfdec_as_object_get_variable (movie, var, &val) ||
 -	!SWFDEC_AS_VALUE_IS_OBJECT (&val) ||
 -	!SWFDEC_IS_MOVIE ((movie = SWFDEC_AS_VALUE_GET_OBJECT (&val))))
 -      return FALSE;
 -    path = s + 1;
 -  }
 -  if (was_slash) {
 -    if (*path) {
 -      const char *var = swfdec_as_context_get_string (cx, path);
 -      movie = SWFDEC_AS_OBJECT (swfdec_movie_get_by_name (SWFDEC_MOVIE (movie), var));
 -      if (movie == NULL)
 -	return FALSE;
 -    }
 -    *object = movie;
 -    *variable = NULL;
 -    return TRUE;
 -  } else {
 -    *object = movie;
 -    *variable = path;
 -    return TRUE;
 -  }
++  if (token != IDENTIFIER && token != DOTS &&
++      !(token == SLASH && !(flags & (BACKS | COLONS | DOTS))))
++    return FALSE;
++  if ((flags & WAS_SLASH) && flags & (COLONS | DOTS | BACKS))
++    return FALSE;
++  if (!(flags & (COLONS | SLASHES | DOTS)))
++    return FALSE;
++  *object = SWFDEC_AS_OBJECT (movie);
++  return TRUE;
  }
  
  static void
diff --cc libswfdec/swfdec_player.c
index 1196519,ac38011..e473fed
@@@ -1613,16 -1608,17 +1613,12 @@@
      swfdec_player_init_global (player, version);
      swfdec_sprite_movie_init_context (player, version);
      swfdec_video_movie_init_context (player, version);
-     swfdec_movie_color_init_context (player, version);
      swfdec_net_connection_init_context (player, version);
      swfdec_net_stream_init_context (player, version);
 -    if (version > 4) {
 -      SwfdecBits bits;
 -      SwfdecScript *script;
 -      swfdec_bits_init_data (&bits, swfdec_initialize, sizeof (swfdec_initialize));
 -      script = swfdec_script_new_from_bits (&bits, "init", version);
 -      g_assert (script);
 -      swfdec_as_object_run (context->global, script);
 -      swfdec_script_unref (script);
 -    }
 +
 +    swfdec_as_context_run_init_script (context, swfdec_initialize, 
 +	sizeof (swfdec_initialize), 8);
 +
-     swfdec_xml_node_init_native (player, version);
-     swfdec_xml_init_native (player, version);
- 
      if (context->state == SWFDEC_AS_CONTEXT_NEW) {
        context->state = SWFDEC_AS_CONTEXT_RUNNING;
        swfdec_as_object_set_constructor (player->roots->data, player->MovieClip);
diff-tree 3641211119fdc27a91f84d33aaff656bd3dfec30 (from ce0e407babe4909a2ee436642931c17add64f165)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:58:53 2007 +0200

    run init script via swfdec_as_context_run_init_script

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index a9e9f51..1196519 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1616,18 +1616,13 @@ swfdec_player_initialize (SwfdecPlayer *
     swfdec_movie_color_init_context (player, version);
     swfdec_net_connection_init_context (player, version);
     swfdec_net_stream_init_context (player, version);
-    if (version > 4) {
-      SwfdecBits bits;
-      SwfdecScript *script;
-      swfdec_bits_init_data (&bits, swfdec_initialize, sizeof (swfdec_initialize));
-      script = swfdec_script_new_from_bits (&bits, "init", version);
-      g_assert (script);
-      swfdec_as_object_run (context->global, script);
-      swfdec_script_unref (script);
 
-      swfdec_xml_node_init_native (player, version);
-      swfdec_xml_init_native (player, version);
-    }
+    swfdec_as_context_run_init_script (context, swfdec_initialize, 
+	sizeof (swfdec_initialize), 8);
+
+    swfdec_xml_node_init_native (player, version);
+    swfdec_xml_init_native (player, version);
+
     if (context->state == SWFDEC_AS_CONTEXT_NEW) {
       context->state = SWFDEC_AS_CONTEXT_RUNNING;
       swfdec_as_object_set_constructor (player->roots->data, player->MovieClip);
diff-tree ce0e407babe4909a2ee436642931c17add64f165 (from 7dbecaf197fef6e23dedc5ecc040174649115c7d)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:58:24 2007 +0200

    return from initializers if the version isn't at least 5

diff --git a/libswfdec/swfdec_xml.c b/libswfdec/swfdec_xml.c
index 4eb1376..e40a3b1 100644
--- a/libswfdec/swfdec_xml.c
+++ b/libswfdec/swfdec_xml.c
@@ -789,7 +789,9 @@ swfdec_xml_init_native (SwfdecPlayer *pl
   SwfdecAsObject *proto;
 
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
-
+  
+  if (version < 5)
+    return;
   context = SWFDEC_AS_CONTEXT (player);
   swfdec_as_object_get_variable (context->global, SWFDEC_AS_STR_XML, &val);
   g_return_if_fail (SWFDEC_AS_VALUE_IS_OBJECT (&val));
diff --git a/libswfdec/swfdec_xml_node.c b/libswfdec/swfdec_xml_node.c
index 563a34d..2b02576 100644
--- a/libswfdec/swfdec_xml_node.c
+++ b/libswfdec/swfdec_xml_node.c
@@ -1059,6 +1059,8 @@ swfdec_xml_node_init_native (SwfdecPlaye
 
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
 
+  if (version < 5)
+    return;
   context = SWFDEC_AS_CONTEXT (player);
   swfdec_as_object_get_variable (context->global, SWFDEC_AS_STR_XMLNode, &val);
   g_return_if_fail (SWFDEC_AS_VALUE_IS_OBJECT (&val));
diff-tree 7dbecaf197fef6e23dedc5ecc040174649115c7d (from ddbf2fc319736342e5c3888a83b827a4276ea637)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:56:51 2007 +0200

    restore the context's version after executing scripts

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 34dd33b..64fbd0a 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -711,6 +711,7 @@ swfdec_as_context_run (SwfdecAsContext *
   guint action, len;
   guint8 *data;
   int version;
+  guint original_version;
   void (* step) (SwfdecAsDebugger *debugger, SwfdecAsContext *context);
   gboolean check_scope; /* some opcodes avoid a scope check */
 
@@ -727,6 +728,7 @@ swfdec_as_context_run (SwfdecAsContext *
 
   last_frame = context->last_frame;
   context->last_frame = context->frame->next;
+  original_version = context->version;
 start:
   /* setup data */
   frame = context->frame;
@@ -899,6 +901,7 @@ error:
     swfdec_as_frame_return (context->frame, NULL);
 out:
   context->last_frame = last_frame;
+  context->version = original_version;
   return;
 }
 
diff-tree ddbf2fc319736342e5c3888a83b827a4276ea637 (from b4a71766918c51dec8be9a0b8fae6e6766bad8c9)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:56:17 2007 +0200

    check the given version here, not the context one
    
    The context's version might not be initialzied yet

diff --git a/libswfdec/swfdec_video_movie_as.c b/libswfdec/swfdec_video_movie_as.c
index 2edf5b4..8ae6656 100644
--- a/libswfdec/swfdec_video_movie_as.c
+++ b/libswfdec/swfdec_video_movie_as.c
@@ -74,7 +74,7 @@ swfdec_video_movie_init_context (SwfdecP
   swfdec_as_object_set_variable_and_flags (video, SWFDEC_AS_STR_prototype, &val,
       SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
   /* set the right properties on the Video.prototype object */
-  if (context->version >= 6) {
+  if (version >= 6) {
     swfdec_as_object_add_function (proto, SWFDEC_AS_STR_attachVideo,
 	SWFDEC_TYPE_VIDEO_MOVIE, swfdec_video_attach_video, 1);
     swfdec_as_object_add_function (proto, SWFDEC_AS_STR_clear,
diff-tree b4a71766918c51dec8be9a0b8fae6e6766bad8c9 (from 106816beccb5bca5c28972837221bfaaeca27a76)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:43:06 2007 +0200

    make sure the player isn't interrupted when unlocking
    
    (Also make it compile again, but I'm not talking about that)

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 3d54325..a9e9f51 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1237,10 +1237,13 @@ swfdec_player_unlock_soft (SwfdecPlayer 
 void
 swfdec_player_unlock (SwfdecPlayer *player)
 {
+  SwfdecAsContext *context;
+
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
   g_assert (swfdec_ring_buffer_get_n_elements (player->actions) == 0);
-
   context = SWFDEC_AS_CONTEXT (player);
+  g_return_if_fail (context->state != SWFDEC_AS_CONTEXT_INTERRUPTED);
+
   if (context->state == SWFDEC_AS_CONTEXT_RUNNING)
     swfdec_as_context_maybe_gc (SWFDEC_AS_CONTEXT (player));
   swfdec_player_unlock_soft (player);
diff-tree 106816beccb5bca5c28972837221bfaaeca27a76 (from 132e8bc8cf53a9d4413683d3be4ed50caaca04b4)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:40:27 2007 +0200

    require the GC to be only run when the player is running
    
    Interrupted and aborted is not allowed.
    Also check for this state when unlocking the player

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 1eb5785..34dd33b 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -381,7 +381,7 @@ swfdec_as_context_gc (SwfdecAsContext *c
 
   g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context));
   g_return_if_fail (context->frame == NULL);
-  g_return_if_fail (context->state != SWFDEC_AS_CONTEXT_NEW);
+  g_return_if_fail (context->state == SWFDEC_AS_CONTEXT_RUNNING);
 
   if (context->state == SWFDEC_AS_CONTEXT_ABORTED)
     return;
@@ -412,8 +412,7 @@ void
 swfdec_as_context_maybe_gc (SwfdecAsContext *context)
 {
   g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context));
-  if (context->state == SWFDEC_AS_CONTEXT_ABORTED)
-    return;
+  g_return_if_fail (context->state == SWFDEC_AS_CONTEXT_RUNNING);
   g_return_if_fail (context->frame == NULL);
 
   if (swfdec_as_context_needs_gc (context))
diff --git a/libswfdec/swfdec_as_internal.h b/libswfdec/swfdec_as_internal.h
index 819a65d..bc3290a 100644
--- a/libswfdec/swfdec_as_internal.h
+++ b/libswfdec/swfdec_as_internal.h
@@ -44,7 +44,8 @@ void		swfdec_as_function_init_context (S
 /* swfdec_as_context.c */
 void		swfdec_as_context_run_init_script (SwfdecAsContext *	context,
 						 const guint8 *		data,
-						 gsize			length);
+						 gsize			length,
+						 guint			version);
 
 /* swfdec_as_object.c */
 typedef SwfdecAsVariableForeach SwfdecAsVariableForeachRemove;
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 7babf41..3d54325 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1240,7 +1240,9 @@ swfdec_player_unlock (SwfdecPlayer *play
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
   g_assert (swfdec_ring_buffer_get_n_elements (player->actions) == 0);
 
-  swfdec_as_context_maybe_gc (SWFDEC_AS_CONTEXT (player));
+  context = SWFDEC_AS_CONTEXT (player);
+  if (context->state == SWFDEC_AS_CONTEXT_RUNNING)
+    swfdec_as_context_maybe_gc (SWFDEC_AS_CONTEXT (player));
   swfdec_player_unlock_soft (player);
   g_object_unref (player);
 }
diff-tree 132e8bc8cf53a9d4413683d3be4ed50caaca04b4 (from c538e44a4f44ac7661d087aeedd39919293164d4)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Sep 8 20:37:56 2007 +0200

    make the init script take a version and always run it as Flash 8

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index ff458f9..1eb5785 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -1187,23 +1187,26 @@ swfdec_as_context_init_global (SwfdecAsC
 }
 
 void
-swfdec_as_context_run_init_script (SwfdecAsContext *context, const guint8 *data, gsize length)
+swfdec_as_context_run_init_script (SwfdecAsContext *context, const guint8 *data, 
+    gsize length, guint version)
 {
   g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context));
   g_return_if_fail (data != NULL);
   g_return_if_fail (length > 0);
 
-  if (context->version > 4) {
+  if (version > 4) {
     SwfdecBits bits;
     SwfdecScript *script;
     swfdec_bits_init_data (&bits, data, length);
-    script = swfdec_script_new_from_bits (&bits, "init", context->version);
+    script = swfdec_script_new_from_bits (&bits, "init", version);
     if (script == NULL) {
       g_warning ("script passed to swfdec_as_context_run_init_script is invalid");
       return;
     }
     swfdec_as_object_run (context->global, script);
     swfdec_script_unref (script);
+  } else {
+    SWFDEC_LOG ("not running init script, since version is <= 4");
   }
 }
 
@@ -1237,7 +1240,7 @@ swfdec_as_context_startup (SwfdecAsConte
   swfdec_as_math_init_context (context, version);
 
   /* run init script */
-  swfdec_as_context_run_init_script (context, swfdec_as_initialize, sizeof (swfdec_as_initialize));
+  swfdec_as_context_run_init_script (context, swfdec_as_initialize, sizeof (swfdec_as_initialize), 8);
 
   if (context->state == SWFDEC_AS_CONTEXT_NEW)
     context->state = SWFDEC_AS_CONTEXT_RUNNING;
diff-tree c538e44a4f44ac7661d087aeedd39919293164d4 (from 89d295a9455fead858e48ffcae0cc5808d72ee22)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Sep 6 14:32:00 2007 +0200

    add special magic for movie lookups

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index a94d3ca..2660c97 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -409,6 +409,25 @@ swfdec_action_push (SwfdecAsContext *cx,
   }
 }
 
+static SwfdecAsObject *
+super_special_movie_lookup_magic (SwfdecAsObject *movie, const char *name)
+{
+  SwfdecAsValue val;
+  SwfdecAsObject *ret;
+
+  ret = SWFDEC_AS_OBJECT (swfdec_movie_get_by_name (SWFDEC_MOVIE (movie), name));
+  if (ret)
+    return ret;
+  if (!swfdec_as_object_get_variable (movie, name, &val))
+    return NULL;
+  if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
+    return NULL;
+  ret = SWFDEC_AS_VALUE_GET_OBJECT (&val);
+  if (!SWFDEC_IS_MOVIE (ret))
+    return NULL;
+  return ret;
+}
+
 /**
  * swfdec_action_get_movie_by_path:
  * @cx: a #SwfdecAsContext
@@ -428,7 +447,6 @@ swfdec_action_get_movie_by_path (SwfdecA
 {
   SwfdecAsObject *movie;
   const char *s;
-  SwfdecAsValue val;
   gboolean was_slash = FALSE;
 
   /* shortcut for the general case */
@@ -509,16 +527,15 @@ swfdec_action_get_movie_by_path (SwfdecA
     }
     was_slash = *s == '/';
     var = swfdec_as_context_give_string (cx, g_strndup (path, s - path));
-    if (!swfdec_as_object_get_variable (movie, var, &val) ||
-	!SWFDEC_AS_VALUE_IS_OBJECT (&val) ||
-	!SWFDEC_IS_MOVIE ((movie = SWFDEC_AS_VALUE_GET_OBJECT (&val))))
+    movie = super_special_movie_lookup_magic (movie, var);
+    if (movie == NULL)
       return FALSE;
     path = s + 1;
   }
   if (was_slash) {
     if (*path) {
       const char *var = swfdec_as_context_get_string (cx, path);
-      movie = SWFDEC_AS_OBJECT (swfdec_movie_get_by_name (SWFDEC_MOVIE (movie), var));
+      movie = super_special_movie_lookup_magic (movie, var);
       if (movie == NULL)
 	return FALSE;
     }
diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 82fa40a..94ea8a8 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -928,7 +928,7 @@ swfdec_movie_get_by_name (SwfdecMovie *m
   SwfdecPlayer *player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context);
 
   if ((version >= 7 && g_str_has_prefix (name, "_level")) ||
-      strncasecmp (name, "_level", 6) == 0) {
+      (version < 7 && strncasecmp (name, "_level", 6) == 0)) {
     errno = 0;
     l = strtoul (name + 6, &end, 10);
     if (errno != 0 || *end != 0 || l > G_MAXINT)
@@ -949,7 +949,7 @@ swfdec_movie_get_by_name (SwfdecMovie *m
     if (cur->original_name == SWFDEC_AS_STR_EMPTY)
       continue;
     if ((version >= 7 && cur->name == name) ||
-	swfdec_str_case_equal (cur->name, name))
+	(version < 7 && swfdec_str_case_equal (cur->name, name)))
       return cur;
   }
   return NULL;


More information about the Swfdec mailing list