Instead of using the None value for the members field, use a dedicated "checking" value to detect recursive misconfigurations.
This is intended to assist with subsequent patches which will seek to remove the "None" value from the members field (which can never be set legally after the final call to check()) in order to simplify static typing of that field, by avoiding needing assertions littered at many callsites. Signed-off-by: John Snow <js...@redhat.com> --- scripts/qapi/schema.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d4d3c3bbcee..a459016e148 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -458,19 +458,21 @@ def __init__(self, name, info, doc, ifcond, features, self.local_members = local_members self.variants = variants self.members = None + self._checking = False def check(self, schema): # This calls another type T's .check() exactly when the C # struct emitted by gen_object() contains that T's C struct # (pointers don't count). - if self.members is not None: - # A previous .check() completed: nothing to do - return - if self._checked: + if self._checking: # Recursed: C struct contains itself raise QAPISemError(self.info, "object %s contains itself" % self.name) + if self._checked: + # A previous .check() completed: nothing to do + return + self._checking = True super().check(schema) assert self._checked and self.members is None @@ -495,7 +497,8 @@ def check(self, schema): self.variants.check(schema, seen) self.variants.check_clash(self.info, seen) - self.members = members # mark completed + self.members = members + self._checking = False # mark completed # Check that the members of this type do not cause duplicate JSON members, # and update seen to track the members seen so far. Report any errors -- 2.43.0