[pygobject] [gi] foreign types now take interface infos instead of type infos



commit 01596a9b7cc0ceef3904da5b96939140ee0732fd
Author: John (J5) Palmieri <johnp redhat com>
Date:   Tue Mar 22 13:20:54 2011 -0400

    [gi] foreign types now take interface infos instead of type infos
    
     * this is a prep for the invoke-rewrite branch
     * when marshalling foreign structs we may not have the type info but
       we will always have the interface info to pass
     * this simplifies the code because we were simply converting the
       type info back to an interface info anyway so there is less
       refcounting to keep track of
     * also fixes a bug where we were leaking PyNone ref counts

 gi/pygi-argument.c         |    4 ++--
 gi/pygi-foreign-cairo.c    |   16 ++++++++--------
 gi/pygi-foreign-gvariant.c |   12 ++++++------
 gi/pygi-foreign.c          |   32 +++++++++++++-------------------
 gi/pygi-foreign.h          |    8 ++++----
 gi/pygi-invoke.c           |    6 +++---
 gi/pygi.h                  |   12 ++++++------
 7 files changed, 42 insertions(+), 48 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index c44307c..58f6fb0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1092,7 +1092,7 @@ array_success:
                     } else if ( (type == G_TYPE_NONE) && (g_struct_info_is_foreign (info))) {
                         PyObject *result;
                         result = pygi_struct_foreign_convert_to_g_argument (
-                                     object, type_info, transfer, &arg);
+                                     object, info, transfer, &arg);
                     } else if (g_type_is_a (type, G_TYPE_POINTER) || type == G_TYPE_NONE) {
                         g_warn_if_fail (!g_type_info_is_pointer (type_info) || transfer == GI_TRANSFER_NOTHING);
                         arg.v_pointer = pyg_pointer_get (object, void);
@@ -1564,7 +1564,7 @@ _pygi_argument_to_object (GIArgument  *arg,
                     if (g_type_is_a (type, G_TYPE_VALUE)) {
                         object = pyg_value_as_pyobject (arg->v_pointer, FALSE);
                     } else if (g_struct_info_is_foreign (info)) {
-                        object = pygi_struct_foreign_convert_from_g_argument (type_info, arg->v_pointer);
+                        object = pygi_struct_foreign_convert_from_g_argument (info, arg->v_pointer);
                     } else if (g_type_is_a (type, G_TYPE_BOXED)) {
                         PyObject *py_type;
 
diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c
index 0264b71..10d5643 100644
--- a/gi/pygi-foreign-cairo.c
+++ b/gi/pygi-foreign-cairo.c
@@ -37,9 +37,9 @@ Pycairo_CAPI_t *Pycairo_CAPI;
 #include <pyglib-python-compat.h>
 
 PyObject *
-cairo_context_to_arg (PyObject       *value,
-                      GITypeInfo     *type_info,
-                      GITransfer      transfer,
+cairo_context_to_arg (PyObject        *value,
+                      GIInterfaceInfo *interface_info,
+                      GITransfer       transfer,
                       GIArgument      *arg)
 {
     cairo_t *cr;
@@ -56,7 +56,7 @@ cairo_context_to_arg (PyObject       *value,
 }
 
 PyObject *
-cairo_context_from_arg (GITypeInfo *type_info, gpointer data)
+cairo_context_from_arg (GIInterfaceInfo *interface_info, gpointer data)
 {
     cairo_t *context = (cairo_t*) data;
 
@@ -75,9 +75,9 @@ cairo_context_release (GIBaseInfo *base_info,
 
 
 PyObject *
-cairo_surface_to_arg (PyObject       *value,
-                      GITypeInfo     *type_info,
-                      GITransfer      transfer,
+cairo_surface_to_arg (PyObject        *value,
+                      GIInterfaceInfo *interface_info,
+                      GITransfer       transfer,
                       GIArgument      *arg)
 {
     cairo_surface_t *surface;
@@ -95,7 +95,7 @@ cairo_surface_to_arg (PyObject       *value,
 }
 
 PyObject *
-cairo_surface_from_arg (GITypeInfo *type_info, gpointer data)
+cairo_surface_from_arg (GIInterfaceInfo *interface_info, gpointer data)
 {
     cairo_surface_t *surface = (cairo_surface_t*) data;
 
diff --git a/gi/pygi-foreign-gvariant.c b/gi/pygi-foreign-gvariant.c
index 3c8ae8d..e799d98 100644
--- a/gi/pygi-foreign-gvariant.c
+++ b/gi/pygi-foreign-gvariant.c
@@ -27,9 +27,9 @@
 #include "pygi-foreign-gvariant.h"
 
 PyObject *
-g_variant_to_arg (PyObject       *value,
-                  GITypeInfo     *type_info,
-                  GITransfer      transfer,
+g_variant_to_arg (PyObject        *value,
+                  GIInterfaceInfo *interface_info,
+                  GITransfer       transfer,
                   GIArgument      *arg)
 {
     g_assert (transfer == GI_TRANSFER_NOTHING);
@@ -41,11 +41,11 @@ g_variant_to_arg (PyObject       *value,
 }
 
 PyObject *
-g_variant_from_arg (GITypeInfo *type_info,
-                    gpointer    data)
+g_variant_from_arg (GIInterfaceInfo *interface_info,
+                    gpointer         data)
 {
     GVariant *variant = (GVariant *) data;
-    GITypeInfo *interface_info = g_type_info_get_interface (type_info);
+
     PyObject *type = _pygi_type_import_by_gi_info (interface_info);
 
     g_variant_ref_sink (variant);
diff --git a/gi/pygi-foreign.c b/gi/pygi-foreign.c
index 5c9a88a..127f8ea 100644
--- a/gi/pygi-foreign.c
+++ b/gi/pygi-foreign.c
@@ -107,37 +107,34 @@ pygi_struct_foreign_lookup (GIBaseInfo *base_info)
 }
 
 PyObject *
-pygi_struct_foreign_convert_to_g_argument (PyObject       *value,
-                                           GITypeInfo     *type_info,
-                                           GITransfer      transfer,
+pygi_struct_foreign_convert_to_g_argument (PyObject        *value,
+                                           GIInterfaceInfo *interface_info,
+                                           GITransfer       transfer,
                                            GIArgument      *arg)
 {
-    GIBaseInfo *base_info = g_type_info_get_interface (type_info);
+    PyObject *result;
+
+    GIBaseInfo *base_info = (GIBaseInfo *) interface_info;
     PyGIForeignStruct *foreign_struct = pygi_struct_foreign_lookup (base_info);
-    g_base_info_unref (base_info);
 
     if (foreign_struct == NULL)
         return NULL;
 
-    if (!foreign_struct->to_func (value, type_info, transfer, arg))
-        return NULL;
-
-    Py_RETURN_NONE;
+    result = foreign_struct->to_func (value, interface_info, transfer, arg);
+    return result;
 }
 
 PyObject *
-pygi_struct_foreign_convert_from_g_argument (GITypeInfo *type_info,
-                                             GIArgument  *arg)
+pygi_struct_foreign_convert_from_g_argument (GIInterfaceInfo *interface_info,
+                                             GIArgument      *arg)
 {
-    GIBaseInfo *base_info = g_type_info_get_interface (type_info);
+    GIBaseInfo *base_info = (GIBaseInfo *) interface_info;
     PyGIForeignStruct *foreign_struct = pygi_struct_foreign_lookup (base_info);
-    g_base_info_unref (base_info);
-
 
     if (foreign_struct == NULL)
         return NULL;
 
-    return foreign_struct->from_func (type_info, arg);
+    return foreign_struct->from_func (interface_info, arg);
 }
 
 PyObject *
@@ -152,10 +149,7 @@ pygi_struct_foreign_release (GIBaseInfo *base_info,
     if (!foreign_struct->release_func)
         Py_RETURN_NONE;
 
-    if (!foreign_struct->release_func (base_info, struct_))
-        return NULL;
-
-    Py_RETURN_NONE;
+    return foreign_struct->release_func (base_info, struct_);
 }
 
 void
diff --git a/gi/pygi-foreign.h b/gi/pygi-foreign.h
index b57f892..dd5f896 100644
--- a/gi/pygi-foreign.h
+++ b/gi/pygi-foreign.h
@@ -31,11 +31,11 @@
 #include "pygi.h"
 
 PyObject *pygi_struct_foreign_convert_to_g_argument (PyObject           *value,
-                                                     GITypeInfo         *type_info,
+                                                     GIInterfaceInfo    *interface_info,
                                                      GITransfer          transfer,
-                                                     GIArgument          *arg);
-PyObject *pygi_struct_foreign_convert_from_g_argument (GITypeInfo *type_info,
-                                                       GIArgument  *arg);
+                                                     GIArgument         *arg);
+PyObject *pygi_struct_foreign_convert_from_g_argument (GIInterfaceInfo *interface_info,
+                                                       GIArgument      *arg);
 PyObject *pygi_struct_foreign_release (GITypeInfo *type_info,
                                        gpointer struct_);
 
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index a2b0fef..b474567 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -382,11 +382,11 @@ _prepare_invocation_state (struct invocation_state *state,
                             state->args[i]->v_pointer = _pygi_boxed_alloc (info, NULL);
                         } else if (g_struct_info_is_foreign((GIStructInfo *) info) ) {
                             PyObject *foreign_struct =
-                                pygi_struct_foreign_convert_from_g_argument(state->arg_type_infos[i], NULL);
+                                pygi_struct_foreign_convert_from_g_argument(info, NULL);
 
                             pygi_struct_foreign_convert_to_g_argument(
                                 foreign_struct,
-                                state->arg_type_infos[i],
+                                info,
                                 GI_TRANSFER_EVERYTHING,
                                 state->args[i]);
 
@@ -694,7 +694,7 @@ _process_invocation_state (struct invocation_state *state,
                 } else if (type == G_TYPE_NONE && g_struct_info_is_foreign (info)) {
                     state->return_value =
                         pygi_struct_foreign_convert_from_g_argument (
-                            state->return_type_info, state->return_arg.v_pointer);
+                            info, state->return_arg.v_pointer);
                 } else if (g_type_is_a (type, G_TYPE_POINTER) || type == G_TYPE_NONE) {
                     if (transfer != GI_TRANSFER_NOTHING)
                         g_warning ("Return argument in %s returns a struct "
diff --git a/gi/pygi.h b/gi/pygi.h
index 274af4d..c9a3fec 100644
--- a/gi/pygi.h
+++ b/gi/pygi.h
@@ -55,12 +55,12 @@ typedef struct {
     gsize size;
 } PyGIBoxed;
 
-typedef PyObject * (*PyGIArgOverrideToGIArgumentFunc) (PyObject       *value,
-                                                      GITypeInfo     *type_info,
-                                                      GITransfer      transfer,
-                                                      GIArgument      *arg);
-typedef PyObject * (*PyGIArgOverrideFromGIArgumentFunc) (GITypeInfo *type_info,
-                                                         gpointer    data);
+typedef PyObject * (*PyGIArgOverrideToGIArgumentFunc) (PyObject        *value,
+                                                       GIInterfaceInfo *interface_info,
+                                                       GITransfer       transfer,
+                                                       GIArgument      *arg);
+typedef PyObject * (*PyGIArgOverrideFromGIArgumentFunc) (GIInterfaceInfo *interface_info,
+                                                         gpointer         data);
 typedef PyObject * (*PyGIArgOverrideReleaseFunc) (GITypeInfo *type_info,
                                                   gpointer  struct_);
 



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