[pygobject/invoke-rewrite] [gi] handle the situation where an aux arg comes before its parent



commit 2fbfe410f4b4394a2018ada0e538585c1bec23ae
Author: John (J5) Palmieri <johnp redhat com>
Date:   Mon Jan 31 16:50:52 2011 -0500

    [gi] handle the situation where an aux arg comes before its parent

 gi/pygi-cache.c  |   70 ++++++++++++++++++++++++++++++++++++++---------------
 gi/pygi-invoke.c |    2 +-
 2 files changed, 51 insertions(+), 21 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 387944a..58b5530 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -495,21 +495,27 @@ _arg_cache_in_array_setup(PyGIArgCache *arg_cache,
     PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
     seq_cache->array_type = g_type_info_get_array_type(type_info);
 
-    if (seq_cache->len_arg_index >= 0) {
-        PyGIArgCache *aux_cache = _arg_cache_new();
+    arg_cache->in_marshaller = _pygi_marshal_in_array;
+    
+    if (seq_cache->len_arg_index >= 0 &&
+        direction == GI_DIRECTION_IN) {
+        PyGIArgCache *aux_cache = 
+            function_cache->args_cache[seq_cache->len_arg_index];
+
+        if (aux_cache == NULL) {
+            aux_cache = _arg_cache_new();
+        } else if (aux_cache->aux_type == PYGI_AUX_TYPE_IGNORE) {
+            return TRUE;
+        }
+
         aux_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
         aux_cache->direction = direction;
-        if (function_cache->args_cache[seq_cache->len_arg_index] != NULL) {
-            PyGIArgCache *invalid_cache = function_cache->args_cache[seq_cache->len_arg_index];
-            arg_cache->c_arg_index = invalid_cache->c_arg_index;
-            _pygi_arg_cache_free(invalid_cache);
-        }
+        aux_cache->in_marshaller = NULL;
+        aux_cache->out_marshaller = NULL;
 
         function_cache->args_cache[seq_cache->len_arg_index] = aux_cache;
     }
 
-    arg_cache->in_marshaller = _pygi_marshal_in_array;
-
     /* arg_cache->cleanup = _pygi_cleanup_array; */
 }
 
@@ -518,6 +524,7 @@ _arg_cache_out_array_setup(PyGIArgCache *arg_cache,
                            PyGIFunctionCache *function_cache,
                            GITypeInfo *type_info,
                            GITransfer transfer,
+                           GIDirection direction,
                            gssize arg_index)
 {
     PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
@@ -530,21 +537,20 @@ _arg_cache_out_array_setup(PyGIArgCache *arg_cache,
         if (seq_cache->len_arg_index < arg_index)
              function_cache->n_out_aux_args++;
 
-        if (aux_cache == NULL) {
+        if (aux_cache != NULL) {
+            if (aux_cache->aux_type == PYGI_AUX_TYPE_IGNORE)
+                return TRUE;
+
+            function_cache->out_args = 
+                g_slist_remove(function_cache->out_args, aux_cache);
+        } else {
             aux_cache = _arg_cache_new();
-        } else if (aux_cache->aux_type == PYGI_AUX_TYPE_IGNORE) {
-            return TRUE;
         }
 
         aux_cache->aux_type = PYGI_AUX_TYPE_IGNORE;
-        if (function_cache->args_cache[seq_cache->len_arg_index] != NULL) {
-            PyGIArgCache *invalid_cache = function_cache->args_cache[seq_cache->len_arg_index];
-            arg_cache->c_arg_index = invalid_cache->c_arg_index;
-            _pygi_arg_cache_free(invalid_cache);
-        }
-
-        if (aux_cache->direction != GI_DIRECTION_INOUT)
-            aux_cache->direction = GI_DIRECTION_OUT;
+        aux_cache->direction = direction;
+        aux_cache->in_marshaller = NULL;
+        aux_cache->out_marshaller = NULL;
 
         function_cache->args_cache[seq_cache->len_arg_index] = aux_cache;
     }
@@ -1086,8 +1092,32 @@ _arg_cache_new_from_type_info (GITypeInfo *type_info,
                                               function_cache,
                                               type_info,
                                               transfer,
+                                              direction,
                                               c_arg_index);
 
+               /* ugly edge case code:
+                *  
+                * length can come before the array parameter which means we
+                * need to update indexes if this happens
+                */ 
+               if (seq_cache->len_arg_index > -1 &&
+                   seq_cache->len_arg_index < c_arg_index) {
+                   gssize i;
+
+                   py_arg_index -= 1;
+                   function_cache->n_py_args -= 1;
+
+                   for (i = seq_cache->len_arg_index + 1; 
+                          i < function_cache->n_args; 
+                            i++) {
+                       PyGIArgCache *update_cache = function_cache->args_cache[i];
+                       if (update_cache == NULL)
+                           break;
+
+                       update_cache->py_arg_index -= 1;
+                   }
+               }
+
                break;
            }
        case GI_TYPE_TAG_GLIST:
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index eb2c8df..15b9c7b 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -1006,7 +1006,7 @@ _invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
                 state->in_args[in_count].v_pointer = &state->out_values[out_count];
                 in_count++;
 
-                if (arg_cache->aux_type == PYGI_AUX_TYPE_NONE) {
+                if (arg_cache->aux_type != PYGI_AUX_TYPE_IGNORE) {
                     if (arg_cache->py_arg_index >= state->n_py_in_args) {
                         PyErr_Format(PyExc_TypeError,
                                      "%s() takes exactly %zd argument(s) (%zd given)",



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