[pygobject] Allow single byte values for int8 types
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Allow single byte values for int8 types
- Date: Fri, 11 Jan 2013 08:15:46 +0000 (UTC)
commit a558d3d3a9274aeccfc54705bf5effdf71dee06b
Author: Martin Pitt <martinpitt gnome org>
Date: Fri Jan 11 09:09:41 2013 +0100
Allow single byte values for int8 types
When fixing gobject-introspection to consider "gchar" as signed (see
https://bugzilla.gnome.org/show_bug.cgi?id=691524), we must also permit a
single-element "bytes" array as a valid value for int8, not just for uint8.
This is caught by the test_overrides_gtk.TestTreeModel.test_tree_store test.
gi/pygi-argument.c | 4 ++--
gi/pygi-marshal-from-py.c | 34 +++++++++++++++++++++-------------
2 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 497a771..34c4970 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -410,7 +410,8 @@ _pygi_g_type_info_check_object (GITypeInfo *type_info,
/* No check; every Python object has a truth value. */
break;
case GI_TYPE_TAG_UINT8:
- /* UINT8 types can be characters */
+ case GI_TYPE_TAG_INT8:
+ /* (U)INT8 types can be characters */
if (PYGLIB_PyBytes_Check(object)) {
if (PYGLIB_PyBytes_Size(object) != 1) {
PyErr_Format (PyExc_TypeError, "Must be a single character");
@@ -420,7 +421,6 @@ _pygi_g_type_info_check_object (GITypeInfo *type_info,
break;
}
- case GI_TYPE_TAG_INT8:
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_INT32:
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index e842227..4ddfbb4 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -262,22 +262,30 @@ _pygi_marshal_from_py_int8 (PyGIInvokeState *state,
PyObject *py_long;
long long_;
- if (!PyNumber_Check (py_arg)) {
- PyErr_Format (PyExc_TypeError, "Must be number, not %s",
- py_arg->ob_type->tp_name);
- return FALSE;
- }
+ if (PYGLIB_PyBytes_Check (py_arg)) {
- py_long = PYGLIB_PyNumber_Long (py_arg);
- if (!py_long)
- return FALSE;
+ if (PYGLIB_PyBytes_Size (py_arg) != 1) {
+ PyErr_Format (PyExc_TypeError, "Must be a single character");
+ return FALSE;
+ }
- long_ = PYGLIB_PyLong_AsLong (py_long);
- Py_DECREF (py_long);
+ long_ = (char)(PYGLIB_PyBytes_AsString (py_arg)[0]);
+ } else if (PyNumber_Check (py_arg)) {
+ py_long = PYGLIB_PyNumber_Long (py_arg);
+ if (!py_long)
+ return FALSE;
- if (PyErr_Occurred ()) {
- PyErr_Clear ();
- PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127);
+ long_ = PYGLIB_PyLong_AsLong (py_long);
+ Py_DECREF (py_long);
+
+ if (PyErr_Occurred ()) {
+ PyErr_Clear ();
+ PyErr_Format (PyExc_ValueError, "%ld not in range %d to %d", long_, -128, 127);
+ return FALSE;
+ }
+ } else {
+ PyErr_Format (PyExc_TypeError, "Must be number or single byte string, not %s",
+ py_arg->ob_type->tp_name);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]