[Swfdec] Branch 'as' - 7 commits - libswfdec/swfdec_as_math.c libswfdec/swfdec_as_object.c libswfdec/swfdec_movie.c libswfdec/swfdec_sprite_movie.c test/trace

Benjamin Otte company at kemper.freedesktop.org
Tue Jul 3 04:16:25 PDT 2007


 libswfdec/swfdec_as_math.c            |   16 ++++++++--------
 libswfdec/swfdec_as_object.c          |    3 ++-
 libswfdec/swfdec_movie.c              |   12 +++++-------
 libswfdec/swfdec_sprite_movie.c       |    3 ++-
 test/trace/Makefile.am                |    7 +++++++
 test/trace/math-constants-5.swf       |binary
 test/trace/math-constants-5.swf.trace |    8 ++++++++
 test/trace/math-constants-6.swf       |binary
 test/trace/math-constants-6.swf.trace |    8 ++++++++
 test/trace/math-constants-7.swf       |binary
 test/trace/math-constants-7.swf.trace |    8 ++++++++
 test/trace/math-constants.as          |   12 ++++++++++++
 12 files changed, 60 insertions(+), 17 deletions(-)

New commits:
diff-tree 1d85fb35f0e2d57d684df1b9df2d42ddc7e7e547 (from a6549a64a50be437716e8ec3dbdc33671ee15f0a)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 3 12:16:00 2007 +0100

    swfdec_as_context_get_string + g_free => swfdec_as_context_give_string
    
    btw: if someone has better names than get_string/give_string, tell me.
    I couldn't come up with any.

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index c0bf0df..dff211f 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -466,8 +466,7 @@ swfdec_movie_set_variables (SwfdecMovie 
       g_free (value);
       break;
     }
-    asname = swfdec_as_context_get_string (as->context, name);
-    g_free (name);
+    asname = swfdec_as_context_give_string (as->context, name);
     SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (as->context, value));
     g_free (value);
     swfdec_as_object_set_variable (as, asname, &val);
diff-tree a6549a64a50be437716e8ec3dbdc33671ee15f0a (from a031f4b7e379e364e82101dd02924cc1b1137b56)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jul 3 00:00:16 2007 +0100

    unset sound stream here, since we're not recreating it in any case

diff --git a/libswfdec/swfdec_sprite_movie.c b/libswfdec/swfdec_sprite_movie.c
index 3e741ea..5a110a9 100644
--- a/libswfdec/swfdec_sprite_movie.c
+++ b/libswfdec/swfdec_sprite_movie.c
@@ -542,6 +542,7 @@ new_decoder:
   if (movie->sound_stream) {
     swfdec_audio_remove (movie->sound_stream);
     g_object_unref (movie->sound_stream);
+    movie->sound_stream = NULL;
   }
 
   if (current->sound_block) {
diff-tree a031f4b7e379e364e82101dd02924cc1b1137b56 (from 90c2424294478b3d5d004e7066fa6db20ae65f22)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Jul 2 23:59:45 2007 +0100

    add the movie to the context at any time
    
    This avoids crashes when functions like _get_variable() get called on the
    movie later on.

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 463b5ba..c0bf0df 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -905,12 +905,11 @@ swfdec_movie_new (SwfdecPlayer *player, 
   }
   /* register it to the VM */
   /* FIXME: It'd be nice if we'd not overuse memory here when calling this function from a script */
-  if (swfdec_as_context_use_mem (SWFDEC_AS_CONTEXT (player), size)) {
-    g_object_ref (movie);
-    swfdec_as_object_add (SWFDEC_AS_OBJECT (movie), SWFDEC_AS_CONTEXT (player), size);
-  } else {
-    SWFDEC_AS_OBJECT (movie)->context = SWFDEC_AS_CONTEXT (player);
+  if (!swfdec_as_context_use_mem (SWFDEC_AS_CONTEXT (player), size)) {
+    size = 0;
   }
+  g_object_ref (movie);
+  swfdec_as_object_add (SWFDEC_AS_OBJECT (movie), SWFDEC_AS_CONTEXT (player), size);
   /* set essential properties */
   movie->depth = depth;
   movie->parent = parent;
diff-tree 90c2424294478b3d5d004e7066fa6db20ae65f22 (from 486cbf5983ccd81aed7ac764f2f7b2a003b8c732)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Jul 2 23:58:52 2007 +0100

    only remove stuff if the object has a size
    
    We allow adding objects without size to make it easier in error cases to handle
    default objects. We might want to rethink this case and not create SwfdecMovie
    objects at all.

diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 34b1ee5..e3bd49e 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -283,7 +283,8 @@ swfdec_as_object_collect (SwfdecAsObject
   g_hash_table_foreach (object->properties, swfdec_as_object_free_property, object);
   g_hash_table_destroy (object->properties);
   object->properties = NULL;
-  swfdec_as_context_unuse_mem (object->context, object->size);
+  if (object->size)
+    swfdec_as_context_unuse_mem (object->context, object->size);
   g_object_unref (object);
 }
 
diff-tree 486cbf5983ccd81aed7ac764f2f7b2a003b8c732 (from a55cf4416f10ff80f138b1d9b339da5574695b36)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Jul 2 23:32:43 2007 +0100

    add movies to the script context before accessing any of their variables

diff --git a/libswfdec/swfdec_sprite_movie.c b/libswfdec/swfdec_sprite_movie.c
index 14ce0ff..3e741ea 100644
--- a/libswfdec/swfdec_sprite_movie.c
+++ b/libswfdec/swfdec_sprite_movie.c
@@ -266,12 +266,12 @@ swfdec_sprite_movie_perform_place (Swfde
     cur = swfdec_movie_new (player, depth, mov, graphic, name);
     swfdec_movie_set_static_properties (cur, has_transform ? &transform : NULL, 
 	has_ctrans ? &ctrans : NULL, ratio, clip_depth, events);
+    swfdec_movie_initialize (cur);
     if (SWFDEC_IS_SPRITE_MOVIE (cur)) {
       g_queue_push_tail (player->init_queue, cur);
       g_queue_push_tail (player->construct_queue, cur);
       swfdec_movie_queue_script (cur, SWFDEC_EVENT_LOAD);
     }
-    swfdec_movie_initialize (cur);
   }
 
   return TRUE;
diff-tree a55cf4416f10ff80f138b1d9b339da5574695b36 (from fc334a6258888b30b192d08bcc621ce7729486c5)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Jul 2 23:05:00 2007 +0100

    fix Math constants to be Math variables not global ones

diff --git a/libswfdec/swfdec_as_math.c b/libswfdec/swfdec_as_math.c
index ddd6987..ad2468a 100644
--- a/libswfdec/swfdec_as_math.c
+++ b/libswfdec/swfdec_as_math.c
@@ -136,21 +136,21 @@ swfdec_as_math_init_context (SwfdecAsCon
 
   /* set the right properties on the Math object */
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_E);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_E, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_E, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_LN10);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_LN10, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_LN10, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_LN2);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_LN2, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_LN2, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_LOG10E);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_LOG10E, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_LOG10E, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_LOG2E);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_LOG2E, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_LOG2E, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_PI);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_PI, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_PI, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_SQRT1_2);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_SQRT1_2, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_SQRT1_2, &val);
   SWFDEC_AS_VALUE_SET_NUMBER (&val, G_SQRT2);
-  swfdec_as_object_set_variable (context->global, SWFDEC_AS_STR_SQRT2, &val);
+  swfdec_as_object_set_variable (math, SWFDEC_AS_STR_SQRT2, &val);
 
   /* set the right functions on the Math object */
   swfdec_as_object_add_function (math, SWFDEC_AS_STR_abs, 0, swfdec_as_math_abs, 1);
diff-tree fc334a6258888b30b192d08bcc621ce7729486c5 (from 17cb8dc33b1e5d9b35a3f24ec559a0ab9b5a5dd4)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Jul 2 23:04:22 2007 +0100

    add test for the Math constants

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 2262934..89172ca 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -338,6 +338,13 @@ EXTRA_DIST = \
 	math-actions-7.swf \
 	math-actions-7.swf.trace \
 	math-actions-7.swf.trace.org \
+	math-constants.as \
+	math-constants-5.swf \
+	math-constants-5.swf.trace \
+	math-constants-6.swf \
+	math-constants-6.swf.trace \
+	math-constants-7.swf \
+	math-constants-7.swf.trace \
 	mouse-scaled.as \
 	mouse-scaled-5.swf \
 	mouse-scaled-5.swf.act \
diff --git a/test/trace/math-constants-5.swf b/test/trace/math-constants-5.swf
new file mode 100644
index 0000000..f62e315
Binary files /dev/null and b/test/trace/math-constants-5.swf differ
diff --git a/test/trace/math-constants-5.swf.trace b/test/trace/math-constants-5.swf.trace
new file mode 100644
index 0000000..0c92434
--- /dev/null
+++ b/test/trace/math-constants-5.swf.trace
@@ -0,0 +1,8 @@
+2.71828182845905
+2.30258509299405
+0.693147180559945
+0.434294481903252
+1.44269504088896
+3.14159265358979
+0.707106781186548
+1.4142135623731
diff --git a/test/trace/math-constants-6.swf b/test/trace/math-constants-6.swf
new file mode 100644
index 0000000..ecdbb4c
Binary files /dev/null and b/test/trace/math-constants-6.swf differ
diff --git a/test/trace/math-constants-6.swf.trace b/test/trace/math-constants-6.swf.trace
new file mode 100644
index 0000000..0c92434
--- /dev/null
+++ b/test/trace/math-constants-6.swf.trace
@@ -0,0 +1,8 @@
+2.71828182845905
+2.30258509299405
+0.693147180559945
+0.434294481903252
+1.44269504088896
+3.14159265358979
+0.707106781186548
+1.4142135623731
diff --git a/test/trace/math-constants-7.swf b/test/trace/math-constants-7.swf
new file mode 100644
index 0000000..dc965ba
Binary files /dev/null and b/test/trace/math-constants-7.swf differ
diff --git a/test/trace/math-constants-7.swf.trace b/test/trace/math-constants-7.swf.trace
new file mode 100644
index 0000000..0c92434
--- /dev/null
+++ b/test/trace/math-constants-7.swf.trace
@@ -0,0 +1,8 @@
+2.71828182845905
+2.30258509299405
+0.693147180559945
+0.434294481903252
+1.44269504088896
+3.14159265358979
+0.707106781186548
+1.4142135623731
diff --git a/test/trace/math-constants.as b/test/trace/math-constants.as
new file mode 100644
index 0000000..8a8f53a
--- /dev/null
+++ b/test/trace/math-constants.as
@@ -0,0 +1,12 @@
+// makeswf -v 7 -s 200x150 -r 1 -o math-constants.swf math-constants.as
+
+trace (Math.E);
+trace (Math.LN10);
+trace (Math.LN2);
+trace (Math.LOG10E);
+trace (Math.LOG2E);
+trace (Math.PI);
+trace (Math.SQRT1_2);
+trace (Math.SQRT2);
+
+loadMovie ("FSCommand:quit", "");


More information about the Swfdec mailing list