Commit 985f239d authored by John (J5) Palmieri's avatar John (J5) Palmieri
Browse files

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
parent 58cfc3cd
......@@ -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(tmp_str));
#else
tmp = PyUnicode_AsUTF8String(tmp_str);
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:
......
......@@ -88,6 +88,14 @@ class TestProperties(unittest.TestCase):
obj.props.normal = UNICODE_UTF8
self.assertEqual(obj.props.normal, TEST_UTF8)
def testIntToStr(self):
obj = new(PropertyObject, construct_only=1)
self.assertEqual(obj.props.construct_only, '1')
obj.set_property('construct', '2')
self.assertEqual(obj.props.construct, '2')
obj.props.normal = 3
self.assertEqual(obj.props.normal, '3')
def testConstructOnly(self):
obj = new(PropertyObject, construct_only="123")
self.assertEqual(obj.props.construct_only, "123")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment