Commit a558d3d3 authored by Martin Pitt's avatar Martin Pitt
Browse files

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.
parent aa7f6cd1
......@@ -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:
......
......@@ -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;
}
......
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