summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2011-02-23 14:14:16 -0500
committerJohn (J5) Palmieri <johnp@redhat.com>2011-02-28 12:57:00 -0500
commit7f013383063c1d1e5a95cf4c056ff152d4aa2645 (patch)
treedcadfac7366e62cb8e601bcba0b52992f4f26122 /gi
parent284e775b6caa86ef6465d17c87ec77376e66931c (diff)
downloadpygobject-7f013383063c1d1e5a95cf4c056ff152d4aa2645.tar.gz
[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
Diffstat (limited to 'gi')
-rw-r--r--gi/pygi-argument.c38
1 files changed, 38 insertions, 0 deletions
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();