diff options
| author | Armin Rigo <arigo@tunes.org> | 2015-06-02 15:56:31 +0200 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2015-06-02 15:56:31 +0200 |
| commit | 5c4f9ba700b3466717c5ddfc9011bf94dea8d32d (patch) | |
| tree | ff4dd4259acc231a21b341eb7b550321ede5dd42 | |
| parent | 8d296fa725a50b050e05ebe5e6601655b82324ce (diff) | |
| download | cffi-5c4f9ba700b3466717c5ddfc9011bf94dea8d32d.tar.gz | |
Test and fix for ffi.verify() only on PyPy (thanks Alex Gaynor for
pointing it out)
| -rw-r--r-- | cffi/vengine_gen.py | 15 | ||||
| -rw-r--r-- | testing/cffi0/test_verify.py | 8 |
2 files changed, 20 insertions, 3 deletions
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py index dc73ac0..2adea85 100644 --- a/cffi/vengine_gen.py +++ b/cffi/vengine_gen.py @@ -402,12 +402,16 @@ class VGenericEngine(object): else: assert tp is not None assert check_value is None - prnt(tp.get_c_name(' %s(void)' % funcname, name),) - prnt('{') if category == 'var': ampersand = '&' else: ampersand = '' + extra = '' + if category == 'const' and isinstance(tp, model.StructOrUnion): + extra = 'const *' + ampersand = '&' + prnt(tp.get_c_name(' %s%s(void)' % (extra, funcname), name)) + prnt('{') prnt(' return (%s%s);' % (ampersand, name)) prnt('}') prnt() @@ -436,9 +440,14 @@ class VGenericEngine(object): value += (1 << (8*self.ffi.sizeof(BLongLong))) else: assert check_value is None - BFunc = self.ffi._typeof_locked(tp.get_c_name('(*)(void)', name))[0] + fntypeextra = '(*)(void)' + if isinstance(tp, model.StructOrUnion): + fntypeextra = '*' + fntypeextra + BFunc = self.ffi._typeof_locked(tp.get_c_name(fntypeextra, name))[0] function = module.load_function(BFunc, funcname) value = function() + if isinstance(tp, model.StructOrUnion): + value = value[0] return value def _loaded_gen_constant(self, tp, name, module, library): diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py index 3e67e67..3bc10d5 100644 --- a/testing/cffi0/test_verify.py +++ b/testing/cffi0/test_verify.py @@ -2227,3 +2227,11 @@ def test_static_const_int_wrong_value(): ffi.cdef("static const int FOO = 123;") e = py.test.raises(VerificationError, ffi.verify, "#define FOO 124") assert str(e.value).endswith("FOO has the real value 124, not 123") + +def test_const_struct_global(): + ffi = FFI() + ffi.cdef("typedef struct { int x; ...; } T; const T myglob;") + lib = ffi.verify("typedef struct { double y; int x; } T;" + "const T myglob = { 0.1, 42 };") + assert ffi.typeof(lib.myglob) == ffi.typeof("T") + assert lib.myglob.x == 42 |
