Author: Armin Rigo <[email protected]>
Branch: len_w
Changeset: r92524:03c40bf2a144
Date: 2017-10-01 09:10 +0200
http://bitbucket.org/pypy/pypy/changeset/03c40bf2a144/
Log: Update to cffi/a60ae346a78f
diff --git a/pypy/module/_cffi_backend/ctypeptr.py
b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -156,10 +156,11 @@
class W_CTypePtrBase(W_CTypePtrOrArray):
# base class for both pointers and pointers-to-functions
- _attrs_ = ['is_void_ptr', 'is_voidchar_ptr']
- _immutable_fields_ = ['is_void_ptr', 'is_voidchar_ptr']
+ _attrs_ = ['is_void_ptr', 'is_voidchar_ptr', 'is_onebyte_ptr']
+ _immutable_fields_ = ['is_void_ptr', 'is_voidchar_ptr', 'is_onebyte_ptr']
is_void_ptr = False
is_voidchar_ptr = False
+ is_onebyte_ptr = False
def convert_to_object(self, cdata):
ptrdata = rffi.cast(rffi.CCHARPP, cdata)[0]
@@ -179,12 +180,20 @@
if self.is_void_ptr or other.is_void_ptr:
pass # cast from or to 'void *'
elif self.is_voidchar_ptr or other.is_voidchar_ptr:
- space = self.space
- msg = ("implicit cast from '%s' to '%s' "
- "will be forbidden in the future (check that the types "
- "are as you expect; use an explicit ffi.cast() if they "
- "are correct)" % (other.name, self.name))
- space.warn(space.newtext(msg), space.w_UserWarning)
+ # for backward compatibility, accept "char *" as either
+ # source of target. This is not what C does, though,
+ # so emit a warning that will eventually turn into an
+ # error. The warning is turned off if both types are
+ # pointers to single bytes.
+ if self.is_onebyte_ptr and other.is_onebyte_ptr:
+ pass # no warning
+ else:
+ space = self.space
+ msg = ("implicit cast from '%s' to '%s' "
+ "will be forbidden in the future (check that the types
"
+ "are as you expect; use an explicit ffi.cast() if they
"
+ "are correct)" % (other.name, self.name))
+ space.warn(space.newtext(msg), space.w_UserWarning)
else:
raise self._convert_error("compatible pointer", w_ob)
@@ -214,6 +223,7 @@
self.is_void_ptr = isinstance(ctitem, ctypevoid.W_CTypeVoid)
self.is_voidchar_ptr = (self.is_void_ptr or
isinstance(ctitem, ctypeprim.W_CTypePrimitiveChar))
+ self.is_onebyte_ptr = (ctitem.size == 1)
W_CTypePtrBase.__init__(self, space, size, extra, 2, ctitem)
def newp(self, w_init, allocator):
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2099,7 +2099,8 @@
if sys.platform.startswith("linux"):
BWChar = new_primitive_type("wchar_t")
assert sizeof(BWChar) == 4
- assert int(cast(BWChar, -1)) == -1 # signed, on linux
+ # wchar_t is often signed on Linux, but not always (e.g. on ARM)
+ assert int(cast(BWChar, -1)) in (-1, 4294967295)
def test_char16():
BChar16 = new_primitive_type("char16_t")
@@ -3903,9 +3904,11 @@
BCharP = new_pointer_type(new_primitive_type("char"))
BIntP = new_pointer_type(new_primitive_type("int"))
BVoidP = new_pointer_type(new_void_type())
+ BUCharP = new_pointer_type(new_primitive_type("unsigned char"))
z1 = cast(BCharP, 0)
z2 = cast(BIntP, 0)
z3 = cast(BVoidP, 0)
+ z4 = cast(BUCharP, 0)
with warnings.catch_warnings(record=True) as w:
newp(new_pointer_type(BIntP), z1) # warn
assert len(w) == 1
@@ -3919,6 +3922,12 @@
assert len(w) == 2
newp(new_pointer_type(BIntP), z3) # fine
assert len(w) == 2
+ newp(new_pointer_type(BCharP), z4) # fine (ignore signedness here)
+ assert len(w) == 2
+ newp(new_pointer_type(BUCharP), z1) # fine (ignore signedness here)
+ assert len(w) == 2
+ newp(new_pointer_type(BUCharP), z3) # fine
+ assert len(w) == 2
# check that the warnings are associated with lines in this file
assert w[1].lineno == w[0].lineno + 4
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit