[pygobject] Use PyMapping_Keys to determine if an object is a dict (py3k fix)
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Use PyMapping_Keys to determine if an object is a dict (py3k fix)
- Date: Fri, 17 Sep 2010 10:25:55 +0000 (UTC)
commit b855562e5c0019cd7e4982fe00c467ede9e3926d
Author: John (J5) Palmieri <johnp redhat com>
Date: Thu Sep 9 22:16:58 2010 -0400
Use PyMapping_Keys to determine if an object is a dict (py3k fix)
* in Py3k PyMapping_Check returns true for sequences such as strings
and lists. Since we need to get the keys anyway, and it returns
NULL if this is not a dict, this is a much better test, even in
Py2
https://bugzilla.gnome.org/show_bug.cgi?id=615872
gi/pygi-argument.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 1f8b652..301a767 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -497,7 +497,8 @@ check_number_release:
GITypeInfo *value_type_info;
Py_ssize_t i;
- if (!PyMapping_Check (object)) {
+ keys = PyMapping_Keys (object);
+ if (keys == NULL) {
PyErr_Format (PyExc_TypeError, "Must be mapping, not %s",
object->ob_type->tp_name);
retval = 0;
@@ -506,12 +507,7 @@ check_number_release:
length = PyMapping_Length (object);
if (length < 0) {
- retval = -1;
- break;
- }
-
- keys = PyMapping_Keys (object);
- if (keys == NULL) {
+ Py_DECREF (keys);
retval = -1;
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]