Avoid storing global state.
diff --git a/tools/mkdoc.py b/tools/mkdoc.py
index ffe37d2..a99357e 100644
--- a/tools/mkdoc.py
+++ b/tools/mkdoc.py
@@ -57,8 +57,6 @@
job_count = cpu_count()
job_semaphore = Semaphore(job_count)
-output = []
-
class NoFilenamesError(ValueError):
pass
@@ -188,7 +186,7 @@
return result.rstrip().lstrip('\n')
-def extract(filename, node, prefix):
+def extract(filename, node, prefix, output):
if not (node.location.file is None or
os.path.samefile(d(node.location.file.name), filename)):
return 0
@@ -199,7 +197,7 @@
sub_prefix += '_'
sub_prefix += d(node.spelling)
for i in node.get_children():
- extract(filename, i, sub_prefix)
+ extract(filename, i, sub_prefix, output)
if node.kind in PRINT_LIST:
comment = d(node.raw_comment) if node.raw_comment is not None else ''
comment = process_comment(comment)
@@ -208,15 +206,15 @@
sub_prefix += '_'
if len(node.spelling) > 0:
name = sanitize_name(sub_prefix + d(node.spelling))
- global output
output.append((name, filename, comment))
class ExtractionThread(Thread):
- def __init__(self, filename, parameters):
+ def __init__(self, filename, parameters, output):
Thread.__init__(self)
self.filename = filename
self.parameters = parameters
+ self.output = output
job_semaphore.acquire()
def run(self):
@@ -225,7 +223,7 @@
index = cindex.Index(
cindex.conf.lib.clang_createIndex(False, True))
tu = index.parse(self.filename, self.parameters)
- extract(self.filename, tu.cursor, '')
+ extract(self.filename, tu.cursor, '', self.output)
finally:
job_semaphore.release()
@@ -300,9 +298,9 @@
#endif
''', file=out_file)
- output.clear()
+ output = []
for filename in filenames:
- thr = ExtractionThread(filename, parameters)
+ thr = ExtractionThread(filename, parameters, output)
thr.start()
print('Waiting for jobs to finish ..', file=sys.stderr)