[pygobject/invoke-rewrite] [gi] implement aux arg handling for array lengths



commit 9be0f1f2dfb89150faf1827ef482feea03645149
Author: John (J5) Palmieri <johnp redhat com>
Date:   Thu Jan 13 23:56:19 2011 -0500

    [gi] implement aux arg handling for array lengths

 gi/pygi-argument.c |    8 ++++++++
 gi/pygi-cache.c    |   36 ++++++++++++++++++++++++++++--------
 gi/pygi-cache.h    |    1 -
 gi/pygi-invoke.c   |    8 ++++++--
 4 files changed, 42 insertions(+), 11 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index cb2f06c..6f64a98 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -2626,6 +2626,14 @@ err:
     }
 
 array_success:
+    if (sequence_cache->len_arg_index >= 0) {
+        /* we have an aux arg to handle */
+        PyGIArgCache *aux_cache = 
+            function_cache->args_cache[sequence_cache->len_arg_index];
+        
+
+        state->in_args[aux_cache->c_arg_index].v_long = length;
+    }
 
     (*arg).v_pointer = array_->data;
     g_array_free(array_, FALSE);
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 2a5f44e..f26a771 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -92,7 +92,6 @@ _pygi_function_cache_free(PyGIFunctionCache *cache)
     if (cache == NULL)
         return;
 
-    g_slist_free(cache->in_args);
     g_slist_free(cache->out_args);
     for (i = 0; i < cache->n_args; i++) {
         PyGIArgCache *tmp = cache->args_cache[i];
@@ -378,10 +377,26 @@ _arg_cache_new_for_in_filename(GITransfer transfer)
 }
 
 static inline PyGIArgCache *
-_arg_cache_new_for_in_array(GITypeInfo *type_info,
+_arg_cache_new_for_in_array(PyGIFunctionCache *function_cache,
+                            GITypeInfo *type_info,
                             GITransfer transfer)
 {
-    PyGIArgCache *arg_cache = (PyGIArgCache *)_sequence_cache_new_from_type_info(type_info);
+    PyGISequenceCache *seq_cache = _sequence_cache_new_from_type_info(type_info);
+    PyGIArgCache *arg_cache = (PyGIArgCache *)seq_cache;
+
+    seq_cache->len_arg_index = g_type_info_get_array_length(type_info);
+    if (seq_cache->len_arg_index >= 0) {
+        PyGIArgCache *aux_cache = _arg_cache_new();
+        aux_cache->is_aux = TRUE;
+        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);
+        }
+
+        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; */
@@ -915,7 +930,8 @@ _arg_cache_in_new_from_type_info (GITypeInfo *type_info,
            arg_cache = _arg_cache_new_for_in_filename(transfer);
            break;
        case GI_TYPE_TAG_ARRAY:
-           arg_cache = _arg_cache_new_for_in_array(type_info,
+           arg_cache = _arg_cache_new_for_in_array(function_cache,
+                                                   type_info,
                                                    transfer);
            break;
        case GI_TYPE_TAG_INTERFACE:
@@ -1022,9 +1038,15 @@ _args_cache_generate(GIFunctionInfo *function_info,
         GITypeTag type_tag;
         gint py_arg_index;
 
-        /* must be an aux arg filled in by its owner so skip */
-        if (function_cache->args_cache[arg_index] != NULL)
+        /* must be an aux arg filled in by its owner
+         * fill in it's c_arg_index, add to the in count
+         * and continue
+         */
+        if (function_cache->args_cache[arg_index] != NULL) {
+            function_cache->args_cache[arg_index]->c_arg_index = function_cache->n_in_args;
+            function_cache->n_in_args++;
             continue;
+        }
 
         arg_info =
             g_callable_info_get_arg( (GICallableInfo *) function_info, i);
@@ -1052,8 +1074,6 @@ _args_cache_generate(GIFunctionInfo *function_info,
                     goto arg_err;
 
                 arg_cache->allow_none = g_arg_info_may_be_null (arg_info);
-                function_cache->in_args =
-                    g_slist_append(function_cache->in_args, arg_cache);
                 break;
 
             case GI_DIRECTION_OUT:
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
index 7ecbc97..dbdddbe 100644
--- a/gi/pygi-cache.h
+++ b/gi/pygi-cache.h
@@ -108,7 +108,6 @@ struct _PyGIFunctionCache
 
     PyGIArgCache *return_cache;
     PyGIArgCache **args_cache;
-    GSList *in_args;
     GSList *out_args;
 
     /* counts */
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 81636c4..96de8a5 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -969,13 +969,17 @@ _invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
         switch (arg_cache->direction) {
             case GI_DIRECTION_IN:
             case GI_DIRECTION_INOUT:
+                state->args[i] = &(state->in_args[in_count]);
+                in_count++;
+
+                if (arg_cache->is_aux)      
+                    continue;
+
                 /* FIXME: get default or throw error if there aren't enough pyargs */
                 py_arg =
                     PyTuple_GET_ITEM(state->py_in_args,
                                      arg_cache->py_arg_index);
 
-                state->args[i] = &(state->in_args[in_count]);
-                in_count++;
                 break;
             case GI_DIRECTION_OUT:
                 state->out_args[out_count].v_pointer = &state->out_values[out_count];



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