[pygobject] Move to Python basic type marshaling out of _pygi_argument_to_object



commit 663fe5893bbc9f34bf8aa4da3cb6f9186a8233b1
Author: Simon Feltman <sfeltman src gnome org>
Date:   Fri Jul 19 18:00:40 2013 -0700

    Move to Python basic type marshaling out of _pygi_argument_to_object
    
    Move the marshaling of GI arguments to Python objects for basic types
    into a new function. The required information for this marshaler
    is a GITypeTag and GITransfer. Argument marshaling matching these
    requirments are now found in: _pygi_argument_to_object_basic_type.
    The new marshaler can be used with a generic argument cache marshaler
    to unify all of the "basic type" marshaling.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693405

 gi/pygi-argument.c |   86 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 63 insertions(+), 23 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 2246d7c..c01c846 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1379,35 +1379,27 @@ hash_table_release:
 }
 
 /**
- * _pygi_argument_to_object:
- * @arg: The argument to convert to an object. 
- * @type_info: Type info for @arg
- * @transfer:
+ * _pygi_argument_to_object_basic_type:
+ * @arg: The argument to convert to an object.
+ * @type_tag: Type tag for @arg
+ * @transfer: Transfer annotation
  *
- * If the argument is of type array, it must be encoded in a GArray, by calling
- * _pygi_argument_to_array(). This logic can not be folded into this method
- * as determining array lengths may require access to method call arguments.
- * 
- * Returns: A PyObject representing @arg
+ * Convert the given argument to a Python object. This function
+ * is restricted to simple types that only require the GITypeTag
+ * and GITransfer. For a more complete conversion routine, use:
+ * _pygi_argument_to_object.
+ *
+ * Returns: A PyObject representing @arg or NULL if it cannot convert
+ *          the argument.
  */
-PyObject *
-_pygi_argument_to_object (GIArgument  *arg,
-                          GITypeInfo *type_info,
-                          GITransfer transfer)
+static PyObject *
+_pygi_argument_to_object_basic_type (GIArgument  *arg,
+                                     GITypeTag type_tag,
+                                     GITransfer transfer)
 {
-    GITypeTag type_tag;
     PyObject *object = NULL;
 
-    type_tag = g_type_info_get_tag (type_info);
     switch (type_tag) {
-        case GI_TYPE_TAG_VOID:
-        {
-            if (g_type_info_is_pointer (type_info)) {
-                g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
-                object = PyLong_FromVoidPtr (arg->v_pointer);
-            }
-            break;
-        }
         case GI_TYPE_TAG_BOOLEAN:
         {
             object = PyBool_FromLong (arg->v_boolean);
@@ -1486,6 +1478,49 @@ _pygi_argument_to_object (GIArgument  *arg,
                                                    arg);
             break;
         }
+        default:
+        {
+            object = NULL;
+            break;
+        }
+    }
+    return object;
+}
+
+/**
+ * _pygi_argument_to_object:
+ * @arg: The argument to convert to an object.
+ * @type_info: Type info for @arg
+ * @transfer:
+ *
+ * If the argument is of type array, it must be encoded in a GArray, by calling
+ * _pygi_argument_to_array(). This logic can not be folded into this method
+ * as determining array lengths may require access to method call arguments.
+ *
+ * Returns: A PyObject representing @arg
+ */
+PyObject *
+_pygi_argument_to_object (GIArgument  *arg,
+                          GITypeInfo *type_info,
+                          GITransfer transfer)
+{
+    GITypeTag type_tag;
+    PyObject *object = NULL;
+
+    type_tag = g_type_info_get_tag (type_info);
+    object = _pygi_argument_to_object_basic_type (arg, type_tag, transfer);
+    if (object)
+        return object;
+
+    switch (type_tag) {
+        case GI_TYPE_TAG_VOID:
+        {
+            if (g_type_info_is_pointer (type_info)) {
+                g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
+                object = PyLong_FromVoidPtr (arg->v_pointer);
+            }
+            break;
+        }
         case GI_TYPE_TAG_ARRAY:
         {
             /* Arrays are assumed to be packed in a GArray */
@@ -1775,6 +1810,11 @@ _pygi_argument_to_object (GIArgument  *arg,
                 Py_INCREF (object);
                 break;
             }
+            break;
+        }
+        default:
+        {
+            g_assert_not_reached();
         }
     }
 


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