[pygobject] [gi] Pass gtype as first parameter to vfuncs (instead of using kwargs).



commit eaad9f3c71cedfe28ff2d2bb05ea6c64e323715f
Author: Laszlo Pandy <lpandy src gnome org>
Date:   Fri Aug 5 21:03:33 2011 +0200

    [gi] Pass gtype as first parameter to vfuncs (instead of using kwargs).

 gi/pygi-invoke.c |   32 ++++++++++++++++++--------------
 gi/types.py      |    2 +-
 2 files changed, 19 insertions(+), 15 deletions(-)
---
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index d42a9de..8861ab3 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -93,12 +93,14 @@ _invoke_state_init_from_callable_cache (PyGIInvokeState *state,
     state->py_in_args = py_args;
     state->n_py_in_args = PySequence_Length (py_args);
 
+    state->implementor_gtype = 0;
+
     /* TODO: We don't use the class parameter sent in by  the structure
      * so we remove it from the py_args tuple but we can keep it 
      * around if we want to call actual gobject constructors
      * in the future instead of calling g_object_new
      */
-    if  (cache->function_type == PYGI_FUNCTION_TYPE_CONSTRUCTOR) {
+    if (cache->function_type == PYGI_FUNCTION_TYPE_CONSTRUCTOR) {
         PyObject *constructor_class;
         constructor_class = PyTuple_GetItem (py_args, 0);
 
@@ -111,20 +113,9 @@ _invoke_state_init_from_callable_cache (PyGIInvokeState *state,
 
             return FALSE;
         }
-
-        /* we could optimize this by using offsets instead of modifying the tuple but it makes the
-         * code more error prone and confusing so don't do that unless profiling shows
-         * significant gain
-         */
-        state->py_in_args = PyTuple_GetSlice (py_args, 1, state->n_py_in_args);
-        state->n_py_in_args--;
-    } else {
-        Py_INCREF (state->py_in_args);
-    }
-    state->implementor_gtype = 0;
-    if (cache->function_type == PYGI_FUNCTION_TYPE_VFUNC) {
+    } else if (cache->function_type == PYGI_FUNCTION_TYPE_VFUNC) {
         PyObject *py_gtype;
-        py_gtype = PyDict_GetItemString (kwargs, "gtype");
+        py_gtype = PyTuple_GetItem (py_args, 0);
         if (py_gtype == NULL) {
             PyErr_SetString (PyExc_TypeError,
                              "need the GType of the implementor class");
@@ -137,6 +128,19 @@ _invoke_state_init_from_callable_cache (PyGIInvokeState *state,
             return FALSE;
     }
 
+    if  (cache->function_type == PYGI_FUNCTION_TYPE_CONSTRUCTOR ||
+            cache->function_type == PYGI_FUNCTION_TYPE_VFUNC) {
+
+        /* we could optimize this by using offsets instead of modifying the tuple but it makes the
+         * code more error prone and confusing so don't do that unless profiling shows
+         * significant gain
+         */
+        state->py_in_args = PyTuple_GetSlice (py_args, 1, state->n_py_in_args);
+        state->n_py_in_args--;
+    } else {
+        Py_INCREF (state->py_in_args);
+    }
+
     state->args = g_slice_alloc0 (cache->n_args * sizeof (GIArgument *));
     if (state->args == NULL && cache->n_args != 0) {
         PyErr_NoMemory();
diff --git a/gi/types.py b/gi/types.py
index 9b250b1..9241a65 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -52,7 +52,7 @@ def Function(info):
 def NativeVFunc(info, cls):
 
     def native_vfunc(*args):
-        return info.invoke(*args, **dict(gtype=cls.__gtype__))
+        return info.invoke(cls.__gtype__, *args)
     native_vfunc.__info__ = info
     native_vfunc.__name__ = info.get_name()
     native_vfunc.__module__ = info.get_namespace()



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