summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cffi/vengine_gen.py15
-rw-r--r--testing/cffi0/test_verify.py8
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