From 7f013383063c1d1e5a95cf4c056ff152d4aa2645 Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Wed, 23 Feb 2011 14:14:16 -0500 Subject: [gi] check to see if object is a member of a union when validating paramaters * union members are not subclasses of the union they belong to so if an inteface requires you pass a union but you pass one of its members there will be a type error * this patch checks to see if the type you are passing is a member of the union and passes the checks if it is * this works in python 3 but in python 2 methods do their own isinstance check on the instance parameter (e.g. self) so we need to figure out how to override that for union methods (e.g. Gdk.Event.get_state) https://bugzilla.gnome.org/show_bug.cgi?id=642554 --- gi/pygi-argument.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'gi') diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c index dc9c2890..bbbad00b 100644 --- a/gi/pygi-argument.c +++ b/gi/pygi-argument.c @@ -241,8 +241,46 @@ _pygi_g_type_interface_check_object (GIBaseInfo *info, case GI_INFO_TYPE_BOXED: case GI_INFO_TYPE_INTERFACE: case GI_INFO_TYPE_OBJECT: + retval = _pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) info, TRUE, object); + break; case GI_INFO_TYPE_UNION: + + retval = _pygi_g_registered_type_info_check_object ( (GIRegisteredTypeInfo *) info, TRUE, object); + + /* If not the same type then check to see if the object's type + * is the same as one of the union's members + */ + if (retval == 0) { + gint i; + gint n_fields; + + n_fields = g_union_info_get_n_fields ( (GIUnionInfo *) info); + + for (i = 0; i < n_fields; i++) { + gint member_retval; + GIFieldInfo *field_info; + GITypeInfo *field_type_info; + + field_info = + g_union_info_get_field ( (GIUnionInfo *) info, i); + field_type_info = g_field_info_get_type (field_info); + + member_retval = _pygi_g_type_info_check_object( + field_type_info, + object, + TRUE); + + g_base_info_unref ( ( GIBaseInfo *) field_type_info); + g_base_info_unref ( ( GIBaseInfo *) field_info); + + if (member_retval == 1) { + retval = member_retval; + break; + } + } + } + break; default: g_assert_not_reached(); -- cgit v1.2.1