[pygobject] cache refactoring: Move GError arg setup and marshaling to new file



commit 18d8274724484a27e05d2e60baac1f20c72b6d2b
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sat Oct 12 11:30:36 2013 -0700

    cache refactoring: Move GError arg setup and marshaling to new file
    
    Move GError argument caching and marshaling fragments into
    isolated file: pygi-error.c.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709700

 gi/Makefile.am            |    2 +
 gi/pygi-cache.c           |   93 ++++++++++++---------------------------
 gi/pygi-error.c           |  109 +++++++++++++++++++++++++++++++++++++++++++++
 gi/pygi-error.h           |   35 ++++++++++++++
 gi/pygi-marshal-from-py.c |   13 -----
 gi/pygi-marshal-from-py.h |    6 ---
 gi/pygi-marshal-to-py.c   |   22 ---------
 gi/pygi-marshal-to-py.h   |    4 --
 8 files changed, 174 insertions(+), 110 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index df4e803..d19a19d 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -109,6 +109,8 @@ _gi_la_SOURCES = \
        pygi-list.h \
        pygi-array.c \
        pygi-array.h \
+       pygi-error.c \
+       pygi-error.h \
        pygi-hashtable.c \
        pygi-hashtable.h
 _gi_la_CFLAGS = \
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 8158c37..d91d8ab 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -31,6 +31,7 @@
 #include "pygi-basictype.h"
 #include "pygi-list.h"
 #include "pygi-array.h"
+#include "pygi-error.h"
 
 
 PyGIArgCache * _arg_cache_new_for_interface (GIInterfaceInfo *iface_info,
@@ -276,20 +277,6 @@ _arg_cache_alloc (void)
 }
 
 static void
-_arg_cache_from_py_gerror_setup (PyGIArgCache *arg_cache)
-{
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_gerror;
-    arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
-}
-
-static void
-_arg_cache_to_py_gerror_setup (PyGIArgCache *arg_cache)
-{
-    arg_cache->to_py_marshaller = _pygi_marshal_to_py_gerror;
-    arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
-}
-
-static void
 _arg_cache_from_py_interface_union_setup (PyGIArgCache *arg_cache,
                                           GITransfer transfer)
 {
@@ -553,14 +540,11 @@ _arg_cache_new (GITypeInfo *type_info,
        case GI_TYPE_TAG_GTYPE:
        case GI_TYPE_TAG_UTF8:
        case GI_TYPE_TAG_FILENAME:
-           arg_cache = pygi_arg_basic_type_new_from_info (type_info, arg_info, transfer, direction);
-           if (arg_cache) {
-               arg_cache->py_arg_index = py_arg_index;
-               arg_cache->c_arg_index = c_arg_index;
-               return arg_cache;
-           } else {
-               return NULL;
-           }
+           arg_cache = pygi_arg_basic_type_new_from_info (type_info,
+                                                          arg_info,
+                                                          transfer,
+                                                          direction);
+           break;
 
        case GI_TYPE_TAG_ARRAY:
            {
@@ -577,42 +561,29 @@ _arg_cache_new (GITypeInfo *type_info,
                                               direction,
                                               c_arg_index,
                                               &py_arg_index);
-
-               arg_cache->py_arg_index = py_arg_index;
-               arg_cache->c_arg_index = c_arg_index;
-               return arg_cache;
            }
+           break;
+
        case GI_TYPE_TAG_GLIST:
-           {
-               arg_cache = pygi_arg_glist_new_from_info (type_info,
-                                                         arg_info,
-                                                         transfer,
-                                                         direction);
-               if (arg_cache == NULL)
-                   return NULL;
+           arg_cache = pygi_arg_glist_new_from_info (type_info,
+                                                     arg_info,
+                                                     transfer,
+                                                     direction);
+           break;
 
-               arg_cache->py_arg_index = py_arg_index;
-               arg_cache->c_arg_index = c_arg_index;
-               return arg_cache;
-           }
        case GI_TYPE_TAG_GSLIST:
-           {
-               arg_cache = pygi_arg_gslist_new_from_info (type_info,
+           arg_cache = pygi_arg_gslist_new_from_info (type_info,
+                                                      arg_info,
+                                                      transfer,
+                                                      direction);
+           break;
+
+       case GI_TYPE_TAG_GHASH:
+           arg_cache = pygi_arg_hash_table_new_from_info (type_info,
                                                           arg_info,
                                                           transfer,
                                                           direction);
-               if (arg_cache == NULL)
-                   return NULL;
-
-               arg_cache->py_arg_index = py_arg_index;
-               arg_cache->c_arg_index = c_arg_index;
-               return arg_cache;
-            }
-       case GI_TYPE_TAG_GHASH:
-           arg_cache = pygi_arg_hash_table_new_from_info (type_info, arg_info, transfer, direction);
-           arg_cache->py_arg_index = py_arg_index;
-           arg_cache->c_arg_index = c_arg_index;
-           return arg_cache;
+           break;
 
        case GI_TYPE_TAG_INTERFACE:
            {
@@ -625,26 +596,18 @@ _arg_cache_new (GITypeInfo *type_info,
                                                          callable_cache);
 
                g_base_info_unref ( (GIBaseInfo *)interface_info);
-               arg_cache->py_arg_index = py_arg_index;
-               arg_cache->c_arg_index = c_arg_index;
-               return arg_cache;
            }
-       case GI_TYPE_TAG_ERROR:
-           arg_cache = _arg_cache_alloc ();
-           if (arg_cache == NULL)
-               break;
-
-           if (direction & PYGI_DIRECTION_FROM_PYTHON)
-               _arg_cache_from_py_gerror_setup (arg_cache);
-
-           if (direction & PYGI_DIRECTION_TO_PYTHON)
-               _arg_cache_to_py_gerror_setup (arg_cache);
+           break;
 
+       case GI_TYPE_TAG_ERROR:
+           arg_cache = pygi_arg_gerror_new_from_info (type_info,
+                                                      arg_info,
+                                                      transfer,
+                                                      direction);
            break;
     }
 
     if (arg_cache != NULL) {
-        pygi_arg_base_setup (arg_cache, type_info, arg_info, transfer, direction);
         arg_cache->py_arg_index = py_arg_index;
         arg_cache->c_arg_index = c_arg_index;
     }
diff --git a/gi/pygi-error.c b/gi/pygi-error.c
new file mode 100644
index 0000000..33bf928
--- /dev/null
+++ b/gi/pygi-error.c
@@ -0,0 +1,109 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2011 John (J5) Palmieri <johnp redhat com>
+ * Copyright (C) 2014 Simon Feltman <sfeltman gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "pyglib.h"
+#include "pygi-private.h"
+#include "pygi-error.h"
+
+
+static gboolean
+_pygi_marshal_from_py_gerror (PyGIInvokeState   *state,
+                              PyGICallableCache *callable_cache,
+                              PyGIArgCache      *arg_cache,
+                              PyObject          *py_arg,
+                              GIArgument        *arg,
+                              gpointer          *cleanup_data)
+{
+    PyErr_Format (PyExc_NotImplementedError,
+                  "Marshalling for GErrors is not implemented");
+    return FALSE;
+}
+
+static PyObject *
+_pygi_marshal_to_py_gerror (PyGIInvokeState   *state,
+                            PyGICallableCache *callable_cache,
+                            PyGIArgCache      *arg_cache,
+                            GIArgument        *arg)
+{
+    GError *error = arg->v_pointer;
+    PyObject *py_obj = NULL;
+
+    py_obj = pyglib_error_marshal(&error);
+
+    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && error != NULL) {
+        g_error_free (error);
+    }
+
+    if (py_obj != NULL) {
+        return py_obj;
+    } else {
+        Py_RETURN_NONE;
+    }
+}
+
+static gboolean
+pygi_arg_gerror_setup_from_info (PyGIArgCache  *arg_cache,
+                                 GITypeInfo    *type_info,
+                                 GIArgInfo     *arg_info,
+                                 GITransfer     transfer,
+                                 PyGIDirection  direction)
+{
+    if (!pygi_arg_base_setup (arg_cache, type_info, arg_info, transfer, direction)) {
+        return FALSE;
+    }
+
+    if (direction & PYGI_DIRECTION_FROM_PYTHON) {
+        arg_cache->from_py_marshaller = _pygi_marshal_from_py_gerror;
+        arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
+    }
+
+    if (direction & PYGI_DIRECTION_TO_PYTHON) {
+        arg_cache->to_py_marshaller = _pygi_marshal_to_py_gerror;
+        arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD;
+    }
+
+    return TRUE;
+}
+
+PyGIArgCache *
+pygi_arg_gerror_new_from_info (GITypeInfo   *type_info,
+                               GIArgInfo    *arg_info,
+                               GITransfer    transfer,
+                               PyGIDirection direction)
+{
+    gboolean res = FALSE;
+    PyGIArgCache *arg_cache = NULL;
+
+    arg_cache = _arg_cache_alloc ();
+    if (arg_cache == NULL)
+        return NULL;
+
+    res = pygi_arg_gerror_setup_from_info (arg_cache,
+                                           type_info,
+                                           arg_info,
+                                           transfer,
+                                           direction);
+    if (res) {
+        return arg_cache;
+    } else {
+        _pygi_arg_cache_free (arg_cache);
+        return NULL;
+    }
+}
diff --git a/gi/pygi-error.h b/gi/pygi-error.h
new file mode 100644
index 0000000..fdeb32f
--- /dev/null
+++ b/gi/pygi-error.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2014 Simon Feltman <sfeltman gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __PYGI_ERROR_H__
+#define __PYGI_ERROR_H__
+
+#include <girepository.h>
+#include "pygi-cache.h"
+
+G_BEGIN_DECLS
+
+PyGIArgCache *pygi_arg_gerror_new_from_info  (GITypeInfo    *type_info,
+                                              GIArgInfo     *arg_info,   /* may be null */
+                                              GITransfer     transfer,
+                                              PyGIDirection  direction);
+
+G_END_DECLS
+
+#endif /*__PYGI_ERROR_H__*/
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index d371432..c6fe1c2 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -140,19 +140,6 @@ _is_union_member (GIInterfaceInfo *interface_info, PyObject *py_arg) {
     return is_member;
 }
 
-gboolean
-_pygi_marshal_from_py_gerror (PyGIInvokeState   *state,
-                              PyGICallableCache *callable_cache,
-                              PyGIArgCache      *arg_cache,
-                              PyObject          *py_arg,
-                              GIArgument        *arg,
-                              gpointer          *cleanup_data)
-{
-    PyErr_Format (PyExc_NotImplementedError,
-                  "Marshalling for GErrors is not implemented");
-    return FALSE;
-}
-
 /* _pygi_destroy_notify_dummy:
  *
  * Dummy method used in the occasion when a method has a GDestroyNotify
diff --git a/gi/pygi-marshal-from-py.h b/gi/pygi-marshal-from-py.h
index 89f6f91..a49c179 100644
--- a/gi/pygi-marshal-from-py.h
+++ b/gi/pygi-marshal-from-py.h
@@ -33,12 +33,6 @@ G_BEGIN_DECLS
 gboolean _pygi_marshal_from_py_ssize_t     (PyGIArgCache      *arg_cache,
                                             Py_ssize_t         size,
                                             GIArgument        *arg);
-gboolean _pygi_marshal_from_py_gerror      (PyGIInvokeState   *state,
-                                            PyGICallableCache *callable_cache,
-                                            PyGIArgCache      *arg_cache,
-                                            PyObject          *py_arg,
-                                            GIArgument        *arg,
-                                            gpointer          *cleanup_data);
 gboolean _pygi_marshal_from_py_interface_callback (PyGIInvokeState   *state,
                                                    PyGICallableCache *callable_cache,
                                                    PyGIArgCache      *arg_cache,
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 645b248..e890b1e 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -75,28 +75,6 @@ gi_argument_to_c_long (GIArgument *arg_in,
 }
 
 PyObject *
-_pygi_marshal_to_py_gerror (PyGIInvokeState   *state,
-                            PyGICallableCache *callable_cache,
-                            PyGIArgCache      *arg_cache,
-                            GIArgument        *arg)
-{
-    GError *error = arg->v_pointer;
-    PyObject *py_obj = NULL;
-
-    py_obj = pyglib_error_marshal(&error);
-
-    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && error != NULL) {
-        g_error_free (error);
-    }
-
-    if (py_obj != NULL) {
-        return py_obj;
-    } else {
-        Py_RETURN_NONE;
-    }
-}
-
-PyObject *
 _pygi_marshal_to_py_interface_callback (PyGIInvokeState   *state,
                                         PyGICallableCache *callable_cache,
                                         PyGIArgCache      *arg_cache,
diff --git a/gi/pygi-marshal-to-py.h b/gi/pygi-marshal-to-py.h
index 5eec183..edf1989 100644
--- a/gi/pygi-marshal-to-py.h
+++ b/gi/pygi-marshal-to-py.h
@@ -22,10 +22,6 @@
 #ifndef __PYGI_MARSHAL_TO_PY_H__
 #define __PYGI_MARSHAL_TO_PY_H__
 
-PyObject *_pygi_marshal_to_py_gerror    (PyGIInvokeState   *state,
-                                         PyGICallableCache *callable_cache,
-                                         PyGIArgCache      *arg_cache,
-                                         GIArgument        *arg);
 PyObject *_pygi_marshal_to_py_interface_callback(PyGIInvokeState   *state,
                                                  PyGICallableCache *callable_cache,
                                                  PyGIArgCache      *arg_cache,


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