aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase.py
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2019-03-14 10:35:00 +0100
committerDylan Baker <dylan@pnwbakers.com>2019-03-18 10:51:44 -0700
commit7a02b76e70e219e5201e322c6c6c232d06601920 (patch)
tree55cfd1d4ad4f96f881659ae77b338d9896cc1618 /mesonbuild/interpreterbase.py
parent222a973918fe01ae0c4051a821797dde96f018af (diff)
downloadmeson-7a02b76e70e219e5201e322c6c6c232d06601920.zip
meson-7a02b76e70e219e5201e322c6c6c232d06601920.tar.gz
meson-7a02b76e70e219e5201e322c6c6c232d06601920.tar.bz2
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>
Diffstat (limited to 'mesonbuild/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 9206d02..650d1e0 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -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.')