[Swfdec] Branch 'as' - 9 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame.h libswfdec/swfdec_as_function.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_stack.c libswfdec/swfdec_as_stack.h libswfdec/swfdec_as_types.h libswfdec/swfdec_script.c libswfdec/swfdec_script.h

Benjamin Otte company at kemper.freedesktop.org
Wed Apr 4 07:51:33 PDT 2007


 libswfdec/swfdec_as_context.c   |    5 -
 libswfdec/swfdec_as_frame.c     |    8 ++
 libswfdec/swfdec_as_frame.h     |    1 
 libswfdec/swfdec_as_function.c  |    3 
 libswfdec/swfdec_as_interpret.c |  146 ++++++++++++++++++----------------------
 libswfdec/swfdec_as_stack.c     |    5 +
 libswfdec/swfdec_as_stack.h     |    2 
 libswfdec/swfdec_as_types.h     |   20 +++--
 libswfdec/swfdec_script.c       |   27 -------
 libswfdec/swfdec_script.h       |   59 +++++++---------
 10 files changed, 122 insertions(+), 154 deletions(-)

New commits:
diff-tree d646f6672f12f65ebab2bf3afd607df71af77dd6 (from af512ce92ec1714ef3844dd488d0ce2240e68228)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:51:17 2007 +0200

    implement ActionGetVariable and ActionSetVariable

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 60c4046..aab5f44 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -512,22 +512,18 @@ swfdec_action_push (SwfdecAsContext *cx,
   }
 }
 
-#if 0
 static void
 swfdec_action_get_variable (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
   const char *s;
 
-  s = swfdec_js_to_string (cx, cx->fp->sp[-1]);
-  if (s == NULL)
-    return JS_FALSE;
-  cx->fp->sp[-1] = swfdec_js_eval (cx, NULL, s);
+  s = swfdec_as_value_to_string (cx, swfdec_as_stack_peek (cx->frame->stack, 1));
+  swfdec_as_context_eval (cx, NULL, s, swfdec_as_stack_peek (cx->frame->stack, 1));
 #ifdef SWFDEC_WARN_MISSING_PROPERTIES
-  if (cx->fp->sp[-1] == JSVAL_VOID) {
+  if (SWFDEC_AS_VALUE_IS_UNDEFINED (swfdec_as_stack_peek (cx->frame->stack, 1))) {
     SWFDEC_WARNING ("no variable named %s", s);
   }
 #endif
-  return JS_TRUE;
 }
 
 static void
@@ -535,15 +531,12 @@ swfdec_action_set_variable (SwfdecAsCont
 {
   const char *s;
 
-  s = swfdec_js_to_string (cx, cx->fp->sp[-2]);
-  if (s == NULL)
-    return JS_FALSE;
-
-  swfdec_js_eval_set (cx, NULL, s, cx->fp->sp[-1]);
-  cx->fp->sp -= 2;
-  return JS_TRUE;
+  s = swfdec_as_value_to_string (cx, swfdec_as_stack_peek (cx->frame->stack, 2));
+  swfdec_as_context_eval_set (cx, NULL, s, swfdec_as_stack_pop (cx->frame->stack));
+  swfdec_as_stack_pop (cx->frame->stack);
 }
 
+#if 0
 static void
 swfdec_action_trace (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
@@ -2356,8 +2349,10 @@ const SwfdecActionSpec swfdec_as_actions
   [0x15] = { "StringExtract", NULL },
   [0x17] = { "Pop", NULL, 1, 0, { NULL, swfdec_action_pop, swfdec_action_pop, swfdec_action_pop, swfdec_action_pop } },
   [0x18] = { "ToInteger", NULL, 1, 1, { NULL, swfdec_action_to_integer, swfdec_action_to_integer, swfdec_action_to_integer, swfdec_action_to_integer } },
-  [0x1c] = { "GetVariable", NULL, 1, 1, { NULL, swfdec_action_get_variable, swfdec_action_get_variable, swfdec_action_get_variable, swfdec_action_get_variable } },
-  [0x1d] = { "SetVariable", NULL, 2, 0, { NULL, swfdec_action_set_variable, swfdec_action_set_variable, swfdec_action_set_variable, swfdec_action_set_variable } },
+#endif
+  [SWFDEC_AS_ACTION_GET_VARIABLE] = { "GetVariable", NULL, 1, 1, { NULL, swfdec_action_get_variable, swfdec_action_get_variable, swfdec_action_get_variable, swfdec_action_get_variable } },
+  [SWFDEC_AS_ACTION_SET_VARIABLE] = { "SetVariable", NULL, 2, 0, { NULL, swfdec_action_set_variable, swfdec_action_set_variable, swfdec_action_set_variable, swfdec_action_set_variable } },
+#if 0
   [0x20] = { "SetTarget2", NULL, 1, 0, { swfdec_action_set_target2, swfdec_action_set_target2, swfdec_action_set_target2, swfdec_action_set_target2, swfdec_action_set_target2 } },
   [0x21] = { "StringAdd", NULL, 2, 1, { NULL, swfdec_action_string_add, swfdec_action_string_add, swfdec_action_string_add, swfdec_action_string_add } },
   [0x22] = { "GetProperty", NULL, 2, 1, { NULL, swfdec_action_get_property, swfdec_action_get_property, swfdec_action_get_property, swfdec_action_get_property } },
diff-tree af512ce92ec1714ef3844dd488d0ce2240e68228 (from 59be1fa4f7c6c7390ef6b6108d722c1f10c8817e)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:50:48 2007 +0200

    make swfdec_as_stack_ensure_size work

diff --git a/libswfdec/swfdec_as_stack.c b/libswfdec/swfdec_as_stack.c
index 86c5356..e6735c9 100644
--- a/libswfdec/swfdec_as_stack.c
+++ b/libswfdec/swfdec_as_stack.c
@@ -73,9 +73,11 @@ swfdec_as_stack_ensure_size (SwfdecAsSta
   guint current;
 
   g_return_if_fail (stack != NULL);
-  g_return_if_fail (n_elements > (guint) (stack->end - stack->base));
+  g_return_if_fail (n_elements <= (guint) (stack->end - stack->base));
 
   current = (guint) (stack->cur - stack->base);
+  if (current >= n_elements)
+    return;
   if (current) {
     n_elements -= current;
     memmove (stack->base + n_elements, stack->base, current * sizeof (SwfdecAsValue));
diff-tree 59be1fa4f7c6c7390ef6b6108d722c1f10c8817e (from 153f7e2d84f0aa9a73ad806f3ba922926db5ed9e)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:50:31 2007 +0200

    evaluate value to set only once in SWFDEC_AS_VALUE_SET_*

diff --git a/libswfdec/swfdec_as_types.h b/libswfdec/swfdec_as_types.h
index 533df03..fe25c3f 100644
--- a/libswfdec/swfdec_as_types.h
+++ b/libswfdec/swfdec_as_types.h
@@ -60,22 +60,25 @@ struct _SwfdecAsValue {
 #define SWFDEC_AS_VALUE_IS_BOOLEAN(val) ((val)->type == SWFDEC_TYPE_AS_BOOLEAN)
 #define SWFDEC_AS_VALUE_GET_BOOLEAN(val) (g_assert ((val)->type == SWFDEC_TYPE_AS_BOOLEAN), (val)->value.boolean)
 #define SWFDEC_AS_VALUE_SET_BOOLEAN(val,b) G_STMT_START { \
-  (val)->type = SWFDEC_TYPE_AS_BOOLEAN; \
-  (val)->value.boolean = b; \
+  SwfdecAsValue *__val = (val); \
+  (__val)->type = SWFDEC_TYPE_AS_BOOLEAN; \
+  (__val)->value.boolean = b; \
 } G_STMT_END
 
 #define SWFDEC_AS_VALUE_IS_NUMBER(val) ((val)->type == SWFDEC_TYPE_AS_NUMBER)
 #define SWFDEC_AS_VALUE_GET_NUMBER(val) (g_assert ((val)->type == SWFDEC_TYPE_AS_NUMBER), (val)->value.number)
 #define SWFDEC_AS_VALUE_SET_NUMBER(val,d) G_STMT_START { \
-  (val)->type = SWFDEC_TYPE_AS_NUMBER; \
-  (val)->value.number = d; \
+  SwfdecAsValue *__val = (val); \
+  (__val)->type = SWFDEC_TYPE_AS_NUMBER; \
+  (__val)->value.number = d; \
 } G_STMT_END
 
 #define SWFDEC_AS_VALUE_IS_STRING(val) ((val)->type == SWFDEC_TYPE_AS_STRING)
 #define SWFDEC_AS_VALUE_GET_STRING(val) (g_assert ((val)->type == SWFDEC_TYPE_AS_STRING), (val)->value.string)
 #define SWFDEC_AS_VALUE_SET_STRING(val,s) G_STMT_START { \
-  (val)->type = SWFDEC_TYPE_AS_STRING; \
-  (val)->value.string = s; \
+  SwfdecAsValue *__val = (val); \
+  (__val)->type = SWFDEC_TYPE_AS_STRING; \
+  (__val)->value.string = s; \
 } G_STMT_END
 
 #define SWFDEC_AS_VALUE_IS_NULL(val) ((val)->type == SWFDEC_TYPE_AS_NULL)
@@ -84,8 +87,9 @@ struct _SwfdecAsValue {
 #define SWFDEC_AS_VALUE_IS_OBJECT(val) ((val)->type == SWFDEC_TYPE_AS_ASOBJECT)
 #define SWFDEC_AS_VALUE_GET_OBJECT(val) (g_assert ((val)->type == SWFDEC_TYPE_AS_ASOBJECT), (val)->value.object)
 #define SWFDEC_AS_VALUE_SET_OBJECT(val,o) G_STMT_START { \
-  (val)->type = SWFDEC_TYPE_AS_ASOBJECT; \
-  (val)->value.object = o; \
+  SwfdecAsValue *__val = (val); \
+  (__val)->type = SWFDEC_TYPE_AS_ASOBJECT; \
+  (__val)->value.object = o; \
 } G_STMT_END
 
 
diff-tree 153f7e2d84f0aa9a73ad806f3ba922926db5ed9e (from 0bcc77dc0490f598b6cb499df78cd4bbbf403b69)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:24:15 2007 +0200

    implement Push and ConstantPool actions

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 6570e65..60c4046 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -24,6 +24,7 @@
 #include "swfdec_as_interpret.h"
 #include "swfdec_as_context.h"
 #include "swfdec_as_frame.h"
+#include "swfdec_as_stack.h"
 #include "swfdec_debug.h"
 
 #include <errno.h>
@@ -44,7 +45,7 @@
 /*** SUPPORT FUNCTIONS ***/
 
 #define swfdec_action_has_register(cx, i) \
-  ((i) < ((SwfdecScript *) (cx)->fp->swf)->n_registers)
+  ((i) < (cx)->frame->n_registers)
 
 static SwfdecMovie *
 swfdec_action_get_target (SwfdecAsContext *context)
@@ -60,16 +61,6 @@ swfdec_action_get_target (SwfdecAsContex
 
 #if 0
 static void
-swfdec_action_push_string (SwfdecAsContext *cx, const char *s)
-{
-  JSString *string = JS_NewStringCopyZ (cx, s);
-  if (string == NULL)
-    return JS_FALSE;
-  *cx->fp->sp++ = STRING_TO_JSVAL (string);
-  return JS_TRUE;
-}
-
-static void
 swfdec_value_to_boolean_5 (SwfdecAsContext *cx, jsval val)
 {
   if (JSVAL_IS_BOOLEAN (val)) {
@@ -407,123 +398,121 @@ swfdec_action_wait_for_frame (SwfdecAsCo
     swfdec_script_skip_actions (cx, jump);
 }
 
-#if 0
 static void
 swfdec_action_constant_pool (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
   SwfdecConstantPool *pool;
+  SwfdecAsFrame *frame;
 
+  frame = cx->frame;
   pool = swfdec_constant_pool_new_from_action (data, len);
   if (pool == NULL)
-    return JS_FALSE;
-  if (cx->fp->constant_pool)
-    swfdec_constant_pool_free (cx->fp->constant_pool);
-  cx->fp->constant_pool = pool;
-  return JS_TRUE;
+    return;
+  swfdec_constant_pool_attach_to_context (pool, cx);
+  if (frame->constant_pool)
+    swfdec_constant_pool_free (frame->constant_pool);
+  frame->constant_pool = pool;
+  if (frame->constant_pool_buffer)
+    swfdec_buffer_unref (frame->constant_pool_buffer);
+  frame->constant_pool_buffer = swfdec_buffer_new_subbuffer (frame->script->buffer,
+      data - frame->script->buffer->data, len);
 }
 
 static void
 swfdec_action_push (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  /* FIXME: supply API for this */
+  SwfdecAsStack *stack = cx->frame->stack;
   SwfdecBits bits;
-  guint stackspace = cx->fp->spend - cx->fp->sp;
 
   swfdec_bits_init_data (&bits, data, len);
-  while (swfdec_bits_left (&bits) && stackspace-- > 0) {
+  while (swfdec_bits_left (&bits)) {
     guint type = swfdec_bits_get_u8 (&bits);
     SWFDEC_LOG ("push type %u", type);
+    swfdec_as_stack_ensure_left (stack, 1);
     switch (type) {
       case 0: /* string */
 	{
 	  const char *s = swfdec_bits_skip_string (&bits);
-	  if (!swfdec_action_push_string (cx, s))
-	    return JS_FALSE;
+	  if (s == NULL)
+	    return;
+	  SWFDEC_AS_VALUE_SET_STRING (swfdec_as_stack_push (stack), 
+	      swfdec_as_context_get_string (cx, s));
 	  break;
 	}
       case 1: /* float */
-	{
-	  double d = swfdec_bits_get_float (&bits);
-	  if (!JS_NewDoubleValue (cx, d, cx->fp->sp))
-	    return JS_FALSE;
-	  cx->fp->sp++;
-	  break;
-	}
+	SWFDEC_AS_VALUE_SET_NUMBER (swfdec_as_stack_push (stack), 
+	    swfdec_bits_get_float (&bits));
+	break;
       case 2: /* null */
-	*cx->fp->sp++ = JSVAL_NULL;
+	SWFDEC_AS_VALUE_SET_NULL (swfdec_as_stack_push (stack));
 	break;
       case 3: /* undefined */
-	*cx->fp->sp++ = JSVAL_VOID;
+	SWFDEC_AS_VALUE_SET_UNDEFINED (swfdec_as_stack_push (stack));
 	break;
       case 4: /* register */
 	{
 	  guint regnum = swfdec_bits_get_u8 (&bits);
 	  if (!swfdec_action_has_register (cx, regnum)) {
 	    SWFDEC_ERROR ("cannot Push register %u: not enough registers", regnum);
-	    return JS_FALSE;
+	    return;
 	  }
-	  *cx->fp->sp++ = cx->fp->vars[regnum];
+	  *swfdec_as_stack_push (stack) = cx->frame->registers[regnum];
 	  break;
 	}
       case 5: /* boolean */
-	*cx->fp->sp++ = swfdec_bits_get_u8 (&bits) ? JSVAL_TRUE : JSVAL_FALSE;
+	SWFDEC_AS_VALUE_SET_BOOLEAN (swfdec_as_stack_push (stack), 
+	    swfdec_bits_get_u8 (&bits) ? TRUE : FALSE);
 	break;
       case 6: /* double */
-	{
-	  double d = swfdec_bits_get_double (&bits);
-	  if (!JS_NewDoubleValue (cx, d, cx->fp->sp))
-	    return JS_FALSE;
-	  cx->fp->sp++;
-	  break;
-	}
+	SWFDEC_AS_VALUE_SET_NUMBER (swfdec_as_stack_push (stack), 
+	    swfdec_bits_get_double (&bits));
+	break;
       case 7: /* 32bit int */
-	{
-	  int i = swfdec_bits_get_u32 (&bits);
-	  *cx->fp->sp++ = INT_TO_JSVAL (i);
-	  break;
-	}
+	SWFDEC_AS_VALUE_SET_NUMBER (swfdec_as_stack_push (stack), 
+	    swfdec_bits_get_u32 (&bits));
+	break;
       case 8: /* 8bit ConstantPool address */
 	{
 	  guint i = swfdec_bits_get_u8 (&bits);
-	  SwfdecConstantPool *pool = cx->fp->constant_pool;
+	  SwfdecConstantPool *pool = cx->frame->constant_pool;
 	  if (pool == NULL) {
 	    SWFDEC_ERROR ("no constant pool to push from");
-	    return JS_FALSE;
+	    return;
 	  }
 	  if (i >= swfdec_constant_pool_size (pool)) {
 	    SWFDEC_ERROR ("constant pool index %u too high - only %u elements",
 		i, swfdec_constant_pool_size (pool));
-	    return JS_FALSE;
+	    return;
 	  }
-	  if (!swfdec_action_push_string (cx, swfdec_constant_pool_get (pool, i)))
-	    return JS_FALSE;
+	  SWFDEC_AS_VALUE_SET_STRING (swfdec_as_stack_push (stack), 
+	      swfdec_constant_pool_get (pool, i));
 	  break;
 	}
       case 9: /* 16bit ConstantPool address */
 	{
 	  guint i = swfdec_bits_get_u16 (&bits);
-	  SwfdecConstantPool *pool = cx->fp->constant_pool;
+	  SwfdecConstantPool *pool = cx->frame->constant_pool;
 	  if (pool == NULL) {
 	    SWFDEC_ERROR ("no constant pool to push from");
-	    return JS_FALSE;
+	    return;
 	  }
 	  if (i >= swfdec_constant_pool_size (pool)) {
 	    SWFDEC_ERROR ("constant pool index %u too high - only %u elements",
 		i, swfdec_constant_pool_size (pool));
-	    return JS_FALSE;
+	    return;
 	  }
-	  if (!swfdec_action_push_string (cx, swfdec_constant_pool_get (pool, i)))
-	    return JS_FALSE;
+	  SWFDEC_AS_VALUE_SET_STRING (swfdec_as_stack_push (stack), 
+	      swfdec_constant_pool_get (pool, i));
 	  break;
 	}
       default:
 	SWFDEC_ERROR ("Push: type %u not implemented", type);
-	return JS_FALSE;
+	return;
     }
   }
-  return swfdec_bits_left (&bits) ? JS_FALSE : JS_TRUE;
 }
 
+#if 0
 static void
 swfdec_action_get_variable (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
@@ -2188,6 +2177,7 @@ swfdec_action_print_jump (guint action, 
   }
   return g_strdup_printf ("Jump %d", GINT16_FROM_LE (*((gint16*) data)));
 }
+#endif
 
 static char *
 swfdec_action_print_push (guint action, const guint8 *data, guint len)
@@ -2246,7 +2236,7 @@ swfdec_action_print_push (guint action, 
 	break;
       default:
 	SWFDEC_ERROR ("Push: type %u not implemented", type);
-	return JS_FALSE;
+	return NULL;
     }
   }
   return g_string_free (string, FALSE);
@@ -2262,7 +2252,7 @@ swfdec_action_print_constant_pool (guint
 
   pool = swfdec_constant_pool_new_from_action (data, len);
   if (pool == NULL)
-    return JS_FALSE;
+    return NULL;
   string = g_string_new ("ConstantPool");
   for (i = 0; i < swfdec_constant_pool_size (pool); i++) {
     g_string_append (string, i ? ", " : " ");
@@ -2272,6 +2262,7 @@ swfdec_action_print_constant_pool (guint
   return g_string_free (string, FALSE);
 }
 
+#if 0
 static char *
 swfdec_action_print_wait_for_frame2 (guint action, const guint8 *data, guint len)
 {
@@ -2441,10 +2432,10 @@ const SwfdecActionSpec swfdec_as_actions
   [0x83] = { "GetURL", swfdec_action_print_get_url, 0, 0, { swfdec_action_get_url, swfdec_action_get_url, swfdec_action_get_url, swfdec_action_get_url, swfdec_action_get_url } },
   /* version 5 */
   [0x87] = { "StoreRegister", swfdec_action_print_store_register, 1, 1, { NULL, NULL, swfdec_action_store_register, swfdec_action_store_register, swfdec_action_store_register } },
-  [0x88] = { "ConstantPool", swfdec_action_print_constant_pool, 0, 0, { NULL, NULL, swfdec_action_constant_pool, swfdec_action_constant_pool, swfdec_action_constant_pool } },
-  /* version 3 */
 #endif
-  [0x8a] = { "WaitForFrame", swfdec_action_print_wait_for_frame, 0, 0, { swfdec_action_wait_for_frame, swfdec_action_wait_for_frame, swfdec_action_wait_for_frame, swfdec_action_wait_for_frame, swfdec_action_wait_for_frame } },
+  [SWFDEC_AS_ACTION_CONSTANT_POOL] = { "ConstantPool", swfdec_action_print_constant_pool, 0, 0, { NULL, NULL, swfdec_action_constant_pool, swfdec_action_constant_pool, swfdec_action_constant_pool } },
+  /* version 3 */
+  [SWFDEC_AS_ACTION_WAIT_FOR_FRAME] = { "WaitForFrame", swfdec_action_print_wait_for_frame, 0, 0, { swfdec_action_wait_for_frame, swfdec_action_wait_for_frame, swfdec_action_wait_for_frame, swfdec_action_wait_for_frame, swfdec_action_wait_for_frame } },
 #if 0
   [0x8b] = { "SetTarget", swfdec_action_print_set_target, 0, 0, { swfdec_action_set_target, swfdec_action_set_target, swfdec_action_set_target, swfdec_action_set_target, swfdec_action_set_target } },
 #endif
@@ -2457,8 +2448,10 @@ const SwfdecActionSpec swfdec_as_actions
   [0x8f] = { "Try", NULL },
   /* version 5 */
   [0x94] = { "With", NULL },
+#endif
   /* version 4 */
-  [0x96] = { "Push", swfdec_action_print_push, 0, -1, { NULL, swfdec_action_push, swfdec_action_push, swfdec_action_push, swfdec_action_push } },
+  [SWFDEC_AS_ACTION_PUSH] = { "Push", swfdec_action_print_push, 0, -1, { NULL, swfdec_action_push, swfdec_action_push, swfdec_action_push, swfdec_action_push } },
+#if 0
   [0x99] = { "Jump", swfdec_action_print_jump, 0, 0, { NULL, swfdec_action_jump, swfdec_action_jump, swfdec_action_jump, swfdec_action_jump } },
   [0x9a] = { "GetURL2", swfdec_action_print_get_url2, 2, 0, { NULL, swfdec_action_get_url2, swfdec_action_get_url2, swfdec_action_get_url2, swfdec_action_get_url2 } },
   /* version 5 */
diff-tree 0bcc77dc0490f598b6cb499df78cd4bbbf403b69 (from 3f4a7c0d79bf74c1c615b94bdc8e0b7cc5d0d311)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:23:18 2007 +0200

    keep the buffer of the constant pool around in case DefineFunction wants it

diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index ca2d201..4614f7c 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -36,6 +36,14 @@ swfdec_as_frame_dispose (GObject *object
   g_slice_free1 (sizeof (SwfdecAsValue) * frame->n_registers, frame->registers);
   swfdec_script_unref (frame->script);
   swfdec_as_stack_free (frame->stack);
+  if (frame->constant_pool) {
+    swfdec_constant_pool_free (frame->constant_pool);
+    frame->constant_pool = NULL;
+  }
+  if (frame->constant_pool_buffer) {
+    swfdec_buffer_unref (frame->constant_pool_buffer);
+    frame->constant_pool_buffer = NULL;
+  }
 
   G_OBJECT_CLASS (swfdec_as_frame_parent_class)->dispose (object);
 }
diff --git a/libswfdec/swfdec_as_frame.h b/libswfdec/swfdec_as_frame.h
index fb3abd0..dd627cd 100644
--- a/libswfdec/swfdec_as_frame.h
+++ b/libswfdec/swfdec_as_frame.h
@@ -45,6 +45,7 @@ struct _SwfdecAsFrame {
   SwfdecAsValue *	registers;	/* the registers */
   guint			n_registers;	/* number of allocated registers */
   SwfdecConstantPool *	constant_pool;	/* constant pool currently in use */
+  SwfdecBuffer *	constant_pool_buffer;	/* buffer containing the raw data for constant_pool */
   SwfdecAsStack *	stack;		/* variables on the stack */
   guint8 *		pc;		/* program counter on stack */
 };
diff-tree 3f4a7c0d79bf74c1c615b94bdc8e0b7cc5d0d311 (from 6db01f017b86da2e15945b333bd7c47701cec970)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:22:26 2007 +0200

    change semantics of swfdec_as_stack_push

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 8d31c73..47458b9 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -445,10 +445,9 @@ swfdec_as_context_return (SwfdecAsContex
   context->frame = context->frame->next;
   swfdec_as_stack_ensure_left (context->frame->stack, 1);
   if (retval) {
-    swfdec_as_stack_push (context->frame->stack, retval);
+    *swfdec_as_stack_push (context->frame->stack) = *retval;
   } else {
-    SwfdecAsValue value = { SWFDEC_TYPE_AS_UNDEFINED, };
-    swfdec_as_stack_push (context->frame->stack, &value);
+    SWFDEC_AS_VALUE_SET_UNDEFINED (swfdec_as_stack_push (context->frame->stack));
   }
 }
 
diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c
index 68e98c5..29ef86e 100644
--- a/libswfdec/swfdec_as_function.c
+++ b/libswfdec/swfdec_as_function.c
@@ -126,9 +126,8 @@ swfdec_as_function_call (SwfdecAsFunctio
     if (n_args < function->min_args) {
       SwfdecAsStack *stack = context->frame->stack;
       if (n_args == 0) {
-	SwfdecAsValue value = { SWFDEC_TYPE_AS_UNDEFINED, };
 	swfdec_as_stack_ensure_size (stack, 1);
-	swfdec_as_stack_push (stack, &value);
+	SWFDEC_AS_VALUE_SET_UNDEFINED (swfdec_as_stack_push (stack));
       } else {
 	stack->cur -= (n_args - 1);
 	SWFDEC_AS_VALUE_SET_UNDEFINED (swfdec_as_stack_peek (stack, 1));
diff --git a/libswfdec/swfdec_as_stack.h b/libswfdec/swfdec_as_stack.h
index 97422a0..a5b14a6 100644
--- a/libswfdec/swfdec_as_stack.h
+++ b/libswfdec/swfdec_as_stack.h
@@ -40,7 +40,7 @@ void		swfdec_as_stack_free		(SwfdecAsSta
 
 #define swfdec_as_stack_peek(stack,n) (&(stack)->cur[-(gssize)(n)])
 #define swfdec_as_stack_pop(stack) (--(stack)->cur)
-#define swfdec_as_stack_push(stack,val) (*(stack)->cur++ = *(val))
+#define swfdec_as_stack_push(stack) ((stack)->cur++)
 #define swfdec_as_stack_get_size(stack) ((guint)((stack)->cur - (stack)->base))
 
 void		swfdec_as_stack_mark		(SwfdecAsStack *	stack);
diff-tree 6db01f017b86da2e15945b333bd7c47701cec970 (from 45407c201bf8996a5d81c3364157e1b4e59eef4b)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:21:46 2007 +0200

    fix error case (make sure enough stack is available)

diff --git a/libswfdec/swfdec_as_stack.c b/libswfdec/swfdec_as_stack.c
index 460afc6..86c5356 100644
--- a/libswfdec/swfdec_as_stack.c
+++ b/libswfdec/swfdec_as_stack.c
@@ -93,6 +93,7 @@ swfdec_as_stack_ensure_left (SwfdecAsSta
   if ((guint) (stack->end - stack->cur) < n_elements) {
     /* FIXME FIXME FIXME */
     swfdec_as_context_abort (stack->context, "Out of stack space");
+    stack->cur = stack->end - n_elements;
   }
 }
 
diff-tree 45407c201bf8996a5d81c3364157e1b4e59eef4b (from e9461bd45e46778db9ec649c48550b254afd0bc2)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:21:10 2007 +0200

    export swfdec_constant_pool_attach_to_context

diff --git a/libswfdec/swfdec_script.h b/libswfdec/swfdec_script.h
index 0a3d966..646c5a3 100644
--- a/libswfdec/swfdec_script.h
+++ b/libswfdec/swfdec_script.h
@@ -21,6 +21,7 @@
 #define _SWFDEC_SCRIPT_H_
 
 #include <libswfdec/swfdec.h>
+#include <libswfdec/swfdec_as_types.h>
 #include <libswfdec/swfdec_types.h>
 #include <libswfdec/swfdec_bits.h>
 
@@ -64,39 +65,31 @@ const char *	swfdec_action_get_name		(gu
 guint		swfdec_action_get_from_name	(const char *		name);
 
 SwfdecConstantPool *
-		swfdec_constant_pool_new_from_action (const guint8 *	data,
-						 guint			len);
-void		swfdec_constant_pool_free	(SwfdecConstantPool *	pool);
-guint		swfdec_constant_pool_size	(SwfdecConstantPool *	pool);
-const char *	swfdec_constant_pool_get	(SwfdecConstantPool *	pool,
-						 guint			i);
-SwfdecBuffer *	swfdec_constant_pool_get_area	(SwfdecScript *		script,
-						 SwfdecConstantPool *	pool);
-
-SwfdecScript *	swfdec_script_new		(SwfdecBits *		bits,
-						 const char *		name,
-						 guint			version);
-SwfdecScript *	swfdec_script_new_for_player  	(SwfdecPlayer *		player,
-						 SwfdecBits *		bits,
-						 const char *		name,
-						 guint			version);
-SwfdecScript *	swfdec_script_ref		(SwfdecScript *		script);
-void		swfdec_script_unref		(SwfdecScript *		script);
-
-#if 0
-JSBool		swfdec_script_interpret		(SwfdecScript *		script,
-						 JSContext *		cx,
-						 jsval *		rval);
-#endif
-void		swfdec_script_execute		(SwfdecScript *		script,
-						 SwfdecScriptable *	scriptable);
-
-gboolean	swfdec_script_foreach		(SwfdecScript *		script,
-						 SwfdecScriptForeachFunc func,
-						 gpointer		user_data);
-char *		swfdec_script_print_action	(guint			action,
-						 const guint8 *		data,
-						 guint			len);
+		swfdec_constant_pool_new_from_action	(const guint8 *	data,
+							 guint			len);
+void		swfdec_constant_pool_free	  	(SwfdecConstantPool *	pool);
+guint		swfdec_constant_pool_size		(SwfdecConstantPool *	pool);
+const char *	swfdec_constant_pool_get		(SwfdecConstantPool *	pool,
+							 guint			i);
+void		swfdec_constant_pool_attach_to_context	(SwfdecConstantPool *	pool,
+							 SwfdecAsContext *	context);
+
+SwfdecScript *	swfdec_script_new			(SwfdecBits *		bits,
+							 const char *		name,
+							 guint			version);
+SwfdecScript *	swfdec_script_new_for_player	  	(SwfdecPlayer *		player,
+							 SwfdecBits *		bits,
+							 const char *		name,
+							 guint			version);
+SwfdecScript *	swfdec_script_ref			(SwfdecScript *		script);
+void		swfdec_script_unref			(SwfdecScript *		script);
+
+gboolean	swfdec_script_foreach			(SwfdecScript *		script,
+							 SwfdecScriptForeachFunc func,
+							 gpointer		user_data);
+char *		swfdec_script_print_action		(guint			action,
+							 const guint8 *		data,
+							 guint			len);
 
 G_END_DECLS
 
diff-tree e9461bd45e46778db9ec649c48550b254afd0bc2 (from 121a4494b3f5c785daac627b908593585b591182)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 4 16:20:57 2007 +0200

    remove commented out swfdec_constant_pool_get_area

diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 293a48e..f5fd334 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -111,33 +111,6 @@ swfdec_constant_pool_free (SwfdecConstan
   g_ptr_array_free (pool, TRUE);
 }
 
-#if 0
-/* FIXME: this is a bit hacky */
-static SwfdecBuffer *
-swfdec_constant_pool_get_area (SwfdecScript *script, SwfdecConstantPool *pool)
-{
-  guint8 *start;
-  SwfdecBuffer *buffer;
-  guint len;
-
-  if (pool->len == 0)
-    return NULL;
-  start = (guint8 *) g_ptr_array_index (pool, 0) - 5;
-  buffer = script->buffer;
-  if (start < buffer->data) {
-    /* DefineFunction inside DefineFunction */
-    g_assert (buffer->parent != NULL);
-    buffer = buffer->parent;
-    g_assert (start >= buffer->data);
-  }
-  g_assert (start + 3 < buffer->data + buffer->length);
-  g_assert (*start == 0x88);
-  len = 3 + (start[1] | start[2] << 8);
-  g_assert (start + len < buffer->data + buffer->length);
-  return swfdec_buffer_new_subbuffer (buffer, start - buffer->data, len);
-}
-#endif
-
 /*** SUPPORT FUNCTIONS ***/
 
 static void


More information about the Swfdec mailing list