[gjs] foreign: Remove type_info from foreign APIs



commit b7ffb7362466d0b95ebbd118a1344fc13822443b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Mar 8 18:20:28 2012 -0500

    foreign: Remove type_info from foreign APIs
    
    If we don't require a type_info in a foreign API, this will make it easier
    to use the foreign API from another place in the code. Swap out the use
    of type_info with the interface info that the type info contains.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671687

 gi/arg.c                |    6 +++---
 gi/foreign.c            |   36 ++++++++++++++++--------------------
 gi/foreign.h            |    9 +++------
 modules/cairo-context.c |    3 ---
 4 files changed, 22 insertions(+), 32 deletions(-)
---
diff --git a/gi/arg.c b/gi/arg.c
index ca38262..40cbf2a 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -1288,7 +1288,7 @@ gjs_value_to_g_argument(JSContext      *context,
             case GI_INFO_TYPE_STRUCT:
                 if (g_struct_info_is_foreign((GIStructInfo*)interface_info)) {
                     return gjs_struct_foreign_convert_to_g_argument(
-                            context, value, type_info, arg_name,
+                            context, value, interface_info, arg_name,
                             arg_type, transfer, may_be_null, arg);
                 }
                 /* fall through */
@@ -2413,7 +2413,7 @@ gjs_value_from_g_argument (JSContext  *context,
                 goto out;
             } else if (interface_type == GI_INFO_TYPE_STRUCT &&
                        g_struct_info_is_foreign((GIStructInfo*)interface_info)) {
-                return gjs_struct_foreign_convert_from_g_argument(context, value_p, type_info, arg);
+                return gjs_struct_foreign_convert_from_g_argument(context, value_p, interface_info, arg);
             }
 
             /* Everything else is a pointer type, NULL is the easy case */
@@ -2698,7 +2698,7 @@ gjs_g_arg_release_internal(JSContext  *context,
             if (interface_type == GI_INFO_TYPE_STRUCT &&
                 g_struct_info_is_foreign((GIStructInfo*)interface_info))
                 return gjs_struct_foreign_release_g_argument(context,
-                        transfer, type_info, arg);
+                        transfer, interface_info, arg);
 
             if (interface_type == GI_INFO_TYPE_ENUM || interface_type == GI_INFO_TYPE_FLAGS)
                 goto out;
diff --git a/gi/foreign.c b/gi/foreign.c
index e75aa78..cb5e4c5 100644
--- a/gi/foreign.c
+++ b/gi/foreign.c
@@ -109,33 +109,29 @@ gjs_struct_foreign_register(const char *namespace,
 
 static GjsForeignInfo *
 gjs_struct_foreign_lookup(JSContext  *context,
-                          GITypeInfo *type_info)
+                          GIBaseInfo *interface_info)
 {
-    GIBaseInfo *base_info;
     GjsForeignInfo *retval = NULL;
     GHashTable *hash_table;
     char *key;
 
-    base_info = g_type_info_get_interface(type_info);
-    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));
+    key = g_strdup_printf("%s.%s",
+                          g_base_info_get_namespace(interface_info),
+                          g_base_info_get_name(interface_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))) {
+        if (gjs_foreign_load_foreign_module(context, g_base_info_get_namespace(interface_info))) {
             retval = (GjsForeignInfo*)g_hash_table_lookup(hash_table, 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_get_namespace(interface_info),
+                  g_base_info_get_name(interface_info));
     }
 
-    g_base_info_unref(base_info);
     g_free(key);
 
     return retval;
@@ -144,7 +140,7 @@ gjs_struct_foreign_lookup(JSContext  *context,
 JSBool
 gjs_struct_foreign_convert_to_g_argument(JSContext      *context,
                                          jsval           value,
-                                         GITypeInfo     *type_info,
+                                         GIBaseInfo     *interface_info,
                                          const char     *arg_name,
                                          GjsArgumentType argument_type,
                                          GITransfer      transfer,
@@ -153,11 +149,11 @@ gjs_struct_foreign_convert_to_g_argument(JSContext      *context,
 {
     GjsForeignInfo *foreign;
 
-    foreign = gjs_struct_foreign_lookup(context, type_info);
+    foreign = gjs_struct_foreign_lookup(context, interface_info);
     if (!foreign)
         return JS_FALSE;
 
-    if (!foreign->to_func(context, value, type_info, arg_name,
+    if (!foreign->to_func(context, value, arg_name,
                            argument_type, transfer, may_be_null, arg))
         return JS_FALSE;
 
@@ -167,16 +163,16 @@ gjs_struct_foreign_convert_to_g_argument(JSContext      *context,
 JSBool
 gjs_struct_foreign_convert_from_g_argument(JSContext  *context,
                                            jsval      *value_p,
-                                           GITypeInfo *type_info,
+                                           GIBaseInfo *interface_info,
                                            GArgument  *arg)
 {
     GjsForeignInfo *foreign;
 
-    foreign = gjs_struct_foreign_lookup(context, type_info);
+    foreign = gjs_struct_foreign_lookup(context, interface_info);
     if (!foreign)
         return JS_FALSE;
 
-    if (!foreign->from_func(context, value_p, type_info, arg))
+    if (!foreign->from_func(context, value_p, arg))
         return JS_FALSE;
 
     return JS_TRUE;
@@ -185,19 +181,19 @@ gjs_struct_foreign_convert_from_g_argument(JSContext  *context,
 JSBool
 gjs_struct_foreign_release_g_argument(JSContext  *context,
                                       GITransfer  transfer,
-                                      GITypeInfo *type_info,
+                                      GIBaseInfo *interface_info,
                                       GArgument  *arg)
 {
     GjsForeignInfo *foreign;
 
-    foreign = gjs_struct_foreign_lookup(context, type_info);
+    foreign = gjs_struct_foreign_lookup(context, interface_info);
     if (!foreign)
         return JS_FALSE;
 
     if (!foreign->release_func)
         return JS_TRUE;
 
-    if (!foreign->release_func(context, transfer, type_info, arg))
+    if (!foreign->release_func(context, transfer, arg))
         return JS_FALSE;
 
     return JS_TRUE;
diff --git a/gi/foreign.h b/gi/foreign.h
index 3611590..2b38601 100644
--- a/gi/foreign.h
+++ b/gi/foreign.h
@@ -30,7 +30,6 @@
 
 typedef JSBool (*GjsArgOverrideToGArgumentFunc) (JSContext      *context,
                                                  jsval           value,
-                                                 GITypeInfo     *type_info,
                                                  const char     *arg_name,
                                                  GjsArgumentType argument_type,
                                                  GITransfer      transfer,
@@ -39,11 +38,9 @@ typedef JSBool (*GjsArgOverrideToGArgumentFunc) (JSContext      *context,
 
 typedef JSBool (*GjsArgOverrideFromGArgumentFunc) (JSContext  *context,
                                                    jsval      *value_p,
-                                                   GITypeInfo *type_info,
                                                    GArgument  *arg);
 typedef JSBool (*GjsArgOverrideReleaseGArgumentFunc) (JSContext  *context,
                                                       GITransfer  transfer,
-                                                      GITypeInfo *type_info,
                                                       GArgument  *arg);
 
 typedef struct {
@@ -58,7 +55,7 @@ JSBool  gjs_struct_foreign_register                (const char         *namespac
 
 JSBool  gjs_struct_foreign_convert_to_g_argument   (JSContext          *context,
                                                     jsval               value,
-                                                    GITypeInfo         *type_info,
+                                                    GIBaseInfo         *interface_info,
                                                     const char         *arg_name,
                                                     GjsArgumentType     argument_type,
                                                     GITransfer          transfer,
@@ -66,11 +63,11 @@ JSBool  gjs_struct_foreign_convert_to_g_argument   (JSContext          *context,
                                                     GArgument          *arg);
 JSBool  gjs_struct_foreign_convert_from_g_argument (JSContext          *context,
                                                     jsval              *value_p,
-                                                    GITypeInfo         *type_info,
+                                                    GIBaseInfo         *interface_info,
                                                     GArgument          *arg);
 JSBool  gjs_struct_foreign_release_g_argument      (JSContext          *context,
                                                     GITransfer          transfer,
-                                                    GITypeInfo         *type_info,
+                                                    GIBaseInfo         *interface_info,
                                                     GArgument          *arg);
 
 #endif /* __GJS_OVERRIDE_H__ */
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 1db749e..4c6f46c 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -982,7 +982,6 @@ gjs_cairo_context_get_context(JSContext *context,
 static JSBool
 context_to_g_argument(JSContext      *context,
                       jsval           value,
-                      GITypeInfo     *type_info,
                       const char     *arg_name,
                       GjsArgumentType argument_type,
                       GITransfer      transfer,
@@ -1006,7 +1005,6 @@ context_to_g_argument(JSContext      *context,
 static JSBool
 context_from_g_argument(JSContext  *context,
                         jsval      *value_p,
-                        GITypeInfo *type_info,
                         GArgument  *arg)
 {
     JSObject *obj;
@@ -1022,7 +1020,6 @@ context_from_g_argument(JSContext  *context,
 static JSBool
 context_release_argument(JSContext  *context,
                          GITransfer  transfer,
-                         GITypeInfo *type_info,
                          GArgument  *arg)
 {
     cairo_destroy((cairo_t*)arg->v_pointer);



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