[pygobject] Move _pygi_argument_from_object_basic_type into pygi-marshal-from-py.c



commit f7748affae3d6ef0cc2e409f65761fb29c01b038
Author: Simon Feltman <sfeltman src gnome org>
Date:   Mon Jul 22 22:19:26 2013 -0700

    Move _pygi_argument_from_object_basic_type into pygi-marshal-from-py.c
    
    Move _pygi_argument_from_object_basic_type into pygi-marshal-from-py.c
    and rename to: _pygi_marshal_from_py_basic_type
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693405

 gi/pygi-argument.c        |  149 +--------------------------------------------
 gi/pygi-marshal-from-py.c |  147 ++++++++++++++++++++++++++++++++++++++++++++
 gi/pygi-marshal-from-py.h |    4 +
 3 files changed, 152 insertions(+), 148 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 1555b50..b0b108f 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -887,153 +887,6 @@ _pygi_argument_to_array (GIArgument  *arg,
     return g_array;
 }
 
-static gboolean
-_pygi_argument_from_object_basic_type (PyObject   *object,   /* in */
-                                       GIArgument *arg,      /* out */
-                                       GITypeTag   type_tag,
-                                       GITransfer  transfer)
-{
-    switch (type_tag) {
-        case GI_TYPE_TAG_VOID:
-            g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
-            if (object == Py_None) {
-                arg->v_pointer = NULL;
-            } else if (!PYGLIB_PyLong_Check(object)  && !PyLong_Check(object)) {
-                PyErr_SetString(PyExc_TypeError,
-                    "Pointer assignment is restricted to integer values. "
-                    "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599";);
-            } else {
-                arg->v_pointer = PyLong_AsVoidPtr (object);
-            }
-            break;
-        case GI_TYPE_TAG_BOOLEAN:
-        {
-            arg->v_boolean = PyObject_IsTrue (object);
-            break;
-        }
-        case GI_TYPE_TAG_INT8:
-        case GI_TYPE_TAG_INT16:
-        case GI_TYPE_TAG_INT32:
-        {
-            PyObject *int_;
-
-            int_ = PYGLIB_PyNumber_Long (object);
-            if (int_ == NULL) {
-                PyErr_SetString (PyExc_TypeError, "expected int argument");
-                break;
-            }
-
-            if (type_tag == GI_TYPE_TAG_INT32)
-                arg->v_int32 = PYGLIB_PyLong_AsLong (int_);
-            else if (type_tag == GI_TYPE_TAG_INT8)
-                arg->v_int8 = PYGLIB_PyLong_AsLong (int_);
-            else if (type_tag == GI_TYPE_TAG_INT16)
-                arg->v_int16 = PYGLIB_PyLong_AsLong (int_);
-
-            Py_DECREF (int_);
-
-            break;
-        }
-        case GI_TYPE_TAG_UINT8:
-        case GI_TYPE_TAG_UINT16:
-        case GI_TYPE_TAG_UINT32:
-        case GI_TYPE_TAG_UINT64:
-        {
-            PyObject *number;
-            guint64 value;
-
-            number = PYGLIB_PyNumber_Long (object);
-            if (number == NULL) {
-                PyErr_SetString (PyExc_TypeError, "expected int argument");
-                break;
-            }
-
-#if PY_VERSION_HEX < 0x03000000
-            if (PyInt_Check (number)) {
-                value = PyInt_AS_LONG (number);
-            } else
-#endif
-            value = PyLong_AsUnsignedLongLong (number);
-
-            if (type_tag == GI_TYPE_TAG_UINT32)
-                arg->v_uint32 = value;
-            else if (type_tag == GI_TYPE_TAG_UINT64)
-                arg->v_uint64 = value;
-            else if (type_tag == GI_TYPE_TAG_UINT8)
-                arg->v_uint8 = value;
-            else if (type_tag == GI_TYPE_TAG_UINT16)
-                arg->v_uint16 = value;
-
-            Py_DECREF (number);
-
-            break;
-        }
-        case GI_TYPE_TAG_INT64:
-        {
-            PyObject *number;
-            gint64 value;
-
-            number = PYGLIB_PyNumber_Long (object);
-            if (number == NULL) {
-                PyErr_SetString (PyExc_TypeError, "expected int argument");
-                break;
-            }
-
-#if PY_VERSION_HEX < 0x03000000
-            if (PyInt_Check (number)) {
-                value = PyInt_AS_LONG (number);
-            } else
-#endif
-            value = PyLong_AsLongLong (number);
-
-            arg->v_int64 = value;
-
-            Py_DECREF (number);
-
-            break;
-        }
-        case GI_TYPE_TAG_FLOAT:
-        {
-            _pygi_marshal_from_py_float (NULL, NULL, NULL,
-                                         object, arg);
-            break;
-        }
-        case GI_TYPE_TAG_DOUBLE:
-        {
-            _pygi_marshal_from_py_double (NULL, NULL, NULL,
-                                          object, arg);
-            break;
-        }
-        case GI_TYPE_TAG_GTYPE:
-        {
-            arg->v_long = pyg_type_from_object (object);
-
-            break;
-        }
-        case GI_TYPE_TAG_UNICHAR:
-        {
-            _pygi_marshal_from_py_unichar (NULL, NULL, NULL,
-                                           object, arg);
-            break;
-        }
-        case GI_TYPE_TAG_UTF8:
-        {
-            _pygi_marshal_from_py_utf8 (NULL, NULL, NULL,
-                                        object, arg);
-            break;
-        }
-        case GI_TYPE_TAG_FILENAME:
-        {
-            _pygi_marshal_from_py_filename (NULL, NULL, NULL,
-                                            object, arg);
-            break;
-        }
-        default:
-            return FALSE;
-    }
-    return TRUE;
-}
-
 GIArgument
 _pygi_argument_from_object (PyObject   *object,
                             GITypeInfo *type_info,
@@ -1045,7 +898,7 @@ _pygi_argument_from_object (PyObject   *object,
     memset(&arg, 0, sizeof(GIArgument));
     type_tag = g_type_info_get_tag (type_info);
 
-    if (_pygi_argument_from_object_basic_type (object, &arg, type_tag, transfer)) {
+    if (_pygi_marshal_from_py_basic_type (object, &arg, type_tag, transfer)) {
         return arg;
     }
 
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 77020d1..6d8629f 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -924,6 +924,153 @@ _pygi_marshal_from_py_filename (PyGIInvokeState   *state,
 }
 
 gboolean
+_pygi_marshal_from_py_basic_type (PyObject   *object,   /* in */
+                                  GIArgument *arg,      /* out */
+                                  GITypeTag   type_tag,
+                                  GITransfer  transfer)
+{
+    switch (type_tag) {
+        case GI_TYPE_TAG_VOID:
+            g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
+            if (object == Py_None) {
+                arg->v_pointer = NULL;
+            } else if (!PYGLIB_PyLong_Check(object)  && !PyLong_Check(object)) {
+                PyErr_SetString(PyExc_TypeError,
+                    "Pointer assignment is restricted to integer values. "
+                    "See: https://bugzilla.gnome.org/show_bug.cgi?id=683599";);
+            } else {
+                arg->v_pointer = PyLong_AsVoidPtr (object);
+            }
+            break;
+        case GI_TYPE_TAG_BOOLEAN:
+        {
+            arg->v_boolean = PyObject_IsTrue (object);
+            break;
+        }
+        case GI_TYPE_TAG_INT8:
+        case GI_TYPE_TAG_INT16:
+        case GI_TYPE_TAG_INT32:
+        {
+            PyObject *int_;
+
+            int_ = PYGLIB_PyNumber_Long (object);
+            if (int_ == NULL) {
+                PyErr_SetString (PyExc_TypeError, "expected int argument");
+                break;
+            }
+
+            if (type_tag == GI_TYPE_TAG_INT32)
+                arg->v_int32 = PYGLIB_PyLong_AsLong (int_);
+            else if (type_tag == GI_TYPE_TAG_INT8)
+                arg->v_int8 = PYGLIB_PyLong_AsLong (int_);
+            else if (type_tag == GI_TYPE_TAG_INT16)
+                arg->v_int16 = PYGLIB_PyLong_AsLong (int_);
+
+            Py_DECREF (int_);
+
+            break;
+        }
+        case GI_TYPE_TAG_UINT8:
+        case GI_TYPE_TAG_UINT16:
+        case GI_TYPE_TAG_UINT32:
+        case GI_TYPE_TAG_UINT64:
+        {
+            PyObject *number;
+            guint64 value;
+
+            number = PYGLIB_PyNumber_Long (object);
+            if (number == NULL) {
+                PyErr_SetString (PyExc_TypeError, "expected int argument");
+                break;
+            }
+
+#if PY_VERSION_HEX < 0x03000000
+            if (PyInt_Check (number)) {
+                value = PyInt_AS_LONG (number);
+            } else
+#endif
+            value = PyLong_AsUnsignedLongLong (number);
+
+            if (type_tag == GI_TYPE_TAG_UINT32)
+                arg->v_uint32 = value;
+            else if (type_tag == GI_TYPE_TAG_UINT64)
+                arg->v_uint64 = value;
+            else if (type_tag == GI_TYPE_TAG_UINT8)
+                arg->v_uint8 = value;
+            else if (type_tag == GI_TYPE_TAG_UINT16)
+                arg->v_uint16 = value;
+
+            Py_DECREF (number);
+
+            break;
+        }
+        case GI_TYPE_TAG_INT64:
+        {
+            PyObject *number;
+            gint64 value;
+
+            number = PYGLIB_PyNumber_Long (object);
+            if (number == NULL) {
+                PyErr_SetString (PyExc_TypeError, "expected int argument");
+                break;
+            }
+
+#if PY_VERSION_HEX < 0x03000000
+            if (PyInt_Check (number)) {
+                value = PyInt_AS_LONG (number);
+            } else
+#endif
+            value = PyLong_AsLongLong (number);
+
+            arg->v_int64 = value;
+
+            Py_DECREF (number);
+
+            break;
+        }
+        case GI_TYPE_TAG_FLOAT:
+        {
+            _pygi_marshal_from_py_float (NULL, NULL, NULL,
+                                         object, arg);
+            break;
+        }
+        case GI_TYPE_TAG_DOUBLE:
+        {
+            _pygi_marshal_from_py_double (NULL, NULL, NULL,
+                                          object, arg);
+            break;
+        }
+        case GI_TYPE_TAG_GTYPE:
+        {
+            arg->v_long = pyg_type_from_object (object);
+
+            break;
+        }
+        case GI_TYPE_TAG_UNICHAR:
+        {
+            _pygi_marshal_from_py_unichar (NULL, NULL, NULL,
+                                           object, arg);
+            break;
+        }
+        case GI_TYPE_TAG_UTF8:
+        {
+            _pygi_marshal_from_py_utf8 (NULL, NULL, NULL,
+                                        object, arg);
+            break;
+        }
+        case GI_TYPE_TAG_FILENAME:
+        {
+            _pygi_marshal_from_py_filename (NULL, NULL, NULL,
+                                            object, arg);
+            break;
+        }
+        default:
+            return FALSE;
+    }
+    return TRUE;
+}
+
+gboolean
 _pygi_marshal_from_py_array (PyGIInvokeState   *state,
                              PyGICallableCache *callable_cache,
                              PyGIArgCache      *arg_cache,
diff --git a/gi/pygi-marshal-from-py.h b/gi/pygi-marshal-from-py.h
index 307d716..99ee2b6 100644
--- a/gi/pygi-marshal-from-py.h
+++ b/gi/pygi-marshal-from-py.h
@@ -185,6 +185,10 @@ gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState   *state,
                                                    GIArgument        *arg);
 
 /* Simplified marshalers shared between vfunc/closure and direct function calls. */
+gboolean _pygi_marshal_from_py_basic_type (PyObject   *object,   /* in */
+                                           GIArgument *arg,      /* out */
+                                           GITypeTag   type_tag,
+                                           GITransfer  transfer);
 
 gboolean pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
                                        GIArgument *arg,  /*out*/


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