Benjamin Otte
2007-Sep-04 08:43 UTC
[Swfdec] 5 commits - doc/Makefile.am doc/swfdec-sections.txt libswfdec/swfdec_as_array.c libswfdec/swfdec_as_boolean.c libswfdec/swfdec_asbroadcaster.c libswfdec/swfdec_as_internal.h libswfdec/swfdec_as_native_function.c libswfdec/swfdec_as_native_function.h libswfdec/swfdec_as_number.c libswfdec/swfdec_as_object.h libswfdec/swfdec_as_string.c libswfdec/swfdec_filter_as.c libswfdec/swfdec_key_as.c libswfdec/swfdec_load_object_as.c libswfdec/swfdec_loadvars_as.c libswfdec/swfdec_mouse_as.c libswfdec/swfdec_player_as.c libswfdec/swfdec_player_internal.h libswfdec/swfdec_stage_as.c libswfdec/swfdec_system_as.c
doc/Makefile.am | 1 doc/swfdec-sections.txt | 3 libswfdec/swfdec_as_array.c | 1 libswfdec/swfdec_as_boolean.c | 2 libswfdec/swfdec_as_internal.h | 4 libswfdec/swfdec_as_native_function.c | 156 ++++++++++++++++++++++++++++++++++ libswfdec/swfdec_as_native_function.h | 21 ++++ libswfdec/swfdec_as_number.c | 2 libswfdec/swfdec_as_object.h | 3 libswfdec/swfdec_as_string.c | 2 libswfdec/swfdec_asbroadcaster.c | 2 libswfdec/swfdec_filter_as.c | 2 libswfdec/swfdec_key_as.c | 1 libswfdec/swfdec_load_object_as.c | 2 libswfdec/swfdec_loadvars_as.c | 5 - libswfdec/swfdec_mouse_as.c | 1 libswfdec/swfdec_player_as.c | 17 +-- libswfdec/swfdec_player_internal.h | 4 libswfdec/swfdec_stage_as.c | 1 libswfdec/swfdec_system_as.c | 1 20 files changed, 204 insertions(+), 27 deletions(-) New commits: diff-tree 300edae0abd60d832b45a12b4904d0bfc0d4f7e0 (from 57eed866d22b1f7fcd6812b6a8b1dee829bd4ff9) Author: Benjamin Otte <otte at gnome.org> Date: Tue Sep 4 10:43:35 2007 +0200 move SWFDEC_AS_NATIVE and SWFDEC_AS_CNSTRUCTOR macros to swfdec_as_internal.h diff --git a/libswfdec/swfdec_as_array.c b/libswfdec/swfdec_as_array.c index 30cf22a..959d906 100644 --- a/libswfdec/swfdec_as_array.c +++ b/libswfdec/swfdec_as_array.c @@ -33,7 +33,6 @@ #include "swfdec_as_native_function.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" -#include "swfdec_player_internal.h" G_DEFINE_TYPE (SwfdecAsArray, swfdec_as_array, SWFDEC_TYPE_AS_OBJECT) diff --git a/libswfdec/swfdec_as_boolean.c b/libswfdec/swfdec_as_boolean.c index 6764cbe..4645254 100644 --- a/libswfdec/swfdec_as_boolean.c +++ b/libswfdec/swfdec_as_boolean.c @@ -25,10 +25,10 @@ #include "swfdec_as_boolean.h" #include "swfdec_as_context.h" +#include "swfdec_as_internal.h" #include "swfdec_as_native_function.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" -#include "swfdec_player_internal.h" G_DEFINE_TYPE (SwfdecAsBoolean, swfdec_as_boolean, SWFDEC_TYPE_AS_OBJECT) diff --git a/libswfdec/swfdec_as_internal.h b/libswfdec/swfdec_as_internal.h index e64bc44..558696c 100644 --- a/libswfdec/swfdec_as_internal.h +++ b/libswfdec/swfdec_as_internal.h @@ -28,6 +28,10 @@ G_BEGIN_DECLS /* This header contains all the non-exported symbols that can't go into * exported headers */ +#define SWFDEC_AS_NATIVE(x, y, func) SWFDEC_AS_CONSTRUCTOR (x, y, func, NULL) +#define SWFDEC_AS_CONSTRUCTOR(x, y, func, type) void func (SwfdecAsContext *cx, \ + SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret); + /* swfdec_as_array.c */ void swfdec_as_array_init_context (SwfdecAsContext * context, diff --git a/libswfdec/swfdec_as_number.c b/libswfdec/swfdec_as_number.c index f047165..4387301 100644 --- a/libswfdec/swfdec_as_number.c +++ b/libswfdec/swfdec_as_number.c @@ -26,10 +26,10 @@ #include "swfdec_as_number.h" #include "swfdec_as_context.h" #include "swfdec_as_frame.h" +#include "swfdec_as_internal.h" #include "swfdec_as_native_function.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" -#include "swfdec_player_internal.h" G_DEFINE_TYPE (SwfdecAsNumber, swfdec_as_number, SWFDEC_TYPE_AS_OBJECT) diff --git a/libswfdec/swfdec_as_string.c b/libswfdec/swfdec_as_string.c index cce29bf..a59ffe6 100644 --- a/libswfdec/swfdec_as_string.c +++ b/libswfdec/swfdec_as_string.c @@ -27,10 +27,10 @@ #include "swfdec_as_string.h" #include "swfdec_as_array.h" #include "swfdec_as_context.h" +#include "swfdec_as_internal.h" #include "swfdec_as_native_function.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" -#include "swfdec_player_internal.h" G_DEFINE_TYPE (SwfdecAsString, swfdec_as_string, SWFDEC_TYPE_AS_OBJECT) diff --git a/libswfdec/swfdec_asbroadcaster.c b/libswfdec/swfdec_asbroadcaster.c index 396ac81..05897e8 100644 --- a/libswfdec/swfdec_asbroadcaster.c +++ b/libswfdec/swfdec_asbroadcaster.c @@ -21,10 +21,10 @@ #include "config.h" #endif +#include "swfdec_as_internal.h" #include "swfdec_as_object.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" -#include "swfdec_player_internal.h" /*** AS CODE ***/ diff --git a/libswfdec/swfdec_filter_as.c b/libswfdec/swfdec_filter_as.c index 53a0674..0f00211 100644 --- a/libswfdec/swfdec_filter_as.c +++ b/libswfdec/swfdec_filter_as.c @@ -22,8 +22,8 @@ #endif #include "swfdec_filter.h" +#include "swfdec_as_internal.h" #include "swfdec_debug.h" -#include "swfdec_player_internal.h" SWFDEC_AS_NATIVE (1112, 1, swfdec_filter_clone) void diff --git a/libswfdec/swfdec_key_as.c b/libswfdec/swfdec_key_as.c index a5523f7..002ad1f 100644 --- a/libswfdec/swfdec_key_as.c +++ b/libswfdec/swfdec_key_as.c @@ -21,6 +21,7 @@ #include "config.h" #endif +#include "swfdec_as_internal.h" #include "swfdec_as_object.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" diff --git a/libswfdec/swfdec_load_object_as.c b/libswfdec/swfdec_load_object_as.c index 9df8c9f..57d91e8 100644 --- a/libswfdec/swfdec_load_object_as.c +++ b/libswfdec/swfdec_load_object_as.c @@ -23,7 +23,7 @@ #include <string.h> #include "swfdec_load_object.h" -#include "swfdec_as_strings.h" +#include "swfdec_as_internal.h" #include "swfdec_debug.h" #include "swfdec_loader_internal.h" #include "swfdec_loadertarget.h" diff --git a/libswfdec/swfdec_loadvars_as.c b/libswfdec/swfdec_loadvars_as.c index 2e1553a..66e7751 100644 --- a/libswfdec/swfdec_loadvars_as.c +++ b/libswfdec/swfdec_loadvars_as.c @@ -25,11 +25,12 @@ #include <string.h> #include "swfdec_debug.h" -#include "swfdec_as_types.h" +#include "swfdec_as_context.h" +#include "swfdec_as_internal.h" #include "swfdec_as_object.h" #include "swfdec_as_string.h" #include "swfdec_as_strings.h" -#include "swfdec_player_internal.h" +#include "swfdec_as_types.h" /*** AS CODE ***/ diff --git a/libswfdec/swfdec_mouse_as.c b/libswfdec/swfdec_mouse_as.c index 1459f0e..914e009 100644 --- a/libswfdec/swfdec_mouse_as.c +++ b/libswfdec/swfdec_mouse_as.c @@ -21,6 +21,7 @@ #include "config.h" #endif +#include "swfdec_as_internal.h" #include "swfdec_as_object.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h index d28a2f6..281b90f 100644 --- a/libswfdec/swfdec_player_internal.h +++ b/libswfdec/swfdec_player_internal.h @@ -28,10 +28,6 @@ G_BEGIN_DECLS -#define SWFDEC_AS_NATIVE(x, y, func) SWFDEC_AS_CONSTRUCTOR (x, y, func, NULL) -#define SWFDEC_AS_CONSTRUCTOR(x, y, func, type) void func (SwfdecAsContext *cx, \ - SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret); - typedef enum { SWFDEC_ALIGN_FLAG_TOP = (1 << 0), SWFDEC_ALIGN_FLAG_BOTTOM = (1 << 1), diff --git a/libswfdec/swfdec_stage_as.c b/libswfdec/swfdec_stage_as.c index 2f27cbb..15975b7 100644 --- a/libswfdec/swfdec_stage_as.c +++ b/libswfdec/swfdec_stage_as.c @@ -22,6 +22,7 @@ #endif #include <string.h> +#include "swfdec_as_internal.h" #include "swfdec_as_strings.h" #include "swfdec_debug.h" #include "swfdec_player_internal.h" diff --git a/libswfdec/swfdec_system_as.c b/libswfdec/swfdec_system_as.c index 1849a32..79cc427 100644 --- a/libswfdec/swfdec_system_as.c +++ b/libswfdec/swfdec_system_as.c @@ -22,6 +22,7 @@ #endif #include "swfdec.h" +#include "swfdec_as_internal.h" #include "swfdec_as_string.h" #include "swfdec_as_strings.h" #include "swfdec_codec_audio.h" diff-tree 57eed866d22b1f7fcd6812b6a8b1dee829bd4ff9 (from parents) Merge: 4fd150cacc14d6332233e8b2a0ce90fdbf39a0d2 13df1826b6865f15a09f190b759613ba7693a35c Author: Benjamin Otte <otte at gnome.org> Date: Tue Sep 4 10:37:49 2007 +0200 Merge branch 'master' of ssh://company at git.freedesktop.org/git/swfdec/swfdec diff-tree 4fd150cacc14d6332233e8b2a0ce90fdbf39a0d2 (from 7ec278506b08c9941e244eb4a31bae29ada08673) Author: Benjamin Otte <otte at gnome.org> Date: Tue Sep 4 10:33:49 2007 +0200 add SWFDEC_AS_CHECK macro for doing checks/conversions for native functions see the inline API docs for what it does diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt index 6ad2114..d8ef4fa 100644 --- a/doc/swfdec-sections.txt +++ b/doc/swfdec-sections.txt @@ -353,6 +353,9 @@ swfdec_as_function_call swfdec_as_native_function_new swfdec_as_native_function_set_construct_type swfdec_as_native_function_set_object_type +swfdec_as_native_function_check +swfdec_as_native_function_checkv +SWFDEC_AS_CHECK <SUBSECTION Standard> swfdec_as_function_get_type SwfdecAsFunctionClass diff --git a/libswfdec/swfdec_as_native_function.c b/libswfdec/swfdec_as_native_function.c index 4088604..c05faba 100644 --- a/libswfdec/swfdec_as_native_function.c +++ b/libswfdec/swfdec_as_native_function.c @@ -196,3 +196,159 @@ swfdec_as_native_function_set_construct_ function->construct_size = query.instance_size; } +/** + * SWFDEC_AS_CHECK: + * @type: required type of this object or 0 for ignoring + * @result: converted this object + * @...: conversion string and pointers taking converted values + * + * This is a shortcut macro for calling swfdec_as_native_function_check() at + * the beginning of a native function. See that function for details. + * It requires the native function parameters to have the default name. So your + * function must be declared like this: + * |[static void + * my_function (SwfdecAsContext *cx, SwfdecAsObject *object, + * guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval);]| + */ +/** + * swfdec_as_native_function_check: + * @cx: a #SwfdecAsContext + * @object: this object passed to the native function + * @type: expected type of @object or 0 for any + * @result: pointer to variable taking cast result of @object + * @argc: count of arguments passed to the function + * @argv: arguments passed to the function + * @args: argument conversion string + * @...: pointers to variables taking converted arguments + * + * This function is a convenience function to validate and convert arguments to + * a native function while avoiding common pitfalls. You typically want to call + * it at the beginning of every native function you write. Or you can use the + * SWFDEC_AS_CHECK() macro instead which calls this function. + * The @cx, @object, @argc and @argv paramters should be passed verbatim from + * the function call to your native function. If @type is not 0, @object is then + * checked to be of that type and cast to @result. After that the @args string + * is used to convert the arguments. Every character in @args describes the + * conversion of one argument. For that argument, you have to pass a pointer + * that takes the value. For the conversion, the default conversion functions + * like swfdec_as_value_to_string() are used. If not enough arguments are + * available, the function stops converting and returns %NULL. The following + * conversion characters are allowed:<itemizedlist> + * <listitem><para>"b": convert to boolean. Requires a %gboolean pointer + * </para></listitem> + * <listitem><para>"i": convert to integer. Requires an %integer pointer + * </para></listitem> + * <listitem><para>"n": convert to number. Requires a %double pointer + * </para></listitem> + * <listitem><para>"o": convert to object. Requires a #SwfdecAsObject pointer. + * If the conversion fails, this function immediately return % + * FALSE.</para></listitem> + * <listitem><para>"O": convert to object or %NULL. Requires a #SwfdecAsObject + * pointer.</para></listitem> + * <listitem><para>"s": convert to garbage-collected string. Requires a const + * %char pointer</para></listitem> + * <listitem><para>"v": copy the value. The given argument must be a pointer + * to a #SwfdecAsValue</para></listitem> + * </itemizedlist> + * + * Returns: %TRUE if the conversion succeeded, %FALSE otherwise + **/ +gboolean +swfdec_as_native_function_check (SwfdecAsContext *cx, SwfdecAsObject *object, + GType type, gpointer *result, guint argc, SwfdecAsValue *argv, + const char *args, ...) +{ + gboolean ret; + va_list varargs; + + g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (cx), FALSE); + g_return_val_if_fail (type == 0 || result != NULL, FALSE); + + va_start (varargs, args); + ret = swfdec_as_native_function_checkv (cx, object, type, result, argc, argv, args, varargs); + va_end (varargs); + return ret; +} + +/** + * swfdec_as_native_function_checkv: + * @cx: a #SwfdecAsContext + * @object: this object passed to the native function + * @type: expected type of @object + * @result: pointer to variable taking cast result of @object + * @argc: count of arguments passed to the function + * @argv: arguments passed to the function + * @args: argument conversion string + * @varargs: pointers to variables taking converted arguments + * + * This is the valist version of swfdec_as_native_function_check(). See that + * function for details. + * + * Returns: %TRUE if the conversion succeeded, %FALSE otherwise + **/ +gboolean +swfdec_as_native_function_checkv (SwfdecAsContext *cx, SwfdecAsObject *object, + GType type, gpointer *result, guint argc, SwfdecAsValue *argv, + const char *args, va_list varargs) +{ + guint i; + + g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (cx), FALSE); + g_return_val_if_fail (type == 0 || result != NULL, FALSE); + + /* check that we got a valid type */ + if (type) { + if (!G_TYPE_CHECK_INSTANCE_TYPE (object, type)) + return FALSE; + *result = object; + } + for (i = 0; i < argc && *args; i++, args++) { + switch (*args) { + case 'v': + { + SwfdecAsValue *val = va_arg (varargs, SwfdecAsValue *); + *val = argv[i]; + } + break; + case 'b': + { + gboolean *b = va_arg (varargs, gboolean *); + *b = swfdec_as_value_to_boolean (cx, &argv[i]); + } + break; + case 'i': + { + int *j = va_arg (varargs, int *); + *j = swfdec_as_value_to_integer (cx, &argv[i]); + } + break; + case 'n': + { + double *d = va_arg (varargs, double *); + *d = swfdec_as_value_to_number (cx, &argv[i]); + } + break; + case 's': + { + const char **s = va_arg (varargs, const char **); + *s = swfdec_as_value_to_string (cx, &argv[i]); + } + break; + case 'o': + case 'O': + { + SwfdecAsObject **o = va_arg (varargs, SwfdecAsObject **); + *o = swfdec_as_value_to_object (cx, &argv[i]); + if (*o == NULL && *args != 'O') + return FALSE; + } + break; + default: + g_warning ("'%c' is not a valid type conversion", *args); + return FALSE; + } + } + if (*args) + return FALSE; + return TRUE; +} diff --git a/libswfdec/swfdec_as_native_function.h b/libswfdec/swfdec_as_native_function.h index 4a1ab28..5d7923c 100644 --- a/libswfdec/swfdec_as_native_function.h +++ b/libswfdec/swfdec_as_native_function.h @@ -69,6 +69,27 @@ void swfdec_as_native_function_set_cons (SwfdecAsNativeFunction *function, GType type); +gboolean swfdec_as_native_function_check (SwfdecAsContext * cx, + SwfdecAsObject * object, + GType type, + gpointer * result, + guint argc, + SwfdecAsValue * argv, + const char * args, + ...); +gboolean swfdec_as_native_function_checkv(SwfdecAsContext * cx, + SwfdecAsObject * object, + GType type, + gpointer * result, + guint argc, + SwfdecAsValue * argv, + const char * args, + va_list varargs); +#define SWFDEC_AS_CHECK(type,result,...) G_STMT_START {\ + if (!swfdec_as_native_function_check (cx, object, type, result, argc, argv, __VA_ARGS__)) \ + return; \ +}G_STMT_END + G_END_DECLS #endif diff --git a/libswfdec/swfdec_player_as.c b/libswfdec/swfdec_player_as.c index 2fd543a..08ccc26 100644 --- a/libswfdec/swfdec_player_as.c +++ b/libswfdec/swfdec_player_as.c @@ -26,6 +26,7 @@ #include "swfdec_player_internal.h" #include "swfdec_as_function.h" +#include "swfdec_as_internal.h" #include "swfdec_as_native_function.h" #include "swfdec_as_object.h" #include "swfdec_as_strings.h" @@ -118,7 +119,7 @@ swfdec_get_asnative (SwfdecAsContext *cx // same as ASnative, but also sets prototype static void -swfdec_player_ASconstructor (SwfdecAsContext *cx, SwfdecAsObject *obj, +swfdec_player_ASconstructor (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval) { SwfdecAsValue val; @@ -126,8 +127,7 @@ swfdec_player_ASconstructor (SwfdecAsCon SwfdecAsFunction *func; guint x, y; - x = swfdec_as_value_to_integer (cx, &argv[0]); - y = swfdec_as_value_to_integer (cx, &argv[1]); + SWFDEC_AS_CHECK (0, NULL, "ii", &x, &y); func = swfdec_get_asnative (cx, x, y); if (func) { @@ -149,14 +149,13 @@ swfdec_player_ASconstructor (SwfdecAsCon } static void -swfdec_player_ASnative (SwfdecAsContext *cx, SwfdecAsObject *obj, +swfdec_player_ASnative (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval) { SwfdecAsFunction *func; guint x, y; - x = swfdec_as_value_to_integer (cx, &argv[0]); - y = swfdec_as_value_to_integer (cx, &argv[1]); + SWFDEC_AS_CHECK (0, NULL, "ii", &x, &y); func = swfdec_get_asnative (cx, x, y); if (func) { @@ -178,12 +177,8 @@ ASSetNative (SwfdecAsContext *cx, Swfdec char **names; guint i, x, y; - if (argc < 3) - return; + SWFDEC_AS_CHECK (0, NULL, "ois", &target, &x, &s); - target = swfdec_as_value_to_object (cx, &argv[0]); - x = swfdec_as_value_to_integer (cx, &argv[1]); - s = swfdec_as_value_to_string (cx, &argv[2]); if (argc > 3) y = swfdec_as_value_to_integer (cx, &argv[3]); else diff-tree 7ec278506b08c9941e244eb4a31bae29ada08673 (from 7966b86c80ce185cf6c03b9abeb11c32b35d60df) Author: Benjamin Otte <otte at gnome.org> Date: Tue Sep 4 10:31:54 2007 +0200 ignore swfdec_filter.h diff --git a/doc/Makefile.am b/doc/Makefile.am index de001b0..21ffd71 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -90,6 +90,7 @@ IGNORE_HFILES= \ swfdec_edittext_movie.h \ swfdec_enums.h \ swfdec_event.h \ + swfdec_filter.h \ swfdec_flv_decoder.h \ swfdec_font.h \ swfdec_graphic.h \ diff-tree 7966b86c80ce185cf6c03b9abeb11c32b35d60df (from b8da9da8a7a5ebd58cb38cf4c981d809ad6fd5ab) Author: Benjamin Otte <otte at gnome.org> Date: Tue Sep 4 10:31:24 2007 +0200 This function is gone already diff --git a/libswfdec/swfdec_as_object.h b/libswfdec/swfdec_as_object.h index 2de6d04..a61bc4b 100644 --- a/libswfdec/swfdec_as_object.h +++ b/libswfdec/swfdec_as_object.h @@ -177,9 +177,6 @@ void swfdec_as_object_call (SwfdecAsOb void swfdec_as_object_run (SwfdecAsObject * object, SwfdecScript * script); -const char* swfdec_as_object_to_string (SwfdecAsContext * context, - SwfdecAsObject * object); - G_END_DECLS #endif
Reasonably Related Threads
- 3 commits - doc/Makefile.am doc/swfdec-docs.sgml doc/swfdec-sections.txt libswfdec/Makefile.am libswfdec/swfdec_as_array.c libswfdec/swfdec_as_boolean.c libswfdec/swfdec_as_context.c libswfdec/swfdec_as_context.h libswfdec/swfdec_as_frame.c
- 12 commits - AUTHORS doc/Makefile.am doc/swfdec-docs.sgml doc/swfdec-sections.txt libswfdec/Makefile.am libswfdec/swfdec_as_array.c libswfdec/swfdec_as_array.h libswfdec/swfdec_as_context.c libswfdec/swfdec_as_function.c libswfdec/swfdec_as_function.h
- [PATCH] Fix compiler warnings that prevent compilation
- libswfdec/swfdec_as_native_function.h
- Branch 'vivi' - 9 commits - libswfdec/swfdec_as_array.c libswfdec/swfdec_as_function.c libswfdec/swfdec_as_function.h libswfdec/swfdec_as_internal.h libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_native_function.c