[gjs: 4/7] gjs-private: Work around a gobject-introspection bug



commit 2bc38038e5ec10b69c5ab8a4c70077d3342b8b9d
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 15 00:53:21 2019 +0000

    gjs-private: Work around a gobject-introspection bug
    
    Until very recently, g_struct_info_find_method() had a bug that prevented
    it from finding some methods. It will be a while until we can rely on the
    fixed version to be available, so for now fall back to our own method
    implementation if the call fails.
    
    https://gitlab.gnome.org/GNOME/gjs/issues/99

 libgjs-private/gjs-util.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
---
diff --git a/libgjs-private/gjs-util.c b/libgjs-private/gjs-util.c
index 00e3f6d1..1148cff7 100644
--- a/libgjs-private/gjs-util.c
+++ b/libgjs-private/gjs-util.c
@@ -206,6 +206,24 @@ int gjs_open_bytes(GBytes* bytes, GError** error) {
 #endif
 }
 
+static GIBaseInfo* find_method_fallback(GIStructInfo* class_info,
+                                        const char* method_name) {
+    GIBaseInfo* method;
+    guint n_methods, i;
+
+    n_methods = g_struct_info_get_n_methods(class_info);
+
+    for (i = 0; i < n_methods; i++) {
+        method = g_struct_info_get_method(class_info, i);
+
+        if (strcmp(g_base_info_get_name(method), method_name) == 0)
+            return method;
+        g_base_info_unref(method);
+    }
+
+    return NULL;
+}
+
 static GParamSpec* gjs_gtk_container_class_find_child_property(
     GIObjectInfo* container_info, GObject* container, const char* property) {
     GIBaseInfo* class_info = NULL;
@@ -218,6 +236,13 @@ static GParamSpec* gjs_gtk_container_class_find_child_property(
     find_child_property_fun =
         g_struct_info_find_method(class_info, "find_child_property");
 
+    /* Workaround for
+       https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/171
+     */
+    if (find_child_property_fun == NULL)
+        find_child_property_fun =
+            find_method_fallback(class_info, "find_child_property");
+
     find_child_property_args[0].v_pointer = G_OBJECT_GET_CLASS(container);
     find_child_property_args[1].v_string = (char*)property;
 


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