From a4e4318b50a24a688e32579273fbcfa51d1b422a Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Fri, 2 Sep 2011 18:39:51 -0400 Subject: refactor in/out marshalling to be to_py/from_py * in/out make sense from a C perspective but when you get to the python layers it makes more sense to label them as to_py and from_py to denote which way we are marshalling * this helps clear up the difference between callbacks which call into python and invoked functions which call into C * in the callback case we marshal in values to Python objects and out values to C types but in the invoke case we do the reverse. Dealing with to_py/from_py makes the code much more resuable and consistant https://bugzilla.gnome.org/show_bug.cgi?id=658362 --- gi/Makefile.am | 8 +- gi/pygi-cache.c | 673 ++++++++++----------- gi/pygi-cache.h | 62 +- gi/pygi-invoke.c | 144 ++--- gi/pygi-marshal-cleanup.c | 168 +++--- gi/pygi-marshal-cleanup.h | 128 ++-- gi/pygi-marshal-from-py.c | 1412 +++++++++++++++++++++++++++++++++++++++++++++ gi/pygi-marshal-from-py.h | 186 ++++++ gi/pygi-marshal-in.c | 1412 --------------------------------------------- gi/pygi-marshal-in.h | 186 ------ gi/pygi-marshal-out.c | 768 ------------------------ gi/pygi-marshal-out.h | 144 ----- gi/pygi-marshal-to-py.c | 768 ++++++++++++++++++++++++ gi/pygi-marshal-to-py.h | 144 +++++ 14 files changed, 3122 insertions(+), 3081 deletions(-) create mode 100644 gi/pygi-marshal-from-py.c create mode 100644 gi/pygi-marshal-from-py.h delete mode 100644 gi/pygi-marshal-in.c delete mode 100644 gi/pygi-marshal-in.h delete mode 100644 gi/pygi-marshal-out.c delete mode 100644 gi/pygi-marshal-out.h create mode 100644 gi/pygi-marshal-to-py.c create mode 100644 gi/pygi-marshal-to-py.h diff --git a/gi/Makefile.am b/gi/Makefile.am index 4cc1d2fc..93bb4f8f 100644 --- a/gi/Makefile.am +++ b/gi/Makefile.am @@ -65,10 +65,10 @@ _gi_la_SOURCES = \ pygi-invoke-state-struct.h \ pygi-cache.h \ pygi-cache.c \ - pygi-marshal-in.c \ - pygi-marshal-in.h \ - pygi-marshal-out.c \ - pygi-marshal-out.h \ + pygi-marshal-from-py.c \ + pygi-marshal-from-py.h \ + pygi-marshal-to-py.c \ + pygi-marshal-to-py.h \ pygi-marshal-cleanup.c \ pygi-marshal-cleanup.h _gi_la_CFLAGS = \ diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c index a3764435..50248998 100644 --- a/gi/pygi-cache.c +++ b/gi/pygi-cache.c @@ -21,8 +21,8 @@ #include "pygi-info.h" #include "pygi-cache.h" -#include "pygi-marshal-in.h" -#include "pygi-marshal-out.h" +#include "pygi-marshal-to-py.h" +#include "pygi-marshal-from-py.h" #include "pygi-marshal-cleanup.h" #include "pygi-type.h" #include @@ -31,7 +31,7 @@ PyGIArgCache * _arg_cache_new (GITypeInfo *type_info, PyGICallableCache *callable_cache, GIArgInfo *arg_info, GITransfer transfer, - GIDirection direction, + PyGIDirection direction, gssize c_arg_index, gssize py_arg_index); @@ -39,7 +39,7 @@ PyGIArgCache * _arg_cache_new_for_interface (GIInterfaceInfo *iface_info, PyGICallableCache *callable_cache, GIArgInfo *arg_info, GITransfer transfer, - GIDirection direction, + PyGIDirection direction, gssize c_arg_index, gssize py_arg_index); /* cleanup */ @@ -108,7 +108,7 @@ _pygi_callable_cache_free (PyGICallableCache *cache) if (cache == NULL) return; - g_slist_free (cache->out_args); + g_slist_free (cache->to_py_args); g_slist_free (cache->arg_name_list); g_hash_table_destroy (cache->arg_name_hash); @@ -262,219 +262,219 @@ _arg_cache_alloc (void) } static void -_arg_cache_in_void_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_void_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_void; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_void; } static void -_arg_cache_out_void_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_void_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_void; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_void; } static void -_arg_cache_in_boolean_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_boolean_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_boolean; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_boolean; } static void -_arg_cache_out_boolean_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_boolean_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_boolean; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_boolean; } static void -_arg_cache_in_int8_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_int8_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_int8; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_int8; } static void -_arg_cache_out_int8_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_int8_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_int8; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_int8; } static void -_arg_cache_in_uint8_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_uint8_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_uint8; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint8; } static void -_arg_cache_out_uint8_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_uint8_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_uint8; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint8; } static void -_arg_cache_in_int16_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_int16_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_int16; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_int16; } static void -_arg_cache_out_int16_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_int16_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_int16; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_int16; } static void -_arg_cache_in_uint16_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_uint16_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_uint16; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint16; } static void -_arg_cache_out_uint16_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_uint16_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_uint16; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint16; } static void -_arg_cache_in_int32_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_int32_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_int32; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_int32; } static void -_arg_cache_out_int32_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_int32_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_int32; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_int32; } static void -_arg_cache_in_uint32_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_uint32_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_uint32; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint32; } static void -_arg_cache_out_uint32_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_uint32_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_uint32; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint32; } static void -_arg_cache_in_int64_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_int64_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_int64; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_int64; } static void -_arg_cache_out_int64_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_int64_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_int64; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_int64; } static void -_arg_cache_in_uint64_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_uint64_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_uint64; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint64; } static void -_arg_cache_out_uint64_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_uint64_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_uint64; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint64; } static void -_arg_cache_in_float_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_float_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_float; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_float; } static void -_arg_cache_out_float_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_float_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_float; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_float; } static void -_arg_cache_in_double_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_double_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_double; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_double; } static void -_arg_cache_out_double_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_double_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_double; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_double; } static void -_arg_cache_in_unichar_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_unichar_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_unichar; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_unichar; } static void -_arg_cache_out_unichar_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_unichar_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_unichar; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_unichar; } static void -_arg_cache_in_gtype_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_gtype_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_gtype; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_gtype; } static void -_arg_cache_out_gtype_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_gtype_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_gtype; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_gtype; } static void -_arg_cache_in_utf8_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_utf8_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_utf8; - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_utf8; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_utf8; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_utf8; } static void -_arg_cache_out_utf8_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_utf8_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_utf8; - arg_cache->out_cleanup = _pygi_marshal_cleanup_out_utf8; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_utf8; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8; } static void -_arg_cache_in_filename_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_filename_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_filename; - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_utf8; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_filename; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_utf8; } static void -_arg_cache_out_filename_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_filename_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_filename; - arg_cache->out_cleanup = _pygi_marshal_cleanup_out_utf8; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_filename; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8; } static gboolean -_arg_cache_in_array_setup (PyGIArgCache *arg_cache, - PyGICallableCache *callable_cache, - GITypeInfo *type_info, - GITransfer transfer, - GIDirection direction) +_arg_cache_from_py_array_setup (PyGIArgCache *arg_cache, + PyGICallableCache *callable_cache, + GITypeInfo *type_info, + GITransfer transfer, + PyGIDirection direction) { PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; seq_cache->array_type = g_type_info_get_array_type (type_info); - arg_cache->in_marshaller = _pygi_marshal_in_array; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_array; if (seq_cache->len_arg_index >= 0 && - direction == GI_DIRECTION_IN) { + direction == PYGI_DIRECTION_FROM_PYTHON) { PyGIArgCache *child_cache = callable_cache->args_cache[seq_cache->len_arg_index]; @@ -486,50 +486,50 @@ _arg_cache_in_array_setup (PyGIArgCache *arg_cache, child_cache->meta_type = PYGI_META_ARG_TYPE_CHILD; child_cache->direction = direction; - child_cache->in_marshaller = NULL; - child_cache->out_marshaller = NULL; + child_cache->to_py_marshaller = NULL; + child_cache->from_py_marshaller = NULL; callable_cache->args_cache[seq_cache->len_arg_index] = child_cache; } - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_array; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_to_py_array; return TRUE; } static gboolean -_arg_cache_out_array_setup (PyGIArgCache *arg_cache, - PyGICallableCache *callable_cache, - GITypeInfo *type_info, - GITransfer transfer, - GIDirection direction, - gssize arg_index) +_arg_cache_to_py_array_setup (PyGIArgCache *arg_cache, + PyGICallableCache *callable_cache, + GITypeInfo *type_info, + GITransfer transfer, + PyGIDirection direction, + gssize arg_index) { PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; - arg_cache->out_marshaller = _pygi_marshal_out_array; - arg_cache->out_cleanup = _pygi_marshal_cleanup_out_array; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_array; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_array; seq_cache->array_type = g_type_info_get_array_type (type_info); if (seq_cache->len_arg_index >= 0) { PyGIArgCache *child_cache = callable_cache->args_cache[seq_cache->len_arg_index]; if (seq_cache->len_arg_index < arg_index) - callable_cache->n_out_child_args++; + callable_cache->n_to_py_child_args++; if (child_cache != NULL) { if (child_cache->meta_type == PYGI_META_ARG_TYPE_CHILD) return TRUE; - callable_cache->out_args = - g_slist_remove (callable_cache->out_args, child_cache); + callable_cache->to_py_args = + g_slist_remove (callable_cache->to_py_args, child_cache); } else { child_cache = _arg_cache_alloc (); } child_cache->meta_type = PYGI_META_ARG_TYPE_CHILD; child_cache->direction = direction; - child_cache->in_marshaller = NULL; - child_cache->out_marshaller = NULL; + child_cache->to_py_marshaller = NULL; + child_cache->from_py_marshaller = NULL; callable_cache->args_cache[seq_cache->len_arg_index] = child_cache; } @@ -538,175 +538,177 @@ _arg_cache_out_array_setup (PyGIArgCache *arg_cache, } static void -_arg_cache_in_glist_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_glist_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_glist; - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_glist; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_glist; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_glist; } static void -_arg_cache_out_glist_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_glist_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_glist; - arg_cache->in_cleanup = _pygi_marshal_cleanup_out_glist; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_glist; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_glist; } static void -_arg_cache_in_gslist_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_gslist_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_gslist; - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_glist; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_gslist; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_glist; } static void -_arg_cache_out_gslist_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_gslist_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_gslist; - arg_cache->out_cleanup = _pygi_marshal_cleanup_out_glist; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_gslist; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_glist; } static void -_arg_cache_in_ghash_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_ghash_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_ghash; - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_ghash; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_ghash; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_ghash; } static void -_arg_cache_out_ghash_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_ghash_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_ghash; - arg_cache->out_cleanup = _pygi_marshal_cleanup_out_ghash; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_ghash; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_ghash; } static void -_arg_cache_in_gerror_setup (PyGIArgCache *arg_cache) +_arg_cache_from_py_gerror_setup (PyGIArgCache *arg_cache) { - arg_cache->in_marshaller = _pygi_marshal_in_gerror; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_gerror; arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD; } static void -_arg_cache_out_gerror_setup (PyGIArgCache *arg_cache) +_arg_cache_to_py_gerror_setup (PyGIArgCache *arg_cache) { - arg_cache->out_marshaller = _pygi_marshal_out_gerror; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_gerror; arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD; } static void -_arg_cache_in_interface_union_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_interface_union_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_interface_struct; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct; } static void -_arg_cache_out_interface_union_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_interface_union_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_interface_struct; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct; } static void -_arg_cache_in_interface_struct_setup (PyGIArgCache *arg_cache, - GIInterfaceInfo *iface_info, - GITransfer transfer) +_arg_cache_from_py_interface_struct_setup (PyGIArgCache *arg_cache, + GIInterfaceInfo *iface_info, + GITransfer transfer) { PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info); - arg_cache->in_marshaller = _pygi_marshal_in_interface_struct; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_struct; if (iface_cache->g_type == G_TYPE_VALUE) - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_interface_struct_gvalue; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_interface_struct_gvalue; else if (iface_cache->is_foreign) - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_interface_struct_foreign; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_interface_struct_foreign; } static void -_arg_cache_out_interface_struct_setup (PyGIArgCache *arg_cache, - GIInterfaceInfo *iface_info, - GITransfer transfer) +_arg_cache_to_py_interface_struct_setup (PyGIArgCache *arg_cache, + GIInterfaceInfo *iface_info, + GITransfer transfer) { PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info); - arg_cache->out_marshaller = _pygi_marshal_out_interface_struct; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_struct; if (iface_cache->is_foreign) - arg_cache->in_cleanup = _pygi_marshal_cleanup_out_interface_struct_foreign; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_interface_struct_foreign; } static void -_arg_cache_in_interface_object_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_interface_object_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_interface_object; - arg_cache->in_cleanup = _pygi_marshal_cleanup_in_interface_object; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_object; + arg_cache->from_py_cleanup = _pygi_marshal_cleanup_from_py_interface_object; } static void -_arg_cache_out_interface_object_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_interface_object_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_interface_object; - arg_cache->out_cleanup = _pygi_marshal_cleanup_out_interface_object; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_object; + arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_interface_object; } static void -_arg_cache_in_interface_callback_setup (PyGIArgCache *arg_cache, - PyGICallableCache *callable_cache) +_arg_cache_from_py_interface_callback_setup (PyGIArgCache *arg_cache, + PyGICallableCache *callable_cache) { PyGICallbackCache *callback_cache = (PyGICallbackCache *)arg_cache; if (callback_cache->user_data_index >= 0) { PyGIArgCache *user_data_arg_cache = _arg_cache_alloc (); user_data_arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD_WITH_PYARG; + user_data_arg_cache->direction = PYGI_DIRECTION_FROM_PYTHON; callable_cache->args_cache[callback_cache->user_data_index] = user_data_arg_cache; } if (callback_cache->destroy_notify_index >= 0) { PyGIArgCache *destroy_arg_cache = _arg_cache_alloc (); destroy_arg_cache->meta_type = PYGI_META_ARG_TYPE_CHILD; + destroy_arg_cache->direction = PYGI_DIRECTION_FROM_PYTHON; callable_cache->args_cache[callback_cache->destroy_notify_index] = destroy_arg_cache; } - arg_cache->in_marshaller = _pygi_marshal_in_interface_callback; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_callback; } static void -_arg_cache_out_interface_callback_setup (void) +_arg_cache_to_py_interface_callback_setup (void) { PyErr_Format(PyExc_NotImplementedError, "Callback returns are not supported"); } static void -_arg_cache_in_interface_enum_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_interface_enum_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_interface_enum; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_enum; } static void -_arg_cache_out_interface_enum_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_interface_enum_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_interface_enum; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_enum; } static void -_arg_cache_in_interface_flags_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_from_py_interface_flags_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->in_marshaller = _pygi_marshal_in_interface_flags; + arg_cache->from_py_marshaller = _pygi_marshal_from_py_interface_flags; } static void -_arg_cache_out_interface_flags_setup (PyGIArgCache *arg_cache, - GITransfer transfer) +_arg_cache_to_py_interface_flags_setup (PyGIArgCache *arg_cache, + GITransfer transfer) { - arg_cache->out_marshaller = _pygi_marshal_out_interface_flags; + arg_cache->to_py_marshaller = _pygi_marshal_to_py_interface_flags; } PyGIArgCache * @@ -714,7 +716,7 @@ _arg_cache_new_for_interface (GIInterfaceInfo *iface_info, PyGICallableCache *callable_cache, GIArgInfo *arg_info, GITransfer transfer, - GIDirection direction, + PyGIDirection direction, gssize c_arg_index, gssize py_arg_index) { @@ -743,52 +745,50 @@ _arg_cache_new_for_interface (GIInterfaceInfo *iface_info, switch (info_type) { case GI_INFO_TYPE_UNION: - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_union_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_union_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_interface_union_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_interface_union_setup (arg_cache, transfer); break; case GI_INFO_TYPE_STRUCT: - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_struct_setup (arg_cache, - iface_info, - transfer); - - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_interface_struct_setup (arg_cache, - iface_info, - transfer); - + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_struct_setup (arg_cache, + iface_info, + transfer); + + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_interface_struct_setup (arg_cache, + iface_info, + transfer); break; case GI_INFO_TYPE_OBJECT: case GI_INFO_TYPE_INTERFACE: - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_object_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_object_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_interface_object_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_interface_object_setup (arg_cache, transfer); break; case GI_INFO_TYPE_BOXED: - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_struct_setup (arg_cache, - iface_info, - transfer); - - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_interface_struct_setup (arg_cache, + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_struct_setup (arg_cache, iface_info, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_interface_struct_setup (arg_cache, + iface_info, + transfer); break; case GI_INFO_TYPE_CALLBACK: { PyGICallbackCache *callback_cache; - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) { - _arg_cache_out_interface_callback_setup (); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) { + _arg_cache_to_py_interface_callback_setup (); return NULL; } @@ -801,25 +801,25 @@ _arg_cache_new_for_interface (GIInterfaceInfo *iface_info, if (arg_cache == NULL) return NULL; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_callback_setup (arg_cache, callable_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_callback_setup (arg_cache, callable_cache); break; } case GI_INFO_TYPE_ENUM: - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_enum_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_enum_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_interface_enum_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_interface_enum_setup (arg_cache, transfer); break; case GI_INFO_TYPE_FLAGS: - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_interface_flags_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_interface_flags_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_interface_flags_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_interface_flags_setup (arg_cache, transfer); break; default: @@ -847,14 +847,14 @@ _arg_cache_new (GITypeInfo *type_info, PyGICallableCache *callable_cache, GIArgInfo *arg_info, GITransfer transfer, - GIDirection direction, + PyGIDirection direction, gssize c_arg_index, gssize py_arg_index) { PyGIArgCache *arg_cache = NULL; gssize child_offset = 0; GITypeTag type_tag; - + GI_IS_TYPE_INFO (type_info); type_tag = g_type_info_get_tag (type_info); @@ -870,22 +870,23 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_void_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_void_setup (arg_cache); + + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_void_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_void_setup (arg_cache); break; case GI_TYPE_TAG_BOOLEAN: arg_cache = _arg_cache_alloc (); if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_boolean_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_boolean_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_boolean_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_boolean_setup (arg_cache); break; case GI_TYPE_TAG_INT8: @@ -893,11 +894,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_int8_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_int8_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_int8_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_int8_setup (arg_cache); break; case GI_TYPE_TAG_UINT8: @@ -905,11 +906,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_uint8_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_uint8_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_uint8_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_uint8_setup (arg_cache); break; case GI_TYPE_TAG_INT16: @@ -917,11 +918,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_int16_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_int16_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_int16_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_int16_setup (arg_cache); break; case GI_TYPE_TAG_UINT16: @@ -929,23 +930,22 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_uint16_setup (arg_cache); - - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_uint16_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_uint16_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_uint16_setup (arg_cache); break; case GI_TYPE_TAG_INT32: arg_cache = _arg_cache_alloc (); if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_int32_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_int32_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_int32_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_int32_setup (arg_cache); break; case GI_TYPE_TAG_UINT32: @@ -953,11 +953,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_uint32_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_uint32_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_uint32_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_uint32_setup (arg_cache); break; case GI_TYPE_TAG_INT64: @@ -965,11 +965,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_int64_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_int64_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_int64_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_int64_setup (arg_cache); break; case GI_TYPE_TAG_UINT64: @@ -977,11 +977,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_uint64_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_uint64_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_uint64_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_uint64_setup (arg_cache); break; case GI_TYPE_TAG_FLOAT: @@ -989,11 +989,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_float_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_float_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_float_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_float_setup (arg_cache); break; case GI_TYPE_TAG_DOUBLE: @@ -1001,11 +1001,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_double_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_double_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_double_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_double_setup (arg_cache); break; case GI_TYPE_TAG_UNICHAR: @@ -1013,11 +1013,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_unichar_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_unichar_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_unichar_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_unichar_setup (arg_cache); break; case GI_TYPE_TAG_GTYPE: @@ -1025,11 +1025,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_gtype_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_gtype_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_gtype_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_gtype_setup (arg_cache); break; case GI_TYPE_TAG_UTF8: @@ -1037,11 +1037,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_utf8_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_utf8_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_utf8_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_utf8_setup (arg_cache, transfer); break; case GI_TYPE_TAG_FILENAME: @@ -1049,11 +1049,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_filename_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_filename_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_filename_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_filename_setup (arg_cache, transfer); break; case GI_TYPE_TAG_ARRAY: @@ -1068,20 +1068,20 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_array_setup (arg_cache, - callable_cache, - type_info, - transfer, - direction); - - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_array_setup (arg_cache, - callable_cache, - type_info, - transfer, - direction, - c_arg_index); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_array_setup (arg_cache, + callable_cache, + type_info, + transfer, + direction); + + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_array_setup (arg_cache, + callable_cache, + type_info, + transfer, + direction, + c_arg_index); /* ugly edge case code: * @@ -1120,11 +1120,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_glist_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_glist_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_glist_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_glist_setup (arg_cache, transfer); break; @@ -1141,11 +1141,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_gslist_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_gslist_setup (arg_cache, transfer); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_gslist_setup (arg_cache, transfer); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_gslist_setup (arg_cache, transfer); break; } @@ -1158,11 +1158,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_ghash_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_ghash_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) { - _arg_cache_out_ghash_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) { + _arg_cache_to_py_ghash_setup (arg_cache); } break; @@ -1185,11 +1185,11 @@ _arg_cache_new (GITypeInfo *type_info, if (arg_cache == NULL) break; - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) - _arg_cache_in_gerror_setup (arg_cache); + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_from_py_gerror_setup (arg_cache); - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) - _arg_cache_out_gerror_setup (arg_cache); + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) + _arg_cache_to_py_gerror_setup (arg_cache); break; } @@ -1225,8 +1225,8 @@ _arg_name_list_generate (PyGICallableCache *callable_cache) arg_cache = callable_cache->args_cache[i]; if (arg_cache->meta_type != PYGI_META_ARG_TYPE_CHILD && - (arg_cache->direction == GI_DIRECTION_IN || - arg_cache->direction == GI_DIRECTION_INOUT)) { + (arg_cache->direction == PYGI_DIRECTION_FROM_PYTHON || + arg_cache->direction == PYGI_DIRECTION_BIDIRECTIONAL)) { gpointer arg_name = (gpointer)arg_cache->arg_name; @@ -1250,6 +1250,13 @@ _args_cache_generate (GICallableInfo *callable_info, GITypeInfo *return_info; GITransfer return_transfer; PyGIArgCache *return_cache; + PyGIDirection return_direction; + + /* determine if we are marshalling the return to or from python */ + if (callable_cache->function_type == PYGI_FUNCTION_TYPE_CALLBACK) + return_direction = PYGI_DIRECTION_FROM_PYTHON; + else + return_direction = PYGI_DIRECTION_TO_PYTHON; /* cache the return arg */ return_info = @@ -1261,7 +1268,7 @@ _args_cache_generate (GICallableInfo *callable_info, callable_cache, NULL, return_transfer, - GI_DIRECTION_OUT, + return_direction, -1, -1); @@ -1274,6 +1281,10 @@ _args_cache_generate (GICallableInfo *callable_info, callable_cache->function_type == PYGI_FUNCTION_TYPE_VFUNC) { GIInterfaceInfo *interface_info; PyGIArgCache *instance_cache; + PyGIDirection instance_direction; + + instance_direction = PYGI_DIRECTION_FROM_PYTHON; + interface_info = g_base_info_get_container ( (GIBaseInfo *)callable_info); @@ -1282,11 +1293,12 @@ _args_cache_generate (GICallableInfo *callable_info, callable_cache, NULL, GI_TRANSFER_NOTHING, - GI_DIRECTION_IN, + instance_direction, arg_index, 0); - instance_cache->in_marshaller = _pygi_marshal_in_interface_instance; + /* FIXME: marshal interfaces from_py */ + instance_cache->from_py_marshaller = _pygi_marshal_from_py_interface_instance; g_base_info_unref ( (GIBaseInfo *)interface_info); if (instance_cache == NULL) @@ -1295,7 +1307,7 @@ _args_cache_generate (GICallableInfo *callable_info, callable_cache->args_cache[arg_index] = instance_cache; arg_index++; - callable_cache->n_in_args++; + callable_cache->n_from_py_args++; callable_cache->n_py_args++; } @@ -1304,7 +1316,8 @@ _args_cache_generate (GICallableInfo *callable_info, PyGIArgCache *arg_cache = NULL; GIArgInfo *arg_info; GITypeInfo *type_info; - GIDirection direction; + GIDirection gi_direction; + PyGIDirection direction; GITransfer transfer; GITypeTag type_tag; gboolean is_caller_allocates = FALSE; @@ -1313,7 +1326,21 @@ _args_cache_generate (GICallableInfo *callable_info, arg_info = g_callable_info_get_arg (callable_info, i); - direction = g_arg_info_get_direction (arg_info); + /* For vfuncs and callbacks our marshalling directions + are reversed */ + gi_direction = g_arg_info_get_direction (arg_info); + if (gi_direction == GI_DIRECTION_INOUT) { + direction = PYGI_DIRECTION_BIDIRECTIONAL; + } else if (gi_direction == GI_DIRECTION_IN) { + direction = PYGI_DIRECTION_FROM_PYTHON; + if (callable_cache->function_type == PYGI_FUNCTION_TYPE_CALLBACK) + direction = PYGI_DIRECTION_TO_PYTHON; + } else { + direction = PYGI_DIRECTION_TO_PYTHON; + if (callable_cache->function_type == PYGI_FUNCTION_TYPE_CALLBACK) + direction = PYGI_DIRECTION_FROM_PYTHON; + } + transfer = g_arg_info_get_ownership_transfer (arg_info); type_info = g_arg_info_get_type (arg_info); type_tag = g_type_info_get_tag (type_info); @@ -1322,8 +1349,8 @@ _args_cache_generate (GICallableInfo *callable_info, is_caller_allocates = g_arg_info_is_caller_allocates (arg_info); /* must be an child arg filled in by its owner - * fill in it's c_arg_index, add to the in count * and continue + * fill in it's c_arg_index, add to the in count */ if (callable_cache->args_cache[arg_index] != NULL) { arg_cache = callable_cache->args_cache[arg_index]; @@ -1332,23 +1359,23 @@ _args_cache_generate (GICallableInfo *callable_info, callable_cache->n_py_args++; } - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) { - arg_cache->c_arg_index = callable_cache->n_in_args; - callable_cache->n_in_args++; + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) { + arg_cache->c_arg_index = callable_cache->n_from_py_args; + callable_cache->n_from_py_args++; } - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) { - callable_cache->n_out_args++; - callable_cache->n_out_child_args++; + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) { + callable_cache->n_to_py_args++; + callable_cache->n_to_py_child_args++; } g_base_info_unref ( (GIBaseInfo *)arg_info); continue; } - if (direction == GI_DIRECTION_IN || direction == GI_DIRECTION_INOUT) { + if (direction == PYGI_DIRECTION_FROM_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) { py_arg_index = callable_cache->n_py_args; - callable_cache->n_in_args++; + callable_cache->n_from_py_args++; callable_cache->n_py_args++; } @@ -1368,14 +1395,14 @@ _args_cache_generate (GICallableInfo *callable_info, arg_cache->allow_none = g_arg_info_may_be_null(arg_info); arg_cache->is_caller_allocates = is_caller_allocates; - if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) { - callable_cache->n_out_args++; + if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL) { + callable_cache->n_to_py_args++; if (arg_cache == NULL) goto arg_err; - callable_cache->out_args = - g_slist_append (callable_cache->out_args, arg_cache); + callable_cache->to_py_args = + g_slist_append (callable_cache->to_py_args, arg_cache); } callable_cache->args_cache[arg_index] = arg_cache; diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h index a0e6e4f2..162c6e25 100644 --- a/gi/pygi-cache.h +++ b/gi/pygi-cache.h @@ -32,16 +32,16 @@ G_BEGIN_DECLS typedef struct _PyGICallableCache PyGICallableCache; typedef struct _PyGIArgCache PyGIArgCache; -typedef gboolean (*PyGIMarshalInFunc) (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); +typedef gboolean (*PyGIMarshalFromPyFunc) (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); -typedef PyObject *(*PyGIMarshalOutFunc) (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); +typedef PyObject *(*PyGIMarshalToPyFunc) (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); typedef void (*PyGIMarshalCleanupFunc) (PyGIInvokeState *state, PyGIArgCache *arg_cache, @@ -72,14 +72,28 @@ typedef enum { * PyGIFunctionType enum consolidates them into one enumeration for ease of * branching and debugging. */ - typedef enum { - PYGI_FUNCTION_TYPE_FUNCTION, - PYGI_FUNCTION_TYPE_METHOD, - PYGI_FUNCTION_TYPE_CONSTRUCTOR, - PYGI_FUNCTION_TYPE_VFUNC, - PYGI_FUNCTION_TYPE_CALLBACK +typedef enum { + PYGI_FUNCTION_TYPE_FUNCTION, + PYGI_FUNCTION_TYPE_METHOD, + PYGI_FUNCTION_TYPE_CONSTRUCTOR, + PYGI_FUNCTION_TYPE_VFUNC, + PYGI_FUNCTION_TYPE_CALLBACK } PyGIFunctionType; +/* + * In PyGI IN and OUT arguments mean different things depending on the context + * of the callable (e.g. is it a callback that is being called from C or a + * function that is being called from python). We don't as much care if the + * parameter is an IN or OUT C parameter, than we do if the parameter is being + * marshalled into Python or from Python. + */ +typedef enum { + PYGI_DIRECTION_TO_PYTHON, + PYGI_DIRECTION_FROM_PYTHON, + PYGI_DIRECTION_BIDIRECTIONAL + } PyGIDirection; + + struct _PyGIArgCache { const gchar *arg_name; @@ -90,16 +104,16 @@ struct _PyGIArgCache gboolean is_skipped; gboolean allow_none; - GIDirection direction; + PyGIDirection direction; GITransfer transfer; GITypeTag type_tag; GITypeInfo *type_info; - PyGIMarshalInFunc in_marshaller; - PyGIMarshalOutFunc out_marshaller; + PyGIMarshalFromPyFunc from_py_marshaller; + PyGIMarshalToPyFunc to_py_marshaller; - PyGIMarshalCleanupFunc in_cleanup; - PyGIMarshalCleanupFunc out_cleanup; + PyGIMarshalCleanupFunc from_py_cleanup; + PyGIMarshalCleanupFunc to_py_cleanup; GDestroyNotify destroy_notify; @@ -152,14 +166,14 @@ struct _PyGICallableCache PyGIArgCache *return_cache; PyGIArgCache **args_cache; - GSList *out_args; + GSList *to_py_args; GSList *arg_name_list; /* for keyword arg matching */ GHashTable *arg_name_hash; /* counts */ - gssize n_in_args; - gssize n_out_args; - gssize n_out_child_args; + gssize n_from_py_args; + gssize n_to_py_args; + gssize n_to_py_child_args; gssize n_args; gssize n_py_args; diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c index 4a7366c2..f669c2e9 100644 --- a/gi/pygi-invoke.c +++ b/gi/pygi-invoke.c @@ -43,17 +43,17 @@ _invoke_callable (PyGIInvokeState *state, retval = g_vfunc_info_invoke ( callable_info, state->implementor_gtype, state->in_args, - cache->n_in_args, + cache->n_from_py_args, state->out_args, - cache->n_out_args, + cache->n_to_py_args, &state->return_arg, &error); else retval = g_function_info_invoke ( callable_info, state->in_args, - cache->n_in_args, + cache->n_from_py_args, state->out_args, - cache->n_out_args, + cache->n_to_py_args, &state->return_arg, &error); pyg_end_allow_threads; @@ -67,7 +67,7 @@ _invoke_callable (PyGIInvokeState *state, * We eventually should marshal directly to FFI so we no longer * have to use the reference implementation */ - pygi_marshal_cleanup_args_in_marshal_success (state, cache); + pygi_marshal_cleanup_args_from_py_marshal_success (state, cache); return FALSE; } @@ -76,7 +76,7 @@ _invoke_callable (PyGIInvokeState *state, if (pyglib_error_check (&(state->error))) { /* even though we errored out, the call itself was successful, so we assume the call processed all of the parameters */ - pygi_marshal_cleanup_args_in_marshal_success (state, cache); + pygi_marshal_cleanup_args_from_py_marshal_success (state, cache); return FALSE; } } @@ -299,20 +299,20 @@ _invoke_state_init_from_callable_cache (PyGIInvokeState *state, return FALSE; } - state->in_args = g_slice_alloc0 (cache->n_in_args * sizeof(GIArgument)); - if (state->in_args == NULL && cache->n_in_args != 0) { + state->in_args = g_slice_alloc0 (cache->n_from_py_args * sizeof(GIArgument)); + if (state->in_args == NULL && cache->n_from_py_args != 0) { PyErr_NoMemory (); return FALSE; } - state->out_values = g_slice_alloc0 (cache->n_out_args * sizeof(GIArgument)); - if (state->out_values == NULL && cache->n_out_args != 0) { + state->out_values = g_slice_alloc0 (cache->n_to_py_args * sizeof(GIArgument)); + if (state->out_values == NULL && cache->n_to_py_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) { + state->out_args = g_slice_alloc0 (cache->n_to_py_args * sizeof(GIArgument)); + if (state->out_args == NULL && cache->n_to_py_args != 0) { PyErr_NoMemory (); return FALSE; } @@ -326,9 +326,9 @@ static inline void _invoke_state_clear (PyGIInvokeState *state, PyGICallableCache *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); - g_slice_free1 (cache->n_out_args * sizeof(GIArgument), state->out_values); + g_slice_free1 (cache->n_from_py_args * sizeof(GIArgument), state->in_args); + g_slice_free1 (cache->n_to_py_args * sizeof(GIArgument), state->out_args); + g_slice_free1 (cache->n_to_py_args * sizeof(GIArgument), state->out_values); Py_XDECREF (state->py_in_args); } @@ -396,7 +396,7 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGICallableCache *cache) PyObject *py_arg = NULL; switch (arg_cache->direction) { - case GI_DIRECTION_IN: + case PYGI_DIRECTION_FROM_PYTHON: state->args[i] = &(state->in_args[in_count]); in_count++; @@ -413,9 +413,9 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGICallableCache *cache) /* clean up all of the args we have already marshalled, * since invoke will not be called */ - pygi_marshal_cleanup_args_in_parameter_fail (state, - cache, - i - 1); + pygi_marshal_cleanup_args_from_py_parameter_fail (state, + cache, + i - 1); return FALSE; } @@ -424,7 +424,7 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGICallableCache *cache) arg_cache->py_arg_index); break; - case GI_DIRECTION_INOUT: + case PYGI_DIRECTION_BIDIRECTIONAL: /* this will be filled in if it is an child value */ if (state->in_args[in_count].v_pointer != NULL) state->out_values[out_count] = state->in_args[in_count]; @@ -439,9 +439,9 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGICallableCache *cache) cache->name, cache->n_py_args, state->n_py_in_args); - pygi_marshal_cleanup_args_in_parameter_fail (state, - cache, - i - 1); + pygi_marshal_cleanup_args_from_py_parameter_fail (state, + cache, + i - 1); return FALSE; } @@ -449,15 +449,15 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGICallableCache *cache) PyTuple_GET_ITEM (state->py_in_args, arg_cache->py_arg_index); } - case GI_DIRECTION_OUT: + case PYGI_DIRECTION_TO_PYTHON: if (arg_cache->is_caller_allocates) { if (!_caller_alloc (state, arg_cache, i, out_count)) { PyErr_Format (PyExc_TypeError, "Could not caller allocate argument %zd of callable %s", i, cache->name); - pygi_marshal_cleanup_args_in_parameter_fail (state, - cache, - i - 1); + pygi_marshal_cleanup_args_from_py_parameter_fail (state, + cache, + i - 1); return FALSE; } } else { @@ -469,26 +469,26 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGICallableCache *cache) } c_arg = state->args[i]; - if (arg_cache->in_marshaller != NULL) { + if (arg_cache->from_py_marshaller != NULL) { if (!arg_cache->allow_none && py_arg == Py_None) { PyErr_Format (PyExc_TypeError, "Argument %i does not allow None as a value", i); - pygi_marshal_cleanup_args_in_parameter_fail (state, - cache, - i - 1); + pygi_marshal_cleanup_args_from_py_parameter_fail (state, + cache, + i - 1); return FALSE; } - gboolean success = arg_cache->in_marshaller (state, - cache, - arg_cache, - py_arg, - c_arg); - if (!success) { - pygi_marshal_cleanup_args_in_parameter_fail (state, + gboolean success = arg_cache->from_py_marshaller (state, cache, - i - 1); + arg_cache, + py_arg, + c_arg); + if (!success) { + pygi_marshal_cleanup_args_from_py_parameter_fail (state, + cache, + i - 1); return FALSE; } @@ -504,7 +504,7 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGICallableCache *cache) { PyObject *py_out = NULL; PyObject *py_return = NULL; - gssize total_out_args = cache->n_out_args; + gssize total_out_args = cache->n_to_py_args; gboolean has_return = FALSE; if (cache->return_cache) { @@ -518,10 +518,10 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGICallableCache *cache) } } - py_return = cache->return_cache->out_marshaller ( state, - cache, - cache->return_cache, - &state->return_arg); + py_return = cache->return_cache->to_py_marshaller ( state, + cache, + cache->return_cache, + &state->return_arg); if (py_return == NULL) { pygi_marshal_cleanup_args_return_fail (state, cache); @@ -535,39 +535,39 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGICallableCache *cache) } } else { if (cache->return_cache->transfer == GI_TRANSFER_EVERYTHING) { - PyGIMarshalCleanupFunc out_cleanup = - cache->return_cache->out_cleanup; - - if (out_cleanup != NULL) - out_cleanup ( state, - cache->return_cache, - &state->return_arg, - FALSE); + PyGIMarshalCleanupFunc to_py_cleanup = + cache->return_cache->to_py_cleanup; + + if (to_py_cleanup != NULL) + to_py_cleanup ( state, + cache->return_cache, + &state->return_arg, + FALSE); } } } - total_out_args -= cache->n_out_child_args; + total_out_args -= cache->n_to_py_child_args; - if (cache->n_out_args - cache->n_out_child_args == 0) { + if (cache->n_to_py_args - cache->n_to_py_child_args == 0) { py_out = py_return; } else if (total_out_args == 1) { /* if we get here there is one out arg an no return */ - PyGIArgCache *arg_cache = (PyGIArgCache *)cache->out_args->data; - py_out = arg_cache->out_marshaller (state, - cache, - arg_cache, - state->args[arg_cache->c_arg_index]); + PyGIArgCache *arg_cache = (PyGIArgCache *)cache->to_py_args->data; + py_out = arg_cache->to_py_marshaller (state, + cache, + arg_cache, + state->args[arg_cache->c_arg_index]); if (py_out == NULL) { - pygi_marshal_cleanup_args_out_parameter_fail (state, - cache, - 0); + pygi_marshal_cleanup_args_to_py_parameter_fail (state, + cache, + 0); return NULL; } } else { gssize py_arg_index = 0; - GSList *cache_item = cache->out_args; + GSList *cache_item = cache->to_py_args; /* return a tuple */ py_out = PyTuple_New (total_out_args); if (has_return) { @@ -577,18 +577,18 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGICallableCache *cache) for(; py_arg_index < total_out_args; py_arg_index++) { PyGIArgCache *arg_cache = (PyGIArgCache *)cache_item->data; - PyObject *py_obj = arg_cache->out_marshaller (state, - cache, - arg_cache, - state->args[arg_cache->c_arg_index]); + PyObject *py_obj = arg_cache->to_py_marshaller (state, + cache, + arg_cache, + state->args[arg_cache->c_arg_index]); if (py_obj == NULL) { if (has_return) py_arg_index--; - pygi_marshal_cleanup_args_out_parameter_fail (state, - cache, - py_arg_index); + pygi_marshal_cleanup_args_to_py_parameter_fail (state, + cache, + py_arg_index); Py_DECREF (py_out); return NULL; } @@ -623,11 +623,11 @@ _wrap_g_callable_info_invoke (PyGIBaseInfo *self, if (!_invoke_callable (&state, self->cache, self->info)) goto err; - pygi_marshal_cleanup_args_in_marshal_success (&state, self->cache); + pygi_marshal_cleanup_args_from_py_marshal_success (&state, self->cache); ret = _invoke_marshal_out_args (&state, self->cache); if (ret) - pygi_marshal_cleanup_args_out_marshal_success (&state, self->cache); + pygi_marshal_cleanup_args_to_py_marshal_success (&state, self->cache); err: _invoke_state_clear (&state, self->cache); return ret; diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c index cd072f42..8ed9bdb2 100644 --- a/gi/pygi-marshal-cleanup.c +++ b/gi/pygi-marshal-cleanup.c @@ -66,42 +66,42 @@ _cleanup_caller_allocates (PyGIInvokeState *state, * stage (either success or failure) * * The in stage must call one of these cleanup functions: - * - pygi_marshal_cleanup_args_in_marshal_success + * - pygi_marshal_cleanup_args_from_py_marshal_success * (continue to out stage) - * - pygi_marshal_cleanup_args_in_parameter_fail + * - pygi_marshal_cleanup_args_from_py_parameter_fail * (final, exit from invoke) * * The out stage must call one of these cleanup functions which are all final: - * - pygi_marshal_cleanup_args_out_marshal_success + * - pygi_marshal_cleanup_args_to_py_marshal_success * - pygi_marshal_cleanup_args_return_fail - * - pygi_marshal_cleanup_args_out_parameter_fail + * - pygi_marshal_cleanup_args_to_py_parameter_fail * **/ void -pygi_marshal_cleanup_args_in_marshal_success (PyGIInvokeState *state, - PyGICallableCache *cache) +pygi_marshal_cleanup_args_from_py_marshal_success (PyGIInvokeState *state, + PyGICallableCache *cache) { gssize i; /* For in success, call cleanup for all GI_DIRECTION_IN values only. */ for (i = 0; i < cache->n_args; i++) { PyGIArgCache *arg_cache = cache->args_cache[i]; - PyGIMarshalCleanupFunc cleanup_func = arg_cache->in_cleanup; + PyGIMarshalCleanupFunc cleanup_func = arg_cache->from_py_cleanup; if (cleanup_func && - arg_cache->direction == GI_DIRECTION_IN && + arg_cache->direction == PYGI_DIRECTION_FROM_PYTHON && state->args[i]->v_pointer != NULL) cleanup_func (state, arg_cache, state->args[i]->v_pointer, TRUE); } } void -pygi_marshal_cleanup_args_out_marshal_success (PyGIInvokeState *state, - PyGICallableCache *cache) +pygi_marshal_cleanup_args_to_py_marshal_success (PyGIInvokeState *state, + PyGICallableCache *cache) { /* clean up the return if available */ if (cache->return_cache != NULL) { - PyGIMarshalCleanupFunc cleanup_func = cache->return_cache->out_cleanup; + PyGIMarshalCleanupFunc cleanup_func = cache->return_cache->to_py_cleanup; if (cleanup_func && state->return_arg.v_pointer != NULL) cleanup_func (state, cache->return_cache, @@ -110,10 +110,10 @@ pygi_marshal_cleanup_args_out_marshal_success (PyGIInvokeState *state, } /* Now clean up args */ - GSList *cache_item = cache->out_args; + GSList *cache_item = cache->to_py_args; while (cache_item) { PyGIArgCache *arg_cache = (PyGIArgCache *) cache_item->data; - PyGIMarshalCleanupFunc cleanup_func = arg_cache->out_cleanup; + PyGIMarshalCleanupFunc cleanup_func = arg_cache->to_py_cleanup; gpointer data = state->args[arg_cache->c_arg_index]->v_pointer; if (cleanup_func != NULL && data != NULL) @@ -127,9 +127,9 @@ pygi_marshal_cleanup_args_out_marshal_success (PyGIInvokeState *state, } void -pygi_marshal_cleanup_args_in_parameter_fail (PyGIInvokeState *state, - PyGICallableCache *cache, - gssize failed_arg_index) +pygi_marshal_cleanup_args_from_py_parameter_fail (PyGIInvokeState *state, + PyGICallableCache *cache, + gssize failed_arg_index) { gssize i; @@ -137,11 +137,11 @@ pygi_marshal_cleanup_args_in_parameter_fail (PyGIInvokeState *state, for (i = 0; i < cache->n_args && i <= failed_arg_index; i++) { PyGIArgCache *arg_cache = cache->args_cache[i]; - PyGIMarshalCleanupFunc cleanup_func = arg_cache->in_cleanup; + PyGIMarshalCleanupFunc cleanup_func = arg_cache->from_py_cleanup; gpointer data = state->args[i]->v_pointer; if (cleanup_func && - arg_cache->direction == GI_DIRECTION_IN && + arg_cache->direction == PYGI_DIRECTION_FROM_PYTHON && data != NULL) { cleanup_func (state, arg_cache, @@ -164,9 +164,9 @@ pygi_marshal_cleanup_args_return_fail (PyGIInvokeState *state, } void -pygi_marshal_cleanup_args_out_parameter_fail (PyGIInvokeState *state, +pygi_marshal_cleanup_args_to_py_parameter_fail (PyGIInvokeState *state, PyGICallableCache *cache, - gssize failed_out_arg_index) + gssize failed_to_py_arg_index) { state->failed = TRUE; } @@ -181,10 +181,10 @@ _pygi_marshal_cleanup_closure_unref (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_utf8 (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_utf8 (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { /* We strdup strings so always free if we have processed this parameter for input */ @@ -193,10 +193,10 @@ _pygi_marshal_cleanup_in_utf8 (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_out_utf8 (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_to_py_utf8 (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { /* Python copies the string so we need to free it if the interface is transfering ownership, @@ -206,10 +206,10 @@ _pygi_marshal_cleanup_out_utf8 (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_interface_object (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_interface_object (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { /* If we processed the parameter but fail before invoking the method, we need to remove the ref we added */ @@ -219,10 +219,10 @@ _pygi_marshal_cleanup_in_interface_object (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_out_interface_object (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_to_py_interface_object (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { /* If we error out and the object is not marshalled into a PyGObject we must take care of removing the ref */ @@ -231,10 +231,10 @@ _pygi_marshal_cleanup_out_interface_object (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_interface_struct_gvalue (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_interface_struct_gvalue (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (was_processed) { PyObject *py_arg = PyTuple_GET_ITEM (state->py_in_args, @@ -250,10 +250,10 @@ _pygi_marshal_cleanup_in_interface_struct_gvalue (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_interface_struct_foreign (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_interface_struct_foreign (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (state->failed && was_processed) pygi_struct_foreign_release ( @@ -262,10 +262,10 @@ _pygi_marshal_cleanup_in_interface_struct_foreign (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_out_interface_struct_foreign (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_to_py_interface_struct_foreign (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (!was_processed && arg_cache->transfer == GI_TRANSFER_EVERYTHING) pygi_struct_foreign_release ( @@ -274,10 +274,10 @@ _pygi_marshal_cleanup_out_interface_struct_foreign (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_array (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (was_processed) { GArray *array_; @@ -311,10 +311,10 @@ _pygi_marshal_cleanup_in_array (PyGIInvokeState *state, } /* clean up items first */ - if (sequence_cache->item_cache->in_cleanup != NULL) { + if (sequence_cache->item_cache->from_py_cleanup != NULL) { gsize i; PyGIMarshalCleanupFunc cleanup_func = - sequence_cache->item_cache->in_cleanup; + sequence_cache->item_cache->from_py_cleanup; for(i = 0; i < array_->len; i++) { cleanup_func (state, @@ -335,10 +335,10 @@ _pygi_marshal_cleanup_in_array (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_out_array (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_to_py_array (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; @@ -351,10 +351,10 @@ _pygi_marshal_cleanup_out_array (PyGIInvokeState *state, return; } - if (sequence_cache->item_cache->out_cleanup != NULL) { + if (sequence_cache->item_cache->to_py_cleanup != NULL) { gsize i; - PyGIMarshalCleanupFunc cleanup_func = sequence_cache->item_cache->out_cleanup; + PyGIMarshalCleanupFunc cleanup_func = sequence_cache->item_cache->to_py_cleanup; for (i = 0; i < array_->len; i++) { cleanup_func (state, sequence_cache->item_cache, @@ -369,10 +369,10 @@ _pygi_marshal_cleanup_out_array (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_glist (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_glist (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (was_processed) { GSList *list_; @@ -381,9 +381,9 @@ _pygi_marshal_cleanup_in_glist (PyGIInvokeState *state, list_ = (GSList *)data; /* clean up items first */ - if (sequence_cache->item_cache->in_cleanup != NULL) { + if (sequence_cache->item_cache->from_py_cleanup != NULL) { PyGIMarshalCleanupFunc cleanup_func = - sequence_cache->item_cache->in_cleanup; + sequence_cache->item_cache->from_py_cleanup; GSList *node = list_; while (node != NULL) { cleanup_func (state, @@ -412,10 +412,10 @@ _pygi_marshal_cleanup_in_glist (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_out_glist (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_to_py_glist (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; @@ -423,9 +423,9 @@ _pygi_marshal_cleanup_out_glist (PyGIInvokeState *state, arg_cache->transfer == GI_TRANSFER_CONTAINER) { GSList *list_ = (GSList *)data; - if (sequence_cache->item_cache->out_cleanup != NULL) { + if (sequence_cache->item_cache->to_py_cleanup != NULL) { PyGIMarshalCleanupFunc cleanup_func = - sequence_cache->item_cache->out_cleanup; + sequence_cache->item_cache->to_py_cleanup; GSList *node = list_; while (node != NULL) { @@ -453,10 +453,10 @@ _pygi_marshal_cleanup_out_glist (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_in_ghash (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_from_py_ghash (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (data == NULL) return; @@ -468,16 +468,16 @@ _pygi_marshal_cleanup_in_ghash (PyGIInvokeState *state, hash_ = (GHashTable *)data; /* clean up keys and values first */ - if (hash_cache->key_cache->in_cleanup != NULL || - hash_cache->value_cache->in_cleanup != NULL) { + if (hash_cache->key_cache->from_py_cleanup != NULL || + hash_cache->value_cache->from_py_cleanup != NULL) { GHashTableIter hiter; gpointer key; gpointer value; PyGIMarshalCleanupFunc key_cleanup_func = - hash_cache->key_cache->in_cleanup; + hash_cache->key_cache->from_py_cleanup; PyGIMarshalCleanupFunc value_cleanup_func = - hash_cache->value_cache->in_cleanup; + hash_cache->value_cache->from_py_cleanup; g_hash_table_iter_init (&hiter, hash_); while (g_hash_table_iter_next (&hiter, &key, &value)) { @@ -503,10 +503,10 @@ _pygi_marshal_cleanup_in_ghash (PyGIInvokeState *state, } void -_pygi_marshal_cleanup_out_ghash (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed) +_pygi_marshal_cleanup_to_py_ghash (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed) { if (data == NULL) return; diff --git a/gi/pygi-marshal-cleanup.h b/gi/pygi-marshal-cleanup.h index 3aff8fa1..92027bef 100644 --- a/gi/pygi-marshal-cleanup.h +++ b/gi/pygi-marshal-cleanup.h @@ -26,72 +26,72 @@ G_BEGIN_DECLS -void pygi_marshal_cleanup_args_in_marshal_success (PyGIInvokeState *state, - PyGICallableCache *cache); -void pygi_marshal_cleanup_args_in_parameter_fail (PyGIInvokeState *state, - PyGICallableCache *cache, - gssize failed_arg_index); +void pygi_marshal_cleanup_args_from_py_marshal_success (PyGIInvokeState *state, + PyGICallableCache *cache); +void pygi_marshal_cleanup_args_from_py_parameter_fail (PyGIInvokeState *state, + PyGICallableCache *cache, + gssize failed_arg_index); -void pygi_marshal_cleanup_args_out_marshal_success (PyGIInvokeState *state, - PyGICallableCache *cache); -void pygi_marshal_cleanup_args_return_fail (PyGIInvokeState *state, - PyGICallableCache *cache); -void pygi_marshal_cleanup_args_out_parameter_fail (PyGIInvokeState *state, - PyGICallableCache *cache, - gssize failed_out_arg_index); +void pygi_marshal_cleanup_args_to_py_marshal_success (PyGIInvokeState *state, + PyGICallableCache *cache); +void pygi_marshal_cleanup_args_return_fail (PyGIInvokeState *state, + PyGICallableCache *cache); +void pygi_marshal_cleanup_args_to_py_parameter_fail (PyGIInvokeState *state, + PyGICallableCache *cache, + gssize failed_to_py_arg_index); -void _pygi_marshal_cleanup_in_utf8 (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_out_utf8 (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_in_interface_struct_gvalue (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_in_interface_struct_foreign (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_out_interface_struct_foreign (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_in_interface_object (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_out_interface_object (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_in_array (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_out_array (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_in_glist (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_out_glist (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_in_ghash (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); -void _pygi_marshal_cleanup_out_ghash (PyGIInvokeState *state, - PyGIArgCache *arg_cache, - gpointer data, - gboolean was_processed); +void _pygi_marshal_cleanup_from_py_utf8 (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_to_py_utf8 (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_from_py_interface_struct_gvalue (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_from_py_interface_struct_foreign (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_to_py_interface_struct_foreign (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_from_py_interface_object (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_to_py_interface_object (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_from_py_array (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_to_py_array (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_from_py_glist (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_to_py_glist (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_from_py_ghash (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); +void _pygi_marshal_cleanup_to_py_ghash (PyGIInvokeState *state, + PyGIArgCache *arg_cache, + gpointer data, + gboolean was_processed); G_END_DECLS #endif /* __PYGI_MARSHAL_CLEANUP_H__ */ diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c new file mode 100644 index 00000000..03244918 --- /dev/null +++ b/gi/pygi-marshal-from-py.c @@ -0,0 +1,1412 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * vim: tabstop=4 shiftwidth=4 expandtab + * + * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. + * + * pygi-marshal-from-py.c: Functions to convert PyObjects to C types. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "pygi-private.h" + +#include +#include + +#include +#include +#include + +#include "pygi-cache.h" +#include "pygi-marshal-cleanup.h" +#include "pygi-marshal-from-py.h" + +gboolean +_pygi_marshal_from_py_void (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING); + + arg->v_pointer = py_arg; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_boolean (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + arg->v_boolean = PyObject_IsTrue (py_arg); + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_int8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + long long_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + + long_ = PYGLIB_PyLong_AsLong (py_long); + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + PyErr_Clear (); + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127); + return FALSE; + } + + if (long_ < -128 || long_ > 127) { + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127); + return FALSE; + } + + arg->v_long = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_uint8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + unsigned long long_; + + if (PYGLIB_PyBytes_Check (py_arg)) { + + if (PYGLIB_PyBytes_Size (py_arg) != 1) { + PyErr_Format (PyExc_TypeError, "Must be a single character"); + return FALSE; + } + + long_ = (unsigned char)(PYGLIB_PyBytes_AsString (py_arg)[0]); + + } else if (PyNumber_Check (py_arg)) { + PyObject *py_long; + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + + long_ = PYGLIB_PyLong_AsLong (py_long); + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + PyErr_Clear(); + + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 255); + return FALSE; + } + } else { + PyErr_Format (PyExc_TypeError, "Must be number or single byte string, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + if (long_ < 0 || long_ > 255) { + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 255); + return FALSE; + } + + arg->v_long = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_int16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + long long_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + + long_ = PYGLIB_PyLong_AsLong (py_long); + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + PyErr_Clear (); + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -32768, 32767); + return FALSE; + } + + if (long_ < -32768 || long_ > 32767) { + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -32768, 32767); + return FALSE; + } + + arg->v_long = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_uint16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + long long_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + + long_ = PYGLIB_PyLong_AsLong (py_long); + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + PyErr_Clear (); + PyErr_Format (PyExc_ValueError, "%li not in range %d to %d", long_, 0, 65535); + return FALSE; + } + + if (long_ < 0 || long_ > 65535) { + PyErr_Format (PyExc_ValueError, "%li not in range %d to %d", long_, 0, 65535); + return FALSE; + } + + arg->v_long = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_int32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + long long_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + + long_ = PYGLIB_PyLong_AsLong (py_long); + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + PyErr_Clear(); + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, G_MININT32, G_MAXINT32); + return FALSE; + } + + if (long_ < G_MININT32 || long_ > G_MAXINT32) { + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, G_MININT32, G_MAXINT32); + return FALSE; + } + + arg->v_long = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_uint32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + long long long_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check (py_long)) + long_ = PyInt_AsLong (py_long); + else +#endif + long_ = PyLong_AsLongLong (py_long); + + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + PyErr_Clear (); + PyErr_Format (PyExc_ValueError, "%lli not in range %i to %u", long_, 0, G_MAXUINT32); + return FALSE; + } + + if (long_ < 0 || long_ > G_MAXUINT32) { + PyErr_Format (PyExc_ValueError, "%lli not in range %i to %u", long_, 0, G_MAXUINT32); + return FALSE; + } + + arg->v_uint64 = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_int64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + long long long_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check (py_long)) + long_ = PyInt_AS_LONG (py_long); + else +#endif + long_ = PyLong_AsLongLong (py_long); + + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + /* OverflowError occured but range errors should be returned as ValueError */ + char *long_str; + PyObject *py_str; + + PyErr_Clear (); + + py_str = PyObject_Str (py_long); + + if (PyUnicode_Check (py_str)) { + PyObject *py_bytes = PyUnicode_AsUTF8String (py_str); + if (py_bytes == NULL) + return FALSE; + + long_str = g_strdup (PYGLIB_PyBytes_AsString (py_bytes)); + if (long_str == NULL) { + PyErr_NoMemory (); + return FALSE; + } + + Py_DECREF (py_bytes); + } else { + long_str = g_strdup (PYGLIB_PyBytes_AsString(py_str)); + } + + Py_DECREF (py_str); + PyErr_Format (PyExc_ValueError, "%s not in range %ld to %ld", + long_str, G_MININT64, G_MAXINT64); + + g_free (long_str); + return FALSE; + } + + if (long_ < G_MININT64 || long_ > G_MAXINT64) { + PyErr_Format (PyExc_ValueError, "%lld not in range %ld to %ld", long_, G_MININT64, G_MAXINT64); + return FALSE; + } + + arg->v_int64 = long_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_uint64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_long; + guint64 ulong_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_long = PYGLIB_PyNumber_Long (py_arg); + if (!py_long) + return FALSE; + +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check (py_long)) { + long long_ = PyInt_AsLong (py_long); + if (long_ < 0) { + PyErr_Format (PyExc_ValueError, "%ld not in range %d to %llu", + long_, 0, G_MAXUINT64); + return FALSE; + } + ulong_ = long_; + } else +#endif + ulong_ = PyLong_AsUnsignedLongLong (py_long); + + Py_DECREF (py_long); + + if (PyErr_Occurred ()) { + /* OverflowError occured but range errors should be returned as ValueError */ + char *long_str; + PyObject *py_str; + + PyErr_Clear (); + + py_str = PyObject_Str (py_long); + + if (PyUnicode_Check (py_str)) { + PyObject *py_bytes = PyUnicode_AsUTF8String (py_str); + if (py_bytes == NULL) + return FALSE; + + long_str = g_strdup (PYGLIB_PyBytes_AsString (py_bytes)); + if (long_str == NULL) { + PyErr_NoMemory (); + return FALSE; + } + + Py_DECREF (py_bytes); + } else { + long_str = g_strdup (PYGLIB_PyBytes_AsString (py_str)); + } + + Py_DECREF (py_str); + + PyErr_Format (PyExc_ValueError, "%s not in range %d to %llu", + long_str, 0, G_MAXUINT64); + + g_free (long_str); + return FALSE; + } + + if (ulong_ > G_MAXUINT64) { + PyErr_Format (PyExc_ValueError, "%llu not in range %d to %llu", ulong_, 0, G_MAXUINT64); + return FALSE; + } + + arg->v_uint64 = ulong_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_float (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_float; + double double_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_float = PyNumber_Float (py_arg); + if (!py_float) + return FALSE; + + double_ = PyFloat_AsDouble (py_float); + Py_DECREF (py_float); + + if (PyErr_Occurred ()) { + PyErr_Clear (); + PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXFLOAT, G_MAXFLOAT); + return FALSE; + } + + if (double_ < -G_MAXFLOAT || double_ > G_MAXFLOAT) { + PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXFLOAT, G_MAXFLOAT); + return FALSE; + } + + arg->v_float = double_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_double (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *py_float; + double double_; + + if (!PyNumber_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be number, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + py_float = PyNumber_Float (py_arg); + if (!py_float) + return FALSE; + + double_ = PyFloat_AsDouble (py_float); + Py_DECREF (py_float); + + if (PyErr_Occurred ()) { + PyErr_Clear (); + PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXDOUBLE, G_MAXDOUBLE); + return FALSE; + } + + if (double_ < -G_MAXDOUBLE || double_ > G_MAXDOUBLE) { + PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXDOUBLE, G_MAXDOUBLE); + return FALSE; + } + + arg->v_double = double_; + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_unichar (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + Py_ssize_t size; + gchar *string_; + + if (PyUnicode_Check (py_arg)) { + PyObject *py_bytes; + + size = PyUnicode_GET_SIZE (py_arg); + py_bytes = PyUnicode_AsUTF8String (py_arg); + string_ = strdup(PYGLIB_PyBytes_AsString (py_bytes)); + Py_DECREF (py_bytes); + +#if PY_VERSION_HEX < 0x03000000 + } else if (PyString_Check (py_arg)) { + PyObject *pyuni = PyUnicode_FromEncodedObject (py_arg, "UTF-8", "strict"); + if (!pyuni) + return FALSE; + + size = PyUnicode_GET_SIZE (pyuni); + string_ = g_strdup (PyString_AsString(py_arg)); + Py_DECREF (pyuni); +#endif + } else { + PyErr_Format (PyExc_TypeError, "Must be string, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + if (size != 1) { + PyErr_Format (PyExc_TypeError, "Must be a one character string, not %ld characters", + size); + g_free (string_); + return FALSE; + } + + arg->v_uint32 = g_utf8_get_char (string_); + g_free (string_); + + return TRUE; +} +gboolean +_pygi_marshal_from_py_gtype (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + long type_ = pyg_type_from_object (py_arg); + + if (type_ == 0) { + PyErr_Format (PyExc_TypeError, "Must be gobject.GType, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + arg->v_long = type_; + return TRUE; +} +gboolean +_pygi_marshal_from_py_utf8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + gchar *string_; + + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + if (PyUnicode_Check (py_arg)) { + PyObject *pystr_obj = PyUnicode_AsUTF8String (py_arg); + if (!pystr_obj) + return FALSE; + + string_ = g_strdup (PYGLIB_PyBytes_AsString (pystr_obj)); + Py_DECREF (pystr_obj); + } +#if PY_VERSION_HEX < 0x03000000 + else if (PyString_Check (py_arg)) { + string_ = g_strdup (PyString_AsString (py_arg)); + } +#endif + else { + PyErr_Format (PyExc_TypeError, "Must be string, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + arg->v_string = string_; + return TRUE; +} + +gboolean +_pygi_marshal_from_py_filename (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + gchar *string_; + GError *error = NULL; + + if (PyUnicode_Check (py_arg)) { + PyObject *pystr_obj = PyUnicode_AsUTF8String (py_arg); + if (!pystr_obj) + return FALSE; + + string_ = g_strdup (PYGLIB_PyBytes_AsString (pystr_obj)); + Py_DECREF (pystr_obj); + } +#if PY_VERSION_HEX < 0x03000000 + else if (PyString_Check (py_arg)) { + string_ = g_strdup (PyString_AsString (py_arg)); + } +#endif + else { + PyErr_Format (PyExc_TypeError, "Must be string, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + arg->v_string = g_filename_from_utf8 (string_, -1, NULL, NULL, &error); + g_free (string_); + + if (arg->v_string == NULL) { + PyErr_SetString (PyExc_Exception, error->message); + g_error_free (error); + /* TODO: Convert the error to an exception. */ + return FALSE; + } + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_array (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyGIMarshalFromPyFunc from_py_marshaller; + int i; + Py_ssize_t length; + gboolean is_ptr_array; + GArray *array_ = NULL; + PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; + + + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + if (!PySequence_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be sequence, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + length = PySequence_Length (py_arg); + if (length < 0) + return FALSE; + + if (sequence_cache->fixed_size >= 0 && + sequence_cache->fixed_size != length) { + PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd", + sequence_cache->fixed_size, length); + + return FALSE; + } + + is_ptr_array = (sequence_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY); + if (is_ptr_array) { + array_ = (GArray *)g_ptr_array_new (); + } else { + array_ = g_array_sized_new (sequence_cache->is_zero_terminated, + FALSE, + sequence_cache->item_size, + length); + } + + if (array_ == NULL) { + PyErr_NoMemory (); + return FALSE; + } + + if (sequence_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8 && + PYGLIB_PyBytes_Check (py_arg)) { + memcpy(array_->data, PYGLIB_PyBytes_AsString (py_arg), length); + + goto array_success; + } + + from_py_marshaller = sequence_cache->item_cache->from_py_marshaller; + for (i = 0; i < length; i++) { + GIArgument item; + PyObject *py_item = PySequence_GetItem (py_arg, i); + if (py_item == NULL) + goto err; + + if (!from_py_marshaller ( state, + callable_cache, + sequence_cache->item_cache, + py_item, + &item)) + goto err; + + /* FIXME: it is much more efficent to have seperate marshaller + * for ptr arrays than doing the evaluation + * and casting each loop iteration + */ + if (is_ptr_array) + g_ptr_array_add((GPtrArray *)array_, item.v_pointer); + else + g_array_insert_val (array_, i, item); + continue; +err: + if (sequence_cache->item_cache->from_py_cleanup != NULL) { + gsize j; + PyGIMarshalCleanupFunc cleanup_func = + sequence_cache->item_cache->from_py_cleanup; + + for(j = 0; j < i; j++) { + cleanup_func (state, + sequence_cache->item_cache, + g_array_index (array_, gpointer, j), + TRUE); + } + } + + if (is_ptr_array) + g_ptr_array_free ( ( GPtrArray *)array_, TRUE); + else + g_array_free (array_, TRUE); + _PyGI_ERROR_PREFIX ("Item %i: ", i); + return FALSE; + } + +array_success: + if (sequence_cache->len_arg_index >= 0) { + /* we have an child arg to handle */ + PyGIArgCache *child_cache = + callable_cache->args_cache[sequence_cache->len_arg_index]; + + if (child_cache->direction == PYGI_DIRECTION_BIDIRECTIONAL) { + gint *len_arg = (gint *)state->in_args[child_cache->c_arg_index].v_pointer; + /* if we are not setup yet just set the in arg */ + if (len_arg == NULL) + state->in_args[child_cache->c_arg_index].v_long = length; + else + *len_arg = length; + } else { + state->in_args[child_cache->c_arg_index].v_long = length; + } + } + + if (sequence_cache->array_type == GI_ARRAY_TYPE_C) { + arg->v_pointer = array_->data; + g_array_free (array_, FALSE); + } else { + arg->v_pointer = array_; + } + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_glist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyGIMarshalFromPyFunc from_py_marshaller; + int i; + Py_ssize_t length; + GList *list_ = NULL; + PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; + + + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + if (!PySequence_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be sequence, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + length = PySequence_Length (py_arg); + if (length < 0) + return FALSE; + + if (sequence_cache->fixed_size >= 0 && + sequence_cache->fixed_size != length) { + PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd", + sequence_cache->fixed_size, length); + + return FALSE; + } + + from_py_marshaller = sequence_cache->item_cache->from_py_marshaller; + for (i = 0; i < length; i++) { + GIArgument item; + PyObject *py_item = PySequence_GetItem (py_arg, i); + if (py_item == NULL) + goto err; + + if (!from_py_marshaller ( state, + callable_cache, + sequence_cache->item_cache, + py_item, + &item)) + goto err; + + list_ = g_list_append (list_, item.v_pointer); + continue; +err: + if (sequence_cache->item_cache->from_py_cleanup != NULL) { + PyGIMarshalCleanupFunc cleanup = sequence_cache->item_cache->from_py_cleanup; + } + + g_list_free (list_); + _PyGI_ERROR_PREFIX ("Item %i: ", i); + return FALSE; + } + + arg->v_pointer = list_; + return TRUE; +} + +gboolean +_pygi_marshal_from_py_gslist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyGIMarshalFromPyFunc from_py_marshaller; + int i; + Py_ssize_t length; + GSList *list_ = NULL; + PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; + + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + if (!PySequence_Check (py_arg)) { + PyErr_Format (PyExc_TypeError, "Must be sequence, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + length = PySequence_Length (py_arg); + if (length < 0) + return FALSE; + + if (sequence_cache->fixed_size >= 0 && + sequence_cache->fixed_size != length) { + PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd", + sequence_cache->fixed_size, length); + + return FALSE; + } + + from_py_marshaller = sequence_cache->item_cache->from_py_marshaller; + for (i = 0; i < length; i++) { + GIArgument item; + PyObject *py_item = PySequence_GetItem (py_arg, i); + if (py_item == NULL) + goto err; + + if (!from_py_marshaller ( state, + callable_cache, + sequence_cache->item_cache, + py_item, + &item)) + goto err; + + list_ = g_slist_append (list_, item.v_pointer); + continue; +err: + if (sequence_cache->item_cache->from_py_cleanup != NULL) { + PyGIMarshalCleanupFunc cleanup = sequence_cache->item_cache->from_py_cleanup; + } + + g_slist_free (list_); + _PyGI_ERROR_PREFIX ("Item %i: ", i); + return FALSE; + } + + arg->v_pointer = list_; + return TRUE; +} + +gboolean +_pygi_marshal_from_py_ghash (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyGIMarshalFromPyFunc key_from_py_marshaller; + PyGIMarshalFromPyFunc value_from_py_marshaller; + + int i; + Py_ssize_t length; + PyObject *py_keys, *py_values; + + GHashFunc hash_func; + GEqualFunc equal_func; + + GHashTable *hash_ = NULL; + PyGIHashCache *hash_cache = (PyGIHashCache *)arg_cache; + + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + py_keys = PyMapping_Keys (py_arg); + if (py_keys == NULL) { + PyErr_Format (PyExc_TypeError, "Must be mapping, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + length = PyMapping_Length (py_arg); + if (length < 0) { + Py_DECREF (py_keys); + return FALSE; + } + + py_values = PyMapping_Values (py_arg); + if (py_values == NULL) { + Py_DECREF (py_keys); + return FALSE; + } + + key_from_py_marshaller = hash_cache->key_cache->from_py_marshaller; + value_from_py_marshaller = hash_cache->value_cache->from_py_marshaller; + + switch (hash_cache->key_cache->type_tag) { + case GI_TYPE_TAG_UTF8: + case GI_TYPE_TAG_FILENAME: + hash_func = g_str_hash; + equal_func = g_str_equal; + break; + default: + hash_func = NULL; + equal_func = NULL; + } + + hash_ = g_hash_table_new (hash_func, equal_func); + if (hash_ == NULL) { + PyErr_NoMemory (); + Py_DECREF (py_keys); + Py_DECREF (py_values); + return FALSE; + } + + for (i = 0; i < length; i++) { + GIArgument key, value; + PyObject *py_key = PyList_GET_ITEM (py_keys, i); + PyObject *py_value = PyList_GET_ITEM (py_values, i); + if (py_key == NULL || py_value == NULL) + goto err; + + if (!key_from_py_marshaller ( state, + callable_cache, + hash_cache->key_cache, + py_key, + &key)) + goto err; + + if (!value_from_py_marshaller ( state, + callable_cache, + hash_cache->value_cache, + py_value, + &value)) + goto err; + + g_hash_table_insert (hash_, key.v_pointer, value.v_pointer); + continue; +err: + /* FIXME: cleanup hash keys and values */ + Py_XDECREF (py_key); + Py_XDECREF (py_value); + Py_DECREF (py_keys); + Py_DECREF (py_values); + g_hash_table_unref (hash_); + _PyGI_ERROR_PREFIX ("Item %i: ", i); + return FALSE; + } + + arg->v_pointer = hash_; + return TRUE; +} + +gboolean +_pygi_marshal_from_py_gerror (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyErr_Format (PyExc_NotImplementedError, + "Marshalling for GErrors is not implemented"); + return FALSE; +} + +gboolean +_pygi_marshal_from_py_interface_callback (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + GICallableInfo *callable_info; + PyGICClosure *closure; + PyGIArgCache *user_data_cache = NULL; + PyGIArgCache *destroy_cache = NULL; + PyGICallbackCache *callback_cache; + PyObject *py_user_data = NULL; + + callback_cache = (PyGICallbackCache *)arg_cache; + + if (callback_cache->user_data_index > 0) { + user_data_cache = callable_cache->args_cache[callback_cache->user_data_index]; + if (user_data_cache->py_arg_index < state->n_py_in_args) { + py_user_data = PyTuple_GetItem (state->py_in_args, user_data_cache->py_arg_index); + if (!py_user_data) + return FALSE; + } else { + py_user_data = Py_None; + Py_INCREF (Py_None); + } + } + + if (py_arg == Py_None && !(py_user_data == Py_None || py_user_data == NULL)) { + Py_DECREF (py_user_data); + PyErr_Format (PyExc_TypeError, + "When passing None for a callback userdata must also be None"); + + return FALSE; + } + + if (py_arg == Py_None) { + Py_XDECREF (py_user_data); + return TRUE; + } + + if (!PyCallable_Check (py_arg)) { + Py_XDECREF (py_user_data); + PyErr_Format (PyExc_TypeError, + "Callback needs to be a function or method not %s", + py_arg->ob_type->tp_name); + + return FALSE; + } + + if (callback_cache->destroy_notify_index > 0) + destroy_cache = callable_cache->args_cache[callback_cache->destroy_notify_index]; + + callable_info = (GICallableInfo *)callback_cache->interface_info; + + closure = _pygi_make_native_closure (callable_info, callback_cache->scope, py_arg, py_user_data); + arg->v_pointer = closure->closure; + if (user_data_cache != NULL) { + state->in_args[user_data_cache->c_arg_index].v_pointer = closure; + } + + if (destroy_cache) { + PyGICClosure *destroy_notify = _pygi_destroy_notify_create (); + state->in_args[destroy_cache->c_arg_index].v_pointer = destroy_notify->closure; + } + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_interface_enum (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *int_; + gint is_instance; + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + + is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type); + + int_ = PYGLIB_PyNumber_Long (py_arg); + if (int_ == NULL) { + PyErr_Clear(); + goto err; + } + + arg->v_long = PYGLIB_PyLong_AsLong (int_); + Py_DECREF (int_); + + /* If this is not an instance of the Enum type that we want + * we need to check if the value is equivilant to one of the + * Enum's memebers */ + if (!is_instance) { + int i; + gboolean is_found = FALSE; + + for (i = 0; i < g_enum_info_get_n_values (iface_cache->interface_info); i++) { + GIValueInfo *value_info = + g_enum_info_get_value (iface_cache->interface_info, i); + glong enum_value = g_value_info_get_value (value_info); + g_base_info_unref ( (GIBaseInfo *)value_info); + if (arg->v_long == enum_value) { + is_found = TRUE; + break; + } + } + + if (!is_found) + goto err; + } + + return TRUE; + +err: + PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", + iface_cache->type_name, py_arg->ob_type->tp_name); + return FALSE; +} + +gboolean +_pygi_marshal_from_py_interface_flags (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyObject *int_; + gint is_instance; + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + + is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type); + + int_ = PYGLIB_PyNumber_Long (py_arg); + if (int_ == NULL) { + PyErr_Clear (); + goto err; + } + + arg->v_long = PYGLIB_PyLong_AsLong (int_); + Py_DECREF (int_); + + /* only 0 or argument of type Flag is allowed */ + if (!is_instance && arg->v_long != 0) + goto err; + + return TRUE; + +err: + PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", + iface_cache->type_name, py_arg->ob_type->tp_name); + return FALSE; + +} + +gboolean +_pygi_marshal_from_py_interface_struct (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + /* FIXME: handle this large if statement in the cache + * and set the correct marshaller + */ + + if (iface_cache->g_type == G_TYPE_CLOSURE) { + GClosure *closure; + GType object_gtype = pyg_type_from_object_strict (py_arg, FALSE); + + if ( !(PyCallable_Check(py_arg) || + g_type_is_a (object_gtype, G_TYPE_CLOSURE))) { + PyErr_Format (PyExc_TypeError, "Must be callable, not %s", + py_arg->ob_type->tp_name); + return FALSE; + } + + if (g_type_is_a (object_gtype, G_TYPE_CLOSURE)) + closure = (GClosure *)pyg_boxed_get (py_arg, void); + else + closure = pyg_closure_new (py_arg, NULL, NULL); + + if (closure == NULL) { + PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GClosure failed"); + return FALSE; + } + + arg->v_pointer = closure; + return TRUE; + } else if (iface_cache->g_type == G_TYPE_VALUE) { + GValue *value; + GType object_type; + + object_type = pyg_type_from_object_strict ( (PyObject *) py_arg->ob_type, FALSE); + if (object_type == G_TYPE_INVALID) { + PyErr_SetString (PyExc_RuntimeError, "unable to retrieve object's GType"); + return FALSE; + } + + /* if already a gvalue, use that, else marshal into gvalue */ + if (object_type == G_TYPE_VALUE) { + value = (GValue *)( (PyGObject *)py_arg)->obj; + } else { + value = g_slice_new0 (GValue); + g_value_init (value, object_type); + if (pyg_value_from_pyobject (value, py_arg) < 0) { + g_slice_free (GValue, value); + PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GValue failed"); + return FALSE; + } + } + + arg->v_pointer = value; + return TRUE; + } else if (iface_cache->is_foreign) { + gboolean success; + success = pygi_struct_foreign_convert_to_g_argument (py_arg, + iface_cache->interface_info, + arg_cache->transfer, + arg); + + return success; + } else if (!PyObject_IsInstance (py_arg, iface_cache->py_type)) { + PyErr_Format (PyExc_TypeError, "Expected %s, but got %s", + iface_cache->type_name, + iface_cache->py_type->ob_type->tp_name); + return FALSE; + } + + if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) { + arg->v_pointer = pyg_boxed_get (py_arg, void); + if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) { + arg->v_pointer = g_boxed_copy (iface_cache->g_type, arg->v_pointer); + } + } else if (g_type_is_a (iface_cache->g_type, G_TYPE_POINTER) || + g_type_is_a (iface_cache->g_type, G_TYPE_VARIANT) || + iface_cache->g_type == G_TYPE_NONE) { + arg->v_pointer = pyg_pointer_get (py_arg, void); + } else { + PyErr_Format (PyExc_NotImplementedError, + "structure type '%s' is not supported yet", + g_type_name(iface_cache->g_type)); + return FALSE; + } + return TRUE; +} + +gboolean +_pygi_marshal_from_py_interface_boxed (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyErr_Format (PyExc_NotImplementedError, + "Marshalling for this type is not implemented yet"); + return FALSE; +} + +gboolean +_pygi_marshal_from_py_interface_object (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + + if (!PyObject_IsInstance (py_arg, ( (PyGIInterfaceCache *)arg_cache)->py_type)) { + PyErr_Format (PyExc_TypeError, "Expected %s, but got %s", + ( (PyGIInterfaceCache *)arg_cache)->type_name, + ( (PyGIInterfaceCache *)arg_cache)->py_type->ob_type->tp_name); + return FALSE; + } + + arg->v_pointer = pygobject_get(py_arg); + if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) + g_object_ref (arg->v_pointer); + + return TRUE; +} + +gboolean +_pygi_marshal_from_py_interface_union (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + PyErr_Format(PyExc_NotImplementedError, + "Marshalling for this type is not implemented yet"); + return FALSE; +} + +gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg) +{ + GIInfoType info_type; + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + + /* FIXME: add instance checks */ + + info_type = g_base_info_get_type (iface_cache->interface_info); + switch (info_type) { + case GI_INFO_TYPE_UNION: + case GI_INFO_TYPE_STRUCT: + { + GType type = iface_cache->g_type; + if (g_type_is_a (type, G_TYPE_BOXED)) { + arg->v_pointer = pyg_boxed_get (py_arg, void); + } else if (g_type_is_a (type, G_TYPE_POINTER) || + g_type_is_a (type, G_TYPE_VARIANT) || + type == G_TYPE_NONE) { + arg->v_pointer = pyg_pointer_get (py_arg, void); + } else { + PyErr_Format (PyExc_TypeError, "unable to convert an instance of '%s'", g_type_name (type)); + return FALSE; + } + + break; + } + case GI_INFO_TYPE_OBJECT: + case GI_INFO_TYPE_INTERFACE: + arg->v_pointer = pygobject_get (py_arg); + break; + default: + /* Other types don't have methods. */ + g_assert_not_reached (); + } + + return TRUE; +} diff --git a/gi/pygi-marshal-from-py.h b/gi/pygi-marshal-from-py.h new file mode 100644 index 00000000..34511db3 --- /dev/null +++ b/gi/pygi-marshal-from-py.h @@ -0,0 +1,186 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * vim: tabstop=4 shiftwidth=4 expandtab + * + * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef __PYGI_MARSHAL_from_py_PY_H__ +#define __PYGI_MARSHAL_from_py_PY_H__ + +#include + +#include + +#include "pygi-private.h" + +G_BEGIN_DECLS + +gboolean _pygi_marshal_from_py_void (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_boolean (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_int8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_uint8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_int16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_uint16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_int32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_uint32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_int64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_uint64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_float (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_double (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_unichar (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_gtype (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_utf8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_filename (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_array (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_glist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_gslist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_ghash (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_gerror (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_callback (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_enum (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_flags (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_struct (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_interface(PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_boxed (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_object (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_union (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); +gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + PyObject *py_arg, + GIArgument *arg); + +G_END_DECLS + +#endif /* __PYGI_MARSHAL_from_py_PY__ */ diff --git a/gi/pygi-marshal-in.c b/gi/pygi-marshal-in.c deleted file mode 100644 index 9ae7def8..00000000 --- a/gi/pygi-marshal-in.c +++ /dev/null @@ -1,1412 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * vim: tabstop=4 shiftwidth=4 expandtab - * - * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. - * - * pygi-marshal-in.c: PyObject conversion functions for in parameters. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -#include "pygi-private.h" - -#include -#include - -#include -#include -#include - -#include "pygi-cache.h" -#include "pygi-marshal-cleanup.h" -#include "pygi-marshal-in.h" - -gboolean -_pygi_marshal_in_void (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING); - - arg->v_pointer = py_arg; - - return TRUE; -} - -gboolean -_pygi_marshal_in_boolean (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - arg->v_boolean = PyObject_IsTrue (py_arg); - - return TRUE; -} - -gboolean -_pygi_marshal_in_int8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - long long_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - - long_ = PYGLIB_PyLong_AsLong (py_long); - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - PyErr_Clear (); - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127); - return FALSE; - } - - if (long_ < -128 || long_ > 127) { - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127); - return FALSE; - } - - arg->v_long = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_uint8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - unsigned long long_; - - if (PYGLIB_PyBytes_Check (py_arg)) { - - if (PYGLIB_PyBytes_Size (py_arg) != 1) { - PyErr_Format (PyExc_TypeError, "Must be a single character"); - return FALSE; - } - - long_ = (unsigned char)(PYGLIB_PyBytes_AsString (py_arg)[0]); - - } else if (PyNumber_Check (py_arg)) { - PyObject *py_long; - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - - long_ = PYGLIB_PyLong_AsLong (py_long); - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - PyErr_Clear(); - - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 255); - return FALSE; - } - } else { - PyErr_Format (PyExc_TypeError, "Must be number or single byte string, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - if (long_ < 0 || long_ > 255) { - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, 0, 255); - return FALSE; - } - - arg->v_long = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_int16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - long long_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - - long_ = PYGLIB_PyLong_AsLong (py_long); - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - PyErr_Clear (); - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -32768, 32767); - return FALSE; - } - - if (long_ < -32768 || long_ > 32767) { - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -32768, 32767); - return FALSE; - } - - arg->v_long = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_uint16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - long long_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - - long_ = PYGLIB_PyLong_AsLong (py_long); - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - PyErr_Clear (); - PyErr_Format (PyExc_ValueError, "%li not in range %d to %d", long_, 0, 65535); - return FALSE; - } - - if (long_ < 0 || long_ > 65535) { - PyErr_Format (PyExc_ValueError, "%li not in range %d to %d", long_, 0, 65535); - return FALSE; - } - - arg->v_long = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_int32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - long long_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - - long_ = PYGLIB_PyLong_AsLong (py_long); - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - PyErr_Clear(); - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, G_MININT32, G_MAXINT32); - return FALSE; - } - - if (long_ < G_MININT32 || long_ > G_MAXINT32) { - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, G_MININT32, G_MAXINT32); - return FALSE; - } - - arg->v_long = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_uint32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - long long long_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check (py_long)) - long_ = PyInt_AsLong (py_long); - else -#endif - long_ = PyLong_AsLongLong (py_long); - - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - PyErr_Clear (); - PyErr_Format (PyExc_ValueError, "%lli not in range %i to %u", long_, 0, G_MAXUINT32); - return FALSE; - } - - if (long_ < 0 || long_ > G_MAXUINT32) { - PyErr_Format (PyExc_ValueError, "%lli not in range %i to %u", long_, 0, G_MAXUINT32); - return FALSE; - } - - arg->v_uint64 = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_int64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - long long long_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check (py_long)) - long_ = PyInt_AS_LONG (py_long); - else -#endif - long_ = PyLong_AsLongLong (py_long); - - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - /* OverflowError occured but range errors should be returned as ValueError */ - char *long_str; - PyObject *py_str; - - PyErr_Clear (); - - py_str = PyObject_Str (py_long); - - if (PyUnicode_Check (py_str)) { - PyObject *py_bytes = PyUnicode_AsUTF8String (py_str); - if (py_bytes == NULL) - return FALSE; - - long_str = g_strdup (PYGLIB_PyBytes_AsString (py_bytes)); - if (long_str == NULL) { - PyErr_NoMemory (); - return FALSE; - } - - Py_DECREF (py_bytes); - } else { - long_str = g_strdup (PYGLIB_PyBytes_AsString(py_str)); - } - - Py_DECREF (py_str); - PyErr_Format (PyExc_ValueError, "%s not in range %ld to %ld", - long_str, G_MININT64, G_MAXINT64); - - g_free (long_str); - return FALSE; - } - - if (long_ < G_MININT64 || long_ > G_MAXINT64) { - PyErr_Format (PyExc_ValueError, "%lld not in range %ld to %ld", long_, G_MININT64, G_MAXINT64); - return FALSE; - } - - arg->v_int64 = long_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_uint64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_long; - guint64 ulong_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_long = PYGLIB_PyNumber_Long (py_arg); - if (!py_long) - return FALSE; - -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check (py_long)) { - long long_ = PyInt_AsLong (py_long); - if (long_ < 0) { - PyErr_Format (PyExc_ValueError, "%ld not in range %d to %llu", - long_, 0, G_MAXUINT64); - return FALSE; - } - ulong_ = long_; - } else -#endif - ulong_ = PyLong_AsUnsignedLongLong (py_long); - - Py_DECREF (py_long); - - if (PyErr_Occurred ()) { - /* OverflowError occured but range errors should be returned as ValueError */ - char *long_str; - PyObject *py_str; - - PyErr_Clear (); - - py_str = PyObject_Str (py_long); - - if (PyUnicode_Check (py_str)) { - PyObject *py_bytes = PyUnicode_AsUTF8String (py_str); - if (py_bytes == NULL) - return FALSE; - - long_str = g_strdup (PYGLIB_PyBytes_AsString (py_bytes)); - if (long_str == NULL) { - PyErr_NoMemory (); - return FALSE; - } - - Py_DECREF (py_bytes); - } else { - long_str = g_strdup (PYGLIB_PyBytes_AsString (py_str)); - } - - Py_DECREF (py_str); - - PyErr_Format (PyExc_ValueError, "%s not in range %d to %llu", - long_str, 0, G_MAXUINT64); - - g_free (long_str); - return FALSE; - } - - if (ulong_ > G_MAXUINT64) { - PyErr_Format (PyExc_ValueError, "%llu not in range %d to %llu", ulong_, 0, G_MAXUINT64); - return FALSE; - } - - arg->v_uint64 = ulong_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_float (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_float; - double double_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_float = PyNumber_Float (py_arg); - if (!py_float) - return FALSE; - - double_ = PyFloat_AsDouble (py_float); - Py_DECREF (py_float); - - if (PyErr_Occurred ()) { - PyErr_Clear (); - PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXFLOAT, G_MAXFLOAT); - return FALSE; - } - - if (double_ < -G_MAXFLOAT || double_ > G_MAXFLOAT) { - PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXFLOAT, G_MAXFLOAT); - return FALSE; - } - - arg->v_float = double_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_double (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *py_float; - double double_; - - if (!PyNumber_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be number, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - py_float = PyNumber_Float (py_arg); - if (!py_float) - return FALSE; - - double_ = PyFloat_AsDouble (py_float); - Py_DECREF (py_float); - - if (PyErr_Occurred ()) { - PyErr_Clear (); - PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXDOUBLE, G_MAXDOUBLE); - return FALSE; - } - - if (double_ < -G_MAXDOUBLE || double_ > G_MAXDOUBLE) { - PyErr_Format (PyExc_ValueError, "%f not in range %f to %f", double_, -G_MAXDOUBLE, G_MAXDOUBLE); - return FALSE; - } - - arg->v_double = double_; - - return TRUE; -} - -gboolean -_pygi_marshal_in_unichar (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - Py_ssize_t size; - gchar *string_; - - if (PyUnicode_Check (py_arg)) { - PyObject *py_bytes; - - size = PyUnicode_GET_SIZE (py_arg); - py_bytes = PyUnicode_AsUTF8String (py_arg); - string_ = strdup(PYGLIB_PyBytes_AsString (py_bytes)); - Py_DECREF (py_bytes); - -#if PY_VERSION_HEX < 0x03000000 - } else if (PyString_Check (py_arg)) { - PyObject *pyuni = PyUnicode_FromEncodedObject (py_arg, "UTF-8", "strict"); - if (!pyuni) - return FALSE; - - size = PyUnicode_GET_SIZE (pyuni); - string_ = g_strdup (PyString_AsString(py_arg)); - Py_DECREF (pyuni); -#endif - } else { - PyErr_Format (PyExc_TypeError, "Must be string, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - if (size != 1) { - PyErr_Format (PyExc_TypeError, "Must be a one character string, not %ld characters", - size); - g_free (string_); - return FALSE; - } - - arg->v_uint32 = g_utf8_get_char (string_); - g_free (string_); - - return TRUE; -} -gboolean -_pygi_marshal_in_gtype (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - long type_ = pyg_type_from_object (py_arg); - - if (type_ == 0) { - PyErr_Format (PyExc_TypeError, "Must be gobject.GType, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - arg->v_long = type_; - return TRUE; -} -gboolean -_pygi_marshal_in_utf8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - gchar *string_; - - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - if (PyUnicode_Check (py_arg)) { - PyObject *pystr_obj = PyUnicode_AsUTF8String (py_arg); - if (!pystr_obj) - return FALSE; - - string_ = g_strdup (PYGLIB_PyBytes_AsString (pystr_obj)); - Py_DECREF (pystr_obj); - } -#if PY_VERSION_HEX < 0x03000000 - else if (PyString_Check (py_arg)) { - string_ = g_strdup (PyString_AsString (py_arg)); - } -#endif - else { - PyErr_Format (PyExc_TypeError, "Must be string, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - arg->v_string = string_; - return TRUE; -} - -gboolean -_pygi_marshal_in_filename (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - gchar *string_; - GError *error = NULL; - - if (PyUnicode_Check (py_arg)) { - PyObject *pystr_obj = PyUnicode_AsUTF8String (py_arg); - if (!pystr_obj) - return FALSE; - - string_ = g_strdup (PYGLIB_PyBytes_AsString (pystr_obj)); - Py_DECREF (pystr_obj); - } -#if PY_VERSION_HEX < 0x03000000 - else if (PyString_Check (py_arg)) { - string_ = g_strdup (PyString_AsString (py_arg)); - } -#endif - else { - PyErr_Format (PyExc_TypeError, "Must be string, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - arg->v_string = g_filename_from_utf8 (string_, -1, NULL, NULL, &error); - g_free (string_); - - if (arg->v_string == NULL) { - PyErr_SetString (PyExc_Exception, error->message); - g_error_free (error); - /* TODO: Convert the error to an exception. */ - return FALSE; - } - - return TRUE; -} - -gboolean -_pygi_marshal_in_array (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyGIMarshalInFunc in_marshaller; - int i; - Py_ssize_t length; - gboolean is_ptr_array; - GArray *array_ = NULL; - PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; - - - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - if (!PySequence_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be sequence, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - length = PySequence_Length (py_arg); - if (length < 0) - return FALSE; - - if (sequence_cache->fixed_size >= 0 && - sequence_cache->fixed_size != length) { - PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd", - sequence_cache->fixed_size, length); - - return FALSE; - } - - is_ptr_array = (sequence_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY); - if (is_ptr_array) { - array_ = (GArray *)g_ptr_array_new (); - } else { - array_ = g_array_sized_new (sequence_cache->is_zero_terminated, - FALSE, - sequence_cache->item_size, - length); - } - - if (array_ == NULL) { - PyErr_NoMemory (); - return FALSE; - } - - if (sequence_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8 && - PYGLIB_PyBytes_Check (py_arg)) { - memcpy(array_->data, PYGLIB_PyBytes_AsString (py_arg), length); - - goto array_success; - } - - in_marshaller = sequence_cache->item_cache->in_marshaller; - for (i = 0; i < length; i++) { - GIArgument item; - PyObject *py_item = PySequence_GetItem (py_arg, i); - if (py_item == NULL) - goto err; - - if (!in_marshaller ( state, - callable_cache, - sequence_cache->item_cache, - py_item, - &item)) - goto err; - - /* FIXME: it is much more efficent to have seperate marshaller - * for ptr arrays than doing the evaluation - * and casting each loop iteration - */ - if (is_ptr_array) - g_ptr_array_add((GPtrArray *)array_, item.v_pointer); - else - g_array_insert_val (array_, i, item); - continue; -err: - if (sequence_cache->item_cache->in_cleanup != NULL) { - gsize j; - PyGIMarshalCleanupFunc cleanup_func = - sequence_cache->item_cache->in_cleanup; - - for(j = 0; j < i; j++) { - cleanup_func (state, - sequence_cache->item_cache, - g_array_index (array_, gpointer, j), - TRUE); - } - } - - if (is_ptr_array) - g_ptr_array_free (array_, TRUE); - else - g_array_free (array_, TRUE); - _PyGI_ERROR_PREFIX ("Item %i: ", i); - return FALSE; - } - -array_success: - if (sequence_cache->len_arg_index >= 0) { - /* we have an child arg to handle */ - PyGIArgCache *child_cache = - callable_cache->args_cache[sequence_cache->len_arg_index]; - - if (child_cache->direction == GI_DIRECTION_INOUT) { - gint *len_arg = (gint *)state->in_args[child_cache->c_arg_index].v_pointer; - /* if we are not setup yet just set the in arg */ - if (len_arg == NULL) - state->in_args[child_cache->c_arg_index].v_long = length; - else - *len_arg = length; - } else { - state->in_args[child_cache->c_arg_index].v_long = length; - } - } - - if (sequence_cache->array_type == GI_ARRAY_TYPE_C) { - arg->v_pointer = array_->data; - g_array_free (array_, FALSE); - } else { - arg->v_pointer = array_; - } - - return TRUE; -} - -gboolean -_pygi_marshal_in_glist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyGIMarshalInFunc in_marshaller; - int i; - Py_ssize_t length; - GList *list_ = NULL; - PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; - - - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - if (!PySequence_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be sequence, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - length = PySequence_Length (py_arg); - if (length < 0) - return FALSE; - - if (sequence_cache->fixed_size >= 0 && - sequence_cache->fixed_size != length) { - PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd", - sequence_cache->fixed_size, length); - - return FALSE; - } - - in_marshaller = sequence_cache->item_cache->in_marshaller; - for (i = 0; i < length; i++) { - GIArgument item; - PyObject *py_item = PySequence_GetItem (py_arg, i); - if (py_item == NULL) - goto err; - - if (!in_marshaller ( state, - callable_cache, - sequence_cache->item_cache, - py_item, - &item)) - goto err; - - list_ = g_list_append (list_, item.v_pointer); - continue; -err: - if (sequence_cache->item_cache->in_cleanup != NULL) { - GDestroyNotify cleanup = sequence_cache->item_cache->in_cleanup; - } - - g_list_free (list_); - _PyGI_ERROR_PREFIX ("Item %i: ", i); - return FALSE; - } - - arg->v_pointer = list_; - return TRUE; -} - -gboolean -_pygi_marshal_in_gslist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyGIMarshalInFunc in_marshaller; - int i; - Py_ssize_t length; - GSList *list_ = NULL; - PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache; - - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - if (!PySequence_Check (py_arg)) { - PyErr_Format (PyExc_TypeError, "Must be sequence, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - length = PySequence_Length (py_arg); - if (length < 0) - return FALSE; - - if (sequence_cache->fixed_size >= 0 && - sequence_cache->fixed_size != length) { - PyErr_Format (PyExc_ValueError, "Must contain %zd items, not %zd", - sequence_cache->fixed_size, length); - - return FALSE; - } - - in_marshaller = sequence_cache->item_cache->in_marshaller; - for (i = 0; i < length; i++) { - GIArgument item; - PyObject *py_item = PySequence_GetItem (py_arg, i); - if (py_item == NULL) - goto err; - - if (!in_marshaller ( state, - callable_cache, - sequence_cache->item_cache, - py_item, - &item)) - goto err; - - list_ = g_slist_append (list_, item.v_pointer); - continue; -err: - if (sequence_cache->item_cache->in_cleanup != NULL) { - GDestroyNotify cleanup = sequence_cache->item_cache->in_cleanup; - } - - g_slist_free (list_); - _PyGI_ERROR_PREFIX ("Item %i: ", i); - return FALSE; - } - - arg->v_pointer = list_; - return TRUE; -} - -gboolean -_pygi_marshal_in_ghash (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyGIMarshalInFunc key_in_marshaller; - PyGIMarshalInFunc value_in_marshaller; - - int i; - Py_ssize_t length; - PyObject *py_keys, *py_values; - - GHashFunc hash_func; - GEqualFunc equal_func; - - GHashTable *hash_ = NULL; - PyGIHashCache *hash_cache = (PyGIHashCache *)arg_cache; - - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - py_keys = PyMapping_Keys (py_arg); - if (py_keys == NULL) { - PyErr_Format (PyExc_TypeError, "Must be mapping, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - length = PyMapping_Length (py_arg); - if (length < 0) { - Py_DECREF (py_keys); - return FALSE; - } - - py_values = PyMapping_Values (py_arg); - if (py_values == NULL) { - Py_DECREF (py_keys); - return FALSE; - } - - key_in_marshaller = hash_cache->key_cache->in_marshaller; - value_in_marshaller = hash_cache->value_cache->in_marshaller; - - switch (hash_cache->key_cache->type_tag) { - case GI_TYPE_TAG_UTF8: - case GI_TYPE_TAG_FILENAME: - hash_func = g_str_hash; - equal_func = g_str_equal; - break; - default: - hash_func = NULL; - equal_func = NULL; - } - - hash_ = g_hash_table_new (hash_func, equal_func); - if (hash_ == NULL) { - PyErr_NoMemory (); - Py_DECREF (py_keys); - Py_DECREF (py_values); - return FALSE; - } - - for (i = 0; i < length; i++) { - GIArgument key, value; - PyObject *py_key = PyList_GET_ITEM (py_keys, i); - PyObject *py_value = PyList_GET_ITEM (py_values, i); - if (py_key == NULL || py_value == NULL) - goto err; - - if (!key_in_marshaller ( state, - callable_cache, - hash_cache->key_cache, - py_key, - &key)) - goto err; - - if (!value_in_marshaller ( state, - callable_cache, - hash_cache->value_cache, - py_value, - &value)) - goto err; - - g_hash_table_insert (hash_, key.v_pointer, value.v_pointer); - continue; -err: - /* FIXME: cleanup hash keys and values */ - Py_XDECREF (py_key); - Py_XDECREF (py_value); - Py_DECREF (py_keys); - Py_DECREF (py_values); - g_hash_table_unref (hash_); - _PyGI_ERROR_PREFIX ("Item %i: ", i); - return FALSE; - } - - arg->v_pointer = hash_; - return TRUE; -} - -gboolean -_pygi_marshal_in_gerror (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyErr_Format (PyExc_NotImplementedError, - "Marshalling for GErrors is not implemented"); - return FALSE; -} - -gboolean -_pygi_marshal_in_interface_callback (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - GICallableInfo *callable_info; - PyGICClosure *closure; - PyGIArgCache *user_data_cache = NULL; - PyGIArgCache *destroy_cache = NULL; - PyGICallbackCache *callback_cache; - PyObject *py_user_data = NULL; - - callback_cache = (PyGICallbackCache *)arg_cache; - - if (callback_cache->user_data_index > 0) { - user_data_cache = callable_cache->args_cache[callback_cache->user_data_index]; - if (user_data_cache->py_arg_index < state->n_py_in_args) { - py_user_data = PyTuple_GetItem (state->py_in_args, user_data_cache->py_arg_index); - if (!py_user_data) - return FALSE; - } else { - py_user_data = Py_None; - Py_INCREF (Py_None); - } - } - - if (py_arg == Py_None && !(py_user_data == Py_None || py_user_data == NULL)) { - Py_DECREF (py_user_data); - PyErr_Format (PyExc_TypeError, - "When passing None for a callback userdata must also be None"); - - return FALSE; - } - - if (py_arg == Py_None) { - Py_XDECREF (py_user_data); - return TRUE; - } - - if (!PyCallable_Check (py_arg)) { - Py_XDECREF (py_user_data); - PyErr_Format (PyExc_TypeError, - "Callback needs to be a function or method not %s", - py_arg->ob_type->tp_name); - - return FALSE; - } - - if (callback_cache->destroy_notify_index > 0) - destroy_cache = callable_cache->args_cache[callback_cache->destroy_notify_index]; - - callable_info = (GICallableInfo *)callback_cache->interface_info; - - closure = _pygi_make_native_closure (callable_info, callback_cache->scope, py_arg, py_user_data); - arg->v_pointer = closure->closure; - if (user_data_cache != NULL) { - state->in_args[user_data_cache->c_arg_index].v_pointer = closure; - } - - if (destroy_cache) { - PyGICClosure *destroy_notify = _pygi_destroy_notify_create (); - state->in_args[destroy_cache->c_arg_index].v_pointer = destroy_notify->closure; - } - - return TRUE; -} - -gboolean -_pygi_marshal_in_interface_enum (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *int_; - gint is_instance; - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - - is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type); - - int_ = PYGLIB_PyNumber_Long (py_arg); - if (int_ == NULL) { - PyErr_Clear(); - goto err; - } - - arg->v_long = PYGLIB_PyLong_AsLong (int_); - Py_DECREF (int_); - - /* If this is not an instance of the Enum type that we want - * we need to check if the value is equivilant to one of the - * Enum's memebers */ - if (!is_instance) { - int i; - gboolean is_found = FALSE; - - for (i = 0; i < g_enum_info_get_n_values (iface_cache->interface_info); i++) { - GIValueInfo *value_info = - g_enum_info_get_value (iface_cache->interface_info, i); - glong enum_value = g_value_info_get_value (value_info); - g_base_info_unref ( (GIBaseInfo *)value_info); - if (arg->v_long == enum_value) { - is_found = TRUE; - break; - } - } - - if (!is_found) - goto err; - } - - return TRUE; - -err: - PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", - iface_cache->type_name, py_arg->ob_type->tp_name); - return FALSE; -} - -gboolean -_pygi_marshal_in_interface_flags (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyObject *int_; - gint is_instance; - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - - is_instance = PyObject_IsInstance (py_arg, iface_cache->py_type); - - int_ = PYGLIB_PyNumber_Long (py_arg); - if (int_ == NULL) { - PyErr_Clear (); - goto err; - } - - arg->v_long = PYGLIB_PyLong_AsLong (int_); - Py_DECREF (int_); - - /* only 0 or argument of type Flag is allowed */ - if (!is_instance && arg->v_long != 0) - goto err; - - return TRUE; - -err: - PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", - iface_cache->type_name, py_arg->ob_type->tp_name); - return FALSE; - -} - -gboolean -_pygi_marshal_in_interface_struct (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - /* FIXME: handle this large if statement in the cache - * and set the correct marshaller - */ - - if (iface_cache->g_type == G_TYPE_CLOSURE) { - GClosure *closure; - GType object_gtype = pyg_type_from_object_strict (py_arg, FALSE); - - if ( !(PyCallable_Check(py_arg) || - g_type_is_a (object_gtype, G_TYPE_CLOSURE))) { - PyErr_Format (PyExc_TypeError, "Must be callable, not %s", - py_arg->ob_type->tp_name); - return FALSE; - } - - if (g_type_is_a (object_gtype, G_TYPE_CLOSURE)) - closure = (GClosure *)pyg_boxed_get (py_arg, void); - else - closure = pyg_closure_new (py_arg, NULL, NULL); - - if (closure == NULL) { - PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GClosure failed"); - return FALSE; - } - - arg->v_pointer = closure; - return TRUE; - } else if (iface_cache->g_type == G_TYPE_VALUE) { - GValue *value; - GType object_type; - - object_type = pyg_type_from_object_strict ( (PyObject *) py_arg->ob_type, FALSE); - if (object_type == G_TYPE_INVALID) { - PyErr_SetString (PyExc_RuntimeError, "unable to retrieve object's GType"); - return FALSE; - } - - /* if already a gvalue, use that, else marshal into gvalue */ - if (object_type == G_TYPE_VALUE) { - value = (GValue *)( (PyGObject *)py_arg)->obj; - } else { - value = g_slice_new0 (GValue); - g_value_init (value, object_type); - if (pyg_value_from_pyobject (value, py_arg) < 0) { - g_slice_free (GValue, value); - PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GValue failed"); - return FALSE; - } - } - - arg->v_pointer = value; - return TRUE; - } else if (iface_cache->is_foreign) { - gboolean success; - success = pygi_struct_foreign_convert_to_g_argument (py_arg, - iface_cache->interface_info, - arg_cache->transfer, - arg); - - return success; - } else if (!PyObject_IsInstance (py_arg, iface_cache->py_type)) { - PyErr_Format (PyExc_TypeError, "Expected %s, but got %s", - iface_cache->type_name, - iface_cache->py_type->ob_type->tp_name); - return FALSE; - } - - if (g_type_is_a (iface_cache->g_type, G_TYPE_BOXED)) { - arg->v_pointer = pyg_boxed_get (py_arg, void); - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) { - arg->v_pointer = g_boxed_copy (iface_cache->g_type, arg->v_pointer); - } - } else if (g_type_is_a (iface_cache->g_type, G_TYPE_POINTER) || - g_type_is_a (iface_cache->g_type, G_TYPE_VARIANT) || - iface_cache->g_type == G_TYPE_NONE) { - arg->v_pointer = pyg_pointer_get (py_arg, void); - } else { - PyErr_Format (PyExc_NotImplementedError, - "structure type '%s' is not supported yet", - g_type_name(iface_cache->g_type)); - return FALSE; - } - return TRUE; -} - -gboolean -_pygi_marshal_in_interface_boxed (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyErr_Format (PyExc_NotImplementedError, - "Marshalling for this type is not implemented yet"); - return FALSE; -} - -gboolean -_pygi_marshal_in_interface_object (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - if (py_arg == Py_None) { - arg->v_pointer = NULL; - return TRUE; - } - - if (!PyObject_IsInstance (py_arg, ( (PyGIInterfaceCache *)arg_cache)->py_type)) { - PyErr_Format (PyExc_TypeError, "Expected %s, but got %s", - ( (PyGIInterfaceCache *)arg_cache)->type_name, - ( (PyGIInterfaceCache *)arg_cache)->py_type->ob_type->tp_name); - return FALSE; - } - - arg->v_pointer = pygobject_get(py_arg); - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) - g_object_ref (arg->v_pointer); - - return TRUE; -} - -gboolean -_pygi_marshal_in_interface_union (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - PyErr_Format(PyExc_NotImplementedError, - "Marshalling for this type is not implemented yet"); - return FALSE; -} - -gboolean _pygi_marshal_in_interface_instance (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg) -{ - GIInfoType info_type; - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - - /* FIXME: add instance checks */ - - info_type = g_base_info_get_type (iface_cache->interface_info); - switch (info_type) { - case GI_INFO_TYPE_UNION: - case GI_INFO_TYPE_STRUCT: - { - GType type = iface_cache->g_type; - if (g_type_is_a (type, G_TYPE_BOXED)) { - arg->v_pointer = pyg_boxed_get (py_arg, void); - } else if (g_type_is_a (type, G_TYPE_POINTER) || - g_type_is_a (type, G_TYPE_VARIANT) || - type == G_TYPE_NONE) { - arg->v_pointer = pyg_pointer_get (py_arg, void); - } else { - PyErr_Format (PyExc_TypeError, "unable to convert an instance of '%s'", g_type_name (type)); - return FALSE; - } - - break; - } - case GI_INFO_TYPE_OBJECT: - case GI_INFO_TYPE_INTERFACE: - arg->v_pointer = pygobject_get (py_arg); - break; - default: - /* Other types don't have methods. */ - g_assert_not_reached (); - } - - return TRUE; -} diff --git a/gi/pygi-marshal-in.h b/gi/pygi-marshal-in.h deleted file mode 100644 index 7d948bc9..00000000 --- a/gi/pygi-marshal-in.h +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * vim: tabstop=4 shiftwidth=4 expandtab - * - * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -#ifndef __PYGI_MARSHAL_H__ -#define __PYGI_MARSHAL_H__ - -#include - -#include - -#include "pygi-private.h" - -G_BEGIN_DECLS - -gboolean _pygi_marshal_in_void (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_boolean (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_int8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_uint8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_int16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_uint16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_int32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_uint32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_int64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_uint64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_float (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_double (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_unichar (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_gtype (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_utf8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_filename (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_array (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_glist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_gslist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_ghash (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_gerror (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_callback (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_enum (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_flags (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_struct (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_interface(PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_boxed (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_object (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_union (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); -gboolean _pygi_marshal_in_interface_instance (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - PyObject *py_arg, - GIArgument *arg); - -G_END_DECLS - -#endif /* __PYGI_MARSHAL_H__ */ diff --git a/gi/pygi-marshal-out.c b/gi/pygi-marshal-out.c deleted file mode 100644 index e72db80c..00000000 --- a/gi/pygi-marshal-out.c +++ /dev/null @@ -1,768 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * vim: tabstop=4 shiftwidth=4 expandtab - * - * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. - * - * pygi-marshal-out.c: PyObject conversion functions for out parameters. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -#include "pygi-private.h" - -#include -#include - -#include -#include -#include - -#include "pygi-cache.h" -#include "pygi-marshal-cleanup.h" -#include "pygi-marshal-out.h" - -PyObject * -_pygi_marshal_out_void (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - if (arg_cache->is_pointer) - py_obj = arg->v_pointer; - else - py_obj = Py_None; - - Py_XINCREF (py_obj); - return py_obj; -} - -PyObject * -_pygi_marshal_out_boolean (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PyBool_FromLong (arg->v_boolean); - return py_obj; -} - -PyObject * -_pygi_marshal_out_int8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int8); - return py_obj; -} - -PyObject * -_pygi_marshal_out_uint8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint8); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_int16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int16); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_uint16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint16); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_int32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int32); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_uint32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PyLong_FromLongLong (arg->v_uint32); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_int64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PyLong_FromLongLong (arg->v_int64); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_uint64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PyLong_FromUnsignedLongLong (arg->v_uint64); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_float (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PyFloat_FromDouble (arg->v_float); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_double (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = PyFloat_FromDouble (arg->v_double); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_unichar (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - /* Preserve the bidirectional mapping between 0 and "" */ - if (arg->v_uint32 == 0) { - py_obj = PYGLIB_PyUnicode_FromString (""); - } else if (g_unichar_validate (arg->v_uint32)) { - gchar utf8[6]; - gint bytes; - - bytes = g_unichar_to_utf8 (arg->v_uint32, utf8); - py_obj = PYGLIB_PyUnicode_FromStringAndSize ((char*)utf8, bytes); - } else { - /* TODO: Convert the error to an exception. */ - PyErr_Format (PyExc_TypeError, - "Invalid unicode codepoint %" G_GUINT32_FORMAT, - arg->v_uint32); - } - - return py_obj; -} - -PyObject * -_pygi_marshal_out_gtype (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - py_obj = pyg_type_wrapper_new ( (GType)arg->v_long); - return py_obj; -} - -PyObject * -_pygi_marshal_out_utf8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - if (arg->v_string == NULL) { - py_obj = Py_None; - Py_INCREF (py_obj); - return py_obj; - } - - py_obj = PYGLIB_PyUnicode_FromString (arg->v_string); - return py_obj; -} - -PyObject * -_pygi_marshal_out_filename (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - gchar *string; - PyObject *py_obj = NULL; - GError *error = NULL; - - if (arg->v_string == NULL) { - py_obj = Py_None; - Py_INCREF (py_obj); - return py_obj; - } - - string = g_filename_to_utf8 (arg->v_string, -1, NULL, NULL, &error); - if (string == NULL) { - PyErr_SetString (PyExc_Exception, error->message); - /* TODO: Convert the error to an exception. */ - return NULL; - } - - py_obj = PYGLIB_PyUnicode_FromString (string); - g_free (string); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_array (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - GArray *array_; - PyObject *py_obj = NULL; - PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; - gsize processed_items = 0; - - array_ = arg->v_pointer; - - /* GArrays make it easier to iterate over arrays - * with different element sizes but requires that - * we allocate a GArray if the argument was a C array - */ - if (seq_cache->array_type == GI_ARRAY_TYPE_C) { - gsize len; - if (seq_cache->fixed_size >= 0) { - len = seq_cache->fixed_size; - } else if (seq_cache->is_zero_terminated) { - len = g_strv_length (arg->v_string); - } else { - GIArgument *len_arg = state->args[seq_cache->len_arg_index]; - len = len_arg->v_long; - } - - array_ = g_array_new (FALSE, - FALSE, - seq_cache->item_size); - if (array_ == NULL) { - PyErr_NoMemory (); - - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) - g_free (arg->v_pointer); - - return NULL; - } - - array_->data = arg->v_pointer; - array_->len = len; - } - - if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) { - if (arg->v_pointer == NULL) { - py_obj = PYGLIB_PyBytes_FromString (""); - } else { - py_obj = PYGLIB_PyBytes_FromStringAndSize (array_->data, array_->len); - } - } else { - if (arg->v_pointer == NULL) { - py_obj = PyList_New (0); - } else { - int i; - - gsize item_size; - PyGIMarshalOutFunc item_out_marshaller; - PyGIArgCache *item_arg_cache; - - py_obj = PyList_New (array_->len); - if (py_obj == NULL) - goto err; - - - item_arg_cache = seq_cache->item_cache; - item_out_marshaller = item_arg_cache->out_marshaller; - - item_size = g_array_get_element_size (array_); - - for (i = 0; i < array_->len; i++) { - GIArgument item_arg; - PyObject *py_item; - - if (seq_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY) { - item_arg.v_pointer = g_ptr_array_index ( ( GPtrArray *)array_, i); - } else if (item_arg_cache->type_tag == GI_TYPE_TAG_INTERFACE) { - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *) item_arg_cache; - - switch (g_base_info_get_type (iface_cache->interface_info)) { - case GI_INFO_TYPE_STRUCT: - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) { - gpointer *_struct = g_malloc (item_size); - memcpy (_struct, array_->data + i * item_size, - item_size); - item_arg.v_pointer = _struct; - } else - item_arg.v_pointer = array_->data + i * item_size; - break; - default: - item_arg.v_pointer = g_array_index (array_, gpointer, i); - break; - } - } else { - memcpy (&item_arg, array_->data + i * item_size, item_size); - } - - py_item = item_out_marshaller ( state, - callable_cache, - item_arg_cache, - &item_arg); - - if (py_item == NULL) { - Py_CLEAR (py_obj); - - if (seq_cache->array_type == GI_ARRAY_TYPE_C) - g_array_unref (array_); - - goto err; - } - PyList_SET_ITEM (py_obj, i, py_item); - processed_items++; - } - } - } - - if (seq_cache->array_type == GI_ARRAY_TYPE_C) - g_array_free (array_, FALSE); - - return py_obj; - -err: - if (seq_cache->array_type == GI_ARRAY_TYPE_C) { - g_array_free (array_, arg_cache->transfer == GI_TRANSFER_EVERYTHING); - } else { - /* clean up unprocessed items */ - if (seq_cache->item_cache->out_cleanup != NULL) { - int j; - PyGIMarshalCleanupFunc cleanup_func = seq_cache->item_cache->out_cleanup; - for (j = processed_items; j < array_->len; j++) { - cleanup_func (state, - seq_cache->item_cache, - g_array_index (array_, gpointer, j), - FALSE); - } - } - - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) - g_array_free (array_, TRUE); - } - - return NULL; -} - -PyObject * -_pygi_marshal_out_glist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - GList *list_; - gsize length; - gsize i; - - PyGIMarshalOutFunc item_out_marshaller; - PyGIArgCache *item_arg_cache; - PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; - - PyObject *py_obj = NULL; - - list_ = arg->v_pointer; - length = g_list_length (list_); - - py_obj = PyList_New (length); - if (py_obj == NULL) - return NULL; - - item_arg_cache = seq_cache->item_cache; - item_out_marshaller = item_arg_cache->out_marshaller; - - for (i = 0; list_ != NULL; list_ = g_list_next (list_), i++) { - GIArgument item_arg; - PyObject *py_item; - - item_arg.v_pointer = list_->data; - py_item = item_out_marshaller ( state, - callable_cache, - item_arg_cache, - &item_arg); - - if (py_item == NULL) { - Py_CLEAR (py_obj); - _PyGI_ERROR_PREFIX ("Item %zu: ", i); - return NULL; - } - - PyList_SET_ITEM (py_obj, i, py_item); - } - - return py_obj; -} - -PyObject * -_pygi_marshal_out_gslist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - GSList *list_; - gsize length; - gsize i; - - PyGIMarshalOutFunc item_out_marshaller; - PyGIArgCache *item_arg_cache; - PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; - - PyObject *py_obj = NULL; - - list_ = arg->v_pointer; - length = g_slist_length (list_); - - py_obj = PyList_New (length); - if (py_obj == NULL) - return NULL; - - item_arg_cache = seq_cache->item_cache; - item_out_marshaller = item_arg_cache->out_marshaller; - - for (i = 0; list_ != NULL; list_ = g_slist_next (list_), i++) { - GIArgument item_arg; - PyObject *py_item; - - item_arg.v_pointer = list_->data; - py_item = item_out_marshaller ( state, - callable_cache, - item_arg_cache, - &item_arg); - - if (py_item == NULL) { - Py_CLEAR (py_obj); - _PyGI_ERROR_PREFIX ("Item %zu: ", i); - return NULL; - } - - PyList_SET_ITEM (py_obj, i, py_item); - } - - return py_obj; -} - -PyObject * -_pygi_marshal_out_ghash (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - GHashTable *hash_; - GHashTableIter hash_table_iter; - - PyGIMarshalOutFunc key_out_marshaller; - PyGIMarshalOutFunc value_out_marshaller; - - PyGIArgCache *key_arg_cache; - PyGIArgCache *value_arg_cache; - PyGIHashCache *hash_cache = (PyGIHashCache *)arg_cache; - - GIArgument key_arg; - GIArgument value_arg; - - PyObject *py_obj = NULL; - - hash_ = arg->v_pointer; - - if (hash_ == NULL) { - py_obj = Py_None; - Py_INCREF (py_obj); - return py_obj; - } - - py_obj = PyDict_New (); - if (py_obj == NULL) - return NULL; - - key_arg_cache = hash_cache->key_cache; - key_out_marshaller = key_arg_cache->out_marshaller; - - value_arg_cache = hash_cache->value_cache; - value_out_marshaller = value_arg_cache->out_marshaller; - - g_hash_table_iter_init (&hash_table_iter, hash_); - while (g_hash_table_iter_next (&hash_table_iter, - &key_arg.v_pointer, - &value_arg.v_pointer)) { - PyObject *py_key; - PyObject *py_value; - int retval; - - py_key = key_out_marshaller ( state, - callable_cache, - key_arg_cache, - &key_arg); - - if (py_key == NULL) { - Py_CLEAR (py_obj); - return NULL; - } - - py_value = value_out_marshaller ( state, - callable_cache, - value_arg_cache, - &value_arg); - - if (py_value == NULL) { - Py_CLEAR (py_obj); - Py_DECREF(py_key); - return NULL; - } - - retval = PyDict_SetItem (py_obj, py_key, py_value); - - Py_DECREF (py_key); - Py_DECREF (py_value); - - if (retval < 0) { - Py_CLEAR (py_obj); - return NULL; - } - } - - return py_obj; -} - -PyObject * -_pygi_marshal_out_gerror (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - PyErr_Format (PyExc_NotImplementedError, - "Marshalling for gerror out is not implemented"); - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_callback (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - PyErr_Format (PyExc_NotImplementedError, - "Callback out values are not supported"); - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_enum (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - - if (iface_cache->g_type == G_TYPE_NONE) { - py_obj = PyObject_CallFunction (iface_cache->py_type, "l", arg->v_long); - } else { - py_obj = pyg_enum_from_gtype (iface_cache->g_type, arg->v_long); - } - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_flags (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - - if (iface_cache->g_type == G_TYPE_NONE) { - /* An enum with a GType of None is an enum without GType */ - - PyObject *py_type = _pygi_type_import_by_gi_info (iface_cache->interface_info); - PyObject *py_args = NULL; - - if (!py_type) - return NULL; - - py_args = PyTuple_New (1); - if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (arg->v_long)) != 0) { - Py_DECREF (py_args); - Py_DECREF (py_type); - return NULL; - } - - py_obj = PyObject_CallFunction (py_type, "l", arg->v_long); - - Py_DECREF (py_args); - Py_DECREF (py_type); - } else { - py_obj = pyg_flags_from_gtype (iface_cache->g_type, arg->v_long); - } - - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_struct (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - GType type = iface_cache->g_type; - - if (arg->v_pointer == NULL) { - py_obj = Py_None; - Py_INCREF (py_obj); - return py_obj; - } - - if (g_type_is_a (type, G_TYPE_VALUE)) { - py_obj = pyg_value_as_pyobject (arg->v_pointer, FALSE); - } else if (iface_cache->is_foreign) { - py_obj = pygi_struct_foreign_convert_from_g_argument (iface_cache->interface_info, - arg->v_pointer); - } else if (g_type_is_a (type, G_TYPE_BOXED)) { - py_obj = _pygi_boxed_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, - arg_cache->transfer == GI_TRANSFER_EVERYTHING); - } else if (g_type_is_a (type, G_TYPE_POINTER)) { - if (iface_cache->py_type == NULL || - !PyType_IsSubtype ( (PyTypeObject *)iface_cache->py_type, &PyGIStruct_Type)) { - g_warn_if_fail(arg_cache->transfer == GI_TRANSFER_NOTHING); - py_obj = pyg_pointer_new (type, arg->v_pointer); - } else { - py_obj = _pygi_struct_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, - arg_cache->transfer == GI_TRANSFER_EVERYTHING); - } - } else if (g_type_is_a (type, G_TYPE_VARIANT)) { - g_variant_ref_sink (arg->v_pointer); - py_obj = _pygi_struct_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, - FALSE); - } else if (type == G_TYPE_NONE && iface_cache->is_foreign) { - py_obj = pygi_struct_foreign_convert_from_g_argument (iface_cache->interface_info, arg->v_pointer); - } else if (type == G_TYPE_NONE) { - py_obj = _pygi_struct_new ( (PyTypeObject *) iface_cache->py_type, arg->v_pointer, - arg_cache->transfer == GI_TRANSFER_EVERYTHING); - } else { - PyErr_Format (PyExc_NotImplementedError, - "structure type '%s' is not supported yet", - g_type_name (type)); - } - - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_interface (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - PyErr_Format (PyExc_NotImplementedError, - "Marshalling for this type is not implemented yet"); - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_boxed (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - PyErr_Format (PyExc_NotImplementedError, - "Marshalling for this type is not implemented yet"); - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_object (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj; - - if (arg->v_pointer == NULL) { - py_obj = Py_None; - Py_INCREF (py_obj); - return py_obj; - } - - py_obj = pygobject_new (arg->v_pointer); - - if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) - g_object_unref (arg->v_pointer); - - return py_obj; -} - -PyObject * -_pygi_marshal_out_interface_union (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg) -{ - PyObject *py_obj = NULL; - - PyErr_Format (PyExc_NotImplementedError, - "Marshalling for this type is not implemented yet"); - return py_obj; -} diff --git a/gi/pygi-marshal-out.h b/gi/pygi-marshal-out.h deleted file mode 100644 index db6bcfed..00000000 --- a/gi/pygi-marshal-out.h +++ /dev/null @@ -1,144 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * vim: tabstop=4 shiftwidth=4 expandtab - * - * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -#ifndef __PYGI_MARSHAL_OUT_H__ -#define __PYGI_MARSHAL_OUT_H__ - -PyObject *_pygi_marshal_out_void (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_boolean (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_int8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_uint8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_int16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_uint16 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_int32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_uint32 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_int64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_uint64 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_float (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_double (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_unichar (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_gtype (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_utf8 (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_filename (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_array (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_glist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_gslist (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_ghash (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_gerror (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_callback(PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_enum (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_flags (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_struct (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_interface(PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_boxed (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_object (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); -PyObject *_pygi_marshal_out_interface_union (PyGIInvokeState *state, - PyGICallableCache *callable_cache, - PyGIArgCache *arg_cache, - GIArgument *arg); - -G_END_DECLS - -#endif /* __PYGI_MARSHAL_OUT_H__ */ diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c new file mode 100644 index 00000000..cb62c49c --- /dev/null +++ b/gi/pygi-marshal-to-py.c @@ -0,0 +1,768 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * vim: tabstop=4 shiftwidth=4 expandtab + * + * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. + * + * pygi-marshal-from-py.c: functions for converting C types to PyObject + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "pygi-private.h" + +#include +#include + +#include +#include +#include + +#include "pygi-cache.h" +#include "pygi-marshal-cleanup.h" +#include "pygi-marshal-to-py.h" + +PyObject * +_pygi_marshal_to_py_void (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + if (arg_cache->is_pointer) + py_obj = arg->v_pointer; + else + py_obj = Py_None; + + Py_XINCREF (py_obj); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_boolean (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PyBool_FromLong (arg->v_boolean); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_int8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int8); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_uint8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint8); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_int16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int16); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_uint16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint16); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_int32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int32); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_uint32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PyLong_FromLongLong (arg->v_uint32); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_int64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PyLong_FromLongLong (arg->v_int64); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_uint64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PyLong_FromUnsignedLongLong (arg->v_uint64); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_float (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PyFloat_FromDouble (arg->v_float); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_double (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = PyFloat_FromDouble (arg->v_double); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_unichar (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + /* Preserve the bidirectional mapping between 0 and "" */ + if (arg->v_uint32 == 0) { + py_obj = PYGLIB_PyUnicode_FromString (""); + } else if (g_unichar_validate (arg->v_uint32)) { + gchar utf8[6]; + gint bytes; + + bytes = g_unichar_to_utf8 (arg->v_uint32, utf8); + py_obj = PYGLIB_PyUnicode_FromStringAndSize ((char*)utf8, bytes); + } else { + /* TODO: Convert the error to an exception. */ + PyErr_Format (PyExc_TypeError, + "Invalid unicode codepoint %" G_GUINT32_FORMAT, + arg->v_uint32); + } + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_gtype (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + py_obj = pyg_type_wrapper_new ( (GType)arg->v_long); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_utf8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + if (arg->v_string == NULL) { + py_obj = Py_None; + Py_INCREF (py_obj); + return py_obj; + } + + py_obj = PYGLIB_PyUnicode_FromString (arg->v_string); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_filename (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + gchar *string; + PyObject *py_obj = NULL; + GError *error = NULL; + + if (arg->v_string == NULL) { + py_obj = Py_None; + Py_INCREF (py_obj); + return py_obj; + } + + string = g_filename_to_utf8 (arg->v_string, -1, NULL, NULL, &error); + if (string == NULL) { + PyErr_SetString (PyExc_Exception, error->message); + /* TODO: Convert the error to an exception. */ + return NULL; + } + + py_obj = PYGLIB_PyUnicode_FromString (string); + g_free (string); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_array (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + GArray *array_; + PyObject *py_obj = NULL; + PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; + gsize processed_items = 0; + + array_ = arg->v_pointer; + + /* GArrays make it easier to iterate over arrays + * with different element sizes but requires that + * we allocate a GArray if the argument was a C array + */ + if (seq_cache->array_type == GI_ARRAY_TYPE_C) { + gsize len; + if (seq_cache->fixed_size >= 0) { + len = seq_cache->fixed_size; + } else if (seq_cache->is_zero_terminated) { + len = g_strv_length (arg->v_string); + } else { + GIArgument *len_arg = state->args[seq_cache->len_arg_index]; + len = len_arg->v_long; + } + + array_ = g_array_new (FALSE, + FALSE, + seq_cache->item_size); + if (array_ == NULL) { + PyErr_NoMemory (); + + if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) + g_free (arg->v_pointer); + + return NULL; + } + + array_->data = arg->v_pointer; + array_->len = len; + } + + if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) { + if (arg->v_pointer == NULL) { + py_obj = PYGLIB_PyBytes_FromString (""); + } else { + py_obj = PYGLIB_PyBytes_FromStringAndSize (array_->data, array_->len); + } + } else { + if (arg->v_pointer == NULL) { + py_obj = PyList_New (0); + } else { + int i; + + gsize item_size; + PyGIMarshalToPyFunc item_to_py_marshaller; + PyGIArgCache *item_arg_cache; + + py_obj = PyList_New (array_->len); + if (py_obj == NULL) + goto err; + + + item_arg_cache = seq_cache->item_cache; + item_to_py_marshaller = item_arg_cache->to_py_marshaller; + + item_size = g_array_get_element_size (array_); + + for (i = 0; i < array_->len; i++) { + GIArgument item_arg; + PyObject *py_item; + + if (seq_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY) { + item_arg.v_pointer = g_ptr_array_index ( ( GPtrArray *)array_, i); + } else if (item_arg_cache->type_tag == GI_TYPE_TAG_INTERFACE) { + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *) item_arg_cache; + + switch (g_base_info_get_type (iface_cache->interface_info)) { + case GI_INFO_TYPE_STRUCT: + if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) { + gpointer *_struct = g_malloc (item_size); + memcpy (_struct, array_->data + i * item_size, + item_size); + item_arg.v_pointer = _struct; + } else + item_arg.v_pointer = array_->data + i * item_size; + break; + default: + item_arg.v_pointer = g_array_index (array_, gpointer, i); + break; + } + } else { + memcpy (&item_arg, array_->data + i * item_size, item_size); + } + + py_item = item_to_py_marshaller ( state, + callable_cache, + item_arg_cache, + &item_arg); + + if (py_item == NULL) { + Py_CLEAR (py_obj); + + if (seq_cache->array_type == GI_ARRAY_TYPE_C) + g_array_unref (array_); + + goto err; + } + PyList_SET_ITEM (py_obj, i, py_item); + processed_items++; + } + } + } + + if (seq_cache->array_type == GI_ARRAY_TYPE_C) + g_array_free (array_, FALSE); + + return py_obj; + +err: + if (seq_cache->array_type == GI_ARRAY_TYPE_C) { + g_array_free (array_, arg_cache->transfer == GI_TRANSFER_EVERYTHING); + } else { + /* clean up unprocessed items */ + if (seq_cache->item_cache->to_py_cleanup != NULL) { + int j; + PyGIMarshalCleanupFunc cleanup_func = seq_cache->item_cache->to_py_cleanup; + for (j = processed_items; j < array_->len; j++) { + cleanup_func (state, + seq_cache->item_cache, + g_array_index (array_, gpointer, j), + FALSE); + } + } + + if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) + g_array_free (array_, TRUE); + } + + return NULL; +} + +PyObject * +_pygi_marshal_to_py_glist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + GList *list_; + gsize length; + gsize i; + + PyGIMarshalToPyFunc item_to_py_marshaller; + PyGIArgCache *item_arg_cache; + PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; + + PyObject *py_obj = NULL; + + list_ = arg->v_pointer; + length = g_list_length (list_); + + py_obj = PyList_New (length); + if (py_obj == NULL) + return NULL; + + item_arg_cache = seq_cache->item_cache; + item_to_py_marshaller = item_arg_cache->to_py_marshaller; + + for (i = 0; list_ != NULL; list_ = g_list_next (list_), i++) { + GIArgument item_arg; + PyObject *py_item; + + item_arg.v_pointer = list_->data; + py_item = item_to_py_marshaller ( state, + callable_cache, + item_arg_cache, + &item_arg); + + if (py_item == NULL) { + Py_CLEAR (py_obj); + _PyGI_ERROR_PREFIX ("Item %zu: ", i); + return NULL; + } + + PyList_SET_ITEM (py_obj, i, py_item); + } + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_gslist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + GSList *list_; + gsize length; + gsize i; + + PyGIMarshalToPyFunc item_to_py_marshaller; + PyGIArgCache *item_arg_cache; + PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; + + PyObject *py_obj = NULL; + + list_ = arg->v_pointer; + length = g_slist_length (list_); + + py_obj = PyList_New (length); + if (py_obj == NULL) + return NULL; + + item_arg_cache = seq_cache->item_cache; + item_to_py_marshaller = item_arg_cache->to_py_marshaller; + + for (i = 0; list_ != NULL; list_ = g_slist_next (list_), i++) { + GIArgument item_arg; + PyObject *py_item; + + item_arg.v_pointer = list_->data; + py_item = item_to_py_marshaller ( state, + callable_cache, + item_arg_cache, + &item_arg); + + if (py_item == NULL) { + Py_CLEAR (py_obj); + _PyGI_ERROR_PREFIX ("Item %zu: ", i); + return NULL; + } + + PyList_SET_ITEM (py_obj, i, py_item); + } + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_ghash (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + GHashTable *hash_; + GHashTableIter hash_table_iter; + + PyGIMarshalToPyFunc key_to_py_marshaller; + PyGIMarshalToPyFunc value_to_py_marshaller; + + PyGIArgCache *key_arg_cache; + PyGIArgCache *value_arg_cache; + PyGIHashCache *hash_cache = (PyGIHashCache *)arg_cache; + + GIArgument key_arg; + GIArgument value_arg; + + PyObject *py_obj = NULL; + + hash_ = arg->v_pointer; + + if (hash_ == NULL) { + py_obj = Py_None; + Py_INCREF (py_obj); + return py_obj; + } + + py_obj = PyDict_New (); + if (py_obj == NULL) + return NULL; + + key_arg_cache = hash_cache->key_cache; + key_to_py_marshaller = key_arg_cache->to_py_marshaller; + + value_arg_cache = hash_cache->value_cache; + value_to_py_marshaller = value_arg_cache->to_py_marshaller; + + g_hash_table_iter_init (&hash_table_iter, hash_); + while (g_hash_table_iter_next (&hash_table_iter, + &key_arg.v_pointer, + &value_arg.v_pointer)) { + PyObject *py_key; + PyObject *py_value; + int retval; + + py_key = key_to_py_marshaller ( state, + callable_cache, + key_arg_cache, + &key_arg); + + if (py_key == NULL) { + Py_CLEAR (py_obj); + return NULL; + } + + py_value = value_to_py_marshaller ( state, + callable_cache, + value_arg_cache, + &value_arg); + + if (py_value == NULL) { + Py_CLEAR (py_obj); + Py_DECREF(py_key); + return NULL; + } + + retval = PyDict_SetItem (py_obj, py_key, py_value); + + Py_DECREF (py_key); + Py_DECREF (py_value); + + if (retval < 0) { + Py_CLEAR (py_obj); + return NULL; + } + } + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_gerror (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + PyErr_Format (PyExc_NotImplementedError, + "Marshalling for gerror to PyObject is not implemented"); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_callback (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + PyErr_Format (PyExc_NotImplementedError, + "Marshalling a callback to PyObject is not supported"); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_enum (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + + if (iface_cache->g_type == G_TYPE_NONE) { + py_obj = PyObject_CallFunction (iface_cache->py_type, "l", arg->v_long); + } else { + py_obj = pyg_enum_from_gtype (iface_cache->g_type, arg->v_long); + } + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_flags (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + + if (iface_cache->g_type == G_TYPE_NONE) { + /* An enum with a GType of None is an enum without GType */ + + PyObject *py_type = _pygi_type_import_by_gi_info (iface_cache->interface_info); + PyObject *py_args = NULL; + + if (!py_type) + return NULL; + + py_args = PyTuple_New (1); + if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (arg->v_long)) != 0) { + Py_DECREF (py_args); + Py_DECREF (py_type); + return NULL; + } + + py_obj = PyObject_CallFunction (py_type, "l", arg->v_long); + + Py_DECREF (py_args); + Py_DECREF (py_type); + } else { + py_obj = pyg_flags_from_gtype (iface_cache->g_type, arg->v_long); + } + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_struct (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; + GType type = iface_cache->g_type; + + if (arg->v_pointer == NULL) { + py_obj = Py_None; + Py_INCREF (py_obj); + return py_obj; + } + + if (g_type_is_a (type, G_TYPE_VALUE)) { + py_obj = pyg_value_as_pyobject (arg->v_pointer, FALSE); + } else if (iface_cache->is_foreign) { + py_obj = pygi_struct_foreign_convert_from_g_argument (iface_cache->interface_info, + arg->v_pointer); + } else if (g_type_is_a (type, G_TYPE_BOXED)) { + py_obj = _pygi_boxed_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, + arg_cache->transfer == GI_TRANSFER_EVERYTHING); + } else if (g_type_is_a (type, G_TYPE_POINTER)) { + if (iface_cache->py_type == NULL || + !PyType_IsSubtype ( (PyTypeObject *)iface_cache->py_type, &PyGIStruct_Type)) { + g_warn_if_fail(arg_cache->transfer == GI_TRANSFER_NOTHING); + py_obj = pyg_pointer_new (type, arg->v_pointer); + } else { + py_obj = _pygi_struct_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, + arg_cache->transfer == GI_TRANSFER_EVERYTHING); + } + } else if (g_type_is_a (type, G_TYPE_VARIANT)) { + g_variant_ref_sink (arg->v_pointer); + py_obj = _pygi_struct_new ( (PyTypeObject *)iface_cache->py_type, arg->v_pointer, + FALSE); + } else if (type == G_TYPE_NONE && iface_cache->is_foreign) { + py_obj = pygi_struct_foreign_convert_from_g_argument (iface_cache->interface_info, arg->v_pointer); + } else if (type == G_TYPE_NONE) { + py_obj = _pygi_struct_new ( (PyTypeObject *) iface_cache->py_type, arg->v_pointer, + arg_cache->transfer == GI_TRANSFER_EVERYTHING); + } else { + PyErr_Format (PyExc_NotImplementedError, + "structure type '%s' is not supported yet", + g_type_name (type)); + } + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_interface (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + PyErr_Format (PyExc_NotImplementedError, + "Marshalling for this type is not implemented yet"); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_boxed (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + PyErr_Format (PyExc_NotImplementedError, + "Marshalling for this type is not implemented yet"); + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_object (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj; + + if (arg->v_pointer == NULL) { + py_obj = Py_None; + Py_INCREF (py_obj); + return py_obj; + } + + py_obj = pygobject_new (arg->v_pointer); + + if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) + g_object_unref (arg->v_pointer); + + return py_obj; +} + +PyObject * +_pygi_marshal_to_py_interface_union (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg) +{ + PyObject *py_obj = NULL; + + PyErr_Format (PyExc_NotImplementedError, + "Marshalling for this type is not implemented yet"); + return py_obj; +} diff --git a/gi/pygi-marshal-to-py.h b/gi/pygi-marshal-to-py.h new file mode 100644 index 00000000..a07a13e8 --- /dev/null +++ b/gi/pygi-marshal-to-py.h @@ -0,0 +1,144 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * vim: tabstop=4 shiftwidth=4 expandtab + * + * Copyright (C) 2011 John (J5) Palmieri , Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef __PYGI_MARSHAL_TO_PY_H__ +#define __PYGI_MARSHAL_TO_PY_H__ + +PyObject *_pygi_marshal_to_py_void (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_boolean (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_int8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_uint8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_int16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_uint16 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_int32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_uint32 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_int64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_uint64 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_float (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_double (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_unichar (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_gtype (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_utf8 (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_filename (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_array (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_glist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_gslist (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_ghash (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_gerror (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_callback(PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_enum (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_flags (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_struct (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_interface(PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_boxed (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_object (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); +PyObject *_pygi_marshal_to_py_interface_union (PyGIInvokeState *state, + PyGICallableCache *callable_cache, + PyGIArgCache *arg_cache, + GIArgument *arg); + +G_END_DECLS + +#endif /* __PYGI_MARSHAL_TO_PY_H__ */ -- cgit v1.2.1