Commits

Armin Rigo committed 6434bd7

Update to cffi/63bf01f22e80 and fix.

Comments (0)

Files changed (2)

pypy/module/_cffi_backend/ctypeptr.py

                 cdata = rffi.ptradd(cdata, ctitem.size)
         elif (self.ctitem.is_primitive_integer and
               self.ctitem.size == rffi.sizeof(lltype.Char)):
-            try:
-                s = space.str_w(w_ob)
-            except OperationError, e:
-                if not e.match(space, space.w_TypeError):
-                    raise
+            if not space.isinstance_w(w_ob, space.w_str):
                 raise self._convert_error("str or list or tuple", w_ob)
+            s = space.str_w(w_ob)
             n = len(s)
             if self.length >= 0 and n > self.length:
                 raise operationerrfmt(space.w_IndexError,
             if n != self.length:
                 cdata[n] = '\x00'
         elif isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveUniChar):
-            try:
-                s = space.unicode_w(w_ob)
-            except OperationError, e:
-                if not e.match(space, space.w_TypeError):
-                    raise
+            if not space.isinstance_w(w_ob, space.w_unicode):
                 raise self._convert_error("unicode or list or tuple", w_ob)
+            s = space.unicode_w(w_ob)
             n = len(s)
             if self.length >= 0 and n > self.length:
                 raise operationerrfmt(space.w_IndexError,

pypy/module/_cffi_backend/test/_backend_test_c.py

                      'uint32_t', 'int64_t', 'uint64_t', 'intptr_t',
                      'uintptr_t', 'ptrdiff_t', 'size_t', 'ssize_t']:
         new_primitive_type(typename)    # works
+
+def test_cannot_convert_unicode_to_charp():
+    BCharP = new_pointer_type(new_primitive_type("char"))
+    BCharArray = new_array_type(BCharP, None)
+    py.test.raises(TypeError, newp, BCharArray, u+'foobar')