[Swfdec] 2 commits - doc/swfdec-sections.txt libswfdec/swfdec_as_context.c libswfdec/swfdec_as_context.h libswfdec/swfdec_player.c libswfdec/swfdec_player_internal.h

Benjamin Otte company at kemper.freedesktop.org
Mon Oct 22 02:29:40 PDT 2007


 doc/swfdec-sections.txt            |    1 +
 libswfdec/swfdec_as_context.c      |   27 +++++++++++++++++++++++++++
 libswfdec/swfdec_as_context.h      |    1 +
 libswfdec/swfdec_player.c          |   19 ++++++++++++++-----
 libswfdec/swfdec_player_internal.h |    2 +-
 5 files changed, 44 insertions(+), 6 deletions(-)

New commits:
commit b5ec34287eacb0a6feb5fa051bfa5fc905afd709
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 11:29:33 2007 +0200

    don't modify the player if it has aborted already

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 749ee31..c167bcb 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1038,7 +1038,8 @@ swfdec_player_do_handle_key (SwfdecPlayer *player, guint keycode, guint characte
 {
   g_assert (keycode < 256);
 
-  swfdec_player_lock (player);
+  if (!swfdec_player_lock (player))
+    return FALSE;
   /* set the correct variables */
   player->last_keycode = keycode;
   player->last_character = character;
@@ -1058,7 +1059,9 @@ static gboolean
 swfdec_player_do_handle_mouse (SwfdecPlayer *player, 
     double x, double y, int button)
 {
-  swfdec_player_lock (player);
+  if (!swfdec_player_lock (player))
+    return FALSE;
+
   SWFDEC_LOG ("handling mouse at %g %g %d", x, y, button);
   if (player->mouse_x != x || player->mouse_y != y) {
     player->mouse_x = x;
@@ -1159,7 +1162,9 @@ swfdec_player_do_advance (SwfdecPlayer *player, gulong msecs, guint audio_sample
   SwfdecTick target_time;
   guint frames_now;
   
-  swfdec_player_lock (player);
+  if (!swfdec_player_lock (player))
+    return;
+
   target_time = player->time + SWFDEC_MSECS_TO_TICKS (msecs);
   SWFDEC_DEBUG ("advancing %lu msecs (%u audio frames)", msecs, audio_samples);
 
@@ -1223,14 +1228,18 @@ swfdec_player_lock_soft (SwfdecPlayer *player)
   SWFDEC_DEBUG ("LOCKED");
 }
 
-void
+gboolean
 swfdec_player_lock (SwfdecPlayer *player)
 {
-  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), FALSE);
   g_assert (swfdec_ring_buffer_get_n_elements (player->actions) == 0);
 
+  if (swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player)))
+    return FALSE;
+
   g_object_ref (player);
   swfdec_player_lock_soft (player);
+  return TRUE;
 }
 
 /* used for breakpoints */
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index 301587c..3baa77f 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -155,7 +155,7 @@ void		swfdec_player_add_movie		(SwfdecPlayer *		player,
 void		swfdec_player_remove_movie	(SwfdecPlayer *		player,
 						 SwfdecMovie *		movie);
 
-void		swfdec_player_lock		(SwfdecPlayer *		player);
+gboolean	swfdec_player_lock		(SwfdecPlayer *		player);
 void		swfdec_player_lock_soft		(SwfdecPlayer *		player);
 void		swfdec_player_unlock		(SwfdecPlayer *		player);
 void		swfdec_player_unlock_soft	(SwfdecPlayer *		player);
commit 6d52076dc837c3d4007971c44e1c83acc6c606ee
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 11:25:39 2007 +0200

    add an "SwfdecAsContext::aborted" and swfdec_as_context_is_aborted()

diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index e423b7a..2442538 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -300,6 +300,7 @@ SWFDEC_AS_VALUE_IS_OBJECT
 SwfdecAsContext
 swfdec_as_context_startup
 swfdec_as_context_abort
+swfdec_as_context_is_aborted
 swfdec_as_context_get_string
 swfdec_as_context_give_string
 swfdec_as_context_use_mem
diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 07eb2fd..3d3215c 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -170,6 +170,7 @@ swfdec_as_context_abort (SwfdecAsContext *context, const char *reason)
 
   SWFDEC_ERROR ("%s", reason);
   context->state = SWFDEC_AS_CONTEXT_ABORTED;
+  g_object_notify (G_OBJECT (context), "aborted");
 }
 
 /*** MEMORY MANAGEMENT ***/
@@ -431,6 +432,7 @@ enum {
 enum {
   PROP_0,
   PROP_DEBUGGER,
+  PROP_ABORTED,
   PROP_UNTIL_GC
 };
 
@@ -448,6 +450,9 @@ swfdec_as_context_get_property (GObject *object, guint param_id, GValue *value,
     case PROP_DEBUGGER:
       g_value_set_object (value, context->debugger);
       break;
+    case PROP_ABORTED:
+      g_value_set_boolean (value, context->state == SWFDEC_AS_CONTEXT_ABORTED);
+      break;
     case PROP_UNTIL_GC:
       g_value_set_ulong (value, (gulong) context->memory_until_gc);
       break;
@@ -512,6 +517,9 @@ swfdec_as_context_class_init (SwfdecAsContextClass *klass)
   g_object_class_install_property (object_class, PROP_DEBUGGER,
       g_param_spec_object ("debugger", "debugger", "debugger used in this player",
 	  SWFDEC_TYPE_AS_DEBUGGER, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class, PROP_ABORTED,
+      g_param_spec_boolean ("aborted", "aborted", "set when the script engine aborts due to an error",
+	FALSE, G_PARAM_READABLE));
   g_object_class_install_property (object_class, PROP_UNTIL_GC,
       g_param_spec_ulong ("memory-until-gc", "memory until gc", 
 	  "amount of bytes that need to be allocated before garbage collection triggers",
@@ -1370,3 +1378,22 @@ swfdec_as_context_check_continue (SwfdecAsContext *context)
   return TRUE;
 }
 
+/**
+ * swfdec_as_context_is_aborted:
+ * @context: a #SwfdecAsContext
+ *
+ * Determines if the given context is aborted. An aborted context is not able
+ * to execute any scripts. Aborting can happen if the script engine detects bad 
+ * scripts that cause excessive memory usage, infinite loops or other problems.
+ * In that case the script engine aborts for safety reasons.
+ *
+ * Returns: %TRUE if the player is aborted, %FALSE if it runs normally.
+ **/
+gboolean
+swfdec_as_context_is_aborted (SwfdecAsContext *context)
+{
+  g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), TRUE);
+
+  return context->state == SWFDEC_AS_CONTEXT_ABORTED;
+}
+
diff --git a/libswfdec/swfdec_as_context.h b/libswfdec/swfdec_as_context.h
index 73feae4..8540cd8 100644
--- a/libswfdec/swfdec_as_context.h
+++ b/libswfdec/swfdec_as_context.h
@@ -97,6 +97,7 @@ GType		swfdec_as_context_get_type	(void);
 void		swfdec_as_context_startup     	(SwfdecAsContext *	context,
 						 guint			version);
 
+gboolean	swfdec_as_context_is_aborted	(SwfdecAsContext *	context);
 gboolean	swfdec_as_context_is_constructing
 						(SwfdecAsContext *	context);
 SwfdecAsFrame *	swfdec_as_context_get_frame	(SwfdecAsContext *	context);


More information about the Swfdec mailing list