aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-06-21 00:37:53 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2016-06-21 00:38:07 +0300
commit10f6295ca81c15a8247dfbf6d105726e708c89a9 (patch)
tree958d2cdf2b46cf61bcf75f3d20ffed98695b53e7
parent642b4ddf71bd2865739570c80135687a8f9bac13 (diff)
downloadmeson-10f6295ca81c15a8247dfbf6d105726e708c89a9.zip
meson-10f6295ca81c15a8247dfbf6d105726e708c89a9.tar.gz
meson-10f6295ca81c15a8247dfbf6d105726e708c89a9.tar.bz2
Do not use [] as a function default argument as the variable persists over multiple invocations.
-rw-r--r--mesonbuild/compilers.py48
1 files changed, 36 insertions, 12 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index be96639..0efe989 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -495,13 +495,17 @@ class CCompiler(Compiler):
code = 'int main(int argc, char **argv) { int class=0; return class; }\n'
return self.sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code)
- def has_header(self, hname, env, extra_args=[]):
+ def has_header(self, hname, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
templ = '''#include<%s>
int someSymbolHereJustForFun;
'''
return self.compiles(templ % hname, env, extra_args)
- def has_header_symbol(self, hname, symbol, prefix, env, extra_args=[]):
+ def has_header_symbol(self, hname, symbol, prefix, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
templ = '''{2}
#include <{0}>
int main () {{ {1}; }}'''
@@ -509,7 +513,9 @@ int main () {{ {1}; }}'''
extra_args += self.get_no_optimization_args()
return self.compiles(templ.format(hname, symbol, prefix), env, extra_args)
- def compile(self, code, srcname, extra_args=[]):
+ def compile(self, code, srcname, extra_args=None):
+ if extra_args is None:
+ extra_args = []
commands = self.get_exelist()
commands.append(srcname)
commands += extra_args
@@ -525,7 +531,9 @@ int main () {{ {1}; }}'''
os.remove(srcname)
return p
- def compiles(self, code, env, extra_args=[]):
+ def compiles(self, code, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
if isinstance(extra_args, str):
extra_args = [extra_args]
suflen = len(self.default_suffix)
@@ -552,7 +560,9 @@ int main () {{ {1}; }}'''
pass
return p.returncode == 0
- def links(self, code, env, extra_args=[]):
+ def links(self, code, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd)
(fd, dstname) = tempfile.mkstemp()
@@ -578,7 +588,9 @@ int main () {{ {1}; }}'''
pass
return p.returncode == 0
- def run(self, code, env, extra_args=[]):
+ def run(self, code, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
mlog.debug('Running code:\n\n', code)
if self.is_cross and self.exe_wrapper is None:
raise CrossNoRunException('Can not run test applications in this cross environment.')
@@ -631,7 +643,9 @@ int main () {{ {1}; }}'''
pass
return RunResult(True, pe.returncode, so, se)
- def cross_sizeof(self, element, prefix, env, extra_args=[]):
+ def cross_sizeof(self, element, prefix, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
element_exists_templ = '''#include <stdio.h>
{0}
int main(int argc, char **argv) {{
@@ -655,7 +669,9 @@ int temparray[%d-sizeof(%s)];
return i
raise EnvironmentException('Cross checking sizeof overflowed.')
- def sizeof(self, element, prefix, env, extra_args=[]):
+ def sizeof(self, element, prefix, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
if self.is_cross:
return self.cross_sizeof(element, prefix, env, extra_args)
templ = '''#include<stdio.h>
@@ -673,7 +689,9 @@ int main(int argc, char **argv) {
raise EnvironmentException('Could not run sizeof test binary.')
return int(res.stdout)
- def cross_alignment(self, typename, env, extra_args=[]):
+ def cross_alignment(self, typename, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
type_exists_templ = '''#include <stdio.h>
int main(int argc, char **argv) {{
{0} something;
@@ -700,7 +718,9 @@ int testarray[%d-offsetof(struct tmp, target)];
return i
raise EnvironmentException('Cross checking offsetof overflowed.')
- def alignment(self, typename, env, extra_args=[]):
+ def alignment(self, typename, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
if self.is_cross:
return self.cross_alignment(typename, env, extra_args)
templ = '''#include<stdio.h>
@@ -726,7 +746,7 @@ int main(int argc, char **argv) {
raise EnvironmentException('Could not determine alignment of %s. Sorry. You might want to file a bug.' % typename)
return align
- def has_function(self, funcname, prefix, env, extra_args=[]):
+ def has_function(self, funcname, prefix, env, extra_args=None):
"""
First, this function looks for the symbol in the default libraries
provided by the compiler (stdlib + a few others usually). If that
@@ -734,6 +754,8 @@ int main(int argc, char **argv) {
an implementation of the function, and if that fails, it checks if it's
implemented as a compiler-builtin.
"""
+ if extra_args is None:
+ extra_args = []
# Define the symbol to something else in case it is defined by the
# includes or defines listed by the user `{0}` or by the compiler.
# Then, undef the symbol to get rid of it completely.
@@ -798,7 +820,9 @@ int main(int argc, char **argv) {
# directly try to link via main().
return self.links('int main() {{ {0}; }}'.format('__builtin_' + funcname), env, extra_args)
- def has_member(self, typename, membername, prefix, env, extra_args=[]):
+ def has_member(self, typename, membername, prefix, env, extra_args=None):
+ if extra_args is None:
+ extra_args = []
templ = '''%s
void bar() {
%s foo;