[pygobject/invoke-rewrite] [gi] refactor cache structs so they inherit from ArgCache



commit 2ec4230a5180f048c26c2e4234b2a098d42f030b
Author: John (J5) Palmieri <johnp redhat com>
Date:   Sun Jan 9 15:58:06 2011 -0500

    [gi] refactor cache structs so they inherit from ArgCache

 gi/pygi-argument.c |  122 ++++++++++---------
 gi/pygi-cache.c    |  344 ++++++++++++++++++++++++++++------------------------
 gi/pygi-cache.h    |   50 ++++----
 3 files changed, 273 insertions(+), 243 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 9525ba0..e264e3d 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1991,9 +1991,9 @@ _pygi_argument_init (void)
 
 /*** argument marshaling and validating routines ***/
 
-gboolean 
+gboolean
 _pygi_marshal_in_void (PyGIState         *state,
-                       PyGIFunctionCache *function_cache, 
+                       PyGIFunctionCache *function_cache,
                        PyGIArgCache      *arg_cache,
                        PyObject          *py_arg,
                        GIArgument        *arg)
@@ -2001,13 +2001,13 @@ _pygi_marshal_in_void (PyGIState         *state,
     g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING);
 
     (*arg).v_pointer = py_arg;
-   
+
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_boolean (PyGIState         *state,
-                          PyGIFunctionCache *function_cache, 
+                          PyGIFunctionCache *function_cache,
                           PyGIArgCache      *arg_cache,
                           PyObject          *py_arg,
                           GIArgument        *arg)
@@ -2017,9 +2017,9 @@ _pygi_marshal_in_boolean (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_int8 (PyGIState         *state,
-                       PyGIFunctionCache *function_cache, 
+                       PyGIFunctionCache *function_cache,
                        PyGIArgCache      *arg_cache,
                        PyObject          *py_arg,
                        GIArgument        *arg)
@@ -2053,16 +2053,16 @@ _pygi_marshal_in_int8 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_uint8 (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
 {
     long long_;
 
-    if (PYGLIB_PyBytes_Check(py_arg)) { 
+    if (PYGLIB_PyBytes_Check(py_arg)) {
 
         if (PYGLIB_PyBytes_Size(py_arg) != 1) {
             PyErr_Format (PyExc_TypeError, "Must be a single character");
@@ -2098,9 +2098,9 @@ _pygi_marshal_in_uint8 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_int16 (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2134,9 +2134,9 @@ _pygi_marshal_in_int16 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_uint16 (PyGIState         *state,
-                         PyGIFunctionCache *function_cache, 
+                         PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
                          GIArgument        *arg)
@@ -2170,9 +2170,9 @@ _pygi_marshal_in_uint16 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_int32 (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2206,9 +2206,9 @@ _pygi_marshal_in_int32 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_uint32 (PyGIState         *state,
-                         PyGIFunctionCache *function_cache, 
+                         PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
                          GIArgument        *arg)
@@ -2248,9 +2248,9 @@ _pygi_marshal_in_uint32 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_int64 (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2290,9 +2290,9 @@ _pygi_marshal_in_int64 (PyGIState         *state,
     return TRUE;
 }
 
-gboolean 
+gboolean
 _pygi_marshal_in_uint64 (PyGIState         *state,
-                         PyGIFunctionCache *function_cache, 
+                         PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
                          GIArgument        *arg)
@@ -2334,7 +2334,7 @@ _pygi_marshal_in_uint64 (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_float (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2370,7 +2370,7 @@ _pygi_marshal_in_float (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_double (PyGIState         *state,
-                         PyGIFunctionCache *function_cache, 
+                         PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
                          GIArgument        *arg)
@@ -2406,14 +2406,14 @@ _pygi_marshal_in_double (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_unichar (PyGIState         *state,
-                          PyGIFunctionCache *function_cache, 
+                          PyGIFunctionCache *function_cache,
                           PyGIArgCache      *arg_cache,
                           PyObject          *py_arg,
                           GIArgument        *arg)
 {
     Py_ssize_t size;
     gchar *string_;
-    
+
     if (PyUnicode_Check (py_arg)) {
        PyObject *py_bytes;
 
@@ -2421,7 +2421,7 @@ _pygi_marshal_in_unichar (PyGIState         *state,
        py_bytes = PyUnicode_AsUTF8String(py_arg);
        string_ = strdup(PYGLIB_PyBytes_AsString(py_bytes));
        Py_DECREF(py_bytes);
- 
+
 #if PY_VERSION_HEX < 0x03000000
     } else if (PyString_Check (py_arg)) {
        PyObject *pyuni = PyUnicode_FromEncodedObject (py_arg, "UTF-8", "strict");
@@ -2452,7 +2452,7 @@ _pygi_marshal_in_unichar (PyGIState         *state,
 }
 gboolean
 _pygi_marshal_in_gtype (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2462,14 +2462,14 @@ _pygi_marshal_in_gtype (PyGIState         *state,
     if (type_ == 0) {
         PyErr_Format (PyExc_TypeError, "Must be gobject.GType, not %s",
                       py_arg->ob_type->tp_name);
-    } 
+    }
 
     (*arg).v_long = type_;
     return TRUE;
 }
 gboolean
 _pygi_marshal_in_utf8 (PyGIState         *state,
-                       PyGIFunctionCache *function_cache, 
+                       PyGIFunctionCache *function_cache,
                        PyGIArgCache      *arg_cache,
                        PyObject          *py_arg,
                        GIArgument        *arg)
@@ -2483,7 +2483,7 @@ _pygi_marshal_in_utf8 (PyGIState         *state,
 
         string_ = g_strdup(PYGLIB_PyBytes_AsString (pystr_obj));
         Py_DECREF(pystr_obj);
-    } 
+    }
 #if PY_VERSION_HEX < 0x03000000
     else if (PyString_Check(py_arg)) {
         string_ = g_strdup(PyString_AsString (py_arg));
@@ -2501,7 +2501,7 @@ _pygi_marshal_in_utf8 (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_filename (PyGIState         *state,
-                           PyGIFunctionCache *function_cache, 
+                           PyGIFunctionCache *function_cache,
                            PyGIArgCache      *arg_cache,
                            PyObject          *py_arg,
                            GIArgument        *arg)
@@ -2516,7 +2516,7 @@ _pygi_marshal_in_filename (PyGIState         *state,
 
         string_ = g_strdup(PYGLIB_PyBytes_AsString (pystr_obj));
         Py_DECREF(pystr_obj);
-    } 
+    }
 #if PY_VERSION_HEX < 0x03000000
     else if (PyString_Check(py_arg)) {
         string_ = g_strdup(PyString_AsString (py_arg));
@@ -2543,7 +2543,7 @@ _pygi_marshal_in_filename (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_array (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2552,6 +2552,8 @@ _pygi_marshal_in_array (PyGIState         *state,
     int i;
     Py_ssize_t length;
     GArray *array_ = NULL;
+    PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache;
+
 
     if (py_arg == Py_None) {
         (*arg).v_pointer = NULL;
@@ -2568,17 +2570,17 @@ _pygi_marshal_in_array (PyGIState         *state,
     if (length < 0)
         return FALSE;
 
-    if (arg_cache->sequence_cache->fixed_size >= 0 &&
-        arg_cache->sequence_cache->fixed_size != length) {
+    if (sequence_cache->fixed_size >= 0 &&
+        sequence_cache->fixed_size != length) {
         PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd",
-                              arg_cache->sequence_cache->fixed_size, length);
+                      sequence_cache->fixed_size, length);
 
         return FALSE;
     }
 
-    array_ = g_array_sized_new (arg_cache->sequence_cache->is_zero_terminated, 
+    array_ = g_array_sized_new (sequence_cache->is_zero_terminated,
                                 FALSE,
-                                arg_cache->sequence_cache->item_size,
+                                sequence_cache->item_size,
                                 length);
 
     if (array_ == NULL) {
@@ -2586,21 +2588,21 @@ _pygi_marshal_in_array (PyGIState         *state,
         return FALSE;
     }
 
-    if (arg_cache->sequence_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8 &&
+    if (sequence_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8 &&
         PYGLIB_PyBytes_Check(py_arg)) {
         memcpy(array_->data, PYGLIB_PyBytes_AsString(py_arg), length);
 
         goto array_success;
     }
 
-    in_marshaller = arg_cache->sequence_cache->item_cache->in_marshaller;
+    in_marshaller = sequence_cache->item_cache->in_marshaller;
     for (i = 0; i < length; i++) {
         GIArgument item;
         PyObject *py_item = PySequence_GetItem (py_arg, i);
         if (py_item == NULL) {
             int j;
-            if (arg_cache->sequence_cache->item_cache->cleanup != NULL) {
-                PyGIArgCleanupFunc cleanup = arg_cache->sequence_cache->item_cache->cleanup;
+            if (sequence_cache->item_cache->cleanup != NULL) {
+                PyGIArgCleanupFunc cleanup = sequence_cache->item_cache->cleanup;
                 /*for(j = 0; j < i; j++)
                     cleanup((gpointer)(array_->data[j]));*/
             }
@@ -2609,11 +2611,11 @@ _pygi_marshal_in_array (PyGIState         *state,
             _PyGI_ERROR_PREFIX ("Item %i: ", i);
             return FALSE;
         }
-        arg_cache->sequence_cache->item_cache->in_marshaller(state, 
-                                                             function_cache, 
-                                                             arg_cache->sequence_cache->item_cache, 
-                                                             py_item, 
-                                                             &item);
+        sequence_cache->item_cache->in_marshaller(state,
+                                                  function_cache,
+                                                  sequence_cache->item_cache,
+                                                  py_item,
+                                                  &item);
         g_array_insert_val(array_, i, item);
     }
 
@@ -2625,7 +2627,7 @@ array_success:
 
 gboolean
 _pygi_marshal_in_glist (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2637,7 +2639,7 @@ _pygi_marshal_in_glist (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_gslist (PyGIState         *state,
-                         PyGIFunctionCache *function_cache, 
+                         PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
                          GIArgument        *arg)
@@ -2649,7 +2651,7 @@ _pygi_marshal_in_gslist (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_ghash (PyGIState         *state,
-                        PyGIFunctionCache *function_cache, 
+                        PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
                         GIArgument        *arg)
@@ -2661,7 +2663,7 @@ _pygi_marshal_in_ghash (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_gerror (PyGIState         *state,
-                         PyGIFunctionCache *function_cache, 
+                         PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
                          GIArgument        *arg)
@@ -2673,7 +2675,7 @@ _pygi_marshal_in_gerror (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_callback (PyGIState         *state,
-                                     PyGIFunctionCache *function_cache, 
+                                     PyGIFunctionCache *function_cache,
                                      PyGIArgCache      *arg_cache,
                                      PyObject          *py_arg,
                                      GIArgument        *arg)
@@ -2685,7 +2687,7 @@ _pygi_marshal_in_interface_callback (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_enum (PyGIState         *state,
-                                 PyGIFunctionCache *function_cache, 
+                                 PyGIFunctionCache *function_cache,
                                  PyGIArgCache      *arg_cache,
                                  PyObject          *py_arg,
                                  GIArgument        *arg)
@@ -2697,7 +2699,7 @@ _pygi_marshal_in_interface_enum (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_flags (PyGIState         *state,
-                                  PyGIFunctionCache *function_cache, 
+                                  PyGIFunctionCache *function_cache,
                                   PyGIArgCache      *arg_cache,
                                   PyObject          *py_arg,
                                   GIArgument        *arg)
@@ -2709,7 +2711,7 @@ _pygi_marshal_in_interface_flags (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_struct (PyGIState         *state,
-                                   PyGIFunctionCache *function_cache, 
+                                   PyGIFunctionCache *function_cache,
                                    PyGIArgCache      *arg_cache,
                                    PyObject          *py_arg,
                                    GIArgument        *arg)
@@ -2721,7 +2723,7 @@ _pygi_marshal_in_interface_struct (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_interface (PyGIState         *state,
-                                      PyGIFunctionCache *function_cache, 
+                                      PyGIFunctionCache *function_cache,
                                       PyGIArgCache      *arg_cache,
                                       PyObject          *py_arg,
                                       GIArgument        *arg)
@@ -2733,7 +2735,7 @@ _pygi_marshal_in_interface_interface (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_boxed (PyGIState         *state,
-                                  PyGIFunctionCache *function_cache, 
+                                  PyGIFunctionCache *function_cache,
                                   PyGIArgCache      *arg_cache,
                                   PyObject          *py_arg,
                                   GIArgument        *arg)
@@ -2745,7 +2747,7 @@ _pygi_marshal_in_interface_boxed (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_object (PyGIState         *state,
-                                   PyGIFunctionCache *function_cache, 
+                                   PyGIFunctionCache *function_cache,
                                    PyGIArgCache      *arg_cache,
                                    PyObject          *py_arg,
                                    GIArgument        *arg)
@@ -2757,7 +2759,7 @@ _pygi_marshal_in_interface_object (PyGIState         *state,
 
 gboolean
 _pygi_marshal_in_interface_union (PyGIState         *state,
-                                  PyGIFunctionCache *function_cache, 
+                                  PyGIFunctionCache *function_cache,
                                   PyGIArgCache      *arg_cache,
                                   PyObject          *py_arg,
                                   GIArgument        *arg)
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 4e52a59..fd4f049 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -22,10 +22,13 @@
 #include "pygi-argument.h"
 #include <girepository.h>
 
-gboolean _arg_cache_generate_metadata_in(PyGIArgCache *arg_cache,
-                                         GITypeInfo *type_info,
-                                         GITypeTag type_tag);
-
+PyGIArgCache * _arg_cache_in_new_from_type_info (GITypeInfo *type_info,
+                                  PyGIFunctionCache *function_cache,
+                                  GITypeTag type_tag,
+                                  GITransfer transfer,
+                                  GIDirection direction,
+                                  gint c_arg_index,
+                                  gint py_arg_index);
 /* cleanup */
 static inline void
 _pygi_interface_cache_free (PyGIInterfaceCache *cache)
@@ -58,28 +61,13 @@ _pygi_callback_cache_free (PyGICallbackCache *cache)
 }
 
 void
-_pygi_arg_cache_clear (PyGIArgCache *cache)
+_pygi_arg_cache_free (PyGIArgCache *cache)
 {
-    cache->is_aux = FALSE;
-    cache->is_pointer = FALSE;
-    cache->direction = 0;
     g_base_info_unref(cache->arg_info);
-
-    cache->in_marshaller = NULL;
-    cache->out_marshaller = NULL;
-    cache->cleanup = NULL;
-
-    _pygi_sequence_cache_free(cache->sequence_cache);
-    cache->sequence_cache = NULL;
-    _pygi_interface_cache_free(cache->interface_cache);
-    cache->interface_cache = NULL;
-    _pygi_hash_cache_free(cache->hash_cache);
-    cache->hash_cache = NULL;
-    _pygi_callback_cache_free(cache->callback_cache);
-    cache->callback_cache = NULL;
-
-    gint c_arg_index = -1;
-    gint py_arg_index = -1;
+    if (cache->destroy_notify)
+        cache->destroy_notify(cache);
+    else
+        g_slice_free(PyGIArgCache, cache);
 }
 
 void
@@ -127,326 +115,368 @@ _sequence_cache_new_from_type_info(GITypeInfo *type_info)
     sc->fixed_size = -1;
     sc->len_arg_index = -1;
     sc->is_zero_terminated = g_type_info_is_zero_terminated(type_info);
-    if (!sc->is_zero_terminated) 
+    if (!sc->is_zero_terminated)
         sc->fixed_size = g_type_info_get_array_fixed_size(type_info);
     if (sc->fixed_size < 0)
-        sc->len_arg_index = g_type_info_get_array_length (type_info);    
-    
+        sc->len_arg_index = g_type_info_get_array_length (type_info);
+
     item_type_info = g_type_info_get_param_type (type_info, 0);
     item_type_tag = g_type_info_get_tag (item_type_info);
 
-    sc->item_cache = g_slice_new0(PyGIArgCache);
     sc->item_cache->type_tag = item_type_tag;
 
-    _arg_cache_generate_metadata_in(sc->item_cache,
-                                    item_type_info,
-                                    item_type_tag);
+    /* FIXME: support out also */
+    sc->item_cache = _arg_cache_in_new_from_type_info(item_type_info,
+                                                      NULL,
+                                                      item_type_tag,
+                                                      GI_TRANSFER_EVERYTHING,
+                                                      GI_DIRECTION_IN,
+                                                      0, 0);
+
+    g_base_info_unref( (GIBaseInfo *) item_type_info);
 
- 
-    g_base_info_unref ( (GIBaseInfo *) item_type_info);
+    ((PyGIArgCache *)sc)->destroy_notify = (GDestroyNotify)_pygi_sequence_cache_free;
 
     return sc;
 }
 
+static inline PyGIArgCache *
+_arg_cache_new(void)
+{
+    return g_slice_new0(PyGIArgCache);
+}
 /* process in args */
 
-static inline gboolean
-_arg_cache_generate_metadata_in_void(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_void(void)
 {
+     PyGIArgCache *arg_cache = _arg_cache_new();
      arg_cache->in_marshaller = _pygi_marshal_in_void;
 
-     return TRUE;
+     return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_boolean(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_boolean(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_boolean;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_int8(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_int8(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_int8;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_uint8(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_uint8(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_uint8;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_int16(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_int16(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_int16;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_uint16(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_uint16(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_uint16;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_int32(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_int32(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_int32;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_uint32(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_uint32(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_uint32;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_int64(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_int64(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_int64;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_uint64(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_uint64(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_uint64;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_float(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_float(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_float;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_double(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_double(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_double;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_unichar(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_unichar(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_unichar;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_gtype(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_gtype(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_gtype;
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_utf8(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_utf8(GITransfer transfer)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_utf8;
     if (arg_cache->transfer == GI_TRANSFER_NOTHING)
         arg_cache->cleanup = g_free;
 
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_filename(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_filename(GITransfer transfer)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_filename;
     if (arg_cache->transfer == GI_TRANSFER_NOTHING)
         arg_cache->cleanup = g_free;
 
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_array(PyGIArgCache *arg_cache,
-                                      GITypeInfo *type_info)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_array(GITypeInfo *type_info,
+                                      GITransfer transfer)
 {
+    PyGIArgCache *arg_cache = (PyGIArgCache *)_sequence_cache_new_from_type_info(type_info);
     arg_cache->in_marshaller = _pygi_marshal_in_array;
-    arg_cache->sequence_cache = _sequence_cache_new_from_type_info(type_info);
 
     /* arg_cache->cleanup = _pygi_cleanup_array; */
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_interface(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_interface(void)
 {
+    PyGIArgCache *arg_cache = NULL;
     /* TODO: Switch on GI_INFO_TYPE_ to determine caching */
     PyErr_Format(PyExc_NotImplementedError,
                  "Caching for this type is not fully implemented yet");
-    return FALSE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_glist(PyGIArgCache *arg_cache,
-                                      GITypeInfo *type_info)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_glist(GITypeInfo *type_info,
+                                      GITransfer transfer)
 {
+    PyGIArgCache *arg_cache = (PyGIArgCache *)_sequence_cache_new_from_type_info(type_info);
     arg_cache->in_marshaller = _pygi_marshal_in_glist;
-    arg_cache->sequence_cache = _sequence_cache_new_from_type_info(type_info);
     /* arg_cache->cleanup = */
 
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_gslist(PyGIArgCache *arg_cache,
-                                       GITypeInfo *type_info)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_gslist(GITypeInfo *type_info,
+                                       GITransfer transfer)
 {
+    PyGIArgCache *arg_cache = (PyGIArgCache *)_sequence_cache_new_from_type_info(type_info);
     arg_cache->in_marshaller = _pygi_marshal_in_gslist;
-    arg_cache->sequence_cache = _sequence_cache_new_from_type_info(type_info);
     /* arg_cache->cleanup = */
 
-    return TRUE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_ghash(PyGIArgCache *arg_cache,
-                                      GITypeInfo *type_info)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_ghash(GITypeInfo *type_info)
 {
-    arg_cache->in_marshaller = _pygi_marshal_in_ghash;
+    PyGIArgCache *arg_cache = NULL;
+    /*arg_cache->in_marshaller = _pygi_marshal_in_ghash;*/
     PyErr_Format(PyExc_NotImplementedError,
                  "Caching for this type is not fully implemented yet");
-    return FALSE;
+    return arg_cache;
 }
 
-static inline gboolean
-_arg_cache_generate_metadata_in_gerror(PyGIArgCache *arg_cache)
+static inline PyGIArgCache *
+_arg_cache_new_for_in_gerror(void)
 {
+    PyGIArgCache *arg_cache = _arg_cache_new();
     arg_cache->in_marshaller = _pygi_marshal_in_gerror;
     arg_cache->is_aux = TRUE;
-    PyErr_Format(PyExc_NotImplementedError,
-                 "Caching for this type is not fully implemented yet");
-    return FALSE;
+    return arg_cache;
 }
 
-gboolean
-_arg_cache_generate_metadata_in(PyGIArgCache *arg_cache,
-                                GITypeInfo *type_info,
-                                GITypeTag type_tag)
+PyGIArgCache *
+_arg_cache_in_new_from_type_info (GITypeInfo *type_info,
+                                  PyGIFunctionCache *function_cache,
+                                  GITypeTag type_tag,
+                                  GITransfer transfer,
+                                  GIDirection direction,
+                                  gint c_arg_index,
+                                  gint py_arg_index)
 {
-    gboolean success = TRUE;
+    PyGIArgCache *arg_cache = NULL;
 
     switch (type_tag) {
        case GI_TYPE_TAG_VOID:
-           success = _arg_cache_generate_metadata_in_void(arg_cache);
+           arg_cache = _arg_cache_new_for_in_void();
            break;
        case GI_TYPE_TAG_BOOLEAN:
-           success = _arg_cache_generate_metadata_in_boolean(arg_cache);
+           arg_cache = _arg_cache_new_for_in_boolean();
            break;
        case GI_TYPE_TAG_INT8:
-           success = _arg_cache_generate_metadata_in_int8(arg_cache);
+           arg_cache = _arg_cache_new_for_in_int8();
            break;
        case GI_TYPE_TAG_UINT8:
-           success = _arg_cache_generate_metadata_in_uint8(arg_cache);
+           arg_cache = _arg_cache_new_for_in_uint8();
            break;
        case GI_TYPE_TAG_INT16:
-           success = _arg_cache_generate_metadata_in_uint16(arg_cache);
+           arg_cache = _arg_cache_new_for_in_uint16();
            break;
        case GI_TYPE_TAG_UINT16:
-           success = _arg_cache_generate_metadata_in_uint16(arg_cache);
+           arg_cache = _arg_cache_new_for_in_uint16();
            break;
        case GI_TYPE_TAG_INT32:
-           success = _arg_cache_generate_metadata_in_int32(arg_cache);
+           arg_cache = _arg_cache_new_for_in_int32();
            break;
        case GI_TYPE_TAG_UINT32:
-           success = _arg_cache_generate_metadata_in_uint32(arg_cache);
+           arg_cache = _arg_cache_new_for_in_uint32();
            break;
        case GI_TYPE_TAG_INT64:
-           success = _arg_cache_generate_metadata_in_int64(arg_cache);
+           arg_cache = _arg_cache_new_for_in_int64();
            break;
        case GI_TYPE_TAG_UINT64:
-           success = _arg_cache_generate_metadata_in_uint64(arg_cache);
+           arg_cache = _arg_cache_new_for_in_uint64();
            break;
        case GI_TYPE_TAG_FLOAT:
-           success = _arg_cache_generate_metadata_in_float(arg_cache);
+           arg_cache = _arg_cache_new_for_in_float();
            break;
        case GI_TYPE_TAG_DOUBLE:
-           success = _arg_cache_generate_metadata_in_double(arg_cache);
+           arg_cache = _arg_cache_new_for_in_double();
            break;
        case GI_TYPE_TAG_UNICHAR:
-           success = _arg_cache_generate_metadata_in_unichar(arg_cache);
+           arg_cache = _arg_cache_new_for_in_unichar();
            break;
        case GI_TYPE_TAG_GTYPE:
-           success = _arg_cache_generate_metadata_in_gtype(arg_cache);
+           arg_cache = _arg_cache_new_for_in_gtype();
            break;
        case GI_TYPE_TAG_UTF8:
-           success = _arg_cache_generate_metadata_in_utf8(arg_cache);
+           arg_cache = _arg_cache_new_for_in_utf8(transfer);
            break;
        case GI_TYPE_TAG_FILENAME:
-           success = _arg_cache_generate_metadata_in_filename(arg_cache);
+           arg_cache = _arg_cache_new_for_in_filename(transfer);
            break;
        case GI_TYPE_TAG_ARRAY:
-           success = _arg_cache_generate_metadata_in_array(arg_cache,
-                                                           type_info);
+           arg_cache = _arg_cache_new_for_in_array(type_info,
+                                                   transfer);
            break;
        case GI_TYPE_TAG_INTERFACE:
-           success = _arg_cache_generate_metadata_in_interface(arg_cache);
+           arg_cache = _arg_cache_new_for_in_interface();
            break;
        case GI_TYPE_TAG_GLIST:
-           success = _arg_cache_generate_metadata_in_glist(arg_cache,
-                                                           type_info);
+           arg_cache = _arg_cache_new_for_in_glist(type_info,
+                                                   transfer);
            break;
        case GI_TYPE_TAG_GSLIST:
-           success = _arg_cache_generate_metadata_in_gslist(arg_cache,
-                                                            type_info);
+           arg_cache = _arg_cache_new_for_in_gslist(type_info,
+                                                    transfer);
            break;
        case GI_TYPE_TAG_GHASH:
-           success = _arg_cache_generate_metadata_in_ghash(arg_cache,
-                                                           type_info);
+           arg_cache = _arg_cache_new_for_in_ghash(type_info);
            break;
        case GI_TYPE_TAG_ERROR:
-           success = _arg_cache_generate_metadata_in_gerror(arg_cache);
+           arg_cache = _arg_cache_new_for_in_gerror();
            break;
     }
 
-    return success;
+    if (arg_cache != NULL) {
+        arg_cache->direction = direction;
+        arg_cache->transfer = transfer;
+        arg_cache->type_tag = type_tag;
+        arg_cache->py_arg_index = py_arg_index;
+        arg_cache->c_arg_index = c_arg_index;
+    }
+
+    return arg_cache;
 }
 
 static inline gboolean
 _args_cache_generate(GIFunctionInfo *function_info,
                      PyGIFunctionCache *function_cache)
 {
-    int i;
-    for (i = 0; i < function_cache->n_args; i++) {
+    int arg_index;
+    for (arg_index = 0; arg_index < function_cache->n_args; arg_index++) {
         PyGIArgCache *arg_cache;
         GIArgInfo *arg_info;
         GITypeInfo *type_info;
+        GIDirection direction;
+        GITransfer transfer;
+        GITypeTag type_tag;
+        gint py_arg_index;
 
         /* must be an aux arg filled in by its owner so skip */
-        if (function_cache->args_cache[i] != NULL)
+        if (function_cache->args_cache[arg_index] != NULL)
             continue;
 
         arg_info =
-            g_callable_info_get_arg ( (GICallableInfo *) function_info, i);
+            g_callable_info_get_arg( (GICallableInfo *) function_info, arg_index);
 
-        arg_cache = function_cache->args_cache[i] = g_slice_new0(PyGIArgCache);
-        arg_cache->direction = g_arg_info_get_direction(arg_info);
-        arg_cache->transfer = g_arg_info_get_ownership_transfer (arg_info);
-        type_info = g_base_info_get_type_info ( (GIBaseInfo *) arg_info);
-        arg_cache->type_tag = g_type_info_get_tag (type_info);
+        direction = g_arg_info_get_direction(arg_info);
+        transfer = g_arg_info_get_ownership_transfer(arg_info);
+        type_info = g_arg_info_get_type_info(arg_info);
+        type_tag = g_type_info_get_tag(type_info);
 
         switch(arg_cache->direction) {
             case GI_DIRECTION_IN:
+                py_arg_index = function_cache->n_in_args;
                 function_cache->n_in_args++;
-                arg_cache->c_arg_index = i + function_cache->is_method;
-                arg_cache->py_arg_index =
-                    function_cache->n_in_args + function_cache->is_method;
 
-                _arg_cache_generate_metadata_in(arg_cache,
-                                                type_info,
-                                                arg_cache->type_tag);
+                arg_cache =
+                    _arg_cache_in_new_from_type_info(type_info,
+                                                     function_cache,
+                                                     type_tag,
+                                                     transfer,
+                                                     direction,
+                                                     arg_index,
+                                                     py_arg_index);
 
                 function_cache->in_args =
                     g_slist_append(function_cache->in_args, arg_cache);
@@ -455,6 +485,8 @@ _args_cache_generate(GIFunctionInfo *function_info,
             case GI_DIRECTION_OUT:
                 function_cache->n_out_args++;
         }
+
+        function_cache->args_cache[arg_index] = arg_cache;
         g_base_info_unref( (GIBaseInfo *) type_info);
     }
     return TRUE;
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
index 7453eeb..9d6d519 100644
--- a/gi/pygi-cache.h
+++ b/gi/pygi-cache.h
@@ -41,9 +41,29 @@ typedef gboolean (*PyGIMarshalInFunc) (PyGIState         *state,
 typedef gboolean (*PyGIMarshalOutFunc) (void);
 typedef gboolean (*PyGIArgCleanupFunc) (gpointer data);
 
+struct _PyGIArgCache
+{
+    gboolean is_aux;
+    gboolean is_pointer;
+    GIDirection direction;
+    GITransfer transfer;
+    GITypeTag type_tag;
+    GIArgInfo *arg_info;
+    GIArgument *default_value;
+
+    PyGIMarshalInFunc in_marshaller;
+    PyGIMarshalOutFunc out_marshaller;
+    GDestroyNotify cleanup;
+
+    GDestroyNotify destroy_notify;
+
+    gint c_arg_index;
+    gint py_arg_index;
+};
 
 typedef struct _PyGISequenceCache
 {
+    PyGIArgCache arg_cache;
     gssize fixed_size;
     gint len_arg_index;
     gboolean is_zero_terminated;
@@ -53,6 +73,7 @@ typedef struct _PyGISequenceCache
 
 typedef struct _PyGIInterfaceCache
 {
+    PyGIArgCache arg_cache;
     gboolean is_foreign;
     GType g_type;
     PyObject *py_type;
@@ -60,45 +81,20 @@ typedef struct _PyGIInterfaceCache
 
 typedef struct _PyGIHashCache
 {
+    PyGIArgCache arg_cache;
     PyGIArgCache *key_cache;
     PyGIArgCache *value_cache;
 } PyGIHashCache;
 
 typedef struct _PyGICallbackCache
 {
+    PyGIArgCache arg_cache;
     gint py_user_data_index;
     gint user_data_index;
     gint destroy_notify_index;
     GIScopeType scope;
 } PyGICallbackCache;
 
-struct _PyGIArgCache
-{
-    gboolean is_aux;
-    gboolean is_pointer;
-    GIDirection direction;
-    GITransfer transfer;
-    GITypeTag type_tag;
-    GIArgInfo *arg_info;
-    GIArgument *default_value;
-
-    PyGIMarshalInFunc in_marshaller;
-    PyGIMarshalOutFunc out_marshaller;
-    PyGIArgCleanupFunc cleanup;
-
-    /* FIXME: we should actually subclass ArgCache for each of these 
-     *        types but that requires we know more about the type
-     *        before we create the cache.
-     */
-    PyGISequenceCache *sequence_cache;
-    PyGIInterfaceCache *interface_cache;
-    PyGIHashCache *hash_cache;
-    PyGICallbackCache *callback_cache;
-
-    gint c_arg_index;
-    gint py_arg_index;
-};
-
 struct _PyGIFunctionCache
 {
     gboolean is_method;



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