[pygobject/invoke-rewrite] [gi] hook up invoke to the cache



commit 441da4a7346ca059630dbc820c5b46e4d0222f4b
Author: John (J5) Palmieri <johnp redhat com>
Date:   Mon Jan 10 15:07:16 2011 -0500

    [gi] hook up invoke to the cache
    
    * We now can invoke with in values
    * out, constructors and returns still don't work along with numerous complex
      in types

 gi/Makefile.am                |    1 +
 gi/pygi-argument.c            |   60 +++++++++--------
 gi/pygi-argument.h            |   60 ++++++++--------
 gi/pygi-cache.h               |    6 +-
 gi/pygi-invoke-state-struct.h |   26 +++++++
 gi/pygi-invoke.c              |  149 +++++++++++++++++++++++++++++++---------
 gi/pygi-invoke.h              |    2 +-
 gi/pygi-private.h             |    1 +
 8 files changed, 208 insertions(+), 97 deletions(-)
---
diff --git a/gi/Makefile.am b/gi/Makefile.am
index d460bad..563aac5 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -32,6 +32,7 @@ _gi_la_SOURCES = \
 	pygi-info.h \
 	pygi-invoke.c \
 	pygi-invoke.h \
+       pygi-invoke-state-struct.h \
 	pygi-foreign.c \
 	pygi-foreign.h \
 	pygi-foreign-gvariant.c \
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index e264e3d..80f1819 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -30,6 +30,8 @@
 #include <pygobject.h>
 #include <pyglib-python-compat.h>
 
+#include "pygi-cache.h"
+
 static void
 _pygi_g_type_tag_py_bounds (GITypeTag   type_tag,
                             PyObject  **lower,
@@ -1992,7 +1994,7 @@ _pygi_argument_init (void)
 /*** argument marshaling and validating routines ***/
 
 gboolean
-_pygi_marshal_in_void (PyGIState         *state,
+_pygi_marshal_in_void (PyGIInvokeState   *state,
                        PyGIFunctionCache *function_cache,
                        PyGIArgCache      *arg_cache,
                        PyObject          *py_arg,
@@ -2006,7 +2008,7 @@ _pygi_marshal_in_void (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_boolean (PyGIState         *state,
+_pygi_marshal_in_boolean (PyGIInvokeState   *state,
                           PyGIFunctionCache *function_cache,
                           PyGIArgCache      *arg_cache,
                           PyObject          *py_arg,
@@ -2018,7 +2020,7 @@ _pygi_marshal_in_boolean (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_int8 (PyGIState         *state,
+_pygi_marshal_in_int8 (PyGIInvokeState   *state,
                        PyGIFunctionCache *function_cache,
                        PyGIArgCache      *arg_cache,
                        PyObject          *py_arg,
@@ -2054,7 +2056,7 @@ _pygi_marshal_in_int8 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_uint8 (PyGIState         *state,
+_pygi_marshal_in_uint8 (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2099,7 +2101,7 @@ _pygi_marshal_in_uint8 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_int16 (PyGIState         *state,
+_pygi_marshal_in_int16 (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2135,7 +2137,7 @@ _pygi_marshal_in_int16 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_uint16 (PyGIState         *state,
+_pygi_marshal_in_uint16 (PyGIInvokeState   *state,
                          PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
@@ -2171,7 +2173,7 @@ _pygi_marshal_in_uint16 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_int32 (PyGIState         *state,
+_pygi_marshal_in_int32 (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2207,7 +2209,7 @@ _pygi_marshal_in_int32 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_uint32 (PyGIState         *state,
+_pygi_marshal_in_uint32 (PyGIInvokeState   *state,
                          PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
@@ -2249,7 +2251,7 @@ _pygi_marshal_in_uint32 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_int64 (PyGIState         *state,
+_pygi_marshal_in_int64 (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2291,7 +2293,7 @@ _pygi_marshal_in_int64 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_uint64 (PyGIState         *state,
+_pygi_marshal_in_uint64 (PyGIInvokeState   *state,
                          PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
@@ -2333,7 +2335,7 @@ _pygi_marshal_in_uint64 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_float (PyGIState         *state,
+_pygi_marshal_in_float (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2369,7 +2371,7 @@ _pygi_marshal_in_float (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_double (PyGIState         *state,
+_pygi_marshal_in_double (PyGIInvokeState   *state,
                          PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
@@ -2405,7 +2407,7 @@ _pygi_marshal_in_double (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_unichar (PyGIState         *state,
+_pygi_marshal_in_unichar (PyGIInvokeState   *state,
                           PyGIFunctionCache *function_cache,
                           PyGIArgCache      *arg_cache,
                           PyObject          *py_arg,
@@ -2451,7 +2453,7 @@ _pygi_marshal_in_unichar (PyGIState         *state,
     return TRUE;
 }
 gboolean
-_pygi_marshal_in_gtype (PyGIState         *state,
+_pygi_marshal_in_gtype (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2468,7 +2470,7 @@ _pygi_marshal_in_gtype (PyGIState         *state,
     return TRUE;
 }
 gboolean
-_pygi_marshal_in_utf8 (PyGIState         *state,
+_pygi_marshal_in_utf8 (PyGIInvokeState   *state,
                        PyGIFunctionCache *function_cache,
                        PyGIArgCache      *arg_cache,
                        PyObject          *py_arg,
@@ -2500,7 +2502,7 @@ _pygi_marshal_in_utf8 (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_filename (PyGIState         *state,
+_pygi_marshal_in_filename (PyGIInvokeState   *state,
                            PyGIFunctionCache *function_cache,
                            PyGIArgCache      *arg_cache,
                            PyObject          *py_arg,
@@ -2542,7 +2544,7 @@ _pygi_marshal_in_filename (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_array (PyGIState         *state,
+_pygi_marshal_in_array (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2626,7 +2628,7 @@ array_success:
 }
 
 gboolean
-_pygi_marshal_in_glist (PyGIState         *state,
+_pygi_marshal_in_glist (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2638,7 +2640,7 @@ _pygi_marshal_in_glist (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_gslist (PyGIState         *state,
+_pygi_marshal_in_gslist (PyGIInvokeState   *state,
                          PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
@@ -2650,7 +2652,7 @@ _pygi_marshal_in_gslist (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_ghash (PyGIState         *state,
+_pygi_marshal_in_ghash (PyGIInvokeState   *state,
                         PyGIFunctionCache *function_cache,
                         PyGIArgCache      *arg_cache,
                         PyObject          *py_arg,
@@ -2662,7 +2664,7 @@ _pygi_marshal_in_ghash (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_gerror (PyGIState         *state,
+_pygi_marshal_in_gerror (PyGIInvokeState   *state,
                          PyGIFunctionCache *function_cache,
                          PyGIArgCache      *arg_cache,
                          PyObject          *py_arg,
@@ -2674,7 +2676,7 @@ _pygi_marshal_in_gerror (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_callback (PyGIState         *state,
+_pygi_marshal_in_interface_callback (PyGIInvokeState   *state,
                                      PyGIFunctionCache *function_cache,
                                      PyGIArgCache      *arg_cache,
                                      PyObject          *py_arg,
@@ -2686,7 +2688,7 @@ _pygi_marshal_in_interface_callback (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_enum (PyGIState         *state,
+_pygi_marshal_in_interface_enum (PyGIInvokeState   *state,
                                  PyGIFunctionCache *function_cache,
                                  PyGIArgCache      *arg_cache,
                                  PyObject          *py_arg,
@@ -2698,7 +2700,7 @@ _pygi_marshal_in_interface_enum (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_flags (PyGIState         *state,
+_pygi_marshal_in_interface_flags (PyGIInvokeState   *state,
                                   PyGIFunctionCache *function_cache,
                                   PyGIArgCache      *arg_cache,
                                   PyObject          *py_arg,
@@ -2710,7 +2712,7 @@ _pygi_marshal_in_interface_flags (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_struct (PyGIState         *state,
+_pygi_marshal_in_interface_struct (PyGIInvokeState   *state,
                                    PyGIFunctionCache *function_cache,
                                    PyGIArgCache      *arg_cache,
                                    PyObject          *py_arg,
@@ -2722,7 +2724,7 @@ _pygi_marshal_in_interface_struct (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_interface (PyGIState         *state,
+_pygi_marshal_in_interface_interface (PyGIInvokeState   *state,
                                       PyGIFunctionCache *function_cache,
                                       PyGIArgCache      *arg_cache,
                                       PyObject          *py_arg,
@@ -2734,7 +2736,7 @@ _pygi_marshal_in_interface_interface (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_boxed (PyGIState         *state,
+_pygi_marshal_in_interface_boxed (PyGIInvokeState   *state,
                                   PyGIFunctionCache *function_cache,
                                   PyGIArgCache      *arg_cache,
                                   PyObject          *py_arg,
@@ -2746,7 +2748,7 @@ _pygi_marshal_in_interface_boxed (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_object (PyGIState         *state,
+_pygi_marshal_in_interface_object (PyGIInvokeState   *state,
                                    PyGIFunctionCache *function_cache,
                                    PyGIArgCache      *arg_cache,
                                    PyObject          *py_arg,
@@ -2758,7 +2760,7 @@ _pygi_marshal_in_interface_object (PyGIState         *state,
 }
 
 gboolean
-_pygi_marshal_in_interface_union (PyGIState         *state,
+_pygi_marshal_in_interface_union (PyGIInvokeState   *state,
                                   PyGIFunctionCache *function_cache,
                                   PyGIArgCache      *arg_cache,
                                   PyObject          *py_arg,
diff --git a/gi/pygi-argument.h b/gi/pygi-argument.h
index ebb0cd7..9f6e82e 100644
--- a/gi/pygi-argument.h
+++ b/gi/pygi-argument.h
@@ -26,7 +26,7 @@
 
 #include <girepository.h>
 
-#include "pygi-cache.h"
+#include "pygi-private.h"
 
 G_BEGIN_DECLS
 
@@ -66,147 +66,147 @@ void _pygi_argument_init (void);
 
 
 /*** argument marshaling and validating routines ***/
-gboolean _pygi_marshal_in_void        (PyGIState         *state,
+gboolean _pygi_marshal_in_void        (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_boolean     (PyGIState         *state,
+gboolean _pygi_marshal_in_boolean     (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_int8        (PyGIState         *state,
+gboolean _pygi_marshal_in_int8        (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_uint8       (PyGIState         *state,
+gboolean _pygi_marshal_in_uint8       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_int16       (PyGIState         *state,
+gboolean _pygi_marshal_in_int16       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_uint16      (PyGIState         *state,
+gboolean _pygi_marshal_in_uint16      (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_int32       (PyGIState         *state,
+gboolean _pygi_marshal_in_int32       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_uint32      (PyGIState         *state,
+gboolean _pygi_marshal_in_uint32      (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_int64       (PyGIState         *state,
+gboolean _pygi_marshal_in_int64       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_uint64      (PyGIState         *state,
+gboolean _pygi_marshal_in_uint64      (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_float       (PyGIState         *state,
+gboolean _pygi_marshal_in_float       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_double      (PyGIState         *state,
+gboolean _pygi_marshal_in_double      (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_unichar     (PyGIState         *state,
+gboolean _pygi_marshal_in_unichar     (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_gtype       (PyGIState         *state,
+gboolean _pygi_marshal_in_gtype       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_utf8        (PyGIState         *state,
+gboolean _pygi_marshal_in_utf8        (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_filename    (PyGIState         *state,
+gboolean _pygi_marshal_in_filename    (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_array       (PyGIState         *state,
+gboolean _pygi_marshal_in_array       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_glist       (PyGIState         *state,
+gboolean _pygi_marshal_in_glist       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_gslist      (PyGIState         *state,
+gboolean _pygi_marshal_in_gslist      (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_ghash       (PyGIState         *state,
+gboolean _pygi_marshal_in_ghash       (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_gerror      (PyGIState         *state,
+gboolean _pygi_marshal_in_gerror      (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
                                        GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_callback (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_callback (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_enum     (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_enum     (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_flags    (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_flags    (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_struct   (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_struct   (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_interface(PyGIState         *state,
+gboolean _pygi_marshal_in_interface_interface(PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_boxed    (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_boxed    (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_object   (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_object   (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
                                               GIArgument        *arg);
-gboolean _pygi_marshal_in_interface_union    (PyGIState         *state,
+gboolean _pygi_marshal_in_interface_union    (PyGIInvokeState   *state,
                                               PyGIFunctionCache *function_cache,
                                               PyGIArgCache      *arg_cache,
                                               PyObject          *py_arg,
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
index 9d6d519..7d7aa89 100644
--- a/gi/pygi-cache.h
+++ b/gi/pygi-cache.h
@@ -25,14 +25,14 @@
 #include <Python.h>
 #include <girepository.h>
 
+#include "pygi-invoke-state-struct.h"
+
 G_BEGIN_DECLS
 
 typedef struct _PyGIFunctionCache PyGIFunctionCache;
 typedef struct _PyGIArgCache PyGIArgCache;
 
-typedef struct _PyGIState PyGIState;
-
-typedef gboolean (*PyGIMarshalInFunc) (PyGIState         *state,
+typedef gboolean (*PyGIMarshalInFunc) (PyGIInvokeState   *state,
                                        PyGIFunctionCache *function_cache,
                                        PyGIArgCache      *arg_cache,
                                        PyObject          *py_arg,
diff --git a/gi/pygi-invoke-state-struct.h b/gi/pygi-invoke-state-struct.h
new file mode 100644
index 0000000..1c9bf3e
--- /dev/null
+++ b/gi/pygi-invoke-state-struct.h
@@ -0,0 +1,26 @@
+#ifndef __PYGI_INVOKE_STATE_STRUCT_H__
+#define __PYGI_INVOKE_STATE_STRUCT_H__
+
+#include <Python.h>
+
+#include <girepository.h>
+
+G_BEGIN_DECLS
+
+typedef struct _PyGIInvokeState
+{
+    PyObject *py_in_args;
+    gint n_py_in_args;
+
+    GIArgument **args;
+    GIArgument *in_args;
+    GIArgument *out_args;
+
+    GIArgument return_arg;
+
+    GError *error;
+} PyGIInvokeState;
+
+G_END_DECLS
+
+#endif
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 2d6870b..64a4cf9 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -550,9 +550,10 @@ _prepare_invocation_state (struct invocation_state *state,
     return TRUE;
 }
 
-static gboolean
-_invoke_function (struct invocation_state *state,
-                  GIFunctionInfo *function_info, PyObject *py_args)
+static inline gboolean
+_invoke_function (PyGIInvokeState *state,
+                  PyGIFunctionCache *cache,
+                  GIFunctionInfo *function_info)
 {
     GError *error;
     gint retval;
@@ -560,11 +561,13 @@ _invoke_function (struct invocation_state *state,
     error = NULL;
 
     pyg_begin_allow_threads;
+
+    /* FIXME: use this for now but we can streamline the call */
     retval = g_function_info_invoke ( (GIFunctionInfo *) function_info,
                                       state->in_args,
-                                      state->n_in_args,
+                                      cache->n_in_args,
                                       state->out_args,
-                                      state->n_out_args,
+                                      cache->n_out_args,
                                       &state->return_arg,
                                       &error);
     pyg_end_allow_threads;
@@ -580,20 +583,13 @@ _invoke_function (struct invocation_state *state,
         return FALSE;
     }
 
-    if (state->error_arg_pos >= 0) {
-        GError **error;
-
-        error = state->args[state->error_arg_pos]->v_pointer;
+    if (state->error != NULL) {
+        /* TODO: raise the right error, out of the error domain, if applicable. */
+        PyErr_SetString (PyExc_Exception, state->error->message);
 
-        if (*error != NULL) {
-            /* TODO: raise the right error, out of the error domain, if applicable. */
-            PyErr_SetString (PyExc_Exception, (*error)->message);
-            g_error_free (*error);
-
-            /* TODO: release input arguments. */
+        /* TODO: release input arguments. */
 
-            return FALSE;
-        }
+        return FALSE;
     }
 
     return TRUE;
@@ -914,35 +910,120 @@ _free_invocation_state (struct invocation_state *state)
     }
 }
 
+static inline gboolean
+_invoke_state_init_from_function_cache(PyGIInvokeState *state,
+                                       PyGIFunctionCache *cache,
+                                       PyObject *py_args)
+{
+    state->py_in_args = py_args;
+    state->n_py_in_args = PySequence_Length(py_args);
+    state->args = g_slice_alloc0(cache->n_args * sizeof(GIArgument *));
+    if (state->args == NULL && cache->n_args != 0) {
+        PyErr_NoMemory();
+        return FALSE;
+    }
+
+    state->in_args = g_slice_alloc0(cache->n_in_args * sizeof(GIArgument));
+    if (state->in_args == NULL && cache->n_in_args != 0) {
+        PyErr_NoMemory();
+        return FALSE;
+    }
+
+    state->out_args = g_slice_alloc0(cache->n_out_args * sizeof(GIArgument));
+    if (state->out_args == NULL && cache->n_out_args != 0) {
+        PyErr_NoMemory();
+        return FALSE;
+    }
+
+    state->error = NULL;
+
+    return TRUE;
+}
+
+static inline void
+_invoke_state_clear(PyGIInvokeState *state, PyGIFunctionCache *cache)
+{
+    g_slice_free1(cache->n_args * sizeof(GIArgument *), state->args);
+    g_slice_free1(cache->n_in_args * sizeof(GIArgument), state->in_args);
+    g_slice_free1(cache->n_out_args * sizeof(GIArgument), state->out_args);
+}
+
+static inline gboolean
+_invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
+{
+    int i, in_count, out_count;
+    in_count = 0;
+    out_count = 0;
+    for (i = 0; i < cache->n_args; i++) {
+        GIArgument *c_arg;
+        PyGIArgCache *arg_cache = cache->args_cache[i];
+        PyObject *py_arg = NULL;
+
+        switch (arg_cache->direction) {
+            case GI_DIRECTION_IN:
+            case GI_DIRECTION_INOUT:
+                /* 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->args[i] = &(state->out_args[out_count]);
+                out_count++;
+                break;
+        }
+
+        c_arg = state->args[i];
+        if (arg_cache->in_marshaller != NULL) {
+            gboolean success = arg_cache->in_marshaller(state,
+                                                        cache,
+                                                        arg_cache,
+                                                        py_arg,
+                                                        c_arg);
+            if (!success)
+                return FALSE;
+        }
+
+    }
+
+    return TRUE;
+}
+
+static inline PyObject *
+_invoke_marshal_out_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
+{
+    /* FIXME: we are just sending back Py_None for now */
+    Py_INCREF(Py_None);
+    return Py_None;
+}
 
 PyObject *
 _wrap_g_function_info_invoke (PyGIBaseInfo *self, PyObject *py_args)
 {
-    struct invocation_state state = { 0, };
+    PyGIInvokeState state = { 0, };
+    PyObject *ret;
 
     if (self->cache == NULL) {
         self->cache = _pygi_function_cache_new(self->info);
         if (self->cache == NULL)
             return NULL;
     }
-    _initialize_invocation_state (&state, self->info, py_args);
+    _invoke_state_init_from_function_cache(&state, self->cache, py_args);
+    if (!_invoke_marshal_in_args (&state, self->cache))
+        goto err;
 
-    if (!_prepare_invocation_state (&state, self->info, py_args)) {
-        _free_invocation_state (&state);
-        return NULL;
-    }
+    if (!_invoke_function(&state, self->cache, self->info))
+        goto err;
 
-    if (!_invoke_function (&state, self->info, py_args)) {
-        _free_invocation_state (&state);
-        return NULL;
-    }
-
-    if (!_process_invocation_state (&state, self->info, py_args)) {
-        _free_invocation_state (&state);
-        return NULL;
-    }
+    ret = _invoke_marshal_out_args (&state, self->cache);
+    _invoke_state_clear (&state, self->cache);
+    return ret;
 
-    _free_invocation_state (&state);
-    return state.return_value;
+err:
+    _invoke_state_clear (&state, self->cache);
+    return NULL;
 }
 
diff --git a/gi/pygi-invoke.h b/gi/pygi-invoke.h
index 0d07b21..10ca544 100644
--- a/gi/pygi-invoke.h
+++ b/gi/pygi-invoke.h
@@ -27,7 +27,7 @@
 #include <girepository.h>
 
 #include "pygi-private.h"
-
+#include "pygi-invoke-state-struct.h"
 G_BEGIN_DECLS
 
 PyObject *_wrap_g_function_info_invoke (PyGIBaseInfo *self, PyObject *py_args);
diff --git a/gi/pygi-private.h b/gi/pygi-private.h
index 3a14bc3..06bd21c 100644
--- a/gi/pygi-private.h
+++ b/gi/pygi-private.h
@@ -29,6 +29,7 @@
 #include "pygi-callbacks.h"
 #include "pygi-invoke.h"
 #include "pygi-property.h"
+#include "pygi-cache.h"
 
 G_BEGIN_DECLS
 #if PY_VERSION_HEX >= 0x03000000



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