[pygobject/pygobject-2-28] fix static ABI for setting string gvalues from python objects
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-2-28] fix static ABI for setting string gvalues from python objects
- Date: Wed, 23 Mar 2011 01:49:06 +0000 (UTC)
commit c1ee6642d4b69a8c417cf92534ba091f89c7f68c
Author: John (J5) Palmieri <johnp redhat com>
Date: Tue Mar 22 18:46:28 2011 -0400
fix static ABI for setting string gvalues from python objects
* the static bindings used to be able to set a string gvalue to any python
object that implemented __str__, for instance when setting a treemodel column
* this restores that code while still keeping unicode and python 3
compatability
gobject/pygtype.c | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index a8c19d8..f317b3b 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -891,17 +891,27 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
case G_TYPE_STRING:
if (obj == Py_None) {
g_value_set_string(value, NULL);
+ } else {
+ PyObject* tmp_str = PyObject_Str(obj);
+ if (tmp_str == NULL) {
+ PyErr_Clear();
+ if (PyUnicode_Check(obj)) {
+ tmp = PyUnicode_AsUTF8String(obj);
+ g_value_set_string(value, PYGLIB_PyBytes_AsString(tmp));
+ Py_DECREF(tmp);
+ } else {
+ return -1;
+ }
+ } else {
#if PY_VERSION_HEX < 0x03000000
- } else if (PyString_Check(obj)) {
- g_value_set_string(value, PyString_AsString(obj));
+ g_value_set_string(value, PyString_AsString(obj));
+#else
+ tmp = PyUnicode_AsUTF8String(obj);
+ g_value_set_string(value, PyBytes_AsString(tmp));
+ Py_DECREF(tmp);
#endif
- } else if (PyUnicode_Check(obj)) {
- tmp = PyUnicode_AsUTF8String(obj);
- g_value_set_string(value, PYGLIB_PyBytes_AsString(tmp));
- Py_DECREF(tmp);
- } else {
- PyErr_Clear();
- return -1;
+ }
+ Py_XDECREF(tmp_str);
}
break;
case G_TYPE_POINTER:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]