[Swfdec] 15 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame_internal.h libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_object.h libswfdec/swfdec_as_super.c libswfdec/swfdec_as_with.c libswfdec/swfdec_codec_screen.c libswfdec/swfdec_flv_decoder.c libswfdec/swfdec_load_object.c libswfdec/swfdec_player_as.c libswfdec/swfdec_player.c test/trace

Benjamin Otte company at kemper.freedesktop.org
Mon Aug 20 06:51:32 PDT 2007


 libswfdec/swfdec_as_context.c                 |   45 +++++++++++++++++++++++++-
 libswfdec/swfdec_as_frame.c                   |   14 ++++----
 libswfdec/swfdec_as_frame_internal.h          |    3 +
 libswfdec/swfdec_as_interpret.c               |   22 ++++++++----
 libswfdec/swfdec_as_object.c                  |   26 ++++++++++-----
 libswfdec/swfdec_as_object.h                  |   11 +++++-
 libswfdec/swfdec_as_super.c                   |    4 +-
 libswfdec/swfdec_as_with.c                    |    2 -
 libswfdec/swfdec_codec_screen.c               |    1 
 libswfdec/swfdec_flv_decoder.c                |    1 
 libswfdec/swfdec_load_object.c                |   11 ++++++
 libswfdec/swfdec_player.c                     |   12 ++----
 libswfdec/swfdec_player_as.c                  |    8 ++--
 test/trace/Makefile.am                        |    9 +++++
 test/trace/construct-constructors-5.swf       |binary
 test/trace/construct-constructors-5.swf.trace |    5 ++
 test/trace/construct-constructors-6.swf       |binary
 test/trace/construct-constructors-6.swf.trace |    7 ++++
 test/trace/construct-constructors-7.swf       |binary
 test/trace/construct-constructors-7.swf.trace |    7 ++++
 test/trace/construct-constructors-8.swf       |binary
 test/trace/construct-constructors-8.swf.trace |    7 ++++
 test/trace/construct-constructors.as          |   20 +++++++++++
 test/trace/trace.c                            |    3 +
 24 files changed, 178 insertions(+), 40 deletions(-)

New commits:
diff-tree c3b035ca1583a420402b965506129bd73ff3f5fe (from parents)
Merge: 8e61c76bed9526865a3b3a295feaed8e82e2b108 8871593035346615d3b0394184271674d5fd725d
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:47:05 2007 +0200

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec/swfdec

diff-tree 8e61c76bed9526865a3b3a295feaed8e82e2b108 (from fc39dd27d21c49d37b3a4fee94b721e798a0fae4)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:45:16 2007 +0200

    gc every time

diff --git a/test/trace/trace.c b/test/trace/trace.c
index 8e5c0f2..af52ef6 100644
--- a/test/trace/trace.c
+++ b/test/trace/trace.c
@@ -101,6 +101,7 @@ run_test (gpointer testp, gpointer unuse
   }
   string = g_string_new ("");
   player = swfdec_player_new ();
+  g_object_set (player, "memory-until-gc", (gulong) 0, NULL);
   g_signal_connect (player, "trace", G_CALLBACK (trace_cb), string);
   g_signal_connect (player, "fscommand", G_CALLBACK (fscommand_cb), &quit);
   swfdec_player_set_loader (player, loader);
diff-tree fc39dd27d21c49d37b3a4fee94b721e798a0fae4 (from 076ba52a01ec3e9348822c37781b6cd4b6c24a28)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:45:07 2007 +0200

    GC intervals, too

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index b1ad1c7..b303408 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1094,6 +1094,7 @@ swfdec_player_mark (SwfdecAsContext *con
   swfdec_as_object_mark (player->MovieClip);
   swfdec_as_object_mark (player->Video);
   g_list_foreach (player->roots, (GFunc) swfdec_as_object_mark, NULL);
+  g_list_foreach (player->intervals, (GFunc) swfdec_as_object_mark, NULL);
   g_list_foreach (player->load_objects, (GFunc) swfdec_as_object_mark, NULL);
 
   SWFDEC_AS_CONTEXT_CLASS (swfdec_player_parent_class)->mark (context);
diff-tree 076ba52a01ec3e9348822c37781b6cd4b6c24a28 (from 613f8fad5514520d82419838475d02e3d704e714)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:44:44 2007 +0200

    reinstate old code that was only commented out for tests
    
    oops

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 23a9396..4e0958b 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -386,8 +386,7 @@ swfdec_as_context_gc (SwfdecAsContext *c
 static gboolean
 swfdec_as_context_needs_gc (SwfdecAsContext *context)
 {
-  return TRUE;
-  //return context->memory_since_gc >= context->memory_until_gc;
+  return context->memory_since_gc >= context->memory_until_gc;
 }
 
 /**
diff-tree 613f8fad5514520d82419838475d02e3d704e714 (from 414a4fc551748f8e3496758e2c2e9207e5ce87a6)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:38:24 2007 +0200

    export property to set how often GC is done

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 75ab9d6..23a9396 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -386,7 +386,8 @@ swfdec_as_context_gc (SwfdecAsContext *c
 static gboolean
 swfdec_as_context_needs_gc (SwfdecAsContext *context)
 {
-  return context->memory_since_gc >= context->memory_until_gc;
+  return TRUE;
+  //return context->memory_since_gc >= context->memory_until_gc;
 }
 
 /**
@@ -417,10 +418,47 @@ enum {
   LAST_SIGNAL
 };
 
+enum {
+  PROP_0,
+  PROP_UNTIL_GC
+};
+
 G_DEFINE_TYPE (SwfdecAsContext, swfdec_as_context, G_TYPE_OBJECT)
 static guint signals[LAST_SIGNAL] = { 0, };
 
 static void
+swfdec_as_context_get_property (GObject *object, guint param_id, GValue *value, 
+    GParamSpec * pspec)
+{
+  SwfdecAsContext *context = SWFDEC_AS_CONTEXT (object);
+  
+  switch (param_id) {
+    case PROP_UNTIL_GC:
+      g_value_set_ulong (value, (gulong) context->memory_until_gc);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+  }
+}
+
+static void
+swfdec_as_context_set_property (GObject *object, guint param_id, const GValue *value, 
+    GParamSpec * pspec)
+{
+  SwfdecAsContext *context = SWFDEC_AS_CONTEXT (object);
+  
+  switch (param_id) {
+    case PROP_UNTIL_GC:
+      context->memory_until_gc = g_value_get_ulong (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+  }
+}
+
+static void
 swfdec_as_context_dispose (GObject *object)
 {
   SwfdecAsContext *context = SWFDEC_AS_CONTEXT (object);
@@ -445,6 +483,13 @@ swfdec_as_context_class_init (SwfdecAsCo
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->dispose = swfdec_as_context_dispose;
+  object_class->get_property = swfdec_as_context_get_property;
+  object_class->set_property = swfdec_as_context_set_property;
+
+  g_object_class_install_property (object_class, PROP_UNTIL_GC,
+      g_param_spec_ulong ("memory-until-gc", "memory until gc", 
+	  "amount of bytes that need to be allocated before garbage collection triggers",
+	  0, G_MAXULONG, 8 * 1024 * 1024, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
   /**
    * SwfdecAsContext::trace:
@@ -466,7 +511,6 @@ swfdec_as_context_init (SwfdecAsContext 
 {
   const char *s;
 
-  context->memory_until_gc = 8 * 1024 * 1024; /* 8 MB before we run the GC */
   context->strings = g_hash_table_new (g_str_hash, g_str_equal);
   context->objects = g_hash_table_new (g_direct_hash, g_direct_equal);
 
diff-tree 414a4fc551748f8e3496758e2c2e9207e5ce87a6 (from 5a49ab2a34b19609ae57ac301cb0f3a3af41f140)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:38:08 2007 +0200

    fix memleak

diff --git a/libswfdec/swfdec_flv_decoder.c b/libswfdec/swfdec_flv_decoder.c
index df8054b..43c6b15 100644
--- a/libswfdec/swfdec_flv_decoder.c
+++ b/libswfdec/swfdec_flv_decoder.c
@@ -281,6 +281,7 @@ swfdec_flv_decoder_parse_video_tag (Swfd
     dec->width = cairo_image_surface_get_width (surface);
     dec->height = cairo_image_surface_get_height (surface);
     swfdec_video_decoder_free (decoder);
+    cairo_surface_destroy (surface);
     return SWFDEC_STATUS_INIT;
   } else {
     return SWFDEC_STATUS_IMAGE;
diff-tree 5a49ab2a34b19609ae57ac301cb0f3a3af41f140 (from adede979b9a128b32eb3c911e1ffa51858a8b312)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:26:32 2007 +0200

    fix memleak

diff --git a/test/trace/trace.c b/test/trace/trace.c
index 9725a0b..8e5c0f2 100644
--- a/test/trace/trace.c
+++ b/test/trace/trace.c
@@ -182,6 +182,8 @@ run_test (gpointer testp, gpointer unuse
   g_string_append (output, "  OK\n");
   test->success = TRUE;
 fail:
+  if (inter)
+    swfdec_interaction_free (inter);
   if (test->mutex)
     g_mutex_lock (test->mutex);
   test->output = g_string_free (output, FALSE);
diff-tree adede979b9a128b32eb3c911e1ffa51858a8b312 (from 04882c75cb8e4b84312af73281c8df32b808ca88)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 15:10:25 2007 +0200

    fix garbage collection
    
    Also plug a memleak by not freeing the load object list on dispose

diff --git a/libswfdec/swfdec_load_object.c b/libswfdec/swfdec_load_object.c
index 4d00a61..a8a51a7 100644
--- a/libswfdec/swfdec_load_object.c
+++ b/libswfdec/swfdec_load_object.c
@@ -148,6 +148,14 @@ swfdec_load_object_reset (SwfdecLoadObje
 }
 
 static void
+swfdec_load_object_mark (SwfdecAsObject *object)
+{
+  swfdec_as_object_mark (SWFDEC_LOAD_OBJECT (object)->target);
+
+  SWFDEC_AS_OBJECT_CLASS (swfdec_load_object_parent_class)->mark (object);
+}
+
+static void
 swfdec_load_object_dispose (GObject *object)
 {
   SwfdecLoadObject *load_object = SWFDEC_LOAD_OBJECT (object);
@@ -161,8 +169,11 @@ static void
 swfdec_load_object_class_init (SwfdecLoadObjectClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecAsObjectClass *as_object_class = SWFDEC_AS_OBJECT_CLASS (klass);
 
   object_class->dispose = swfdec_load_object_dispose;
+
+  as_object_class->mark = swfdec_load_object_mark;
 }
 
 static void
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 942dadf..b1ad1c7 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -666,6 +666,7 @@ swfdec_player_dispose (GObject *object)
   }
   g_assert (player->timeouts == NULL);
   g_list_free (player->intervals);
+  g_list_free (player->load_objects);
   player->intervals = NULL;
   g_assert (g_queue_is_empty (player->init_queue));
   g_assert (g_queue_is_empty (player->construct_queue));
@@ -1088,18 +1089,12 @@ static void
 swfdec_player_mark (SwfdecAsContext *context)
 {
   SwfdecPlayer *player = SWFDEC_PLAYER (context);
-  GList *walk;
 
   g_hash_table_foreach (player->registered_classes, swfdec_player_mark_string_object, NULL);
   swfdec_as_object_mark (player->MovieClip);
   swfdec_as_object_mark (player->Video);
-  for (walk = player->roots; walk; walk = walk->next) {
-    swfdec_as_object_mark (walk->data);
-  }
-  for (walk = player->load_objects; walk; walk = walk->next) {
-    swfdec_as_object_mark (walk->data);
-    swfdec_as_object_mark (SWFDEC_LOAD_OBJECT (walk->data)->target);
-  }
+  g_list_foreach (player->roots, (GFunc) swfdec_as_object_mark, NULL);
+  g_list_foreach (player->load_objects, (GFunc) swfdec_as_object_mark, NULL);
 
   SWFDEC_AS_CONTEXT_CLASS (swfdec_player_parent_class)->mark (context);
 }
diff-tree 04882c75cb8e4b84312af73281c8df32b808ca88 (from c13484c2bf562b37799aa5cce70beb04fe430cd6)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 13:43:50 2007 +0200

    fix valgrind reported memleaks

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 23e4116..4a712c2 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -331,7 +331,7 @@ swfdec_action_push (SwfdecAsContext *cx,
 	  if (s == NULL)
 	    return;
 	  SWFDEC_AS_VALUE_SET_STRING (swfdec_as_stack_push (cx), 
-	      swfdec_as_context_get_string (cx, s));
+	      swfdec_as_context_give_string (cx, s));
 	  break;
 	}
       case 1: /* float */
diff-tree c13484c2bf562b37799aa5cce70beb04fe430cd6 (from fc811de19b9f90a01513466483a782c28fa8bbe1)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 13:43:19 2007 +0200

    fix valgrind reported memleaks

diff --git a/libswfdec/swfdec_codec_screen.c b/libswfdec/swfdec_codec_screen.c
index b0d757e..2cb6312 100644
--- a/libswfdec/swfdec_codec_screen.c
+++ b/libswfdec/swfdec_codec_screen.c
@@ -106,6 +106,7 @@ swfdec_video_decoder_screen_decode (Swfd
 	  out[x * 4 - y * stride + SWFDEC_COLOR_INDEX_ALPHA] = 0xFF;
 	}
       }
+      swfdec_buffer_unref (buf);
     }
   }
   *width = screen->width;
diff-tree fc811de19b9f90a01513466483a782c28fa8bbe1 (from 614cf854109af1972529510d686fa67945f06ff0)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 13:06:46 2007 +0200

    fix valgrind reported memleaks

diff --git a/libswfdec/swfdec_player_as.c b/libswfdec/swfdec_player_as.c
index 125b9e8..1b8503a 100644
--- a/libswfdec/swfdec_player_as.c
+++ b/libswfdec/swfdec_player_as.c
@@ -161,13 +161,13 @@ ASSetNative (SwfdecAsContext *cx, Swfdec
     function = swfdec_get_asnative (cx, x, y);
     if (function == NULL) {
       SWFDEC_FIXME ("no ASnative function for %u, %u, what now?", x, y);
-      return;
+      break;
     }
     SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (function));
     swfdec_as_object_set_variable (target, swfdec_as_context_get_string (cx, s), &val);
     y++;
   }
-  g_free (names);
+  g_strfreev (names);
 }
 
 SWFDEC_AS_NATIVE (4, 1, ASSetNativeAccessor)
@@ -202,12 +202,12 @@ ASSetNativeAccessor (SwfdecAsContext *cx
     set = swfdec_get_asnative (cx, x, y++);
     if (get == NULL) {
       SWFDEC_ERROR ("no getter for %s", s);
-      return;
+      break;
     }
     swfdec_as_object_add_variable (target, swfdec_as_context_get_string (cx, s),
 	get, set);
   }
-  g_free (names);
+  g_strfreev (names);
 }
 
 static void
diff-tree 614cf854109af1972529510d686fa67945f06ff0 (from a4b5d04765d9c1f62c525a0d14097c3cc65aed23)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 13:06:39 2007 +0200

    fix valgrind reported memleaks

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 9e69d46..23e4116 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -1465,7 +1465,7 @@ static void
 swfdec_action_define_function (SwfdecAsContext *cx, guint action,
     const guint8 *data, guint len)
 {
-  const char *function_name;
+  char *function_name;
   const char *name = NULL;
   guint i, n_args, size, n_registers;
   SwfdecBuffer *buffer;
@@ -1533,6 +1533,7 @@ swfdec_action_define_function (SwfdecAsC
   if (frame->script->buffer->data + frame->script->buffer->length < frame->pc + 3 + len + size) {
     SWFDEC_ERROR ("size of function is too big");
     g_free (args);
+    g_free (function_name);
     return;
   }
   /* create the script */
@@ -1554,9 +1555,11 @@ swfdec_action_define_function (SwfdecAsC
   if (name == NULL)
     name = "unnamed_function";
   script = swfdec_script_new (&bits, name, cx->version);
+  swfdec_buffer_unref (buffer);
   if (script == NULL) {
     SWFDEC_ERROR ("failed to create script");
     g_free (args);
+    g_free (function_name);
     return;
   }
   if (frame->constant_pool_buffer)
@@ -1574,13 +1577,14 @@ swfdec_action_define_function (SwfdecAsC
   } else {
     SwfdecAsValue funval;
     /* FIXME: really varobj? Not eval or sth like that? */
-    function_name = swfdec_as_context_get_string (cx, function_name);
+    name = swfdec_as_context_get_string (cx, function_name);
     SWFDEC_AS_VALUE_SET_OBJECT (&funval, SWFDEC_AS_OBJECT (fun));
-    swfdec_as_object_set_variable (frame->target, function_name, &funval);
+    swfdec_as_object_set_variable (frame->target, name, &funval);
   }
 
   /* update current context */
   frame->pc += 3 + len + size;
+  g_free (function_name);
 }
 
 static void
diff-tree a4b5d04765d9c1f62c525a0d14097c3cc65aed23 (from parents)
Merge: d2af9b321edb904a42f483ff806ac6dfbdce9b59 58a57fd8b8361870a39382099717b3fe2fdf38e7
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 12:35:01 2007 +0200

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec/swfdec

diff-tree d2af9b321edb904a42f483ff806ac6dfbdce9b59 (from 409340bd1cd81d54715abb7d816f9f2e076432e9)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 12:34:43 2007 +0200

    rework delete so it can return TRUE, FALSE, AND MAYBE

diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index 4608b0a..d47f589 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -503,20 +503,21 @@ swfdec_as_frame_find_variable (SwfdecAsF
   return NULL;
 }
 
-/* FIXME: merge with find_variable somehow */
-gboolean
+SwfdecAsDeleteReturn
 swfdec_as_frame_delete_variable (SwfdecAsFrame *frame, const char *variable)
 {
   SwfdecAsScope *cur;
   guint i;
+  SwfdecAsDeleteReturn ret;
 
   g_return_val_if_fail (SWFDEC_IS_AS_FRAME (frame), FALSE);
   g_return_val_if_fail (variable != NULL, FALSE);
 
   cur = frame->scope;
   for (i = 0; i < 256; i++) {
-    if (swfdec_as_object_delete_variable (SWFDEC_AS_OBJECT (cur), variable))
-      return TRUE;
+    ret = swfdec_as_object_delete_variable (SWFDEC_AS_OBJECT (cur), variable);
+    if (ret)
+      return ret;
     if (cur->next == NULL)
       break;
     cur = cur->next;
@@ -528,8 +529,9 @@ swfdec_as_frame_delete_variable (SwfdecA
   g_assert (SWFDEC_IS_AS_FRAME (cur));
   /* we've walked the scope chain down. Now look in the special objects. */
   /* 1) the target set via SetTarget */
-  if (swfdec_as_object_delete_variable (frame->target, variable))
-    return TRUE;
+  ret = swfdec_as_object_delete_variable (frame->target, variable);
+  if (ret)
+    return ret;
   /* 2) the global object */
   return swfdec_as_object_delete_variable (SWFDEC_AS_OBJECT (frame)->context->global, variable);
 }
diff --git a/libswfdec/swfdec_as_frame_internal.h b/libswfdec/swfdec_as_frame_internal.h
index f6d7644..ca435c9 100644
--- a/libswfdec/swfdec_as_frame_internal.h
+++ b/libswfdec/swfdec_as_frame_internal.h
@@ -70,7 +70,8 @@ void		swfdec_as_frame_preload		(SwfdecAs
 
 SwfdecAsObject *swfdec_as_frame_find_variable	(SwfdecAsFrame *	frame,
 						 const char *		variable);
-gboolean	swfdec_as_frame_delete_variable	(SwfdecAsFrame *	frame,
+SwfdecAsDeleteReturn
+		swfdec_as_frame_delete_variable	(SwfdecAsFrame *	frame,
 						 const char *		variable);
 
 void		swfdec_as_frame_set_target	(SwfdecAsFrame *	frame,
diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 72cf447..9e69d46 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -1713,8 +1713,10 @@ swfdec_action_delete (SwfdecAsContext *c
   
   name = swfdec_as_value_to_string (cx, swfdec_as_stack_peek (cx, 1));
   val = swfdec_as_stack_peek (cx, 2);
-  if (SWFDEC_AS_VALUE_IS_OBJECT (val))
-    success = swfdec_as_object_delete_variable (SWFDEC_AS_VALUE_GET_OBJECT (val), name);
+  if (SWFDEC_AS_VALUE_IS_OBJECT (val)) {
+    success = swfdec_as_object_delete_variable (
+	SWFDEC_AS_VALUE_GET_OBJECT (val), name) == SWFDEC_AS_DELETE_DELETED;
+  }
   SWFDEC_AS_VALUE_SET_BOOLEAN (val, success);
   swfdec_as_stack_pop_n (cx, 1);
 }
@@ -1724,10 +1726,12 @@ swfdec_action_delete2 (SwfdecAsContext *
 {
   SwfdecAsValue *val;
   const char *name;
+  gboolean success = FALSE;
   
   val = swfdec_as_stack_peek (cx, 1);
   name = swfdec_as_value_to_string (cx, val);
-  SWFDEC_AS_VALUE_SET_BOOLEAN (val, swfdec_as_frame_delete_variable (cx->frame, name));
+  success = swfdec_as_frame_delete_variable (cx->frame, name) == SWFDEC_AS_DELETE_DELETED;
+  SWFDEC_AS_VALUE_SET_BOOLEAN (val, success);
 }
 
 static void
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 749b0d7..213ddb3 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -73,6 +73,18 @@
  */
 
 /**
+ * SwfdecAsDeleteReturn:
+ * @SWFDEC_AS_DELETE_NOT_FOUND: The variable was not found and therefore 
+ *                              couldn't be deleted.
+ * @SWFDEC_AS_DELETE_DELETED: The variable was deleted.
+ * @SWFDEC_AS_DELETE_NOT_DELETED: The variable was found but could not be 
+ *                                deleted.
+ *
+ * This is the return value used by swfdec_as_object_delete_variable(). It 
+ * describes the various outcomes of trying to delete a variable.
+ */
+
+/**
  * SwfdecAsVariableForeach:
  * @object: The object this function is run on
  * @variable: garbage-collected name of the current variables
@@ -266,22 +278,22 @@ swfdec_as_object_free_property (gpointer
   g_slice_free (SwfdecAsVariable, value);
 }
 
-static gboolean
+static SwfdecAsDeleteReturn
 swfdec_as_object_do_delete (SwfdecAsObject *object, const char *variable)
 {
   SwfdecAsVariable *var;
 
   var = g_hash_table_lookup (object->properties, variable);
   if (var == NULL)
-    return FALSE;
+    return SWFDEC_AS_DELETE_NOT_FOUND;
   if (var->flags & SWFDEC_AS_VARIABLE_PERMANENT)
-    return TRUE;
+    return SWFDEC_AS_DELETE_NOT_DELETED;
 
   swfdec_as_object_free_property (NULL, var, object);
   if (!g_hash_table_remove (object->properties, variable)) {
     g_assert_not_reached ();
   }
-  return TRUE;
+  return SWFDEC_AS_DELETE_DELETED;
 }
 
 typedef struct {
@@ -647,11 +659,9 @@ swfdec_as_object_get_variable_and_flags 
  * Deletes the given variable if possible. If the variable is protected from 
  * deletion, it will not be deleted.
  *
- * Returns: %TRUE if the variable existed. Note that this doesn't mean that the
- *          variable was actually removed. Permanent variables for example 
- *          cannot be removed.
+ * Returns: See #SwfdecAsDeleteReutnr for details of the return value.
  **/
-gboolean
+SwfdecAsDeleteReturn
 swfdec_as_object_delete_variable (SwfdecAsObject *object, const char *variable)
 {
   SwfdecAsObjectClass *klass;
diff --git a/libswfdec/swfdec_as_object.h b/libswfdec/swfdec_as_object.h
index 1109110..e396294 100644
--- a/libswfdec/swfdec_as_object.h
+++ b/libswfdec/swfdec_as_object.h
@@ -34,6 +34,12 @@ typedef enum {
   SWFDEC_AS_VARIABLE_FLASH6_UP = (1 << 7)
 } SwfdecAsVariableFlag;
 
+typedef enum {
+  SWFDEC_AS_DELETE_NOT_FOUND = 0,
+  SWFDEC_AS_DELETE_DELETED,
+  SWFDEC_AS_DELETE_NOT_DELETED
+} SwfdecAsDeleteReturn;
+
 typedef struct _SwfdecAsObjectClass SwfdecAsObjectClass;
 typedef gboolean (* SwfdecAsVariableForeach) (SwfdecAsObject *object, 
     const char *variable, SwfdecAsValue *value, guint flags, gpointer data);
@@ -80,7 +86,7 @@ struct _SwfdecAsObjectClass {
 						 guint			flags,
 						 guint			mask);
   /* delete the variable - return TRUE if it exists */
-  gboolean		(* del)			(SwfdecAsObject *       object,
+  SwfdecAsDeleteReturn	(* del)			(SwfdecAsObject *       object,
 						 const char *		variable);
   /* call with every variable until func returns FALSE */
   gboolean		(* foreach)		(SwfdecAsObject *	object,
@@ -129,7 +135,8 @@ gboolean	swfdec_as_object_get_variable_a
 						 SwfdecAsValue *	value,
 						 guint *		flags,
 						 SwfdecAsObject **	pobject);
-gboolean	swfdec_as_object_delete_variable(SwfdecAsObject *	object,
+SwfdecAsDeleteReturn
+		swfdec_as_object_delete_variable(SwfdecAsObject *	object,
 						 const char *		variable);
 void		swfdec_as_object_set_variable_flags
 						(SwfdecAsObject *       object,
diff --git a/libswfdec/swfdec_as_super.c b/libswfdec/swfdec_as_super.c
index aa75a0b..c66d93b 100644
--- a/libswfdec/swfdec_as_super.c
+++ b/libswfdec/swfdec_as_super.c
@@ -99,11 +99,11 @@ swfdec_as_super_set_flags (SwfdecAsObjec
   /* if we have no variables, we also can't set its flags... */
 }
 
-static gboolean
+static SwfdecAsDeleteReturn
 swfdec_as_super_delete (SwfdecAsObject *object, const char *variable)
 {
   /* if we have no variables... */
-  return FALSE;
+  return SWFDEC_AS_DELETE_NOT_FOUND;
 }
 
 static SwfdecAsObject *
diff --git a/libswfdec/swfdec_as_with.c b/libswfdec/swfdec_as_with.c
index a6b032e..4484079 100644
--- a/libswfdec/swfdec_as_with.c
+++ b/libswfdec/swfdec_as_with.c
@@ -78,7 +78,7 @@ swfdec_as_with_set_flags (SwfdecAsObject
   klass->set_flags (with->object, variable, flags, mask);
 }
 
-static gboolean
+static SwfdecAsDeleteReturn
 swfdec_as_with_delete (SwfdecAsObject *object, const char *variable)
 {
   SwfdecAsWith *with = SWFDEC_AS_WITH (object);
diff-tree 409340bd1cd81d54715abb7d816f9f2e076432e9 (from c7b91a2f93c264e6c06adabe1b4fcd97fb590c50)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Aug 20 11:40:47 2007 +0200

    check {} and [] don't call any constructors

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 800954c..91f6c63 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -230,6 +230,15 @@ EXTRA_DIST = \
 	comparisons-6.swf.trace \
 	comparisons-7.swf \
 	comparisons-7.swf.trace \
+	construct-constructors.as \
+	construct-constructors-5.swf \
+	construct-constructors-5.swf.trace \
+	construct-constructors-6.swf \
+	construct-constructors-6.swf.trace \
+	construct-constructors-7.swf \
+	construct-constructors-7.swf.trace \
+	construct-constructors-8.swf \
+	construct-constructors-8.swf.trace \
 	construct-properties.as \
 	construct-properties-5.swf \
 	construct-properties-5.swf.trace \
diff --git a/test/trace/construct-constructors-5.swf b/test/trace/construct-constructors-5.swf
new file mode 100644
index 0000000..9fb1cd1
Binary files /dev/null and b/test/trace/construct-constructors-5.swf differ
diff --git a/test/trace/construct-constructors-5.swf.trace b/test/trace/construct-constructors-5.swf.trace
new file mode 100644
index 0000000..3bc9e90
--- /dev/null
+++ b/test/trace/construct-constructors-5.swf.trace
@@ -0,0 +1,5 @@
+Check that [] and {} don't call their constructors
+new Array ()
+[]
+new Object ()
+{}
diff --git a/test/trace/construct-constructors-6.swf b/test/trace/construct-constructors-6.swf
new file mode 100644
index 0000000..e868a83
Binary files /dev/null and b/test/trace/construct-constructors-6.swf differ
diff --git a/test/trace/construct-constructors-6.swf.trace b/test/trace/construct-constructors-6.swf.trace
new file mode 100644
index 0000000..6f77d1d
--- /dev/null
+++ b/test/trace/construct-constructors-6.swf.trace
@@ -0,0 +1,7 @@
+Check that [] and {} don't call their constructors
+new Array ()
+  Array
+[]
+new Object ()
+  Object
+{}
diff --git a/test/trace/construct-constructors-7.swf b/test/trace/construct-constructors-7.swf
new file mode 100644
index 0000000..c9102a3
Binary files /dev/null and b/test/trace/construct-constructors-7.swf differ
diff --git a/test/trace/construct-constructors-7.swf.trace b/test/trace/construct-constructors-7.swf.trace
new file mode 100644
index 0000000..6f77d1d
--- /dev/null
+++ b/test/trace/construct-constructors-7.swf.trace
@@ -0,0 +1,7 @@
+Check that [] and {} don't call their constructors
+new Array ()
+  Array
+[]
+new Object ()
+  Object
+{}
diff --git a/test/trace/construct-constructors-8.swf b/test/trace/construct-constructors-8.swf
new file mode 100644
index 0000000..f795c9e
Binary files /dev/null and b/test/trace/construct-constructors-8.swf differ
diff --git a/test/trace/construct-constructors-8.swf.trace b/test/trace/construct-constructors-8.swf.trace
new file mode 100644
index 0000000..6f77d1d
--- /dev/null
+++ b/test/trace/construct-constructors-8.swf.trace
@@ -0,0 +1,7 @@
+Check that [] and {} don't call their constructors
+new Array ()
+  Array
+[]
+new Object ()
+  Object
+{}
diff --git a/test/trace/construct-constructors.as b/test/trace/construct-constructors.as
new file mode 100644
index 0000000..a71b1b9
--- /dev/null
+++ b/test/trace/construct-constructors.as
@@ -0,0 +1,20 @@
+// makeswf -v 7 -s 200x150 -r 1 -o construct-constructors.swf construct-constructors.as
+
+trace ("Check that [] and {} don't call their constructors");
+
+_global.Array = function () {
+  trace ("  Array");
+};
+_global.Object = function () {
+  trace ("  Object");
+};
+trace ("new Array ()");
+x = new Array ();
+trace ("[]");
+x = [];
+trace ("new Object ()");
+x = new Object ();
+trace ("{}");
+x = {};
+
+loadMovie ("FSCommand:quit", "");


More information about the Swfdec mailing list