[pygobject] Cleanup struct marshalling function names



commit 1e606287e1244cba45e3bb174d27f1c01e4f9577
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun May 25 02:00:00 2014 -0700

    Cleanup struct marshalling function names
    
    Use a consistent naming scheme for struct marshalling cache related
    functions. This removes prefixed underscores from function names
    as well as redundant wording.
    
    To ignore this commit with git blame use:
      git blame <this-commit-sha>^ -- gi/pygi-struct-marshal.c
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685218

 gi/pygi-argument.c       |   34 ++++----
 gi/pygi-array.c          |    2 +-
 gi/pygi-struct-marshal.c |  221 ++++++++++++++++++++--------------------------
 gi/pygi-struct-marshal.h |   56 ++++++------
 4 files changed, 142 insertions(+), 171 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 23d7c89..15be78c 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1029,16 +1029,16 @@ array_success:
                      * Further re-factoring is needed to fix this leak.
                      * See: https://bugzilla.gnome.org/show_bug.cgi?id=693405
                      */
-                    _pygi_marshal_from_py_interface_struct (object,
-                                                            &arg,
-                                                            NULL, /*arg_name*/
-                                                            info, /*interface_info*/
-                                                            g_type,
-                                                            py_type,
-                                                            transfer,
-                                                            FALSE, /*copy_reference*/
-                                                            g_struct_info_is_foreign (info),
-                                                            g_type_info_is_pointer (type_info));
+                    pygi_arg_struct_from_py_marshal (object,
+                                                     &arg,
+                                                     NULL, /*arg_name*/
+                                                     info, /*interface_info*/
+                                                     g_type,
+                                                     py_type,
+                                                     transfer,
+                                                     FALSE, /*copy_reference*/
+                                                     g_struct_info_is_foreign (info),
+                                                     g_type_info_is_pointer (type_info));
 
                     Py_DECREF (py_type);
                     break;
@@ -1372,13 +1372,13 @@ _pygi_argument_to_object (GIArgument  *arg,
                         py_type = _pygi_type_get_from_g_type (g_type);
                     }
 
-                    object = _pygi_marshal_to_py_interface_struct (arg,
-                                                                   info, /*interface_info*/
-                                                                   g_type,
-                                                                   py_type,
-                                                                   transfer,
-                                                                   FALSE, /*is_allocated*/
-                                                                   g_struct_info_is_foreign (info));
+                    object = pygi_arg_struct_to_py_marshal (arg,
+                                                            info, /*interface_info*/
+                                                            g_type,
+                                                            py_type,
+                                                            transfer,
+                                                            FALSE, /*is_allocated*/
+                                                            g_struct_info_is_foreign (info));
 
                     Py_XDECREF (py_type);
                     break;
diff --git a/gi/pygi-array.c b/gi/pygi-array.c
index c17ace0..fceffc6 100644
--- a/gi/pygi-array.c
+++ b/gi/pygi-array.c
@@ -454,7 +454,7 @@ _pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state,
                      * allocated in _pygi_marshal_from_py_array(), so we must
                      * not try to deallocate it as a slice and thus
                      * short-circuit cleanup_func. */
-                    if (cleanup_func == _pygi_marshal_cleanup_from_py_interface_struct_gvalue) {
+                    if (cleanup_func == pygi_arg_gvalue_from_py_cleanup) {
                         g_value_unset ((GValue*) item);
                         continue;
                     }
diff --git a/gi/pygi-struct-marshal.c b/gi/pygi-struct-marshal.c
index 7346eae..412153b 100644
--- a/gi/pygi-struct-marshal.c
+++ b/gi/pygi-struct-marshal.c
@@ -84,7 +84,7 @@ _is_union_member (GIInterfaceInfo *interface_info, PyObject *py_arg) {
  * GValue from Python
  */
 
-/* _pygi_marshal_from_py_gvalue:
+/* pygi_arg_gvalue_from_py_marshal:
  * py_arg: (in):
  * arg: (out):
  * transfer:
@@ -92,10 +92,10 @@ _is_union_member (GIInterfaceInfo *interface_info, PyObject *py_arg) {
  *                 when it is already holding a GValue vs. copying the value.
  */
 gboolean
-_pygi_marshal_from_py_gvalue (PyObject *py_arg,
-                              GIArgument *arg,
-                              GITransfer transfer,
-                              gboolean copy_reference) {
+pygi_arg_gvalue_from_py_marshal (PyObject *py_arg,
+                                 GIArgument *arg,
+                                 GITransfer transfer,
+                                 gboolean copy_reference) {
     GValue *value;
     GType object_type;
 
@@ -130,11 +130,11 @@ _pygi_marshal_from_py_gvalue (PyObject *py_arg,
 }
 
 void
-_pygi_marshal_cleanup_from_py_interface_struct_gvalue (PyGIInvokeState *state,
-                                                       PyGIArgCache    *arg_cache,
-                                                       PyObject        *py_arg,
-                                                       gpointer         data,
-                                                       gboolean         was_processed)
+pygi_arg_gvalue_from_py_cleanup (PyGIInvokeState *state,
+                                 PyGIArgCache    *arg_cache,
+                                 PyObject        *py_arg,
+                                 gpointer         data,
+                                 gboolean         was_processed)
 {
     /* Note py_arg can be NULL for hash table which is a bug. */
     if (was_processed && py_arg != NULL) {
@@ -151,13 +151,13 @@ _pygi_marshal_cleanup_from_py_interface_struct_gvalue (PyGIInvokeState *state,
     }
 }
 
-/* _pygi_marshal_from_py_gclosure:
+/* pygi_arg_gclosure_from_py_marshal:
  * py_arg: (in):
  * arg: (out):
  */
 gboolean
-_pygi_marshal_from_py_gclosure(PyObject *py_arg,
-                               GIArgument *arg)
+pygi_arg_gclosure_from_py_marshal (PyObject *py_arg,
+                                   GIArgument *arg)
 {
     GClosure *closure;
     GType object_gtype = pyg_type_from_object_strict (py_arg, FALSE);
@@ -183,21 +183,21 @@ _pygi_marshal_from_py_gclosure(PyObject *py_arg,
     return TRUE;
 }
 
-/* _pygi_marshal_from_py_interface_struct:
+/* pygi_arg_struct_from_py_marshal:
  *
  * Dispatcher to various sub marshalers
  */
 gboolean
-_pygi_marshal_from_py_interface_struct (PyObject *py_arg,
-                                        GIArgument *arg,
-                                        const gchar *arg_name,
-                                        GIBaseInfo *interface_info,
-                                        GType g_type,
-                                        PyObject *py_type,
-                                        GITransfer transfer,
-                                        gboolean copy_reference,
-                                        gboolean is_foreign,
-                                        gboolean is_pointer)
+pygi_arg_struct_from_py_marshal (PyObject *py_arg,
+                                 GIArgument *arg,
+                                 const gchar *arg_name,
+                                 GIBaseInfo *interface_info,
+                                 GType g_type,
+                                 PyObject *py_type,
+                                 GITransfer transfer,
+                                 gboolean copy_reference,
+                                 gboolean is_foreign,
+                                 gboolean is_pointer)
 {
     gboolean is_union = FALSE;
 
@@ -211,12 +211,12 @@ _pygi_marshal_from_py_interface_struct (PyObject *py_arg,
      */
 
     if (g_type_is_a (g_type, G_TYPE_CLOSURE)) {
-        return _pygi_marshal_from_py_gclosure (py_arg, arg);
+        return pygi_arg_gclosure_from_py_marshal (py_arg, arg);
     } else if (g_type_is_a (g_type, G_TYPE_VALUE)) {
-        return _pygi_marshal_from_py_gvalue(py_arg,
-                                            arg,
-                                            transfer,
-                                            copy_reference);
+        return pygi_arg_gvalue_from_py_marshal(py_arg,
+                                               arg,
+                                               transfer,
+                                               copy_reference);
     } else if (is_foreign) {
         PyObject *success;
         success = pygi_struct_foreign_convert_to_g_argument (py_arg,
@@ -292,25 +292,25 @@ type_error:
 }
 
 static gboolean
-_pygi_marshal_from_py_interface_struct_cache_adapter (PyGIInvokeState   *state,
-                                                      PyGICallableCache *callable_cache,
-                                                      PyGIArgCache      *arg_cache,
-                                                      PyObject          *py_arg,
-                                                      GIArgument        *arg,
-                                                      gpointer          *cleanup_data)
+arg_struct_from_py_marshal_adapter (PyGIInvokeState   *state,
+                                    PyGICallableCache *callable_cache,
+                                    PyGIArgCache      *arg_cache,
+                                    PyObject          *py_arg,
+                                    GIArgument        *arg,
+                                    gpointer          *cleanup_data)
 {
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
 
-    gboolean res =  _pygi_marshal_from_py_interface_struct (py_arg,
-                                                            arg,
-                                                            arg_cache->arg_name,
-                                                            iface_cache->interface_info,
-                                                            iface_cache->g_type,
-                                                            iface_cache->py_type,
-                                                            arg_cache->transfer,
-                                                            TRUE, /*copy_reference*/
-                                                            iface_cache->is_foreign,
-                                                            arg_cache->is_pointer);
+    gboolean res =  pygi_arg_struct_from_py_marshal (py_arg,
+                                                     arg,
+                                                     arg_cache->arg_name,
+                                                     iface_cache->interface_info,
+                                                     iface_cache->g_type,
+                                                     iface_cache->py_type,
+                                                     arg_cache->transfer,
+                                                     TRUE, /*copy_reference*/
+                                                     iface_cache->is_foreign,
+                                                     arg_cache->is_pointer);
 
     /* Assume struct marshaling is always a pointer and assign cleanup_data
      * here rather than passing it further down the chain.
@@ -320,27 +320,28 @@ _pygi_marshal_from_py_interface_struct_cache_adapter (PyGIInvokeState   *state,
 }
 
 static void
-_pygi_marshal_cleanup_from_py_interface_struct_foreign (PyGIInvokeState *state,
-                                                        PyGIArgCache    *arg_cache,
-                                                        PyObject        *py_arg,
-                                                        gpointer         data,
-                                                        gboolean         was_processed)
+arg_foreign_from_py_cleanup (PyGIInvokeState *state,
+                             PyGIArgCache    *arg_cache,
+                             PyObject        *py_arg,
+                             gpointer         data,
+                             gboolean         was_processed)
 {
-    if (state->failed && was_processed)
+    if (state->failed && was_processed) {
         pygi_struct_foreign_release (
             ( (PyGIInterfaceCache *)arg_cache)->interface_info,
             data);
+    }
 }
 
 
 PyObject *
-_pygi_marshal_to_py_interface_struct (GIArgument *arg,
-                                      GIInterfaceInfo *interface_info,
-                                      GType g_type,
-                                      PyObject *py_type,
-                                      GITransfer transfer,
-                                      gboolean is_allocated,
-                                      gboolean is_foreign)
+pygi_arg_struct_to_py_marshal (GIArgument *arg,
+                               GIInterfaceInfo *interface_info,
+                               GType g_type,
+                               PyObject *py_type,
+                               GITransfer transfer,
+                               gboolean is_allocated,
+                               gboolean is_foreign)
 {
     PyObject *py_obj = NULL;
 
@@ -400,89 +401,63 @@ _pygi_marshal_to_py_interface_struct (GIArgument *arg,
 }
 
 static PyObject *
-_pygi_marshal_to_py_interface_struct_cache_adapter (PyGIInvokeState   *state,
-                                                    PyGICallableCache *callable_cache,
-                                                    PyGIArgCache      *arg_cache,
-                                                    GIArgument        *arg)
+arg_struct_to_py_marshal_adapter (PyGIInvokeState   *state,
+                                  PyGICallableCache *callable_cache,
+                                  PyGIArgCache      *arg_cache,
+                                  GIArgument        *arg)
 {
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
 
-    return _pygi_marshal_to_py_interface_struct (arg,
-                                                 iface_cache->interface_info,
-                                                 iface_cache->g_type,
-                                                 iface_cache->py_type,
-                                                 arg_cache->transfer,
-                                                 arg_cache->is_caller_allocates,
-                                                 iface_cache->is_foreign);
+    return pygi_arg_struct_to_py_marshal (arg,
+                                          iface_cache->interface_info,
+                                          iface_cache->g_type,
+                                          iface_cache->py_type,
+                                          arg_cache->transfer,
+                                          arg_cache->is_caller_allocates,
+                                          iface_cache->is_foreign);
 }
 
 static void
-_pygi_marshal_cleanup_to_py_interface_struct_foreign (PyGIInvokeState *state,
-                                                      PyGIArgCache    *arg_cache,
-                                                      PyObject        *dummy,
-                                                      gpointer         data,
-                                                      gboolean         was_processed)
+arg_foreign_to_py_cleanup (PyGIInvokeState *state,
+                           PyGIArgCache    *arg_cache,
+                           PyObject        *dummy,
+                           gpointer         data,
+                           gboolean         was_processed)
 {
-    if (!was_processed && arg_cache->transfer == GI_TRANSFER_EVERYTHING)
+    if (!was_processed && arg_cache->transfer == GI_TRANSFER_EVERYTHING) {
         pygi_struct_foreign_release (
             ( (PyGIInterfaceCache *)arg_cache)->interface_info,
             data);
+    }
 }
 
 
 static void
-_arg_cache_from_py_interface_struct_setup (PyGIArgCache *arg_cache,
-                                           GIInterfaceInfo *iface_info,
-                                           GITransfer transfer)
+arg_struct_from_py_setup (PyGIArgCache     *arg_cache,
+                          GIInterfaceInfo  *iface_info,
+                          GITransfer        transfer)
 {
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
     iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info);
-    arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct_cache_adapter;
+    arg_cache->from_py_marshaller = arg_struct_from_py_marshal_adapter;
 
     if (iface_cache->g_type == G_TYPE_VALUE)
-        arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_interface_struct_gvalue;
+        arg_cache->from_py_cleanup = pygi_arg_gvalue_from_py_cleanup;
     else if (iface_cache->is_foreign)
-        arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_interface_struct_foreign;
+        arg_cache->from_py_cleanup = arg_foreign_from_py_cleanup;
 }
 
 static void
-_arg_cache_to_py_interface_struct_setup (PyGIArgCache *arg_cache,
-                                         GIInterfaceInfo *iface_info,
-                                         GITransfer transfer)
+arg_struct_to_py_setup (PyGIArgCache     *arg_cache,
+                        GIInterfaceInfo  *iface_info,
+                        GITransfer        transfer)
 {
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
     iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info);
-    arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct_cache_adapter;
+    arg_cache->to_py_marshaller = arg_struct_to_py_marshal_adapter;
 
     if (iface_cache->is_foreign)
-        arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_interface_struct_foreign;
-}
-
-static gboolean
-pygi_arg_struct_setup_from_info (PyGIArgCache    *arg_cache,
-                                 GITypeInfo      *type_info,
-                                 GIArgInfo       *arg_info,
-                                 GITransfer       transfer,
-                                 PyGIDirection    direction,
-                                 GIInterfaceInfo *iface_info)
-{
-    /* NOTE: usage of pygi_arg_interface_new_from_info already calls
-     * pygi_arg_interface_setup so no need to do it here.
-     */
-
-    if (direction & PYGI_DIRECTION_FROM_PYTHON) {
-        _arg_cache_from_py_interface_struct_setup (arg_cache,
-                                                   iface_info,
-                                                   transfer);
-    }
-
-    if (direction & PYGI_DIRECTION_TO_PYTHON) {
-        _arg_cache_to_py_interface_struct_setup (arg_cache,
-                                                 iface_info,
-                                                 transfer);
-    }
-
-    return TRUE;
+        arg_cache->to_py_cleanup = arg_foreign_to_py_cleanup;
 }
 
 PyGIArgCache *
@@ -492,7 +467,6 @@ pygi_arg_struct_new_from_info (GITypeInfo      *type_info,
                                PyGIDirection    direction,
                                GIInterfaceInfo *iface_info)
 {
-    gboolean res = FALSE;
     PyGIArgCache *cache = NULL;
 
     cache = pygi_arg_interface_new_from_info (type_info,
@@ -503,16 +477,13 @@ pygi_arg_struct_new_from_info (GITypeInfo      *type_info,
     if (cache == NULL)
         return NULL;
 
-    res = pygi_arg_struct_setup_from_info (cache,
-                                           type_info,
-                                           arg_info,
-                                           transfer,
-                                           direction,
-                                           iface_info);
-    if (res) {
-        return cache;
-    } else {
-        pygi_arg_cache_free (cache);
-        return NULL;
+    if (direction & PYGI_DIRECTION_FROM_PYTHON) {
+        arg_struct_from_py_setup (cache, iface_info, transfer);
     }
+
+    if (direction & PYGI_DIRECTION_TO_PYTHON) {
+        arg_struct_to_py_setup (cache, iface_info, transfer);
+    }
+
+    return cache;
 }
diff --git a/gi/pygi-struct-marshal.h b/gi/pygi-struct-marshal.h
index 66e3ecf..6a7f92d 100644
--- a/gi/pygi-struct-marshal.h
+++ b/gi/pygi-struct-marshal.h
@@ -33,40 +33,40 @@ PyGIArgCache *pygi_arg_struct_new_from_info  (GITypeInfo      *type_info,
                                               GIInterfaceInfo *iface_info);
 
 
-gboolean _pygi_marshal_from_py_gvalue (PyObject *py_arg, /*in*/
-                                       GIArgument *arg,  /*out*/
-                                       GITransfer transfer,
-                                       gboolean is_allocated);
+gboolean pygi_arg_gvalue_from_py_marshal     (PyObject        *py_arg, /*in*/
+                                              GIArgument      *arg,    /*out*/
+                                              GITransfer       transfer,
+                                              gboolean         is_allocated);
 
 
-gboolean _pygi_marshal_from_py_gclosure(PyObject *py_arg, /*in*/
-                                        GIArgument *arg); /*out*/
+gboolean pygi_arg_gclosure_from_py_marshal   (PyObject        *py_arg, /*in*/
+                                              GIArgument      *arg);   /*out*/
 
-gboolean _pygi_marshal_from_py_interface_struct (PyObject *py_arg,
-                                                 GIArgument *arg,
-                                                 const gchar *arg_name,
-                                                 GIBaseInfo *interface_info,
-                                                 GType g_type,
-                                                 PyObject *py_type,
-                                                 GITransfer transfer,
-                                                 gboolean is_allocated,
-                                                 gboolean is_foreign,
-                                                 gboolean is_pointer);
+gboolean pygi_arg_struct_from_py_marshal     (PyObject        *py_arg,
+                                              GIArgument      *arg,
+                                              const gchar     *arg_name,
+                                              GIBaseInfo      *interface_info,
+                                              GType            g_type,
+                                              PyObject        *py_type,
+                                              GITransfer       transfer,
+                                              gboolean         is_allocated,
+                                              gboolean         is_foreign,
+                                              gboolean         is_pointer);
 
-PyObject *_pygi_marshal_to_py_interface_struct (GIArgument *arg,
-                                                GIInterfaceInfo *interface_info,
-                                                GType g_type,
-                                                PyObject *py_type,
-                                                GITransfer transfer,
-                                                gboolean is_allocated,
-                                                gboolean is_foreign);
+PyObject *pygi_arg_struct_to_py_marshal      (GIArgument      *arg,
+                                              GIInterfaceInfo *interface_info,
+                                              GType            g_type,
+                                              PyObject        *py_type,
+                                              GITransfer       transfer,
+                                              gboolean         is_allocated,
+                                              gboolean         is_foreign);
 
 /* Needed for hack in pygi-arg-garray.c */
-void _pygi_marshal_cleanup_from_py_interface_struct_gvalue   (PyGIInvokeState *state,
-                                                              PyGIArgCache    *arg_cache,
-                                                              PyObject        *py_arg,
-                                                              gpointer         data,
-                                                              gboolean         was_processed);
+void pygi_arg_gvalue_from_py_cleanup         (PyGIInvokeState *state,
+                                              PyGIArgCache    *arg_cache,
+                                              PyObject        *py_arg,
+                                              gpointer         data,
+                                              gboolean         was_processed);
 
 G_END_DECLS
 


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