Author: Armin Rigo <[email protected]>
Branch:
Changeset: r97825:847f17dd11a6
Date: 2019-10-21 11:29 +0200
http://bitbucket.org/pypy/pypy/changeset/847f17dd11a6/
Log: manual update corresponding to cffi/3873bbdd3b9e
diff --git a/pypy/module/_cffi_backend/realize_c_type.py
b/pypy/module/_cffi_backend/realize_c_type.py
--- a/pypy/module/_cffi_backend/realize_c_type.py
+++ b/pypy/module/_cffi_backend/realize_c_type.py
@@ -83,6 +83,7 @@
self.space = space
self.all_primitives = [None] * cffi_opcode._NUM_PRIM
self.file_struct = None
+ self.rec_level = 0
def get_file_struct(self):
if self.file_struct is None:
@@ -406,12 +407,18 @@
if from_ffi and ffi.cached_types[index] is not None:
return ffi.cached_types[index]
- opcodes[index] = rffi.cast(rffi.VOIDP, 255)
+ realize_cache = ffi.space.fromcache(RealizeCache)
+ if realize_cache.rec_level >= 1000:
+ raise oefmt(ffi.space.w_RuntimeError,
+ "type-building recursion too deep or infinite. "
+ "This is known to occur e.g. in ``struct s { void(*callable)"
+ "(struct s); }''. Please report if you get this error and "
+ "really need support for your case.")
+ realize_cache.rec_level += 1
try:
x = realize_c_type_or_func_now(ffi, op, opcodes, index)
finally:
- if opcodes[index] == rffi.cast(rffi.VOIDP, 255):
- opcodes[index] = op
+ realize_cache.rec_level -= 1
if from_ffi:
assert ffi.cached_types[index] is None or ffi.cached_types[index] is x
@@ -461,13 +468,6 @@
'c_type_index')
x = realize_c_type_or_func(ffi, ffi.ctxobj.ctx.c_types, type_index)
- elif case == 255:
- raise oefmt(ffi.space.w_RuntimeError,
- "found a situation in which we try to build a type recursively. "
- "This is known to occur e.g. in ``struct s { void(*callable)"
- "(struct s); }''. Please report if you get this error and "
- "really need support for your case.")
-
else:
raise oefmt(ffi.space.w_NotImplementedError, "op=%d", case)
diff --git a/pypy/module/_cffi_backend/test/test_re_python.py
b/pypy/module/_cffi_backend/test/test_re_python.py
--- a/pypy/module/_cffi_backend/test/test_re_python.py
+++ b/pypy/module/_cffi_backend/test/test_re_python.py
@@ -74,6 +74,7 @@
struct foo_s;
typedef struct bar_s { int x; signed char a[]; } bar_t;
enum foo_e { AA, BB, CC };
+ typedef struct selfref { struct selfref *next; } *selfref_ptr_t;
""")
ffi.set_source('re_python_pysrc', None)
ffi.emit_python_code(str(tmpdir.join('re_python_pysrc.py')))
@@ -237,3 +238,9 @@
"foobar", _version=0x2594)
assert str(e.value).startswith(
"cffi out-of-line Python module 'foobar' has unknown version")
+
+ def test_selfref(self):
+ # based on cffi issue #429
+ self.fix_path()
+ from re_python_pysrc import ffi
+ ffi.new("selfref_ptr_t")
diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py
b/pypy/module/_cffi_backend/test/test_recompiler.py
--- a/pypy/module/_cffi_backend/test/test_recompiler.py
+++ b/pypy/module/_cffi_backend/test/test_recompiler.py
@@ -2151,8 +2151,8 @@
};
""")
e = raises(RuntimeError, ffi.new, "struct BinaryTree *")
- assert str(e.value) == (
- "found a situation in which we try to build a type recursively. "
- "This is known to occur e.g. in ``struct s { void(*callable)"
- "(struct s); }''. Please report if you get this error and "
- "really need support for your case.")
+ # we should check e.value, but untranslated it crashes with a
+ # regular recursion error. There is a chance it occurs translated
+ # too, but likely the check in the code ">= 1000" usually triggers
+ # before that, and raise a RuntimeError too, but with the more
+ # explicit message.
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit