[Swfdec] 4 commits - libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_interpret.h libswfdec/swfdec_movie.c libswfdec/swfdec_system_as.c libswfdec/swfdec_text_field_movie.c test/trace

Pekka Lampila medar at kemper.freedesktop.org
Wed Oct 17 06:15:48 PDT 2007


 libswfdec/swfdec_as_interpret.c            |    2 -
 libswfdec/swfdec_as_interpret.h            |    6 ++++
 libswfdec/swfdec_movie.c                   |    8 ++++-
 libswfdec/swfdec_system_as.c               |    6 +++-
 libswfdec/swfdec_text_field_movie.c        |   42 ++++++++++++++++++++++++++---
 test/trace/Makefile.am                     |    7 ++++
 test/trace/text-field-variable-6.swf       |binary
 test/trace/text-field-variable-6.swf.trace |    9 ++++++
 test/trace/text-field-variable-7.swf       |binary
 test/trace/text-field-variable-7.swf.trace |    9 ++++++
 test/trace/text-field-variable-8.swf       |binary
 test/trace/text-field-variable-8.swf.trace |    9 ++++++
 test/trace/text-field-variable.as          |   36 ++++++++++++++++++++++++
 13 files changed, 128 insertions(+), 6 deletions(-)

New commits:
commit 89ed587507cc1e0687b4e5aa0e8aa142d498487c
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 17 16:14:00 2007 +0300

    Add a test for TextField's variable property

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index cd5b3ba..85c4eb9 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -1841,6 +1841,13 @@ EXTRA_DIST = \
 	targetpath-6.swf.trace \
 	targetpath-7.swf \
 	targetpath-7.swf.trace \
+	text-field-variable.as \
+	text-field-variable-6.swf \
+	text-field-variable-6.swf.trace \
+	text-field-variable-7.swf \
+	text-field-variable-7.swf.trace \
+	text-field-variable-8.swf \
+	text-field-variable-8.swf.trace \
 	textformat.as \
 	textformat-5.swf \
 	textformat-5.swf.trace \
diff --git a/test/trace/text-field-variable-6.swf b/test/trace/text-field-variable-6.swf
new file mode 100644
index 0000000..277d1b3
Binary files /dev/null and b/test/trace/text-field-variable-6.swf differ
diff --git a/test/trace/text-field-variable-6.swf.trace b/test/trace/text-field-variable-6.swf.trace
new file mode 100644
index 0000000..2e92da2
--- /dev/null
+++ b/test/trace/text-field-variable-6.swf.trace
@@ -0,0 +1,9 @@
+1
+2
+3
+1
+undefined
+3
+3
+undefined
+undefined
diff --git a/test/trace/text-field-variable-7.swf b/test/trace/text-field-variable-7.swf
new file mode 100644
index 0000000..83d2875
Binary files /dev/null and b/test/trace/text-field-variable-7.swf differ
diff --git a/test/trace/text-field-variable-7.swf.trace b/test/trace/text-field-variable-7.swf.trace
new file mode 100644
index 0000000..2e92da2
--- /dev/null
+++ b/test/trace/text-field-variable-7.swf.trace
@@ -0,0 +1,9 @@
+1
+2
+3
+1
+undefined
+3
+3
+undefined
+undefined
diff --git a/test/trace/text-field-variable-8.swf b/test/trace/text-field-variable-8.swf
new file mode 100644
index 0000000..a466b89
Binary files /dev/null and b/test/trace/text-field-variable-8.swf differ
diff --git a/test/trace/text-field-variable-8.swf.trace b/test/trace/text-field-variable-8.swf.trace
new file mode 100644
index 0000000..2e92da2
--- /dev/null
+++ b/test/trace/text-field-variable-8.swf.trace
@@ -0,0 +1,9 @@
+1
+2
+3
+1
+undefined
+3
+3
+undefined
+undefined
diff --git a/test/trace/text-field-variable.as b/test/trace/text-field-variable.as
new file mode 100644
index 0000000..68dee49
--- /dev/null
+++ b/test/trace/text-field-variable.as
@@ -0,0 +1,36 @@
+// makeswf -v 7 -r 1 -o text-field-variable-7.swf text-field-variable.as
+
+this.createTextField ("t", 0, 0, 0, 50, 50);
+
+// movie clip
+this.createEmptyMovieClip ("m", 1);
+m.test = 1;
+t.variable = "m.test";
+trace (t.text);
+m.test = 2;
+trace (t.text);
+t.text = 3;
+trace (m.test);
+
+// object
+o = new Object();
+o.test = 1;
+t.variable = "o.test";
+trace (t.text);
+o.test = 2;
+trace (o.text);
+t.text = 3;
+trace (o.test);
+
+// nothing
+delete n;
+n.test = 1;
+t.variable = "n.test";
+trace (t.text);
+n.test = 2;
+trace (o.text);
+t.text = 3;
+trace (n.test);
+
+loadMovie ("FSCommand:quit", "");
+
commit 8b212c377e8823e46b2ea3d1e11c13a768aec0b9
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 17 16:09:16 2007 +0300

    Fix crash causing errors in TextField's variable stuff, implement proper lookup

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index e11397f..b88f484 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -464,7 +464,7 @@ swfdec_action_get_movie_by_slash_path (SwfdecAsContext *cx, const char *path)
   return o;
 }
 
-static SwfdecAsObject *
+SwfdecAsObject *
 swfdec_action_lookup_object (SwfdecAsContext *cx, SwfdecAsObject *o, const char *path, const char *end)
 {
   gboolean dot_allowed = TRUE;
diff --git a/libswfdec/swfdec_as_interpret.h b/libswfdec/swfdec_as_interpret.h
index 557abf4..44f1425 100644
--- a/libswfdec/swfdec_as_interpret.h
+++ b/libswfdec/swfdec_as_interpret.h
@@ -144,5 +144,11 @@ typedef enum {
   SWFDEC_AS_ACTION_GOTO_FRAME2 = 0x9F
 } SwfdecAsAction;
 
+// FIXME: move
+SwfdecAsObject *	swfdec_action_lookup_object	(SwfdecAsContext *	cx,
+							 SwfdecAsObject *	o,
+							 const char *		path,
+							 const char *		end);
+
 G_END_DECLS
 #endif
diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 937e5a5..65d1116 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -1101,9 +1101,9 @@ swfdec_movie_remove_variable_listener (SwfdecMovie *movie,
   if (iter == NULL)
     return;
 
+  g_free (iter->data);
   movie->variable_listeners =
     g_slist_remove (movie->variable_listeners, iter->data);
-  g_free (iter->data);
 }
 
 static void
diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index 82071ad..4f238b7 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -28,6 +28,7 @@
 #include "swfdec_text_field_movie.h"
 #include "swfdec_as_context.h"
 #include "swfdec_as_strings.h"
+#include "swfdec_as_interpret.h"
 #include "swfdec_text_format.h"
 #include "swfdec_xml.h"
 #include "swfdec_debug.h"
@@ -525,8 +526,6 @@ swfdec_text_field_movie_dispose (GObject *object)
 
   text = SWFDEC_TEXT_FIELD_MOVIE (object);
 
-  swfdec_text_field_movie_set_listen_variable (text, NULL);
-
   swfdec_text_field_movie_free_paragraphs (text);
 
   for (iter = text->formats; iter != NULL; iter = iter->next) {
@@ -618,6 +617,14 @@ swfdec_text_field_movie_init_movie (SwfdecMovie *movie)
 }
 
 static void
+swfdec_text_field_movie_finish_movie (SwfdecMovie *movie)
+{
+  SwfdecTextFieldMovie *text = SWFDEC_TEXT_FIELD_MOVIE (movie);
+
+  swfdec_text_field_movie_set_listen_variable (text, NULL);
+}
+
+static void
 swfdec_text_field_movie_class_init (SwfdecTextFieldMovieClass * g_class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (g_class);
@@ -629,6 +636,7 @@ swfdec_text_field_movie_class_init (SwfdecTextFieldMovieClass * g_class)
   asobject_class->mark = swfdec_text_field_movie_mark;
 
   movie_class->init_movie = swfdec_text_field_movie_init_movie;
+  movie_class->finish_movie = swfdec_text_field_movie_finish_movie;
   movie_class->update_extents = swfdec_text_field_movie_update_extents;
   movie_class->render = swfdec_text_field_movie_render;
 }
@@ -722,14 +730,40 @@ static void
 swfdec_text_field_movie_parse_listen_variable (SwfdecTextFieldMovie *text,
     const char *variable, SwfdecAsObject **object, const char **name)
 {
+  SwfdecAsContext *cx;
+  SwfdecAsObject *parent;
+  const char *p1, *p2;
+
   g_return_if_fail (SWFDEC_IS_TEXT_FIELD_MOVIE (text));
   g_return_if_fail (variable != NULL);
   g_return_if_fail (object != NULL);
   g_return_if_fail (name != NULL);
 
-  // FIXME: proper variable lookup (have fun)
-  *object = SWFDEC_AS_OBJECT (SWFDEC_MOVIE (text)->parent);
-  *name = variable;
+  *object = NULL;
+  *name = NULL;
+
+  if (SWFDEC_MOVIE (text)->parent == NULL)
+    return;
+
+  g_assert (SWFDEC_IS_AS_OBJECT (SWFDEC_MOVIE (text)->parent));
+  cx = SWFDEC_AS_OBJECT (text)->context;
+  parent = SWFDEC_AS_OBJECT (SWFDEC_MOVIE (text)->parent);
+
+  p1 = strrchr (variable, '.');
+  p2 = strrchr (variable, ':');
+  if (p1 == NULL && p2 == NULL) {
+    *object = parent;
+    *name = variable;
+  } else {
+    if (p1 == NULL || (p2 != NULL && p2 > p1))
+      p1 = p2;
+    if (strlen (p1) == 1)
+      return;
+    *object = swfdec_action_lookup_object (cx, parent, variable, p1);
+    if (*object == NULL)
+      return;
+    *name = swfdec_as_context_get_string (cx, p1 + 1);
+  }
 }
 
 void
commit 09c3ecd42ccba7f292c65e0464271a942960a449
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 17 15:25:50 2007 +0300

    Format AR number in system query independent of the locale

diff --git a/libswfdec/swfdec_system_as.c b/libswfdec/swfdec_system_as.c
index a6f594f..4610b96 100644
--- a/libswfdec/swfdec_system_as.c
+++ b/libswfdec/swfdec_system_as.c
@@ -265,7 +265,11 @@ swfdec_system_query (SwfdecAsContext *cx, SwfdecAsObject *object,
     if (queries[i].name == SWFDEC_AS_STR_screenResolutionY) {
       g_string_append_printf (server, "x%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val));
     } else if (queries[i].name == SWFDEC_AS_STR_pixelAspectRatio) {
-      g_string_append_printf (server, "&AR=%.1f", SWFDEC_AS_VALUE_GET_NUMBER (&val));
+      char buffer[10];
+      g_ascii_formatd (buffer, sizeof (buffer), "%.1f",
+	  SWFDEC_AS_VALUE_GET_NUMBER (&val));
+      g_string_append (server, "&AR=");
+      g_string_append (server, buffer);
     } else if (queries[i].name == SWFDEC_AS_STR_manufacturer) {
       char *s = swfdec_as_string_escape (cx, player->system->server_manufacturer);
       g_string_append_printf (server, "&M=%s", s);
commit 9f675e25b7e025468fbc7c173d79cd720a27bf36
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Wed Oct 17 14:53:16 2007 +0300

    Clean up variable listener stuff in Movie's and TextMovie's dispose

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index a5ffa00..937e5a5 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -922,6 +922,7 @@ static void
 swfdec_movie_dispose (GObject *object)
 {
   SwfdecMovie * movie = SWFDEC_MOVIE (object);
+  GSList *iter;
 
   g_assert (movie->list == NULL);
 
@@ -938,6 +939,11 @@ swfdec_movie_dispose (GObject *object)
     g_object_unref (movie->graphic);
     movie->graphic = NULL;
   }
+  for (iter = movie->variable_listeners; iter != NULL; iter = iter->next) {
+    g_free (iter->data);
+  }
+  g_slist_free (movie->variable_listeners);
+  movie->variable_listeners = NULL;
 
   G_OBJECT_CLASS (swfdec_movie_parent_class)->dispose (G_OBJECT (movie));
 }
diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index e9f7800..82071ad 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -525,6 +525,8 @@ swfdec_text_field_movie_dispose (GObject *object)
 
   text = SWFDEC_TEXT_FIELD_MOVIE (object);
 
+  swfdec_text_field_movie_set_listen_variable (text, NULL);
+
   swfdec_text_field_movie_free_paragraphs (text);
 
   for (iter = text->formats; iter != NULL; iter = iter->next) {


More information about the Swfdec mailing list