[Swfdec-commits] 3 commits - swfdec/swfdec_as_array.c test/trace vivified/code

Benjamin Otte company at kemper.freedesktop.org
Tue Sep 2 03:29:30 PDT 2008


 swfdec/swfdec_as_array.c            |   27 +++++++++++++++------------
 test/trace/Makefile.am              |    9 +++++++++
 test/trace/array-splice-5.swf       |binary
 test/trace/array-splice-5.swf.trace |    3 +++
 test/trace/array-splice-6.swf       |binary
 test/trace/array-splice-6.swf.trace |    3 +++
 test/trace/array-splice-7.swf       |binary
 test/trace/array-splice-7.swf.trace |    3 +++
 test/trace/array-splice-8.swf       |binary
 test/trace/array-splice-8.swf.trace |    3 +++
 test/trace/array-splice.as          |   17 +++++++++++++++++
 vivified/code/rewrite.c             |    9 ++++++++-
 12 files changed, 61 insertions(+), 13 deletions(-)

New commits:
commit f9e77cd80829e4f9efb9f428c426887ed0ac5e7e
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Sep 2 12:11:31 2008 +0200

    add test for the recent bug fix

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 304c863..ca4e6ef 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -239,6 +239,15 @@ EXTRA_DIST = \
 	array-sort-unique-abort-7.swf.trace \
 	array-sort-unique-abort-8.swf \
 	array-sort-unique-abort-8.swf.trace \
+	array-splice-5.swf \
+	array-splice-5.swf.trace \
+	array-splice-6.swf \
+	array-splice-6.swf.trace \
+	array-splice-7.swf \
+	array-splice-7.swf.trace \
+	array-splice-8.swf \
+	array-splice-8.swf.trace \
+	array-splice.as \
 	array2.as \
 	array2-5.swf \
 	array2-5.swf.trace \
diff --git a/test/trace/array-splice-5.swf b/test/trace/array-splice-5.swf
new file mode 100644
index 0000000..6396252
Binary files /dev/null and b/test/trace/array-splice-5.swf differ
diff --git a/test/trace/array-splice-5.swf.trace b/test/trace/array-splice-5.swf.trace
new file mode 100644
index 0000000..9df3e92
--- /dev/null
+++ b/test/trace/array-splice-5.swf.trace
@@ -0,0 +1,3 @@
+checking...
+checking...
+0
diff --git a/test/trace/array-splice-6.swf b/test/trace/array-splice-6.swf
new file mode 100644
index 0000000..59e23cc
Binary files /dev/null and b/test/trace/array-splice-6.swf differ
diff --git a/test/trace/array-splice-6.swf.trace b/test/trace/array-splice-6.swf.trace
new file mode 100644
index 0000000..9df3e92
--- /dev/null
+++ b/test/trace/array-splice-6.swf.trace
@@ -0,0 +1,3 @@
+checking...
+checking...
+0
diff --git a/test/trace/array-splice-7.swf b/test/trace/array-splice-7.swf
new file mode 100644
index 0000000..147b8e7
Binary files /dev/null and b/test/trace/array-splice-7.swf differ
diff --git a/test/trace/array-splice-7.swf.trace b/test/trace/array-splice-7.swf.trace
new file mode 100644
index 0000000..9df3e92
--- /dev/null
+++ b/test/trace/array-splice-7.swf.trace
@@ -0,0 +1,3 @@
+checking...
+checking...
+0
diff --git a/test/trace/array-splice-8.swf b/test/trace/array-splice-8.swf
new file mode 100644
index 0000000..9d858dd
Binary files /dev/null and b/test/trace/array-splice-8.swf differ
diff --git a/test/trace/array-splice-8.swf.trace b/test/trace/array-splice-8.swf.trace
new file mode 100644
index 0000000..9df3e92
--- /dev/null
+++ b/test/trace/array-splice-8.swf.trace
@@ -0,0 +1,3 @@
+checking...
+checking...
+0
diff --git a/test/trace/array-splice.as b/test/trace/array-splice.as
new file mode 100644
index 0000000..d1a4f3f
--- /dev/null
+++ b/test/trace/array-splice.as
@@ -0,0 +1,17 @@
+// makeswf -v 7 -s 200x150 -r 1 -o array-splice.swf array-splice.as
+
+function check (a) {
+  trace ("checking...");
+  for (i in a)
+    trace (i);
+};
+
+a = ["x"];
+a.splice (0, 1);
+check (a);
+
+a = [1, 2, 3, 4];
+a.splice (0, 3);
+check (a);
+
+getURL ("fscommand:quit", "");
commit 25b4cd535746060ece623768f01ddd0212ad072f
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Sep 2 12:03:16 2008 +0200

    fix Array.splice leaving properties that should have been spliced
    
    It took me 3 full days to find this. Either I suck, the buggy file did or our
    tools do.

diff --git a/swfdec/swfdec_as_array.c b/swfdec/swfdec_as_array.c
index ce53c72..3b1e9b1 100644
--- a/swfdec/swfdec_as_array.c
+++ b/swfdec/swfdec_as_array.c
@@ -182,12 +182,9 @@ swfdec_as_array_foreach_remove_range (SwfdecAsObject *object,
 }
 
 static void
-swfdec_as_array_remove_range (SwfdecAsArray *array, gint32 start_index,
+swfdec_as_array_remove_range (SwfdecAsObject *object, gint32 start_index,
     gint32 num)
 {
-  SwfdecAsObject *object = SWFDEC_AS_OBJECT (array);
-
-  g_return_if_fail (SWFDEC_IS_AS_ARRAY (array));
   g_return_if_fail (start_index >= 0);
   g_return_if_fail (num >= 0);
 
@@ -534,7 +531,7 @@ swfdec_as_array_set (SwfdecAsObject *object, const char *variable,
     gint32 length_new = swfdec_as_value_to_integer (swfdec_gc_object_get_context (object), val);
     length_new = MAX (0, length_new);
     if (length_old > length_new) {
-      swfdec_as_array_remove_range (SWFDEC_AS_ARRAY (object), length_new,
+      swfdec_as_array_remove_range (object, length_new,
 	  length_old - length_new);
     }
   }
@@ -864,7 +861,7 @@ void
 swfdec_as_array_splice (SwfdecAsContext *cx, SwfdecAsObject *object,
     guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
 {
-  gint32 length, start_index, num_remove, num_add;
+  gint32 length, start_index, num_remove, num_add, at_end;
   SwfdecAsArray *array_new;
 
   if (object == NULL || SWFDEC_IS_MOVIE (object) || argc == 0)
@@ -887,21 +884,27 @@ swfdec_as_array_splice (SwfdecAsContext *cx, SwfdecAsObject *object,
   }
 
   num_add = (argc > 2 ? argc - 2 : 0);
+  at_end = length - num_remove - start_index;
 
+  /* create return value */
   array_new = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx));
-  if (array_new == NULL)
-    return;
-
   swfdec_as_array_append_array_range (array_new, object, start_index,
       num_remove);
+  SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (array_new));
+
+  /* move old data to the right spot */
   swfdec_as_array_move_range (object, start_index + num_remove,
-      length - (start_index + num_remove), start_index + num_add);
+      at_end, start_index + num_add);
+  if (num_remove > at_end) {
+    swfdec_as_array_remove_range (object, start_index + at_end + num_add,
+	length - (start_index + at_end + num_add));
+  }
   if (num_remove > num_add)
     swfdec_as_array_set_length_object (object, length - (num_remove - num_add));
+
+  /* add new data */
   if (argc > 2)
     swfdec_as_array_set_range (object, start_index, argc - 2, argv + 2);
-
-  SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (array_new));
 }
 
 // Sorting
commit 869d50f8e2b89ed758249c05645576b4a762eb99
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Sep 1 23:09:33 2008 +0200

    put numbers in front of all the traces
    
    This makes it easier to distinguish different code paths taken by different
    players

diff --git a/vivified/code/rewrite.c b/vivified/code/rewrite.c
index 24497ac..b2ca8cc 100644
--- a/vivified/code/rewrite.c
+++ b/vivified/code/rewrite.c
@@ -290,14 +290,21 @@ replace_random (ViviCodeAssembler *assembler, guint init)
 static void
 rewrite_getters (ViviCodeAssembler *assembler)
 {
-  guint i;
+  guint i, count;
+  char *s;
 
+  count = 0;
   for (i = 0; i < vivi_code_assembler_get_n_codes (assembler); i++) {
     ViviCodeAsm *code = vivi_code_assembler_get_code (assembler, i);
     if (VIVI_IS_CODE_ASM_GET_VARIABLE (code) ||
 	VIVI_IS_CODE_ASM_GET_MEMBER (code)) {
       i++;
       INSERT_CODE (assembler, i, vivi_code_asm_push_duplicate_new ());
+      s = g_strdup_printf ("%u: ", ++count);
+      INSERT_PUSH_STRING (assembler, i, s);
+      g_free (s);
+      INSERT_CODE (assembler, i, vivi_code_asm_swap_new ());
+      INSERT_CODE (assembler, i, vivi_code_asm_add2_new ());
       INSERT_CODE (assembler, i, vivi_code_asm_trace_new ());
       i--;
     }


More information about the Swfdec-commits mailing list