[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/7] qapi: Eliminate accidental global frontend state
From: |
Markus Armbruster |
Subject: |
[PATCH v2 3/7] qapi: Eliminate accidental global frontend state |
Date: |
Fri, 18 Oct 2019 09:43:41 +0200 |
The frontend can't be run more than once due to its global state.
A future commit will want to do that.
The only global frontend state remaining is accidental:
QAPISchemaParser.__init__()'s parameter previously_included=[].
Python evaluates the default once, at definition time. Any
modifications to it are visible in subsequent calls. Well-known
Python trap. Change the default to None and replace it by the real
default in the function body. Use the opportunity to convert
previously_included to a set.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
scripts/qapi/common.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 5abab44302..9d5c05f6a1 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -391,8 +391,9 @@ class QAPIDoc(object):
class QAPISchemaParser(object):
- def __init__(self, fname, previously_included=[], incl_info=None):
- previously_included.append(os.path.abspath(fname))
+ def __init__(self, fname, previously_included=None, incl_info=None):
+ previously_included = previously_included or set()
+ previously_included.add(os.path.abspath(fname))
try:
if sys.version_info[0] >= 3:
--
2.21.0
- [PATCH v2 0/7] qapi: Cleanups and test speedup, Markus Armbruster, 2019/10/18
- [PATCH v2 3/7] qapi: Eliminate accidental global frontend state,
Markus Armbruster <=
- [PATCH v2 1/7] qapi: Don't suppress doc generation without pragma doc-required, Markus Armbruster, 2019/10/18
- [PATCH v2 2/7] qapi: Store pragma state in QAPISourceInfo, not global state, Markus Armbruster, 2019/10/18
- [PATCH v2 7/7] qapi: Clear scripts/qapi/doc.py executable bits again, Markus Armbruster, 2019/10/18
- [PATCH v2 5/7] qapi: Move gen_enum(), gen_enum_lookup() back to qapi/types.py, Markus Armbruster, 2019/10/18
- [PATCH v2 4/7] qapi: Speed up frontend tests, Markus Armbruster, 2019/10/18
- [PATCH v2 6/7] qapi: Split up scripts/qapi/common.py, Markus Armbruster, 2019/10/18