[pygobject] Move _pygi_argument_to_object_basic_type into pygi-marshal-to-py.c



commit fae58044ea0b2e7f47fbdacc5b58ac36f673ecbd
Author: Simon Feltman <sfeltman src gnome org>
Date:   Tue Jul 23 14:25:01 2013 -0700

    Move _pygi_argument_to_object_basic_type into pygi-marshal-to-py.c
    
    Move _pygi_argument_to_object_basic_type into pygi-marshal-to-py.c
    and rename to _pygi_marshal_to_py_basic_type.
    Cleanup and simplify dependant sub-marshalers for unichar, utf8,
    and filename types.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693405

 gi/pygi-argument.c      |   73 +-----------------------------
 gi/pygi-argument.h      |    4 --
 gi/pygi-cache.c         |    4 +-
 gi/pygi-marshal-to-py.c |  115 ++++++++++++++++++++++++++++++++++++-----------
 gi/pygi-marshal-to-py.h |   27 +++--------
 5 files changed, 99 insertions(+), 124 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 249f59b..cda0be7 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1252,77 +1252,6 @@ hash_table_release:
 }
 
 /**
- * _pygi_argument_to_object_basic_type:
- * @arg: The argument to convert to an object.
- * @type_tag: Type tag for @arg
- * @transfer: Transfer annotation
- *
- * 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_basic_type (GIArgument  *arg,
-                                     GITypeTag type_tag,
-                                     GITransfer transfer)
-{
-    switch (type_tag) {
-        case GI_TYPE_TAG_BOOLEAN:
-            return PyBool_FromLong (arg->v_boolean);
-
-        case GI_TYPE_TAG_INT8:
-            return PYGLIB_PyLong_FromLong (arg->v_int8);
-
-        case GI_TYPE_TAG_UINT8:
-            return PYGLIB_PyLong_FromLong (arg->v_uint8);
-
-        case GI_TYPE_TAG_INT16:
-            return PYGLIB_PyLong_FromLong (arg->v_int16);
-
-        case GI_TYPE_TAG_UINT16:
-            return PYGLIB_PyLong_FromLong (arg->v_uint16);
-
-        case GI_TYPE_TAG_INT32:
-            return PYGLIB_PyLong_FromLong (arg->v_int32);
-
-        case GI_TYPE_TAG_UINT32:
-            return PyLong_FromLongLong (arg->v_uint32);
-
-        case GI_TYPE_TAG_INT64:
-            return PyLong_FromLongLong (arg->v_int64);
-
-        case GI_TYPE_TAG_UINT64:
-            return PyLong_FromUnsignedLongLong (arg->v_uint64);
-
-        case GI_TYPE_TAG_FLOAT:
-            return PyFloat_FromDouble (arg->v_float);
-
-        case GI_TYPE_TAG_DOUBLE:
-            return PyFloat_FromDouble (arg->v_double);
-
-        case GI_TYPE_TAG_GTYPE:
-            return pyg_type_wrapper_new ( (GType) arg->v_long);
-
-        case GI_TYPE_TAG_UNICHAR:
-            return _pygi_marshal_to_py_unichar (NULL, NULL, NULL, arg);
-
-        case GI_TYPE_TAG_UTF8:
-            return _pygi_marshal_to_py_utf8 (NULL, NULL, NULL, arg);
-
-        case GI_TYPE_TAG_FILENAME:
-            return _pygi_marshal_to_py_filename (NULL, NULL, NULL, arg);
-
-        default:
-            return NULL;
-    }
-    return NULL;
-}
-
-/**
  * _pygi_argument_to_object:
  * @arg: The argument to convert to an object.
  * @type_info: Type info for @arg
@@ -1343,7 +1272,7 @@ _pygi_argument_to_object (GIArgument  *arg,
     PyObject *object = NULL;
 
     type_tag = g_type_info_get_tag (type_info);
-    object = _pygi_argument_to_object_basic_type (arg, type_tag, transfer);
+    object = _pygi_marshal_to_py_basic_type (arg, type_tag, transfer);
     if (object)
         return object;
 
diff --git a/gi/pygi-argument.h b/gi/pygi-argument.h
index ac551a1..ed88214 100644
--- a/gi/pygi-argument.h
+++ b/gi/pygi-argument.h
@@ -59,10 +59,6 @@ GIArgument _pygi_argument_from_object (PyObject   *object,
                                       GITypeInfo *type_info,
                                       GITransfer  transfer);
 
-PyObject *_pygi_argument_to_object_basic_type (GIArgument  *arg,
-                                               GITypeTag type_tag,
-                                               GITransfer transfer);
-
 PyObject* _pygi_argument_to_object (GIArgument  *arg,
                                     GITypeInfo *type_info,
                                     GITransfer  transfer);
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index ca71e75..8604abb 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -268,7 +268,7 @@ _arg_cache_from_py_basic_type_setup (PyGIArgCache *arg_cache)
 static void
 _arg_cache_to_py_basic_type_setup (PyGIArgCache *arg_cache)
 {
-    arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
+    arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type_cache_adapter;
 }
 
 static void
@@ -295,7 +295,7 @@ static void
 _arg_cache_to_py_utf8_setup (PyGIArgCache *arg_cache,
                                GITransfer transfer)
 {
-    arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
+    arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type_cache_adapter;
     arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
 }
 
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 8a6470e..af45db0 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -112,17 +112,6 @@ gi_argument_to_gsize (GIArgument *arg_in,
 }
 
 PyObject *
-_pygi_marshal_to_py_basic_type (PyGIInvokeState   *state,
-                                PyGICallableCache *callable_cache,
-                                PyGIArgCache      *arg_cache,
-                                GIArgument        *arg)
-{
-    return _pygi_argument_to_object_basic_type (arg,
-                                                arg_cache->type_tag,
-                                                arg_cache->transfer);
-}
-
-PyObject *
 _pygi_marshal_to_py_void (PyGIInvokeState   *state,
                           PyGICallableCache *callable_cache,
                           PyGIArgCache      *arg_cache,
@@ -144,11 +133,8 @@ _pygi_marshal_to_py_void (PyGIInvokeState   *state,
     return py_obj;
 }
 
-PyObject *
-_pygi_marshal_to_py_unichar (PyGIInvokeState   *state,
-                             PyGICallableCache *callable_cache,
-                             PyGIArgCache      *arg_cache,
-                             GIArgument        *arg)
+static PyObject *
+_pygi_marshal_to_py_unichar (GIArgument *arg)
 {
     PyObject *py_obj = NULL;
 
@@ -171,11 +157,8 @@ _pygi_marshal_to_py_unichar (PyGIInvokeState   *state,
     return py_obj;
 }
 
-PyObject *
-_pygi_marshal_to_py_utf8 (PyGIInvokeState   *state,
-                          PyGICallableCache *callable_cache,
-                          PyGIArgCache      *arg_cache,
-                          GIArgument        *arg)
+static PyObject *
+_pygi_marshal_to_py_utf8 (GIArgument *arg)
 {
     PyObject *py_obj = NULL;
     if (arg->v_string == NULL) {
@@ -186,11 +169,8 @@ _pygi_marshal_to_py_utf8 (PyGIInvokeState   *state,
     return py_obj;
 }
 
-PyObject *
-_pygi_marshal_to_py_filename (PyGIInvokeState   *state,
-                              PyGICallableCache *callable_cache,
-                              PyGIArgCache      *arg_cache,
-                              GIArgument        *arg)
+static PyObject *
+_pygi_marshal_to_py_filename (GIArgument *arg)
 {
     gchar *string = NULL;
     PyObject *py_obj = NULL;
@@ -213,6 +193,89 @@ _pygi_marshal_to_py_filename (PyGIInvokeState   *state,
     return py_obj;
 }
 
+
+/**
+ * _pygi_marshal_to_py_basic_type:
+ * @arg: The argument to convert to an object.
+ * @type_tag: Type tag for @arg
+ * @transfer: Transfer annotation
+ *
+ * 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_marshal_to_py_basic_type (GIArgument  *arg,
+                                 GITypeTag type_tag,
+                                 GITransfer transfer)
+{
+    switch (type_tag) {
+        case GI_TYPE_TAG_BOOLEAN:
+            return PyBool_FromLong (arg->v_boolean);
+
+        case GI_TYPE_TAG_INT8:
+            return PYGLIB_PyLong_FromLong (arg->v_int8);
+
+        case GI_TYPE_TAG_UINT8:
+            return PYGLIB_PyLong_FromLong (arg->v_uint8);
+
+        case GI_TYPE_TAG_INT16:
+            return PYGLIB_PyLong_FromLong (arg->v_int16);
+
+        case GI_TYPE_TAG_UINT16:
+            return PYGLIB_PyLong_FromLong (arg->v_uint16);
+
+        case GI_TYPE_TAG_INT32:
+            return PYGLIB_PyLong_FromLong (arg->v_int32);
+
+        case GI_TYPE_TAG_UINT32:
+            return PyLong_FromLongLong (arg->v_uint32);
+
+        case GI_TYPE_TAG_INT64:
+            return PyLong_FromLongLong (arg->v_int64);
+
+        case GI_TYPE_TAG_UINT64:
+            return PyLong_FromUnsignedLongLong (arg->v_uint64);
+
+        case GI_TYPE_TAG_FLOAT:
+            return PyFloat_FromDouble (arg->v_float);
+
+        case GI_TYPE_TAG_DOUBLE:
+            return PyFloat_FromDouble (arg->v_double);
+
+        case GI_TYPE_TAG_GTYPE:
+            return pyg_type_wrapper_new ( (GType) arg->v_long);
+
+        case GI_TYPE_TAG_UNICHAR:
+            return _pygi_marshal_to_py_unichar (arg);
+
+        case GI_TYPE_TAG_UTF8:
+            return _pygi_marshal_to_py_utf8 (arg);
+
+        case GI_TYPE_TAG_FILENAME:
+            return _pygi_marshal_to_py_filename (arg);
+
+        default:
+            return NULL;
+    }
+    return NULL;
+}
+
+PyObject *
+_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState   *state,
+                                              PyGICallableCache *callable_cache,
+                                              PyGIArgCache      *arg_cache,
+                                              GIArgument        *arg)
+{
+    return _pygi_marshal_to_py_basic_type (arg,
+                                            arg_cache->type_tag,
+                                            arg_cache->transfer);
+}
+
 PyObject *
 _pygi_marshal_to_py_array (PyGIInvokeState   *state,
                            PyGICallableCache *callable_cache,
diff --git a/gi/pygi-marshal-to-py.h b/gi/pygi-marshal-to-py.h
index 0ecc488..fa8fb49 100644
--- a/gi/pygi-marshal-to-py.h
+++ b/gi/pygi-marshal-to-py.h
@@ -22,30 +22,17 @@
 #ifndef __PYGI_MARSHAL_TO_PY_H__
 #define __PYGI_MARSHAL_TO_PY_H__
 
-PyObject *_pygi_marshal_to_py_basic_type (PyGIInvokeState   *state,
-                                          PyGICallableCache *callable_cache,
-                                          PyGIArgCache      *arg_cache,
-                                          GIArgument        *arg);
+PyObject *_pygi_marshal_to_py_basic_type (GIArgument  *arg,
+                                          GITypeTag type_tag,
+                                          GITransfer transfer);
+PyObject *_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState   *state,
+                                                        PyGICallableCache *callable_cache,
+                                                        PyGIArgCache      *arg_cache,
+                                                        GIArgument        *arg);
 PyObject *_pygi_marshal_to_py_void      (PyGIInvokeState   *state,
                                          PyGICallableCache *callable_cache,
                                          PyGIArgCache      *arg_cache,
                                          GIArgument        *arg);
-PyObject *_pygi_marshal_to_py_unichar   (PyGIInvokeState   *state,
-                                         PyGICallableCache *callable_cache,
-                                         PyGIArgCache      *arg_cache,
-                                         GIArgument        *arg);
-PyObject *_pygi_marshal_to_py_gtype     (PyGIInvokeState   *state,
-                                         PyGICallableCache *callable_cache,
-                                         PyGIArgCache      *arg_cache,
-                                         GIArgument        *arg);
-PyObject *_pygi_marshal_to_py_utf8      (PyGIInvokeState   *state,
-                                         PyGICallableCache *callable_cache,
-                                         PyGIArgCache      *arg_cache,
-                                         GIArgument        *arg);
-PyObject *_pygi_marshal_to_py_filename  (PyGIInvokeState   *state,
-                                         PyGICallableCache *callable_cache,
-                                         PyGIArgCache      *arg_cache,
-                                         GIArgument        *arg);
 PyObject *_pygi_marshal_to_py_array     (PyGIInvokeState   *state,
                                          PyGICallableCache *callable_cache,
                                          PyGIArgCache      *arg_cache,


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