[pypy-commit] cffi default: Test and fix.
arigo
noreply at buildbot.pypy.org
Tue Jul 17 10:24:18 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r662:af85c6508b72
Date: 2012-07-17 10:24 +0200
http://bitbucket.org/cffi/cffi/changeset/af85c6508b72/
Log: Test and fix.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1578,6 +1578,22 @@
static cif_description_t *
fb_prepare_cif(PyObject *fargs, CTypeDescrObject *, ffi_abi); /*forward*/
+static PyObject *
+b_new_primitive_type(PyObject *self, PyObject *args); /*forward*/
+
+static CTypeDescrObject *_get_ct_int(void)
+{
+ static CTypeDescrObject *ct_int = NULL;
+ if (ct_int == NULL) {
+ PyObject *args = Py_BuildValue("(s)", "int");
+ if (args == NULL)
+ return NULL;
+ ct_int = (CTypeDescrObject *)b_new_primitive_type(NULL, args);
+ Py_DECREF(args);
+ }
+ return ct_int;
+}
+
static PyObject*
cdata_call(CDataObject *cd, PyObject *args, PyObject *kwds)
{
@@ -1639,8 +1655,17 @@
if (CData_Check(obj)) {
ct = ((CDataObject *)obj)->c_type;
- if (ct->ct_flags & CT_ARRAY)
+ if (ct->ct_flags & (CT_PRIMITIVE_CHAR|CT_PRIMITIVE_UNSIGNED|
+ CT_PRIMITIVE_SIGNED)) {
+ if (ct->ct_size < sizeof(int)) {
+ ct = _get_ct_int();
+ if (ct == NULL)
+ goto error;
+ }
+ }
+ else if (ct->ct_flags & CT_ARRAY) {
ct = (CTypeDescrObject *)ct->ct_stuff;
+ }
Py_INCREF(ct);
}
else {
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -800,6 +800,11 @@
assert f(2, cast(BInt, 40), cast(BInt, 2)) == 42
py.test.raises(TypeError, f, 1, 42)
py.test.raises(TypeError, f, 2, None)
+ # promotion of chars and shorts to ints
+ BSChar = new_primitive_type("signed char")
+ BUChar = new_primitive_type("unsigned char")
+ BSShort = new_primitive_type("short")
+ assert f(3, cast(BSChar, -3), cast(BUChar, 200), cast(BSShort, -5)) == 192
def test_cannot_call_with_a_autocompleted_struct():
BSChar = new_primitive_type("signed char")
More information about the pypy-commit
mailing list