From cbf2b51e4003e5b08aa402c55fb428b888cdf8b1 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 28 Aug 2017 15:29:33 +0300 Subject: [PATCH] bindings(py): fix handling of 'isalgorithm' --- modules/python/src2/gen2.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py index c0cc83ca79..4f15715ccc 100755 --- a/modules/python/src2/gen2.py +++ b/modules/python/src2/gen2.py @@ -1027,10 +1027,28 @@ class PythonWrapperGenerator(object): print("Generator error: unable to resolve base %s for %s" % (classinfo.base, classinfo.name)) sys.exit(-1) + base_instance = self.classes[base] classinfo.base = base - classinfo.isalgorithm |= self.classes[base].isalgorithm + classinfo.isalgorithm |= base_instance.isalgorithm # wrong processing of 'isalgorithm' flag: + # doesn't work for trees(graphs) with depth > 2 self.classes[name] = classinfo + # tree-based propagation of 'isalgorithm' + processed = dict() + def process_isalgorithm(classinfo): + if classinfo.isalgorithm or classinfo in processed: + return classinfo.isalgorithm + res = False + if classinfo.base: + res = process_isalgorithm(self.classes[classinfo.base]) + #assert not (res == True or classinfo.isalgorithm is False), "Internal error: " + classinfo.name + " => " + classinfo.base + classinfo.isalgorithm |= res + res = classinfo.isalgorithm + processed[classinfo] = True + return res + for name, classinfo in self.classes.items(): + process_isalgorithm(classinfo) + # step 2: generate code for the classes and their methods classlist = list(self.classes.items()) classlist.sort()