seed r150 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r150 - trunk/libseed
- Date: Fri, 7 Nov 2008 04:29:43 +0000 (UTC)
Author: racarr
Date: Fri Nov 7 04:29:43 2008
New Revision: 150
URL: http://svn.gnome.org/viewvc/seed?rev=150&view=rev
Log:
Make class and instance init functions work.
Modified:
trunk/libseed/seed-closure.c
trunk/libseed/seed-gtype.c
Modified: trunk/libseed/seed-closure.c
==============================================================================
--- trunk/libseed/seed-closure.c (original)
+++ trunk/libseed/seed-closure.c Fri Nov 7 04:29:43 2008
@@ -332,7 +332,7 @@
num_args = g_callable_info_get_n_args(info);
return_type = g_callable_info_get_return_type(info);
- arg_types = (ffi_type **)g_new0(ffi_type, num_args+1);
+ arg_types = (ffi_type **)g_new0(ffi_type *, num_args+1);
cif = g_new0(ffi_cif, 1);
privates = g_new0(SeedNativeClosure, 1);
Modified: trunk/libseed/seed-gtype.c
==============================================================================
--- trunk/libseed/seed-gtype.c (original)
+++ trunk/libseed/seed-gtype.c Fri Nov 7 04:29:43 2008
@@ -18,9 +18,96 @@
*/
#include "seed-private.h"
+#include <sys/mman.h>
JSClassRef seed_gtype_class;
+static void seed_handle_class_init_closure(ffi_cif * cif,
+ void * result,
+ void ** args,
+ void * userdata)
+{
+ JSObjectRef function = (JSObjectRef) userdata;
+ JSValueRef jsargs[2];
+
+ jsargs[0] = seed_make_struct(*(gpointer*)args[0], 0);
+ jsargs[1] = seed_value_from_int(*(gint*)args[1],0);
+
+ JSObjectCallAsFunction(eng->context,
+ function,
+ 0, 2, jsargs, 0);
+}
+
+static void seed_handle_instance_init_closure(ffi_cif * cif,
+ void * result,
+ void ** args,
+ void * userdata)
+{
+ JSObjectRef function = (JSObjectRef) userdata;
+ JSValueRef jsargs[2];
+
+ jsargs[0] = seed_value_from_object(*(GObject**)args[0], 0);
+ jsargs[1] = seed_make_struct(*(gpointer*)args[1],0);
+
+ JSObjectCallAsFunction(eng->context,
+ function,
+ 0, 2, jsargs, 0);
+}
+
+static ffi_closure * seed_make_class_init_closure(JSObjectRef function)
+{
+ ffi_cif * cif;
+ ffi_closure * closure;
+ ffi_type ** arg_types;;
+ ffi_arg result;
+ ffi_status status;
+
+ JSValueProtect(eng->context, function);
+
+ cif = g_new0(ffi_cif, 1);
+ arg_types = g_new0(ffi_type *, 3);
+
+ arg_types[0] = &ffi_type_pointer;
+ arg_types[1] = &ffi_type_uint;
+ arg_types[2] = 0;
+
+ closure = mmap(0, sizeof(ffi_closure), PROT_READ | PROT_WRITE |
+ PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
+
+ ffi_prep_cif(cif, FFI_DEFAULT_ABI, 2,
+ &ffi_type_void, arg_types);
+ ffi_prep_closure(closure, cif, seed_handle_class_init_closure,
+ function);
+ return closure;
+}
+
+static ffi_closure * seed_make_instance_init_closure(JSObjectRef function)
+{
+ ffi_cif * cif;
+ ffi_closure * closure;
+ ffi_type ** arg_types;;
+ ffi_arg result;
+ ffi_status status;
+
+ JSValueProtect(eng->context, function);
+
+ cif = g_new0(ffi_cif, 1);
+ arg_types = g_new0(ffi_type *, 3);
+
+ arg_types[0] = &ffi_type_pointer;
+ arg_types[1] = &ffi_type_pointer;
+ arg_types[2] = 0;
+
+ closure = mmap(0, sizeof(ffi_closure), PROT_READ | PROT_WRITE |
+ PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
+
+ ffi_prep_cif(cif, FFI_DEFAULT_ABI, 2,
+ &ffi_type_void, arg_types);
+ ffi_prep_closure(closure, cif, seed_handle_instance_init_closure,
+ function);
+ return closure;
+}
+
static JSObjectRef seed_gtype_constructor_invoked(JSContextRef ctx,
JSObjectRef constructor,
size_t argumentCount,
@@ -41,7 +128,8 @@
0,
NULL
};
-
+ ffi_closure * init_closure = 0;
+ ffi_closure * instance_init_closure = 0;
GTypeQuery query;
if (argumentCount != 1)
@@ -73,12 +161,25 @@
"GType constructor expected"
" GObject type for parent");
}
+ if (!JSValueIsNull(eng->context, class_init) &&
+ JSObjectIsFunction(eng->context, (JSObjectRef)class_init))
+ {
+ init_closure = seed_make_class_init_closure((JSObjectRef)class_init);
+ }
+ if (!JSValueIsNull(eng->context, instance_init) &&
+ JSObjectIsFunction(eng->context, (JSObjectRef)instance_init))
+ {
+ instance_init_closure =
+ seed_make_instance_init_closure((JSObjectRef)instance_init);
+ }
parent_type = (GType)JSObjectGetPrivate((JSObjectRef)parent_ref);
g_type_query(parent_type, &query);
type_info.class_size = query.class_size;
type_info.instance_size = query.instance_size;
+ type_info.class_init = (GClassInitFunc)init_closure;
+ type_info.instance_init = (GInstanceInitFunc)instance_init_closure;
new_type = g_type_register_static(parent_type,
new_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]