[pypy-commit] cffi default: Fixes for Python 3.
arigo
noreply at buildbot.pypy.org
Wed Oct 10 11:09:13 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r997:69cddb87c25f
Date: 2012-10-10 11:07 +0200
http://bitbucket.org/cffi/cffi/changeset/69cddb87c25f/
Log: Fixes for Python 3.
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -1161,7 +1161,7 @@
assert "must be a str or int, not NoneType" in str(e.value)
def test_enum_overflow():
- for ovf in (sys.maxint+1, -sys.maxint-2, 2**31, -2**31-1):
+ for ovf in (2**63, -2**63-1, 2**31, -2**31-1):
e = py.test.raises(OverflowError, new_enum_type, "foo", ('a', 'b'),
(5, ovf))
assert str(e.value) == (
@@ -2134,9 +2134,9 @@
py.test.raises(OverflowError, newp, BBoolP, 2)
py.test.raises(OverflowError, newp, BBoolP, -1)
BCharP = new_pointer_type(new_primitive_type("char"))
- p = newp(BCharP, 'X')
+ p = newp(BCharP, b'X')
q = cast(BBoolP, p)
- assert q[0] == ord('X')
+ assert q[0] == ord(b'X')
py.test.raises(TypeError, string, cast(BBool, False))
BDouble = new_primitive_type("double")
assert int(cast(BBool, cast(BDouble, 0.1))) == 1
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -71,7 +71,7 @@
csource = '\n'.join(csourcelines)
try:
ast = _get_parser().parse(csource)
- except pycparser.c_parser.ParseError, e:
+ except pycparser.c_parser.ParseError as e:
self.convert_pycparser_error(e, csource)
return ast, macros
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -356,7 +356,7 @@
type(ffi._backend).__typecache = weakref.WeakValueDictionary()
try:
res = getattr(ffi._backend, funcname)(*args)
- except NotImplementedError, e:
+ except NotImplementedError as e:
raise NotImplementedError("%r: %s" % (srctype, e))
ffi._backend.__typecache[args] = res
return res
diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py
--- a/cffi/vengine_cpy.py
+++ b/cffi/vengine_cpy.py
@@ -384,7 +384,7 @@
try:
prnt(' { %s = &p->%s; (void)tmp; }' % (
ftype.get_c_name('(*tmp)', 'field %r'%fname), fname))
- except ffiplatform.VerificationError, e:
+ except ffiplatform.VerificationError as e:
prnt(' /* %s */' % str(e)) # cannot verify it, ignore
prnt('}')
prnt('static PyObject *')
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py
--- a/cffi/vengine_gen.py
+++ b/cffi/vengine_gen.py
@@ -207,7 +207,7 @@
try:
prnt(' { %s = &p->%s; (void)tmp; }' % (
ftype.get_c_name('(*tmp)', 'field %r'%fname), fname))
- except ffiplatform.VerificationError, e:
+ except ffiplatform.VerificationError as e:
prnt(' /* %s */' % str(e)) # cannot verify it, ignore
prnt('}')
self.export_symbols.append(layoutfuncname)
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -1266,7 +1266,8 @@
return a - b
#
assert cb(-100, -10) == -90
- assert cb(sys.maxint, -10) == 42
+ sz = ffi.sizeof("long")
+ assert cb((1 << (sz*8-1)) - 1, -10) == 42
def test_unique_types(self):
ffi1 = FFI(backend=self.Backend())
@@ -1400,15 +1401,18 @@
assert not isinstance(ffi.typeof("int"), ffi.CData)
assert not isinstance(ffi.cast("int", 0), ffi.CType)
assert not isinstance(ffi.new("int *"), ffi.CType)
+
+ def test_CData_CType_2(self):
+ ffi = FFI(backend=self.Backend())
assert isinstance(ffi.typeof("int"), ffi.CType)
def test_bool(self):
ffi = FFI(backend=self.Backend())
assert int(ffi.cast("_Bool", 0.1)) == 1
assert int(ffi.cast("_Bool", -0.0)) == 0
- assert int(ffi.cast("_Bool", '\x02')) == 1
- assert int(ffi.cast("_Bool", '\x00')) == 0
- assert int(ffi.cast("_Bool", '\x80')) == 1
+ assert int(ffi.cast("_Bool", b'\x02')) == 1
+ assert int(ffi.cast("_Bool", b'\x00')) == 0
+ assert int(ffi.cast("_Bool", b'\x80')) == 1
assert ffi.new("_Bool *", False)[0] == 0
assert ffi.new("_Bool *", 1)[0] == 1
py.test.raises(OverflowError, ffi.new, "_Bool *", 2)
diff --git a/testing/callback_in_thread.py b/testing/callback_in_thread.py
--- a/testing/callback_in_thread.py
+++ b/testing/callback_in_thread.py
@@ -35,6 +35,6 @@
assert count > 0, "timeout"
assert seen == [(10, 10), (12, 15)]
-print 'STARTING'
+print('STARTING')
_run_callback_in_thread()
-print 'DONE'
+print('DONE')
diff --git a/testing/test_ctypes.py b/testing/test_ctypes.py
--- a/testing/test_ctypes.py
+++ b/testing/test_ctypes.py
@@ -1,4 +1,4 @@
-import py
+import py, sys
from testing import backend_tests
from cffi.backend_ctypes import CTypesBackend
@@ -30,3 +30,8 @@
def test_nested_anonymous_union(self):
py.test.skip("ctypes backend: not supported: nested anonymous union")
+
+ def test_CData_CType_2(self):
+ if sys.version_info >= (3,):
+ py.test.skip("ctypes backend: not supported in Python 3: CType")
+ backend_tests.BackendTests.test_CData_CType_2(self)
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -986,12 +986,12 @@
p = ffi.new("struct foo_s *")
assert ffi.sizeof(p[0]) == 3 * ffi.sizeof("int") # with alignment
p.a = 1234567
- p.b = 'X'
- p.c = 'Y'
+ p.b = b'X'
+ p.c = b'Y'
assert p.a == 1234567
- assert p.b == 'X'
- assert p.c == 'Y'
- assert p.d == 'Y'
+ assert p.b == b'X'
+ assert p.c == b'Y'
+ assert p.d == b'Y'
def test_nested_anonymous_struct_exact_error():
if sys.platform == 'win32':
More information about the pypy-commit
mailing list