[pygobject/gsoc2009: 148/160] Fix enum checking in _pygi_g_type_info_check_object
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 148/160] Fix enum checking in _pygi_g_type_info_check_object
- Date: Fri, 14 Aug 2009 21:36:10 +0000 (UTC)
commit 8429553247d3b468a48d4872cefbbd4065894e80
Author: Simon van der Linden <svdlinden src gnome org>
Date: Wed Aug 12 23:29:39 2009 +0200
Fix enum checking in _pygi_g_type_info_check_object
gi/pygi-argument.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index b8e9527..26e31da 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -536,14 +536,22 @@ check_number_release:
switch (info_type) {
case GI_INFO_TYPE_ENUM:
{
- (void) PyInt_AsLong(object);
- if (PyErr_Occurred()) {
- PyErr_Clear();
- PyErr_Format(PyExc_TypeError, "Must be int, not %s",
- object->ob_type->tp_name);
+ PyTypeObject *type;
+
+ type = (PyTypeObject *)pygi_type_find_by_gi_info(info);
+ if (type == NULL) {
+ retval = -1;
+ break;
+ }
+
+ if (!PyObject_TypeCheck(object, type)) {
+ PyErr_Format(PyExc_TypeError, "Must be %s, not %s",
+ type->tp_name, object->ob_type->tp_name);
retval = 0;
}
- /* XXX: What if the value doesn't correspond to any enum field? */
+
+ Py_DECREF(type);
+
break;
}
case GI_INFO_TYPE_STRUCT:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]