[gjs/309-fix-stuffed-pointer-marshalling: 1/2] arg: Factor out determination of GITypeInfo storage type



commit 8f8bbee8d000de3bc1ee3fcf19da22f291811f03
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Apr 4 19:46:14 2020 -0700

    arg: Factor out determination of GITypeInfo storage type
    
    This is used in several places and can be a separate function, ideally
    provided by gobject-introspection in the future.
    
    See: #309

 gi/arg.cpp | 41 +++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 24 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index b41cd3ea..04bd3c8c 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -263,6 +263,21 @@ type_needs_out_release(GITypeInfo *type_info,
     return false;
 }
 
+/* FIXME: This should be added to gobject-introspection */
+GJS_USE
+static GITypeTag _g_type_info_get_storage_type(GITypeInfo* info) {
+    GITypeTag type_tag = g_type_info_get_tag(info);
+
+    if (type_tag == GI_TYPE_TAG_INTERFACE) {
+        GjsAutoBaseInfo interface = g_type_info_get_interface(info);
+        GIInfoType info_type = g_base_info_get_type(interface);
+        if (info_type == GI_INFO_TYPE_ENUM || info_type == GI_INFO_TYPE_FLAGS)
+            return g_enum_info_get_storage_type(interface);
+    }
+
+    return type_tag;
+}
+
 GJS_JSAPI_RETURN_CONVENTION
 static bool
 gjs_array_to_g_list(JSContext   *context,
@@ -1101,22 +1116,13 @@ static bool gjs_array_to_array(JSContext* context, JS::HandleValue array_value,
                                size_t length, GITransfer transfer,
                                GITypeInfo* param_info, void** arr_p) {
     enum { UNSIGNED=false, SIGNED=true };
-    GITypeTag element_type;
 
-    element_type = g_type_info_get_tag(param_info);
+    GITypeTag element_type = _g_type_info_get_storage_type(param_info);
 
     /* Special case for GValue "flat arrays" */
     if (is_gvalue_flat_array(param_info, element_type))
         return gjs_array_to_flat_gvalue_array(context, array_value, length, arr_p);
 
-    if (element_type == GI_TYPE_TAG_INTERFACE) {
-        GIBaseInfo *interface_info = g_type_info_get_interface(param_info);
-        GIInfoType info_type = g_base_info_get_type(interface_info);
-        if (info_type == GI_INFO_TYPE_ENUM || info_type == GI_INFO_TYPE_FLAGS)
-            element_type = g_enum_info_get_storage_type ((GIEnumInfo*) interface_info);
-        g_base_info_unref(interface_info);
-    }
-
     switch (element_type) {
     case GI_TYPE_TAG_UTF8:
         return gjs_array_to_strv (context, array_value, length, arr_p);
@@ -1201,21 +1207,8 @@ gjs_g_array_new_for_type(JSContext    *context,
                          unsigned int  length,
                          GITypeInfo   *param_info)
 {
-    GITypeTag element_type;
     guint element_size;
-
-    element_type = g_type_info_get_tag(param_info);
-
-    if (element_type == GI_TYPE_TAG_INTERFACE) {
-        GIInterfaceInfo *interface_info = g_type_info_get_interface(param_info);
-        GIInfoType interface_type = g_base_info_get_type(interface_info);
-
-        if (interface_type == GI_INFO_TYPE_ENUM
-            || interface_type == GI_INFO_TYPE_FLAGS)
-            element_type = g_enum_info_get_storage_type((GIEnumInfo*) interface_info);
-
-        g_base_info_unref((GIBaseInfo*) interface_info);
-    }
+    GITypeTag element_type = _g_type_info_get_storage_type(param_info);
 
     switch (element_type) {
     case GI_TYPE_TAG_BOOLEAN:


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