Commits

Armin Rigo committed 12a797f

Test and fix

Comments (0)

Files changed (2)

c/_cffi_backend.c

     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;
         }
     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)