seed r121 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r121 - trunk/libseed
- Date: Wed, 5 Nov 2008 10:40:09 +0000 (UTC)
Author: racarr
Date: Wed Nov 5 10:40:09 2008
New Revision: 121
URL: http://svn.gnome.org/viewvc/seed?rev=121&view=rev
Log:
Add finalize handler for Seed native closure, and store more data in the
privates (so as to free the cif...).
Modified:
trunk/libseed/seed-builtins.c
trunk/libseed/seed-builtins.h
trunk/libseed/seed-types.c
Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c (original)
+++ trunk/libseed/seed-builtins.c Wed Nov 5 10:40:09 2008
@@ -417,11 +417,17 @@
return rettype;
}
-typedef struct _SeedClosurePrivates
+
+static void seed_closure_finalize(JSObjectRef object)
{
- GICallableInfo * info;
- JSValueRef function;
-} SeedClosurePrivates;
+ SeedClosurePrivates * privates =
+ (SeedClosurePrivates*)JSObjectGetPrivate(object);
+
+ g_free(privates->cif->arg_types);
+ g_free(privates->cif);
+ JSValueUnprotect(eng->context, privates->function);
+ munmap(privates->closure, sizeof(ffi_closure));
+}
static void
seed_handle_closure(ffi_cif *cif,
@@ -577,6 +583,7 @@
privates = g_new0(SeedClosurePrivates, 1);
privates->info = info;
privates->function = arguments[0];
+ privates->cif = cif;
//Leaks the function? Would need a new class for closures and finalize
//handler.
JSValueProtect(eng->context, privates->function);
@@ -592,13 +599,13 @@
closure = mmap(0, sizeof(ffi_closure), PROT_READ | PROT_WRITE |
PROT_EXEC,
MAP_ANON | MAP_PRIVATE, -1, 0);
+ privates->closure = closure;
ffi_prep_cif(cif, FFI_DEFAULT_ABI, 2,
&ffi_type_void, arg_types);
ffi_prep_closure(closure, cif, seed_handle_closure, privates);
-
- return JSObjectMake(eng->context, seed_native_callback_class, closure);
+ return JSObjectMake(eng->context, seed_native_callback_class, privates);
}
JSClassDefinition seed_native_callback_def = {
@@ -609,7 +616,7 @@
NULL, /* Static Values */
NULL, /* Static Functions */
NULL,
- NULL, /* Finalize */
+ seed_closure_finalize, /* Finalize */
NULL, /* Has Property */
NULL, /* Get Property */
NULL, /* Set Property */
@@ -641,7 +648,6 @@
seed_create_function("closure_native", &seed_closure_native, obj);
- seed_native_callback_def.parentClass = seed_struct_class;
seed_native_callback_class = JSClassCreate(&seed_native_callback_def);
JSClassRetain(seed_native_callback_class);
Modified: trunk/libseed/seed-builtins.h
==============================================================================
--- trunk/libseed/seed-builtins.h (original)
+++ trunk/libseed/seed-builtins.h Wed Nov 5 10:40:09 2008
@@ -24,6 +24,17 @@
// TODO: someday, maybe, move import_namespace here!
+typedef struct _SeedClosurePrivates
+{
+ GICallableInfo * info;
+ JSValueRef function;
+
+ ffi_closure * closure;
+ ffi_cif * cif;
+} SeedClosurePrivates;
+
+extern JSClassRef seed_native_callback_class;
+
JSValueRef
seed_include(JSContextRef ctx,
JSObjectRef function,
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Wed Nov 5 10:40:09 2008
@@ -280,9 +280,13 @@
break;
}
}
- else
+ else if (JSValueIsObjectOfClass(eng->context,
+ value, seed_native_callback_class))
{
- arg->v_pointer = seed_struct_get_pointer(value);
+ SeedClosurePrivates * privates =
+ (SeedClosurePrivates*)
+ JSObjectGetPrivate((JSObjectRef)value);
+ arg->v_pointer = privates->closure;
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]