[gjs: 2/6] function: move completed trampolines out of gjs_invoke_c_function



commit ab016ea56d347e2876f0430885fde45863ded310
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Apr 19 20:29:57 2013 +0200

    function: move completed trampolines out of gjs_invoke_c_function
    
    Just a code cleanup, as that function is already too long to read.
    
    (Philip Chimento: Rebased and fixed coding style)

 gi/function.cpp | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 97573da0..060fa848 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -728,6 +728,19 @@ format_function_name(Function *function,
                            g_base_info_get_name(baseinfo));
 }
 
+static void
+complete_async_calls(void)
+{
+    if (completed_trampolines) {
+        for (GSList *iter = completed_trampolines; iter; iter = iter->next) {
+            auto trampoline = static_cast<GjsCallbackTrampoline *>(iter->data);
+            gjs_callback_trampoline_unref(trampoline);
+        }
+        g_slist_free(completed_trampolines);
+        completed_trampolines = nullptr;
+    }
+}
+
 /*
  * This function can be called in 2 different ways. You can either use
  * it to create javascript objects by providing a @js_rval argument or
@@ -776,20 +789,12 @@ gjs_invoke_c_function(JSContext                             *context,
     GITypeTag return_tag;
     JS::AutoValueVector return_values(context);
     guint8 next_rval = 0; /* index into return_values */
-    GSList *iter;
 
     /* Because we can't free a closure while we're in it, we defer
      * freeing until the next time a C function is invoked.  What
      * we should really do instead is queue it for a GC thread.
      */
-    if (completed_trampolines) {
-        for (iter = completed_trampolines; iter; iter = iter->next) {
-            GjsCallbackTrampoline *trampoline = (GjsCallbackTrampoline *) iter->data;
-            gjs_callback_trampoline_unref(trampoline);
-        }
-        g_slist_free(completed_trampolines);
-        completed_trampolines = NULL;
-    }
+    complete_async_calls();
 
     is_method = g_callable_info_is_method(function->info);
     can_throw_gerror = g_callable_info_can_throw_gerror(function->info);


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