[gjs/wip/xulrunner-2-rebase4: 4/8] boxed: Avoid recursion and conversion during construction



commit ce197f7b7971035a6a56fdcbb98dbcc21b40e9de
Author: Colin Walters <walters verbum org>
Date:   Fri Oct 29 11:51:10 2010 -0400

    boxed: Avoid recursion and conversion during construction
    
    boxed_new previously called gjs_invoke_c_function_uncached() on
    the first C constructor it found; this recursed and we would
    wrap the boxed, creating a JSObject etc., only to unwrap it
    and get the native pointer again.
    
    For a reason I'm not going to debug in depth, this started failing
    with xulrunner 2.  Regardless, we should avoid this insanity and
    call the C function more directly with g_function_info_invoke,
    which gives us the raw pointer we wanted anyways.

 gi/boxed.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/gi/boxed.c b/gi/boxed.c
index afc752a..a29867c 100644
--- a/gi/boxed.c
+++ b/gi/boxed.c
@@ -233,24 +233,19 @@ boxed_new(JSContext   *context,
             if ((flags & GI_FUNCTION_IS_CONSTRUCTOR) != 0 &&
                 g_callable_info_get_n_args((GICallableInfo*) func_info) == 0) {
 
-                jsval rval;
-                void *gboxed;
+                GIArgument rval;
+                GError *error = NULL;
 
-                rval = JSVAL_NULL;
-                gjs_invoke_c_function_uncached(context, func_info, obj,
-                                               0, NULL, &rval);
+                if (!g_function_info_invoke(func_info, NULL, 0, NULL, 0, &rval, &error)) {
+                    gjs_throw(context, "Failed to invoke boxed constructor: %s", error->message);
+                    g_clear_error(&error);
+                    g_base_info_unref((GIBaseInfo*) func_info);
+                    return JS_FALSE;
+                }
 
                 g_base_info_unref((GIBaseInfo*) func_info);
 
-                if (JSVAL_IS_NULL(rval))
-                    return JS_FALSE;
-
-                /* We are somewhat wasteful here; invoke_c_function() above
-                 * creates a JSObject wrapper for the boxed that we immediately
-                 * discard.
-                 */
-                gboxed = gjs_c_struct_from_boxed(context, JSVAL_TO_OBJECT(rval));
-                priv->gboxed = g_boxed_copy (gtype, gboxed);
+                priv->gboxed = g_boxed_copy (gtype, rval.v_pointer);
 
                 gjs_debug_lifecycle(GJS_DEBUG_GBOXED,
                                     "JSObject created with boxed instance %p type %s",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]