[pygobject] Added args_offset to the cache instead of checking the function type



commit 964ced98e03c704074d10cc362abfa14c00457ba
Author: Garrett Regier <Garrett Regier riftio com>
Date:   Thu Jul 31 10:16:47 2014 -0400

    Added args_offset to the cache instead of checking the function type

 gi/pygi-array.c   |    6 ++----
 gi/pygi-cache.c   |    6 +++---
 gi/pygi-cache.h   |    3 +++
 gi/pygi-closure.c |    4 +---
 4 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/gi/pygi-array.c b/gi/pygi-array.c
index fceffc6..9dff53b 100644
--- a/gi/pygi-array.c
+++ b/gi/pygi-array.c
@@ -761,10 +761,8 @@ pygi_arg_garray_len_arg_setup (PyGIArgCache *arg_cache,
         seq_cache->len_arg_index = g_type_info_get_array_length (type_info);
 
         /* offset by self arg for methods and vfuncs */
-        if (seq_cache->len_arg_index >= 0 && callable_cache != NULL &&
-                (callable_cache->function_type == PYGI_FUNCTION_TYPE_METHOD ||
-                 callable_cache->function_type == PYGI_FUNCTION_TYPE_VFUNC)) {
-            seq_cache->len_arg_index += 1;
+        if (seq_cache->len_arg_index >= 0 && callable_cache != NULL) {
+            seq_cache->len_arg_index += callable_cache->args_offset;
         }
     }
 
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 24bb1a4..5f60766 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -769,12 +769,12 @@ pygi_callable_cache_new (GICallableInfo *callable_info,
         cache->function_type = PYGI_FUNCTION_TYPE_METHOD;
     }
 
-    n_args = g_callable_info_get_n_args (callable_info);
-
     /* if we are a method or vfunc make sure the instance parameter is counted */
     if (cache->function_type == PYGI_FUNCTION_TYPE_METHOD ||
             cache->function_type == PYGI_FUNCTION_TYPE_VFUNC)
-        n_args++;
+        cache->args_offset = 1;
+
+    n_args = cache->args_offset + g_callable_info_get_n_args (callable_info);
 
     if (n_args >= 0) {
         cache->args_cache = g_ptr_array_new_full (n_args, (GDestroyNotify) pygi_arg_cache_free);
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
index cb8a2e7..1a160c4 100644
--- a/gi/pygi-cache.h
+++ b/gi/pygi-cache.h
@@ -171,6 +171,9 @@ struct _PyGICallableCache
     /* Index of user_data arg that can eat variable args passed to a callable. */
     gssize user_data_varargs_index;
 
+    /* Number of args already added */
+    gssize args_offset;
+
     /* Number of out args passed to g_function_info_invoke.
      * This is used for the length of PyGIInvokeState.out_values */
     gssize n_to_py_args;
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index 42692e9..6da27b6 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -927,9 +927,7 @@ pygi_arg_callback_setup_from_info (PyGICallbackCache  *arg_cache,
     }
 
     if (callable_cache != NULL)
-        child_offset =
-            (callable_cache->function_type == PYGI_FUNCTION_TYPE_METHOD ||
-                 callable_cache->function_type == PYGI_FUNCTION_TYPE_VFUNC) ? 1: 0;
+        child_offset = callable_cache->args_offset;
 
     ( (PyGIArgCache *)arg_cache)->destroy_notify = (GDestroyNotify)_callback_cache_free_func;
 


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