[pygobject/pygobject-2-28] [gi] check to see if object is a member of a union when validating paramaters
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-2-28] [gi] check to see if object is a member of a union when validating paramaters
- Date: Mon, 28 Feb 2011 17:58:32 +0000 (UTC)
commit 7f013383063c1d1e5a95cf4c056ff152d4aa2645
Author: John (J5) Palmieri <johnp redhat com>
Date: Wed Feb 23 14:14:16 2011 -0500
[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 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index dc9c289..bbbad00 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();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]