interpreterbase: protect string division with FeatureNew

Meson is not warning if you join paths with / but you are requesting a
version older than 0.49.0; fix this before adding more features to the
division operator.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/5110/head
Paolo Bonzini 6 years ago committed by Dylan Baker
parent 222a973918
commit 7a02b76e70
  1. 25
      mesonbuild/interpreterbase.py
  2. 8
      run_project_tests.py
  3. 3
      test cases/warning/1 version for string div/a/b.c
  4. 3
      test cases/warning/1 version for string div/meson.build

@ -606,6 +606,23 @@ The result of this is undefined and will become a hard error in a future Meson r
raise InterpreterException('Argument to negation is not an integer.')
return -v
@FeatureNew('/ with string arguments', '0.49.0')
def evaluate_path_join(self, l, r):
if not isinstance(l, str):
raise InvalidCode('The division operator can only append to a string.')
if not isinstance(r, str):
raise InvalidCode('The division operator can only append a string.')
return self.join_path_strings((l, r))
def evaluate_division(self, l, r):
if isinstance(l, str) or isinstance(r, str):
return self.evaluate_path_join(l, r)
if isinstance(l, int) and isinstance(r, int):
if r == 0:
raise InvalidCode('Division by zero.')
return l // r
raise InvalidCode('Division works only with strings or integers.')
def evaluate_arithmeticstatement(self, cur):
l = self.evaluate_statement(cur.left)
if is_disabler(l):
@ -630,13 +647,7 @@ The result of this is undefined and will become a hard error in a future Meson r
raise InvalidCode('Multiplication works only with integers.')
return l * r
elif cur.operation == 'div':
if isinstance(l, str) and isinstance(r, str):
return self.join_path_strings((l, r))
if isinstance(l, int) and isinstance(r, int):
if r == 0:
raise InvalidCode('Division by zero.')
return l // r
raise InvalidCode('Division works only with strings or integers.')
return self.evaluate_division(l, r)
elif cur.operation == 'mod':
if not isinstance(l, int) or not isinstance(r, int):
raise InvalidCode('Modulo works only with integers.')

@ -547,6 +547,7 @@ def detect_tests_to_run():
# Name, subdirectory, skip condition.
all_tests = [
('common', 'common', False),
('warning-meson', 'warning', False),
('failing-meson', 'failing', False),
('failing-build', 'failing build', False),
('failing-test', 'failing test', False),
@ -623,9 +624,14 @@ def _run_tests(all_tests, log_name_base, failfast, extra_args):
(testnum, testbase) = t.name.split(' ', 1)
testname = '%.3d %s' % (int(testnum), testbase)
should_fail = False
suite_args = []
if name.startswith('failing'):
should_fail = name.split('failing-')[1]
result = executor.submit(run_test, skipped, t.as_posix(), extra_args, system_compiler, backend, backend_flags, commands, should_fail)
if name.startswith('warning'):
suite_args = ['--fatal-meson-warnings']
should_fail = name.split('warning-')[1]
result = executor.submit(run_test, skipped, t.as_posix(), extra_args + suite_args,
system_compiler, backend, backend_flags, commands, should_fail)
futures.append((testname, t, result))
for (testname, t, result) in futures:
sys.stdout.flush()

@ -0,0 +1,3 @@
project('warn on string division', 'c', meson_version: '>=0.48.0')
executable('prog', 'a' / 'b.c')
Loading…
Cancel
Save