summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2012-11-30 15:46:42 -0800
committerArmin Rigo <arigo@tunes.org>2012-11-30 15:46:42 -0800
commit9784a01f54287e3b0022deb27c041903b6141998 (patch)
treebb427be0ff79ef25ead2fea9d2c6f0f9c6b05b44
parentc98a4c4ec33ffcae409d4568634f0d25676d3af7 (diff)
downloadcffi-9784a01f54287e3b0022deb27c041903b6141998.tar.gz
Test and fix
-rw-r--r--c/_cffi_backend.c4
-rw-r--r--c/test_c.py10
2 files changed, 13 insertions, 1 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
index 5f1cb00..6170715 100644
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1915,7 +1915,9 @@ _prepare_pointer_call_argument(CTypeDescrObject *ctptr, PyObject *init,
if (PyBytes_Check(init)) {
/* from a string: just returning the string here is fine.
We assume that the C code won't modify the 'char *' data. */
- if (ctptr->ct_flags & CT_CAST_ANYTHING) {
+ if ((ctptr->ct_flags & CT_CAST_ANYTHING) ||
+ ((ctitem->ct_flags & (CT_PRIMITIVE_SIGNED|CT_PRIMITIVE_UNSIGNED))
+ && (ctitem->ct_size == sizeof(char)))) {
output_data[0] = PyBytes_AS_STRING(init);
return 1;
}
diff --git a/c/test_c.py b/c/test_c.py
index 9a37e7b..9f9e6b6 100644
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1001,6 +1001,16 @@ def test_call_function_23():
res = f(b"foo")
assert res == 1000 * ord(b'f')
+def test_call_function_23_bis():
+ # declaring the function as int(unsigned char*)
+ BUChar = new_primitive_type("unsigned char")
+ BUCharP = new_pointer_type(BUChar)
+ BInt = new_primitive_type("int")
+ BFunc23 = new_function_type((BUCharP,), BInt, False)
+ f = cast(BFunc23, _testfunc(23))
+ res = f(b"foo")
+ assert res == 1000 * ord(b'f')
+
def test_cannot_pass_struct_with_array_of_length_0():
BInt = new_primitive_type("int")
BArray0 = new_array_type(new_pointer_type(BInt), 0)