[pygobject] Permit plain integers for "gchar" values
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Permit plain integers for "gchar" values
- Date: Fri, 11 Jan 2013 08:15:51 +0000 (UTC)
commit 609636424b5f9b659e99a4bb53a48c165187c430
Author: Martin Pitt <martinpitt gnome org>
Date: Fri Jan 11 09:13:36 2013 +0100
Permit plain integers for "gchar" values
Similar to guchar/guint8, allow plain integers (withing correct boundaries) as
values for gchar/gint8 types.
This is covered by the test_gi.TestPropertiesObject.test_char test when
removing the "expected failure" flag.
gi/_gobject/pygtype.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/gi/_gobject/pygtype.c b/gi/_gobject/pygtype.c
index 921f75f..8be601b 100644
--- a/gi/_gobject/pygtype.c
+++ b/gi/_gobject/pygtype.c
@@ -823,12 +823,20 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
}
break;
case G_TYPE_CHAR:
+ if (PYGLIB_PyLong_Check(obj)) {
+ glong val;
+ val = PYGLIB_PyLong_AsLong(obj);
+ if (val >= -128 && val <= 127)
+ g_value_set_schar(value, (gchar) val);
+ else
+ return -1;
+ }
#if PY_VERSION_HEX < 0x03000000
- if (PyString_Check(obj)) {
+ else if (PyString_Check(obj)) {
g_value_set_schar(value, PyString_AsString(obj)[0]);
- } else
+ }
#endif
- if (PyUnicode_Check(obj)) {
+ else if (PyUnicode_Check(obj)) {
tmp = PyUnicode_AsUTF8String(obj);
g_value_set_schar(value, PYGLIB_PyBytes_AsString(tmp)[0]);
Py_DECREF(tmp);
@@ -843,7 +851,7 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
glong val;
val = PYGLIB_PyLong_AsLong(obj);
if (val >= 0 && val <= 255)
- g_value_set_uchar(value, (guchar)PYGLIB_PyLong_AsLong (obj));
+ g_value_set_uchar(value, (guchar) val);
else
return -1;
#if PY_VERSION_HEX < 0x03000000
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]