[gjs] Throw an exception when failing to look up a foreign struct



commit d4103f4280aa95fdf3872152913cc3bccfa15dd2
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Nov 20 12:25:57 2010 -0500

    Throw an exception when failing to look up a foreign struct
    
    Returning failure without setting an exception was causing control
    to mysteriously jump out of the enclosing function. The function
    is also changed to g_assert() rather than returning NULL when
    a non-interface GITypeInfo is passed in - it's a case that should
    not happen if the calling code is correct so throwing an exception
    doesn't make sense.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=635359

 gi/foreign.c |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/gi/foreign.c b/gi/foreign.c
index 548ddde..e75aa78 100644
--- a/gi/foreign.c
+++ b/gi/foreign.c
@@ -114,21 +114,30 @@ gjs_struct_foreign_lookup(JSContext  *context,
     GIBaseInfo *base_info;
     GjsForeignInfo *retval = NULL;
     GHashTable *hash_table;
+    char *key;
 
     base_info = g_type_info_get_interface(type_info);
-    if (base_info) {
-        char *key = g_strdup_printf("%s.%s", g_base_info_get_namespace(base_info),
-                                    g_base_info_get_name(base_info));
-        hash_table = get_foreign_structs();
-        retval = (GjsForeignInfo*)g_hash_table_lookup(hash_table, key);
-        if (!retval) {
-            if (gjs_foreign_load_foreign_module(context, g_base_info_get_namespace(base_info))) {
-                retval = (GjsForeignInfo*)g_hash_table_lookup(hash_table, key);
-            }
+    g_assert (base_info != NULL);
+
+    key = g_strdup_printf("%s.%s", g_base_info_get_namespace(base_info),
+                          g_base_info_get_name(base_info));
+    hash_table = get_foreign_structs();
+    retval = (GjsForeignInfo*)g_hash_table_lookup(hash_table, key);
+    if (!retval) {
+        if (gjs_foreign_load_foreign_module(context, g_base_info_get_namespace(base_info))) {
+            retval = (GjsForeignInfo*)g_hash_table_lookup(hash_table, key);
         }
-        g_base_info_unref(base_info);
-        g_free(key);
     }
+
+    if (!retval) {
+        gjs_throw(context, "Unable to find module implementing foreign type %s.%s",
+                  g_base_info_get_namespace(base_info),
+                  g_base_info_get_name(base_info));
+    }
+
+    g_base_info_unref(base_info);
+    g_free(key);
+
     return retval;
 }
 



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