From 09161ff690ad37c94668d5d65191f4d84829d41f Mon Sep 17 00:00:00 2001 From: Simon Feltman Date: Sun, 7 Sep 2014 15:53:35 -0700 Subject: Limit foreign struct checks to GI_INFO_TYPE_STRUCT Add struct type check before calling g_struct_info_is_foreign(). https://bugzilla.gnome.org/show_bug.cgi?id=736175 --- gi/pygi-argument.c | 11 ++++++++--- gi/pygi-struct-marshal.c | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c index 3d643fe8..d63520d5 100644 --- a/gi/pygi-argument.c +++ b/gi/pygi-argument.c @@ -1036,6 +1036,8 @@ array_success: { GType g_type; PyObject *py_type; + gboolean is_foreign = (info_type == GI_INFO_TYPE_STRUCT) && + (g_struct_info_is_foreign ((GIStructInfo *) info)); g_type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) info); py_type = _pygi_type_import_by_gi_info ( (GIBaseInfo *) info); @@ -1055,7 +1057,7 @@ array_success: py_type, transfer, FALSE, /*copy_reference*/ - g_struct_info_is_foreign (info), + is_foreign, g_type_info_is_pointer (type_info)); Py_DECREF (py_type); @@ -1382,6 +1384,8 @@ _pygi_argument_to_object (GIArgument *arg, { PyObject *py_type; GType g_type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) info); + gboolean is_foreign = (info_type == GI_INFO_TYPE_STRUCT) && + (g_struct_info_is_foreign ((GIStructInfo *) info)); /* Special case variant and none to force loading from py module. */ if (g_type == G_TYPE_VARIANT || g_type == G_TYPE_NONE) { @@ -1396,7 +1400,7 @@ _pygi_argument_to_object (GIArgument *arg, py_type, transfer, FALSE, /*is_allocated*/ - g_struct_info_is_foreign (info)); + is_foreign); Py_XDECREF (py_type); break; @@ -1703,7 +1707,8 @@ _pygi_argument_release (GIArgument *arg, if (direction == GI_DIRECTION_IN && transfer == GI_TRANSFER_NOTHING) { g_closure_unref (arg->v_pointer); } - } else if (g_struct_info_is_foreign ( (GIStructInfo*) info)) { + } else if (info_type == GI_INFO_TYPE_STRUCT && + g_struct_info_is_foreign ((GIStructInfo*) info)) { if (direction == GI_DIRECTION_OUT && transfer == GI_TRANSFER_EVERYTHING) { pygi_struct_foreign_release (info, arg->v_pointer); } diff --git a/gi/pygi-struct-marshal.c b/gi/pygi-struct-marshal.c index 5068064a..9bf3b542 100644 --- a/gi/pygi-struct-marshal.c +++ b/gi/pygi-struct-marshal.c @@ -528,7 +528,6 @@ arg_struct_from_py_setup (PyGIArgCache *arg_cache, GITransfer transfer) { PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info); if (g_struct_info_is_gtype_struct ((GIStructInfo*)iface_info)) { arg_cache->from_py_marshaller = arg_type_class_from_py_marshal; @@ -560,7 +559,6 @@ arg_struct_to_py_setup (PyGIArgCache *arg_cache, GIArgInfo *arg_info) { PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache; - iface_cache->is_foreign = g_struct_info_is_foreign ( (GIStructInfo*)iface_info); /* HACK to force GtkTreeModel:iter_next() and iter_previous() vfunc implementations * to receive their Gtk.TreeIter argument as pass-by-reference. We create a new @@ -615,6 +613,7 @@ pygi_arg_struct_new_from_info (GITypeInfo *type_info, GIInterfaceInfo *iface_info) { PyGIArgCache *cache = NULL; + PyGIInterfaceCache *iface_cache; cache = pygi_arg_interface_new_from_info (type_info, arg_info, @@ -624,6 +623,10 @@ pygi_arg_struct_new_from_info (GITypeInfo *type_info, if (cache == NULL) return NULL; + iface_cache = (PyGIInterfaceCache *)cache; + iface_cache->is_foreign = (g_base_info_get_type ((GIBaseInfo *) iface_info) == GI_INFO_TYPE_STRUCT) && + (g_struct_info_is_foreign ((GIStructInfo*) iface_info)); + if (direction & PYGI_DIRECTION_FROM_PYTHON) { arg_struct_from_py_setup (cache, iface_info, transfer); } -- cgit v1.2.1