[pygobject] Unify and clean up from Python marshalers for basic types



commit cba401ac1543c2fdb68fff0dba8f6da7eed23bfa
Author: Simon Feltman <sfeltman src gnome org>
Date:   Tue Jul 23 13:06:33 2013 -0700

    Unify and clean up from Python marshalers for basic types
    
    Unify and cleanup boolean, float, double, gtype, unichar, utf8,
    and filename marshalers.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693405

 gi/pygi-cache.c           |  101 +-------------------------------------------
 gi/pygi-marshal-from-py.c |   86 +++++++++++---------------------------
 gi/pygi-marshal-from-py.h |   30 -------------
 3 files changed, 28 insertions(+), 189 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index ed4878c..ca71e75 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -284,34 +284,10 @@ _arg_cache_to_py_void_setup (PyGIArgCache *arg_cache)
 }
 
 static void
-_arg_cache_from_py_float_setup (PyGIArgCache *arg_cache)
-{
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_float;
-}
-
-static void
-_arg_cache_from_py_double_setup (PyGIArgCache *arg_cache)
-{
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_double;
-}
-
-static void
-_arg_cache_from_py_unichar_setup (PyGIArgCache *arg_cache)
-{
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_unichar;
-}
-
-static void
-_arg_cache_from_py_gtype_setup (PyGIArgCache *arg_cache)
-{
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_gtype;
-}
-
-static void
 _arg_cache_from_py_utf8_setup (PyGIArgCache *arg_cache,
                                GITransfer transfer)
 {
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_utf8;
+    arg_cache->from_py_marshaller = _pygi_marshal_from_py_basic_type_cache_adapter;
     arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_utf8;
 }
 
@@ -323,22 +299,6 @@ _arg_cache_to_py_utf8_setup (PyGIArgCache *arg_cache,
     arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
 }
 
-static void
-_arg_cache_from_py_filename_setup (PyGIArgCache *arg_cache,
-                                 GITransfer transfer)
-{
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_filename;
-    arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_utf8;
-}
-
-static void
-_arg_cache_to_py_filename_setup (PyGIArgCache *arg_cache,
-                                 GITransfer transfer)
-{
-    arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
-    arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
-}
-
 static gboolean
 _arg_cache_from_py_array_setup (PyGIArgCache *arg_cache,
                                 PyGICallableCache *callable_cache,
@@ -758,66 +718,23 @@ _arg_cache_new (GITypeInfo *type_info,
        case GI_TYPE_TAG_UINT32:
        case GI_TYPE_TAG_INT64:
        case GI_TYPE_TAG_UINT64:
-           arg_cache = _arg_cache_alloc ();
-           if (arg_cache == NULL)
-               break;
-
-           if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_from_py_basic_type_setup (arg_cache);
-
-           if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_to_py_basic_type_setup (arg_cache);
-
-           break;
        case GI_TYPE_TAG_FLOAT:
-           arg_cache = _arg_cache_alloc ();
-           if (arg_cache == NULL)
-               break;
-
-           if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_from_py_float_setup (arg_cache);
-
-           if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_to_py_basic_type_setup (arg_cache);
-
-           break;
        case GI_TYPE_TAG_DOUBLE:
-           arg_cache = _arg_cache_alloc ();
-           if (arg_cache == NULL)
-               break;
-
-           if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_from_py_double_setup (arg_cache);
-
-           if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_to_py_basic_type_setup (arg_cache);
-
-           break;
        case GI_TYPE_TAG_UNICHAR:
-           arg_cache = _arg_cache_alloc ();
-           if (arg_cache == NULL)
-               break;
-
-           if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_from_py_unichar_setup (arg_cache);
-
-           if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_to_py_basic_type_setup (arg_cache);
-
-           break;
        case GI_TYPE_TAG_GTYPE:
            arg_cache = _arg_cache_alloc ();
            if (arg_cache == NULL)
                break;
 
            if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_from_py_gtype_setup (arg_cache);
+               _arg_cache_from_py_basic_type_setup (arg_cache);
 
            if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
                _arg_cache_to_py_basic_type_setup (arg_cache);
 
            break;
        case GI_TYPE_TAG_UTF8:
+       case GI_TYPE_TAG_FILENAME:
            arg_cache = _arg_cache_alloc ();
            if (arg_cache == NULL)
                break;
@@ -829,18 +746,6 @@ _arg_cache_new (GITypeInfo *type_info,
                _arg_cache_to_py_utf8_setup (arg_cache, transfer);
 
            break;
-       case GI_TYPE_TAG_FILENAME:
-           arg_cache = _arg_cache_alloc ();
-           if (arg_cache == NULL)
-               break;
-
-           if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_from_py_filename_setup (arg_cache, transfer);
-
-           if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
-               _arg_cache_to_py_filename_setup (arg_cache, transfer);
-
-           break;
        case GI_TYPE_TAG_ARRAY:
            {
                PyGISequenceCache *seq_cache =
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index f213cf8..f12ad03 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -314,11 +314,8 @@ _pygi_py_arg_to_double (PyObject *py_arg, double *double_)
     return TRUE;
 }
 
-gboolean
-_pygi_marshal_from_py_float (PyGIInvokeState   *state,
-                             PyGICallableCache *callable_cache,
-                             PyGIArgCache      *arg_cache,
-                             PyObject          *py_arg,
+static gboolean
+_pygi_marshal_from_py_float (PyObject          *py_arg,
                              GIArgument        *arg)
 {
     double double_;
@@ -333,11 +330,8 @@ _pygi_marshal_from_py_float (PyGIInvokeState   *state,
     return TRUE;
 }
 
-gboolean
-_pygi_marshal_from_py_double (PyGIInvokeState   *state,
-                              PyGICallableCache *callable_cache,
-                              PyGIArgCache      *arg_cache,
-                              PyObject          *py_arg,
+static gboolean
+_pygi_marshal_from_py_double (PyObject          *py_arg,
                               GIArgument        *arg)
 {
     double double_;
@@ -352,11 +346,8 @@ _pygi_marshal_from_py_double (PyGIInvokeState   *state,
     return TRUE;
 }
 
-gboolean
-_pygi_marshal_from_py_unichar (PyGIInvokeState   *state,
-                               PyGICallableCache *callable_cache,
-                               PyGIArgCache      *arg_cache,
-                               PyObject          *py_arg,
+static gboolean
+_pygi_marshal_from_py_unichar (PyObject          *py_arg,
                                GIArgument        *arg)
 {
     Py_ssize_t size;
@@ -407,11 +398,8 @@ _pygi_marshal_from_py_unichar (PyGIInvokeState   *state,
     return TRUE;
 }
 
-gboolean
-_pygi_marshal_from_py_gtype (PyGIInvokeState   *state,
-                             PyGICallableCache *callable_cache,
-                             PyGIArgCache      *arg_cache,
-                             PyObject          *py_arg,
+static gboolean
+_pygi_marshal_from_py_gtype (PyObject          *py_arg,
                              GIArgument        *arg)
 {
     long type_ = pyg_type_from_object (py_arg);
@@ -425,11 +413,9 @@ _pygi_marshal_from_py_gtype (PyGIInvokeState   *state,
     arg->v_long = type_;
     return TRUE;
 }
-gboolean
-_pygi_marshal_from_py_utf8 (PyGIInvokeState   *state,
-                            PyGICallableCache *callable_cache,
-                            PyGIArgCache      *arg_cache,
-                            PyObject          *py_arg,
+
+static gboolean
+_pygi_marshal_from_py_utf8 (PyObject          *py_arg,
                             GIArgument        *arg)
 {
     gchar *string_;
@@ -462,11 +448,8 @@ _pygi_marshal_from_py_utf8 (PyGIInvokeState   *state,
     return TRUE;
 }
 
-gboolean
-_pygi_marshal_from_py_filename (PyGIInvokeState   *state,
-                                PyGICallableCache *callable_cache,
-                                PyGIArgCache      *arg_cache,
-                                PyObject          *py_arg,
+static gboolean
+_pygi_marshal_from_py_filename (PyObject          *py_arg,
                                 GIArgument        *arg)
 {
     gchar *string_;
@@ -713,46 +696,27 @@ _pygi_marshal_from_py_basic_type (PyObject   *object,   /* in */
             return _pygi_marshal_from_py_long (object, arg, type_tag, transfer);
 
         case GI_TYPE_TAG_BOOLEAN:
-        {
             arg->v_boolean = PyObject_IsTrue (object);
             break;
-        }
+
         case GI_TYPE_TAG_FLOAT:
-        {
-            _pygi_marshal_from_py_float (NULL, NULL, NULL,
-                                         object, arg);
-            break;
-        }
+            return _pygi_marshal_from_py_float (object, arg);
+
         case GI_TYPE_TAG_DOUBLE:
-        {
-            _pygi_marshal_from_py_double (NULL, NULL, NULL,
-                                          object, arg);
-            break;
-        }
+            return _pygi_marshal_from_py_double (object, arg);
+
         case GI_TYPE_TAG_GTYPE:
-        {
-            arg->v_long = pyg_type_from_object (object);
+            return _pygi_marshal_from_py_gtype (object, arg);
 
-            break;
-        }
         case GI_TYPE_TAG_UNICHAR:
-        {
-            _pygi_marshal_from_py_unichar (NULL, NULL, NULL,
-                                           object, arg);
-            break;
-        }
+            return _pygi_marshal_from_py_unichar (object, arg);
+
         case GI_TYPE_TAG_UTF8:
-        {
-            _pygi_marshal_from_py_utf8 (NULL, NULL, NULL,
-                                        object, arg);
-            break;
-        }
+            return _pygi_marshal_from_py_utf8 (object, arg);
+
         case GI_TYPE_TAG_FILENAME:
-        {
-            _pygi_marshal_from_py_filename (NULL, NULL, NULL,
-                                            object, arg);
-            break;
-        }
+            return _pygi_marshal_from_py_filename (object, arg);
+
         default:
             return FALSE;
     }
diff --git a/gi/pygi-marshal-from-py.h b/gi/pygi-marshal-from-py.h
index 7e28bce..0a60dd6 100644
--- a/gi/pygi-marshal-from-py.h
+++ b/gi/pygi-marshal-from-py.h
@@ -38,36 +38,6 @@ gboolean _pygi_marshal_from_py_void        (PyGIInvokeState   *state,
                                             PyGIArgCache      *arg_cache,
                                             PyObject          *py_arg,
                                             GIArgument        *arg);
-gboolean _pygi_marshal_from_py_float       (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg);
-gboolean _pygi_marshal_from_py_double      (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg);
-gboolean _pygi_marshal_from_py_unichar     (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg);
-gboolean _pygi_marshal_from_py_gtype       (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg);
-gboolean _pygi_marshal_from_py_utf8        (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg);
-gboolean _pygi_marshal_from_py_filename    (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg);
 gboolean _pygi_marshal_from_py_array       (PyGIInvokeState   *state,
                                             PyGICallableCache *callable_cache,
                                             PyGIArgCache      *arg_cache,


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