[pypy-commit] pypy rffi-parser-2: Avoid infinite recursion in recursive definitions
rlamy
pypy.commits at gmail.com
Mon Dec 26 09:59:09 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: rffi-parser-2
Changeset: r89226:08804887d145
Date: 2016-12-24 11:30 +0100
http://bitbucket.org/pypy/pypy/changeset/08804887d145/
Log: Avoid infinite recursion in recursive definitions
diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -666,7 +666,7 @@
self.fields = fields
def __repr__(self):
- return "<struct {struct_name}>".format(vars(self))
+ return "<struct {struct_name}>".format(**vars(self))
class ParsedSource(object):
@@ -703,12 +703,16 @@
def new_struct(self, obj):
if obj.fldtypes is None:
- return lltype.ForwardReference()
+ struct = lltype.ForwardReference()
else:
- fields = zip(
- obj.fldnames,
- [self.convert_type(field) for field in obj.fldtypes])
- return DelayedStruct(obj.name, fields)
+ struct = DelayedStruct(obj.name, None)
+ # Cache it early, to avoid infinite recursion
+ self.structs[obj] = struct
+ if obj.fldtypes is not None:
+ struct.fields = zip(
+ obj.fldnames,
+ [self.convert_type(field) for field in obj.fldtypes])
+ return struct
def realize_struct(self, struct, type_name):
configname = type_name.replace(' ', '__')
@@ -729,9 +733,7 @@
elif isinstance(obj, model.StructType):
if obj in self.structs:
return self.structs[obj]
- result = self.new_struct(obj)
- self.structs[obj] = result
- return result
+ return self.new_struct(obj)
elif isinstance(obj, model.PointerType):
TO = self.convert_type(obj.totype)
if TO is lltype.Void:
More information about the pypy-commit
mailing list