diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-04-20 23:33:30 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-04-23 09:10:48 +0200 |
commit | 38f2eae6815baad42248f5461bea049f1f2e1f13 (patch) | |
tree | 95b0ab6f28a2e4848c48d622dfb2198f7544c0b4 | |
parent | 75b7a856cd7a5fc8af697584aec453c82c7c923d (diff) | |
download | meson-38f2eae6815baad42248f5461bea049f1f2e1f13.zip meson-38f2eae6815baad42248f5461bea049f1f2e1f13.tar.gz meson-38f2eae6815baad42248f5461bea049f1f2e1f13.tar.bz2 |
ast: Make sure to avoid infinite recursions
-rw-r--r-- | mesonbuild/ast/interpreter.py | 18 | ||||
-rw-r--r-- | test cases/unit/55 introspection/meson.build | 14 |
2 files changed, 23 insertions, 9 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index bef1296..d0bbc69 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -244,12 +244,12 @@ class AstInterpreter(interpreterbase.InterpreterBase): self.reverse_assignment[node.value.ast_id] = node self.assign_vals[node.var_name] = [self.evaluate_statement(node.value)] # Evaluate the value just in case - def flatten_args(self, args: Any, include_unknown_args: bool = False) -> List[str]: - def quick_resolve(n: BaseNode) -> Any: + def flatten_args(self, args: Any, include_unknown_args: bool = False, id_loop_detect: List[str] = []) -> List[str]: + def quick_resolve(n: BaseNode, loop_detect: List[str] = []) -> Any: if isinstance(n, IdNode): - if n.value not in self.assignments: + if n.value in loop_detect or n.value not in self.assignments: return [] - return quick_resolve(self.assignments[n.value][0]) + return quick_resolve(self.assignments[n.value][0], loop_detect = loop_detect + [n.value]) elif isinstance(n, ElementaryNode): return n.value else: @@ -271,11 +271,11 @@ class AstInterpreter(interpreterbase.InterpreterBase): if isinstance(l, str) and isinstance(r, str): args = [l + r] # String concatination detected else: - args = self.flatten_args(l) + self.flatten_args(r) + args = self.flatten_args(l, include_unknown_args, id_loop_detect) + self.flatten_args(r, include_unknown_args, id_loop_detect) elif isinstance(args, MethodNode): src = quick_resolve(args.source_object) - margs = self.flatten_args(args.args) + margs = self.flatten_args(args.args, include_unknown_args, id_loop_detect) try: if isinstance(src, str): args = [self.string_method_call(src, args.name, margs)] @@ -298,10 +298,10 @@ class AstInterpreter(interpreterbase.InterpreterBase): # Resolve the contents of args for i in args: - if isinstance(i, IdNode): - flattend_args += self.flatten_args(quick_resolve(i), include_unknown_args) + if isinstance(i, IdNode) and i.value not in id_loop_detect: + flattend_args += self.flatten_args(quick_resolve(i), include_unknown_args, id_loop_detect + [i.value]) elif isinstance(i, (ArrayNode, ArgumentNode, ArithmeticNode, MethodNode)): - flattend_args += self.flatten_args(i, include_unknown_args) + flattend_args += self.flatten_args(i, include_unknown_args, id_loop_detect) elif isinstance(i, mparser.ElementaryNode): flattend_args += [i.value] elif isinstance(i, (str, bool, int, float)): diff --git a/test cases/unit/55 introspection/meson.build b/test cases/unit/55 introspection/meson.build index 7ee11a8..8ae00c2 100644 --- a/test cases/unit/55 introspection/meson.build +++ b/test cases/unit/55 introspection/meson.build @@ -28,6 +28,20 @@ t1 = executable('test' + var1, ['t1.cpp'], link_with: [sharedlib], install: true t2 = executable('test@0@'.format('@0@'.format(var2)), 't2.cpp', link_with: [staticlib]) t3 = executable(var3, 't3.cpp', link_with: [sharedlib, staticlib], dependencies: [dep1]) +### BEGIN: Test stolen from taisei: https://github.com/taisei-project/taisei/blob/master/meson.build#L293 +have_posix = true +systype = (have_posix ? 'POSIX (@0@)' : '@0@').format(host_machine.system()) +systype = '@0@, @1@, @2@'.format(systype, host_machine.cpu_family(), host_machine.cpu()) +systype = '@0@ (cross-compiling)'.format(systype) +summary = ''' + +Summary: + System type: @0@ +'''.format(systype) + +message(summary) +### END: Test stolen from taisei + test('test case 1', t1) test('test case 2', t2) benchmark('benchmark 1', t3) |