[pypy-commit] cffi cffi-1.0: Fix the test, still xfail
arigo
noreply at buildbot.pypy.org
Tue Apr 28 11:44:41 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1870:b8665b33150c
Date: 2015-04-28 11:45 +0200
http://bitbucket.org/cffi/cffi/changeset/b8665b33150c/
Log: Fix the test, still xfail
diff --git a/_cffi1/ffi_obj.c b/_cffi1/ffi_obj.c
--- a/_cffi1/ffi_obj.c
+++ b/_cffi1/ffi_obj.c
@@ -766,7 +766,7 @@
static PyTypeObject FFI_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "FFI",
+ "CompiledFFI",
sizeof(FFIObject),
0,
(destructor)ffi_dealloc, /* tp_dealloc */
diff --git a/_cffi1/lib_obj.c b/_cffi1/lib_obj.c
--- a/_cffi1/lib_obj.c
+++ b/_cffi1/lib_obj.c
@@ -328,7 +328,7 @@
static PyTypeObject Lib_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "Lib",
+ "CompiledLib",
sizeof(LibObject),
0,
(destructor)lib_dealloc, /* tp_dealloc */
diff --git a/_cffi1/test_new_ffi_1.py b/_cffi1/test_new_ffi_1.py
--- a/_cffi1/test_new_ffi_1.py
+++ b/_cffi1/test_new_ffi_1.py
@@ -14,7 +14,7 @@
def setup_module():
- global ffi
+ global ffi, ffi1
ffi1 = cffi.FFI()
DEFS = r"""
struct repr { short a, b, c; };
@@ -1500,64 +1500,32 @@
assert foo2.a == 20
assert foo2.b == 30
- def test_missing_include(self):
+ def test_include_struct_union_enum_typedef(self):
py.test.xfail("ffi.include")
- backend = self.Backend()
- ffi1 = FFI(backend=backend)
- ffi2 = FFI(backend=backend)
- ffi1.cdef("typedef signed char schar_t;")
- py.test.raises(CDefError, ffi2.cast, "schar_t", 142)
-
- def test_include_typedef(self):
- py.test.xfail("ffi.include")
- backend = self.Backend()
- ffi1 = FFI(backend=backend)
- ffi2 = FFI(backend=backend)
- ffi1.cdef("typedef signed char schar_t;")
+ ffi2 = cffi.FFI()
ffi2.include(ffi1)
- p = ffi2.cast("schar_t", 142)
- assert int(p) == 142 - 256
-
- def test_include_struct(self):
- py.test.xfail("ffi.include")
- backend = self.Backend()
- ffi1 = FFI(backend=backend)
- ffi2 = FFI(backend=backend)
- ffi1.cdef("struct foo { int x; };")
- ffi2.include(ffi1)
- p = ffi2.new("struct foo *", [142])
- assert p.x == 142
-
- def test_include_union(self):
- py.test.xfail("ffi.include")
- backend = self.Backend()
- ffi1 = FFI(backend=backend)
- ffi2 = FFI(backend=backend)
- ffi1.cdef("union foo { int x; };")
- ffi2.include(ffi1)
- p = ffi2.new("union foo *", [142])
- assert p.x == 142
-
- def test_include_enum(self):
- py.test.xfail("ffi.include")
- backend = self.Backend()
- ffi1 = FFI(backend=backend)
- ffi2 = FFI(backend=backend)
- ffi1.cdef("enum foo { FA, FB, FC };")
- ffi2.include(ffi1)
- p = ffi2.cast("enum foo", 1)
- assert ffi2.string(p) == "FB"
- assert ffi2.sizeof("char[FC]") == 2
-
- def test_include_typedef_2(self):
- py.test.xfail("ffi.include")
- backend = self.Backend()
- ffi1 = FFI(backend=backend)
- ffi2 = FFI(backend=backend)
- ffi1.cdef("typedef struct { int x; } *foo_p;")
- ffi2.include(ffi1)
- p = ffi2.new("foo_p", [142])
- assert p.x == 142
+ outputfilename = recompile(ffi2,
+ "test_include_struct_union_enum_typedef",
+ "", tmpdir=str(udir))
+ module = imp.load_dynamic("test_include_struct_union_enum_typedef",
+ outputfilename)
+ ffi2 = module.ffi
+ #
+ p = ffi2.new("struct nonpacked *", ['A', -43141])
+ assert p.a == 'A'
+ assert p.b == -43141
+ #
+ p = ffi.new("union simple_u", [-52525])
+ assert p.a == -52525
+ #
+ p = ffi.cast("enum foq", 2)
+ assert ffi.string(p) == "CC0"
+ assert ffi2.sizeof("char[CC0]") == 2
+ #
+ p = ffi.new("anon_foo_t *", [-52526])
+ assert p.a == -52526
+ p = ffi.new("named_foo_p", [-52527])
+ assert p.a == -52527
def test_struct_packed(self):
# struct nonpacked { char a; int b; };
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -419,6 +419,10 @@
variables, which must anyway be accessed directly from the
lib object returned by the original FFI instance.
"""
+ if not isinstance(ffi_to_include, FFI):
+ raise TypeError("ffi.include() expects an argument that is also of"
+ " type cffi.FFI, not %r" % (
+ type(ffi_to_include).__name__,))
with ffi_to_include._lock:
with self._lock:
self._parser.include(ffi_to_include._parser)
More information about the pypy-commit
mailing list