Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1920:65f72675ba93
Date: 2015-05-07 15:59 +0200
http://bitbucket.org/cffi/cffi/changeset/65f72675ba93/
Log: Increase laziness in a small case.
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -288,7 +288,7 @@
ffi.cdef("""struct foo_s { int b; short a; };""")
lib = verify(ffi, 'test_verify_exact_field_offset',
"""struct foo_s { short a; int b; };""")
- e = py.test.raises(ffi.error, ffi.new, "struct foo_s *") # lazily
+ e = py.test.raises(ffi.error, ffi.new, "struct foo_s *", []) # lazily
assert str(e.value) == ("struct foo_s: wrong offset for field 'b' (cdef "
'says 0, but C compiler says 4). fix it or use "...;" '
"in the cdef for struct foo_s to make it flexible")
@@ -360,8 +360,9 @@
verify(ffi, 'test_misdeclared_field_1',
"struct foo_s { int a[6]; };")
assert ffi.sizeof("struct foo_s") == 24 # found by the actual C code
+ p = ffi.new("struct foo_s *")
# lazily build the fields and boom:
- e = py.test.raises(ffi.error, ffi.new, "struct foo_s *")
+ e = py.test.raises(ffi.error, "p.a")
assert str(e.value).startswith("struct foo_s: wrong size for field 'a' "
"(cdef says 20, but C compiler says 24)")
diff --git a/_cffi1/test_verify1.py b/_cffi1/test_verify1.py
--- a/_cffi1/test_verify1.py
+++ b/_cffi1/test_verify1.py
@@ -412,7 +412,7 @@
ffi = FFI()
ffi.cdef("struct foo_s { char x; int y; long *z; };")
ffi.verify(verified_code)
- ffi.new("struct foo_s *")
+ ffi.new("struct foo_s *", {})
check("struct foo_s { char x; int y; long *z; };")
#
@@ -482,7 +482,7 @@
ffi.cdef("struct foo_s { %s x; ...; };" % typename)
try:
ffi.verify("struct foo_s { %s x; };" % real)
- ffi.new("struct foo_s *") # because some mismatches show up lazily
+ ffi.new("struct foo_s *", []) # because some mismatches show up lazily
except (VerificationError, ffi.error):
if not expect_mismatch:
if testing_by_size and typename != real:
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2850,15 +2850,16 @@
if (ctitem->ct_flags & CT_PRIMITIVE_CHAR)
datasize *= 2; /* forcefully add another character: a null */
- if (ctitem->ct_flags & (CT_STRUCT | CT_UNION)) {
+ if ((ctitem->ct_flags & (CT_STRUCT | CT_UNION)) && init != Py_None) {
if (force_lazy_struct(ctitem) < 0) /* for CT_WITH_VAR_ARRAY */
return NULL;
- }
- if ((ctitem->ct_flags & CT_WITH_VAR_ARRAY) && init != Py_None) {
- Py_ssize_t optvarsize = datasize;
- if (convert_struct_from_object(NULL,ctitem, init, &optvarsize) < 0)
- return NULL;
- datasize = optvarsize;
+ if (ctitem->ct_flags & CT_WITH_VAR_ARRAY) {
+ Py_ssize_t optvarsize = datasize;
+ if (convert_struct_from_object(NULL,ctitem, init,
+ &optvarsize) < 0)
+ return NULL;
+ datasize = optvarsize;
+ }
}
}
else if (ct->ct_flags & CT_ARRAY) {
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit