[pygobject/invoke-rewrite] [gi] support struct out



commit 5eb779439daa8bf1e86df689377dc10ef1430eab
Author: John (J5) Palmieri <johnp redhat com>
Date:   Fri Jan 21 04:26:11 2011 -0500

    [gi] support struct out

 gi/pygi-argument.c |   30 ++++++++++++++++++++++++++----
 gi/pygi-cache.c    |   15 ++-------------
 2 files changed, 28 insertions(+), 17 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 13c576c..ccbe8b0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -2969,14 +2969,13 @@ _pygi_marshal_in_interface_callback (PyGIInvokeState   *state,
                                      GIArgument        *arg)
 {
     GICallableInfo *callable_info;
-    GITypeInfo *type_info;
     PyGICClosure *closure;
     PyGIArgCache *user_data_cache = NULL;
     PyGIArgCache *destroy_cache = NULL;
     PyGICallbackCache *callback_cache;
     PyObject *py_user_data = NULL;
 
-    callback_cache =(PyGICallbackCache *)arg_cache;
+    callback_cache = (PyGICallbackCache *)arg_cache;
 
     if (callback_cache->user_data_index > 0) {
         user_data_cache = function_cache->args_cache[callback_cache->user_data_index];
@@ -3583,9 +3582,32 @@ _pygi_marshal_out_interface_struct (PyGIInvokeState   *state,
                                     GIArgument        *arg)
 {
     PyObject *py_obj = NULL;
+    PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
+    GType type = iface_cache->g_type;
+
+    if (g_type_is_a (type, G_TYPE_VALUE)) {
+        py_obj = pyg_value_as_pyobject (arg->v_pointer, FALSE);
+    } else if (g_type_is_a (type, G_TYPE_BOXED)) {
+        py_obj = _pygi_boxed_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, 
+                                  arg_cache->transfer == GI_TRANSFER_EVERYTHING);
+    } else if (g_type_is_a (type, G_TYPE_POINTER)) {
+        if (iface_cache->py_type == NULL ||
+                !PyType_IsSubtype( (PyTypeObject *)iface_cache->py_type, &PyGIStruct_Type)) {
+            g_warn_if_fail(arg_cache->transfer == GI_TRANSFER_NOTHING);
+            py_obj = pyg_pointer_new(type, arg->v_pointer);
+        } else {
+            py_obj = _pygi_struct_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, 
+                                      arg_cache->transfer == GI_TRANSFER_EVERYTHING);
+        }
+    } else if (type == G_TYPE_NONE && iface_cache->is_foreign) {
+        py_obj = pygi_struct_foreign_convert_from_g_argument (iface_cache->interface_info, arg->v_pointer);
+    } else if (type == G_TYPE_NONE) {
+        py_obj = _pygi_struct_new((PyTypeObject *) iface_cache->py_type, arg->v_pointer, 
+                                  arg_cache->transfer == GI_TRANSFER_EVERYTHING);
+    } else {
+        PyErr_Format (PyExc_NotImplementedError, "structure type '%s' is not supported yet", g_type_name (type));
+    }
 
-    PyErr_Format(PyExc_NotImplementedError,
-                 "Marshalling for this type is not implemented yet");
     return py_obj;
 }
 
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 1be0323..d65439a 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -819,17 +819,10 @@ static inline PyGIArgCache *
 _arg_cache_new_for_out_interface_struct(GIInterfaceInfo *iface_info,
                                         GITransfer transfer)
 {
-    PyErr_Format(PyExc_NotImplementedError,
-                 "Caching for Out Interface Struct is not fully implemented yet");
-    return FALSE;
     PyGIInterfaceCache *iface_cache = _interface_cache_new_from_interface_info(iface_info);
     PyGIArgCache *arg_cache = (PyGIArgCache *)iface_cache;
     iface_cache->is_foreign = g_struct_info_is_foreign( (GIStructInfo*)iface_info);
-    arg_cache->in_marshaller = _pygi_marshal_in_interface_struct;
-    if (iface_cache->g_type == G_TYPE_VALUE)
-        arg_cache->cleanup = _g_slice_free_gvalue_func;
-    if (iface_cache->g_type == G_TYPE_CLOSURE)
-        arg_cache->cleanup = g_closure_unref;
+    arg_cache->out_marshaller = _pygi_marshal_out_interface_struct;
 
     return arg_cache;
 }
@@ -848,12 +841,8 @@ static inline PyGIArgCache *
 _arg_cache_new_for_out_interface_boxed(GIInterfaceInfo *iface_info,
                                       GITransfer transfer)
 {
-    PyErr_Format(PyExc_NotImplementedError,
-                 "Caching for Out Interface Boxed is not fully implemented yet");
-    return FALSE;
-
     PyGIArgCache *arg_cache = (PyGIArgCache *)_interface_cache_new_from_interface_info(iface_info);
-    arg_cache->in_marshaller = _pygi_marshal_in_interface_boxed;
+    arg_cache->out_marshaller = _pygi_marshal_out_interface_struct;
     return arg_cache;
 }
 



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