Author: Armin Rigo <ar...@tunes.org> Branch: cpy-extension Changeset: r324:4bf2208474b2 Date: 2012-06-14 11:59 +0200 http://bitbucket.org/cffi/cffi/changeset/4bf2208474b2/
Log: Opaque structs. diff --git a/cffi/model.py b/cffi/model.py --- a/cffi/model.py +++ b/cffi/model.py @@ -158,11 +158,15 @@ BType = self.get_btype(ffi) ffi._cached_btypes[self] = BType args = [BType] - for tp in self.fldtypes: - args.append(ffi._get_cached_btype(tp)) + if self.fldtypes is not None: + for tp in self.fldtypes: + args.append(ffi._get_cached_btype(tp)) return args def finish_backend_type(self, ffi, BType, *fldtypes): + if self.fldnames is None: + return BType # not completing it: it's an opaque struct + # if self.fixedlayout is None: lst = zip(self.fldnames, fldtypes, self.fldbitsize) ffi._backend.complete_struct_or_union(BType, lst, self) diff --git a/cffi/verifier.py b/cffi/verifier.py --- a/cffi/verifier.py +++ b/cffi/verifier.py @@ -224,6 +224,8 @@ # struct declarations def generate_cpy_struct_decl(self, tp, name): + if tp.fldnames is None: + return # nothing to do with opaque structs assert name == tp.name prnt = self.prnt prnt('static PyObject *') @@ -286,10 +288,14 @@ prnt() def generate_cpy_struct_method(self, tp, name): + if tp.fldnames is None: + return # nothing to do with opaque structs self.prnt(' {"_cffi_struct_%s", _cffi_struct_%s, METH_NOARGS},' % ( name, name)) def loading_cpy_struct(self, tp, name, module): + if tp.fldnames is None: + return # nothing to do with opaque structs assert name == tp.name function = getattr(module, '_cffi_struct_%s' % name) layout = function() @@ -307,6 +313,8 @@ tp.fixedlayout = fieldofs, fieldsize, totalsize, totalalignment def loaded_cpy_struct(self, tp, name, module): + if tp.fldnames is None: + return # nothing to do with opaque structs self.ffi._get_cached_btype(tp) # force 'fixedlayout' to be considered # ---------- diff --git a/testing/test_verify.py b/testing/test_verify.py --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -138,6 +138,13 @@ py.test.raises(VerificationError, ffi.verify, "typedef %s foo_t;" % real) +def test_nondecl_struct(): + ffi = FFI() + ffi.cdef("typedef struct foo_s foo_t; int bar(foo_t *);") + lib = ffi.verify("typedef struct foo_s foo_t;\n" + "int bar(foo_t *f) { return 42; }\n") + assert lib.bar(None) == 42 + def test_missing_typedef(): py.test.skip("in-progress") ffi = FFI() _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit