Author: Armin Rigo <[email protected]>
Branch:
Changeset: r2121:ae85f5a0e121
Date: 2015-05-28 13:34 +0200
http://bitbucket.org/cffi/cffi/changeset/ae85f5a0e121/
Log: Issue #198 bis: fix for constants of unknown size
diff --git a/c/lib_obj.c b/c/lib_obj.c
--- a/c/lib_obj.c
+++ b/c/lib_obj.c
@@ -259,7 +259,10 @@
return NULL;
assert(g->address);
- assert(ct->ct_size > 0);
+ if (ct->ct_size <= 0) {
+ PyErr_SetString(PyExc_SystemError, "constant has no known size");
+ return NULL;
+ }
/* xxx the few bytes of memory we allocate here leak, but it's
a minor concern because it should only occur for
OP_CONSTANT. There is one per real non-integer C constant
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -982,6 +982,10 @@
if isinstance(tp, model.PrimitiveType) and tp.is_integer_type():
type_op = CffiOp(OP_CONSTANT_INT, -1)
else:
+ if not tp.sizeof_enabled():
+ raise ffiplatform.VerificationError(
+ "constant '%s' is of type '%s', whose size is not known"
+ % (name, tp._get_c_name()))
type_index = self._typesdict[tp]
type_op = CffiOp(OP_CONSTANT, type_index)
self._lsts["global"].append(
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -850,3 +850,14 @@
#define almost_forty_two (f())
""")
assert lib.almost_forty_two == 42.25
+
+def test_constant_of_unknown_size():
+ ffi = FFI()
+ ffi.cdef("""
+ typedef ... opaque_t;
+ const opaque_t CONSTANT;
+ """)
+ e = py.test.raises(VerificationError, verify, ffi,
+ 'test_constant_of_unknown_size', "stuff")
+ assert str(e.value) == ("constant CONSTANT: constant 'CONSTANT' is of "
+ "type 'opaque_t', whose size is not known")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit