[Swfdec] 4 commits - libswfdec/swfdec_as_function.c libswfdec/swfdec_as_object.c test/trace

Benjamin Otte company at kemper.freedesktop.org
Fri Sep 14 05:20:27 PDT 2007


 libswfdec/swfdec_as_function.c        |   35 ++++++++++++++++++----------------
 libswfdec/swfdec_as_object.c          |    2 -
 test/trace/Makefile.am                |    9 ++++++++
 test/trace/function-apply-crash-5.swf |binary
 test/trace/function-apply-crash-6.swf |binary
 test/trace/function-apply-crash-7.swf |binary
 test/trace/function-apply-crash-8.swf |binary
 test/trace/function-apply-crash.as    |    7 ++++++
 8 files changed, 36 insertions(+), 17 deletions(-)

New commits:
diff-tree 28bdc729ce326cb4b08540d6e0cae1c67a793ebe (from 65259fb7606118b8357b08abcdee90f4438b48b7)
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Sep 14 12:29:26 2007 +0200

    add test for last commit

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index eb8a89a..10e2210 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -503,6 +503,15 @@ EXTRA_DIST = \
 	function-apply-6.swf.trace \
 	function-apply-7.swf \
 	function-apply-7.swf.trace \
+	function-apply-crash.as \
+	function-apply-crash-5.swf \
+	function-apply-crash-5.swf.trace \
+	function-apply-crash-6.swf \
+	function-apply-crash-6.swf.trace \
+	function-apply-crash-7.swf \
+	function-apply-crash-7.swf.trace \
+	function-apply-crash-8.swf \
+	function-apply-crash-8.swf.trace \
 	function-prototype-chain.swf \
 	function-prototype-chain.swf.trace \
 	function-scope.as \
diff --git a/test/trace/function-apply-crash-5.swf b/test/trace/function-apply-crash-5.swf
new file mode 100644
index 0000000..dabdb1d
Binary files /dev/null and b/test/trace/function-apply-crash-5.swf differ
diff --git a/test/trace/function-apply-crash-5.swf.trace b/test/trace/function-apply-crash-5.swf.trace
new file mode 100644
index 0000000..e69de29
diff --git a/test/trace/function-apply-crash-6.swf b/test/trace/function-apply-crash-6.swf
new file mode 100644
index 0000000..0331122
Binary files /dev/null and b/test/trace/function-apply-crash-6.swf differ
diff --git a/test/trace/function-apply-crash-6.swf.trace b/test/trace/function-apply-crash-6.swf.trace
new file mode 100644
index 0000000..e69de29
diff --git a/test/trace/function-apply-crash-7.swf b/test/trace/function-apply-crash-7.swf
new file mode 100644
index 0000000..ff1a77a
Binary files /dev/null and b/test/trace/function-apply-crash-7.swf differ
diff --git a/test/trace/function-apply-crash-7.swf.trace b/test/trace/function-apply-crash-7.swf.trace
new file mode 100644
index 0000000..e69de29
diff --git a/test/trace/function-apply-crash-8.swf b/test/trace/function-apply-crash-8.swf
new file mode 100644
index 0000000..03b6e56
Binary files /dev/null and b/test/trace/function-apply-crash-8.swf differ
diff --git a/test/trace/function-apply-crash-8.swf.trace b/test/trace/function-apply-crash-8.swf.trace
new file mode 100644
index 0000000..e69de29
diff --git a/test/trace/function-apply-crash.as b/test/trace/function-apply-crash.as
new file mode 100644
index 0000000..b265ca8
--- /dev/null
+++ b/test/trace/function-apply-crash.as
@@ -0,0 +1,7 @@
+// makeswf -v 7 -s 200x150 -r 1 -o function-apply-crash.swf function-apply-crash.as
+
+a = [];
+a[10000] = "moi";
+Object.prototype.isPrototypeOf.apply (this, a);
+
+loadMovie ("FSCommand:quit", "");
diff-tree 65259fb7606118b8357b08abcdee90f4438b48b7 (from ab6ffb4d04434ff98ae0df7cfe1b302479fd74e6)
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Sep 14 12:27:23 2007 +0200

    document that the args need to stay available.

diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c
index 3af3b46..b1fdec2 100644
--- a/libswfdec/swfdec_as_function.c
+++ b/libswfdec/swfdec_as_function.c
@@ -105,7 +105,9 @@ swfdec_as_function_set_constructor (Swfd
  * @function: the #SwfdecAsFunction to call
  * @thisp: this argument to use for the call or %NULL for none
  * @n_args: number of arguments to pass to the function
- * @args: the arguments to pass or %NULL to read the last @n_args stack elements
+ * @args: the arguments to pass or %NULL to read the last @n_args stack elements.
+ *        The memory must be unchanged until the function call has completed.
+ *        This is after the call to swfdec_as_context_run () has finished.
  * @return_value: pointer for return value or %NULL to push the return value to 
  *                the stack
  *
diff-tree ab6ffb4d04434ff98ae0df7cfe1b302479fd74e6 (from b4647a3053056d27c63cee6acdd9140766ced411)
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Sep 14 12:25:42 2007 +0200

    fix Function.apply
    
    It used to free argv before calling swfdec_as_context_run()

diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c
index 6cc40a4..3af3b46 100644
--- a/libswfdec/swfdec_as_function.c
+++ b/libswfdec/swfdec_as_function.c
@@ -172,6 +172,8 @@ void
 swfdec_as_function_apply (SwfdecAsContext *cx, SwfdecAsObject *fun,
     guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
 {
+  SwfdecAsValue *argv_pass = NULL;
+  int length = 0;
   SwfdecAsObject *thisp;
 
   if (argc > 0) {
@@ -182,11 +184,10 @@ swfdec_as_function_apply (SwfdecAsContex
   if (thisp == NULL)
     thisp = swfdec_as_object_new_empty (cx);
 
-  if (argc > 1 && SWFDEC_AS_VALUE_IS_OBJECT (&argv[1]))
-  {
-    int length, i;
+  if (argc > 1 && SWFDEC_AS_VALUE_IS_OBJECT (&argv[1])) {
+    int i;
     SwfdecAsObject *array;
-    SwfdecAsValue val, *argv_pass;
+    SwfdecAsValue val;
 
     array = SWFDEC_AS_VALUE_GET_OBJECT (&argv[1]);
 
@@ -194,6 +195,9 @@ swfdec_as_function_apply (SwfdecAsContex
     length = swfdec_as_value_to_integer (cx, &val);
 
     if (length > 0) {
+      /* FIXME: find a smarter way to do this, like providing argv not as an array */
+      if (!swfdec_as_context_use_mem (cx, sizeof (SwfdecAsValue) * length))
+	return;
       argv_pass = g_malloc (sizeof (SwfdecAsValue) * length);
 
       for (i = 0; i < length; i++) {
@@ -201,21 +205,18 @@ swfdec_as_function_apply (SwfdecAsContex
 	    swfdec_as_double_to_string (cx, i), &argv_pass[i]);
       }
     } else {
-      argv_pass = NULL;
+      length = 0;
     }
-
-    swfdec_as_function_call (SWFDEC_AS_FUNCTION (fun), thisp, length,
-	argv_pass, ret);
-
-    if (argv_pass != NULL)
-      g_free (argv_pass);
-  }
-  else
-  {
-    swfdec_as_function_call (SWFDEC_AS_FUNCTION (fun), thisp, 0, NULL, ret);
   }
 
+  swfdec_as_function_call (SWFDEC_AS_FUNCTION (fun), thisp, length,
+      argv_pass, ret);
   swfdec_as_context_run (cx);
+
+  if (argv_pass) {
+    swfdec_as_context_unuse_mem (cx, sizeof (SwfdecAsValue) * length);
+    g_free (argv_pass);
+  }
 }
 
 void
diff-tree b4647a3053056d27c63cee6acdd9140766ced411 (from 3da08c899f62a2f814dcacabb3214870578ccabc)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Sep 13 22:16:31 2007 +0200

    use g_ascii_strcasecmp here

diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 81631c7..fd67729 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -176,7 +176,7 @@ swfdec_as_object_do_add (SwfdecAsObject 
 static gboolean
 swfdec_as_object_lookup_case_insensitive (gpointer key, gpointer value, gpointer user_data)
 {
-  return strcasecmp (key, user_data) == 0;
+  return g_ascii_strcasecmp (key, user_data) == 0;
 }
 
 static gboolean


More information about the Swfdec mailing list