Skip to content

Commit cbf2b51

Browse files
committed
bindings(py): fix handling of 'isalgorithm'
1 parent f071a48 commit cbf2b51

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

modules/python/src2/gen2.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,10 +1027,28 @@ def gen(self, srcfiles, output_path):
10271027
print("Generator error: unable to resolve base %s for %s"
10281028
% (classinfo.base, classinfo.name))
10291029
sys.exit(-1)
1030+
base_instance = self.classes[base]
10301031
classinfo.base = base
1031-
classinfo.isalgorithm |= self.classes[base].isalgorithm
1032+
classinfo.isalgorithm |= base_instance.isalgorithm # wrong processing of 'isalgorithm' flag:
1033+
# doesn't work for trees(graphs) with depth > 2
10321034
self.classes[name] = classinfo
10331035

1036+
# tree-based propagation of 'isalgorithm'
1037+
processed = dict()
1038+
def process_isalgorithm(classinfo):
1039+
if classinfo.isalgorithm or classinfo in processed:
1040+
return classinfo.isalgorithm
1041+
res = False
1042+
if classinfo.base:
1043+
res = process_isalgorithm(self.classes[classinfo.base])
1044+
#assert not (res == True or classinfo.isalgorithm is False), "Internal error: " + classinfo.name + " => " + classinfo.base
1045+
classinfo.isalgorithm |= res
1046+
res = classinfo.isalgorithm
1047+
processed[classinfo] = True
1048+
return res
1049+
for name, classinfo in self.classes.items():
1050+
process_isalgorithm(classinfo)
1051+
10341052
# step 2: generate code for the classes and their methods
10351053
classlist = list(self.classes.items())
10361054
classlist.sort()

0 commit comments

Comments
 (0)