[Swfdec] 9 commits - configure.ac libswfdec/swfdec_bits.c libswfdec/swfdec_debug.c libswfdec/swfdec_js.c libswfdec/swfdec_script.c libswfdec/swfdec_sound.c

Benjamin Otte company at kemper.freedesktop.org
Tue Mar 20 11:04:18 PDT 2007


 configure.ac              |    4 ++++
 libswfdec/swfdec_bits.c   |   20 ++++++++++++++++++--
 libswfdec/swfdec_debug.c  |   14 +++++++-------
 libswfdec/swfdec_js.c     |   35 -----------------------------------
 libswfdec/swfdec_script.c |   28 ++++++++++++++++++++++++----
 libswfdec/swfdec_sound.c  |    2 +-
 6 files changed, 54 insertions(+), 49 deletions(-)

New commits:
diff-tree b5d3509c3db17551aa138c21ee9c133d9d4b183e (from a215263d77d59089a6caf849e11b95db07d9f366)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 19:04:25 2007 +0100

    set default debug level to ERROR for releases

diff --git a/configure.ac b/configure.ac
index 6ea8b8d..d4a48c1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,11 @@ AS_COMPILER_FLAG(-Wextra -Wno-missing-fi
 dnl if we're in nano >= 1, add -Werror if supported
 if test x$SWFDEC_CVS = xyes ; then
   AS_COMPILER_FLAG(-Werror, GLOBAL_CFLAGS="$GLOBAL_CFLAGS -Werror")
+  DEFAULT_DEBUG_LEVEL="SWFDEC_LEVEL_WARNING"
+else
+  DEFAULT_DEBUG_LEVEL="SWFDEC_LEVEL_ERROR"
 fi
+AC_DEFINE_UNQUOTED(SWFDEC_LEVEL_DEFAULT, $DEFAULT_DEBUG_LEVEL, [Default debug level used])
 
 SWFDEC_LIBVERSION="1:2:0"
 AC_SUBST(SWFDEC_LIBVERSION)
diff --git a/libswfdec/swfdec_debug.c b/libswfdec/swfdec_debug.c
index 4026292..cf95a14 100644
--- a/libswfdec/swfdec_debug.c
+++ b/libswfdec/swfdec_debug.c
@@ -35,7 +35,11 @@ static const char *swfdec_debug_level_na
   "LOG  "
 };
 
-static unsigned int swfdec_debug_level = SWFDEC_LEVEL_WARNING;
+#ifndef SWFDEC_LEVEL_DEFAULT
+#  define SWFDEC_LEVEL_DEFAULT SWFDEC_LEVEL_ERROR
+#endif
+
+static unsigned int swfdec_debug_level = SWFDEC_LEVEL_DEFAULT;
 
 void
 swfdec_debug_log (unsigned int level, const char *file, const char *function,
diff-tree a215263d77d59089a6caf849e11b95db07d9f366 (from c8b42caf93a8452742b0718882322aa91a608e36)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 15:12:51 2007 +0100

    remove SWFDEC_JS env var and related debugging stuff
    
    This was used when Swfdec compiled AS bytecode to Spidermonkey bytecode and
    is useless now.

diff --git a/libswfdec/swfdec_js.c b/libswfdec/swfdec_js.c
index 3e96503..5ec2303 100644
--- a/libswfdec/swfdec_js.c
+++ b/libswfdec/swfdec_js.c
@@ -68,16 +68,6 @@ static JSClass global_class = {
   JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub
 };
 
-static JSTrapStatus G_GNUC_UNUSED
-swfdec_js_debug_one (JSContext *cx, JSScript *script, jsbytecode *pc, 
-    jsval *rval, void *closure)
-{
-  if (g_getenv ("SWFDEC_JS") && g_str_equal (g_getenv ("SWFDEC_JS"), "trace"))
-    js_Disassemble1 (cx, script, pc, pc - script->code,
-	JS_TRUE, stderr);
-  return JSTRAP_CONTINUE;
-}
-
 /**
  * swfdec_js_init_player:
  * @player: a #SwfdecPlayer
@@ -93,10 +83,6 @@ swfdec_js_init_player (SwfdecPlayer *pla
     return;
   }
 
-  /* the new Flash opcodes mess up this, so this will most likely crash */
-  if (g_getenv ("SWFDEC_JS") && g_str_equal (g_getenv ("SWFDEC_JS"), "full"))
-    player->jscx->tracefp = stderr;
-  JS_SetInterrupt (swfdec_js_runtime, swfdec_js_debug_one, NULL);
   JS_SetErrorReporter (player->jscx, swfdec_js_error_report);
   JS_SetContextPrivate(player->jscx, player);
   player->jsobj = JS_NewObject (player->jscx, &global_class, NULL, NULL);
@@ -143,23 +129,6 @@ swfdec_js_finish_player (SwfdecPlayer *p
   }
 }
 
-static void
-swfdec_disassemble (SwfdecPlayer *player, JSScript *script)
-{
-  guint i;
-
-  for (i = 0; i < script->length; i ++) {
-    g_print ("%02X ", script->code[i]);
-    if (i % 16 == 15)
-      g_print ("\n");
-    else if (i % 4 == 3)
-      g_print (" ");
-  }
-  if (i % 16 != 15)
-    g_print ("\n");
-  js_Disassemble (player->jscx, script, JS_TRUE, stdout);
-}
-
 /**
  * swfdec_js_execute_script:
  * @s: a @SwfdecPlayer
@@ -185,10 +154,6 @@ swfdec_js_execute_script (SwfdecPlayer *
   g_return_val_if_fail (SWFDEC_IS_MOVIE (movie), FALSE);
   g_return_val_if_fail (script != NULL, FALSE);
 
-  if (g_getenv ("SWFDEC_JS") && g_str_equal (g_getenv ("SWFDEC_JS"), "disassemble")) {
-    g_print ("executing script %p:%p\n", movie, script);
-    swfdec_disassemble (s, script);
-  }
   if (rval == NULL)
     rval = &returnval;
   if (!(jsobj = swfdec_scriptable_get_object (SWFDEC_SCRIPTABLE (movie))))
diff-tree c8b42caf93a8452742b0718882322aa91a608e36 (from ca2faf15194e5f3003a513950322bad9722d6cae)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 15:10:03 2007 +0100

    remove env var SWFDEC_DEBUG_ABORT - we have a real debuggger now

diff --git a/libswfdec/swfdec_debug.c b/libswfdec/swfdec_debug.c
index 86082ae..4026292 100644
--- a/libswfdec/swfdec_debug.c
+++ b/libswfdec/swfdec_debug.c
@@ -51,12 +51,8 @@ swfdec_debug_log (unsigned int level, co
   s = g_strdup_vprintf (format, varargs);
   va_end (varargs);
 
-  if (g_getenv ("SWFDEC_DEBUG_ABORT"))
-    g_error ("SWFDEC: %s: %s(%d): %s: %s\n",
-	swfdec_debug_level_names[level], file, line, function, s);
-  else
-    g_printerr ("SWFDEC: %s: %s(%d): %s: %s\n",
-	swfdec_debug_level_names[level], file, line, function, s);
+  g_printerr ("SWFDEC: %s: %s(%d): %s: %s\n",
+      swfdec_debug_level_names[level], file, line, function, s);
   g_free (s);
 }
 
diff-tree ca2faf15194e5f3003a513950322bad9722d6cae (from e818e899b7bc6d82ab5927c3a7088853efcff83e)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 15:08:10 2007 +0100

    implement warning about missing properties, but disable by default.

diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 5eda3c1..4853d3c 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -41,6 +41,11 @@
 #include "js/jsfun.h"
 #include "js/jsscope.h"
 
+/* Define this to get SWFDEC_WARN'd about missing properties of objects.
+ * This can be useful to find out about unimplemented native properties,
+ * but usually just causes a lot of spam. */
+//#define SWFDEC_WARN_MISSING_PROPERTIES
+
 /*** CONSTANT POOLS ***/
 
 SwfdecConstantPool *
@@ -655,6 +660,11 @@ swfdec_action_get_variable (JSContext *c
   if (s == NULL)
     return JS_FALSE;
   cx->fp->sp[-1] = swfdec_js_eval (cx, NULL, s);
+#ifdef SWFDEC_WARN_MISSING_PROPERTIES
+  if (cx->fp->sp[-1] == JSVAL_VOID) {
+    SWFDEC_WARNING ("no variable named %s", s);
+  }
+#endif
   return JS_TRUE;
 }
 
@@ -1066,14 +1076,24 @@ static JSBool
 swfdec_action_get_member (JSContext *cx, guint action, const guint8 *data, guint len)
 {
   const char *s;
+  jsval o;
 
   s = swfdec_js_to_string (cx, cx->fp->sp[-1]);
   if (s == NULL)
     return JS_FALSE;
 
-  if (JSVAL_IS_OBJECT (cx->fp->sp[-2]) && !JSVAL_IS_NULL (cx->fp->sp[-2])) {
-    if (!JS_GetProperty (cx, JSVAL_TO_OBJECT (cx->fp->sp[-2]), s, &cx->fp->sp[-2]))
-      return JS_FALSE;
+  o = cx->fp->sp[-2];
+  if (JSVAL_IS_OBJECT (o) && !JSVAL_IS_NULL (o)) {
+    if (!JS_GetProperty (cx, JSVAL_TO_OBJECT (o), s, &cx->fp->sp[-2]))
+      return JS_FALSE;
+#ifdef SWFDEC_WARN_MISSING_PROPERTIES
+    if (cx->fp->sp[-2] == JSVAL_VOID) {
+      const JSClass *clasp = JS_GetClass (JSVAL_TO_OBJECT (o));
+      if (clasp != &js_ObjectClass) {
+	SWFDEC_WARNING ("no variable named %s:%s", clasp->name, s);
+      }
+    }
+#endif
   } else {
     cx->fp->sp[-2] = JSVAL_VOID;
   }
diff-tree e818e899b7bc6d82ab5927c3a7088853efcff83e (from ae406dd44a102d76df043508f8ca3e85daddbf60)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 14:54:25 2007 +0100

    compute the skip offset correctly when upsampling
    
    fixes segfaults with quite some Flash movies.
    And it wasn't ALSA's fault, I should stop blaming anything on ALSA...

diff --git a/libswfdec/swfdec_sound.c b/libswfdec/swfdec_sound.c
index 7f302c1..85e3bb8 100644
--- a/libswfdec/swfdec_sound.c
+++ b/libswfdec/swfdec_sound.c
@@ -518,10 +518,10 @@ swfdec_sound_buffer_render (gint16 *dest
   src += channels * (offset / rate);
   offset %= rate;
   if (offset) {
+    offset = rate - offset;
     /* NB: dest will be pointing to uninitialized memory now */
     dest -= offset * 2;
     n_samples += offset;
-    offset = rate - offset;
   }
   /* this is almost the same as the channels == 1 case, so check for bugfixes in both branches */
   if (channels == 1) {
diff-tree ae406dd44a102d76df043508f8ca3e85daddbf60 (from parents)
Merge: 967ab0d8cf7ed20024ee8ea798343efec1b4fcf4 82bed9c9883df0ea0d012b8c59a8d4986175c671
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 14:02:16 2007 +0100

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

diff-tree 967ab0d8cf7ed20024ee8ea798343efec1b4fcf4 (from ffb08d9848f1c2d7525f7d0c714316e5127ebb48)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Mar 20 14:01:32 2007 +0100

    some improvements to SwfdecBits
    
    - validate strings as utf-8
    - slight speed improvement for SWFDEC_BITS_CHECK_BYTES macro

diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c
index 860d2c4..7327413 100644
--- a/libswfdec/swfdec_bits.c
+++ b/libswfdec/swfdec_bits.c
@@ -96,8 +96,16 @@ swfdec_bits_left (SwfdecBits *b)
   } \
 }G_STMT_END
 #define SWFDEC_BYTES_CHECK(b,n) G_STMT_START { \
+  gulong __bytes; \
   swfdec_bits_syncbits (b); \
-  SWFDEC_BITS_CHECK (b, 8 * n); \
+  __bytes = b->end - b->ptr; \
+  if (!(__bytes > n || \
+        (__bytes == n && b->idx == 0))) { \
+    SWFDEC_ERROR ("reading past end of buffer"); \
+    b->ptr = b->end; \
+    b->idx = 0; \
+    return 0; \
+  } \
 } G_STMT_END
 
 int
@@ -434,8 +442,11 @@ swfdec_bits_skip_string (SwfdecBits *bit
   
   len = end - (const char *) bits->ptr;
   s = (char *) bits->ptr;
-
   bits->ptr += len + 1;
+  if (!g_utf8_validate (s, -1, NULL)) {
+    SWFDEC_ERROR ("parsed string is not valid utf-8");
+    s = NULL;
+  }
 
   return s;
 }
@@ -472,6 +483,11 @@ swfdec_bits_get_string_length (SwfdecBit
 
   ret = g_strndup ((char *) bits->ptr, len);
   bits->ptr += len;
+  if (!g_utf8_validate (ret, -1, NULL)) {
+    SWFDEC_ERROR ("parsed string is not valid utf-8");
+    g_free (ret);
+    ret = NULL;
+  }
   return ret;
 }
 
diff-tree ffb08d9848f1c2d7525f7d0c714316e5127ebb48 (from parents)
Merge: 3ef867a384c6aa1520540d5303ca679f224d18c7 72e2c95e9fbd6cdebc5755652ee3a8bb0b6af6b3
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Mar 19 23:40:24 2007 +0100

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

diff-tree 3ef867a384c6aa1520540d5303ca679f224d18c7 (from 98cefbbedf8f1b5f7c1b9169f546cc92e149c341)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Mar 19 23:39:47 2007 +0100

    in ActionDelete, only remove one item from the stack, not two

diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index c869e7b..5eda3c1 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -1933,7 +1933,7 @@ swfdec_action_delete2 (JSContext *cx, gu
   JSProperty *prop;
   JSAtom *atom;
   
-  cx->fp->sp -= 2;
+  cx->fp->sp -= 1;
   name = swfdec_js_to_string (cx, cx->fp->sp[1]);
   if (name == NULL)
     return JS_FALSE;


More information about the Swfdec mailing list