diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-07-30 21:44:40 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-07-30 21:44:40 +0300 |
commit | 658a82651897676ab036d922b9603e81a5ba7333 (patch) | |
tree | 696223805ae020bb20e0fb80b1852972079fd969 | |
parent | 08d18671aeefda22325375909f3bc960d29a6c52 (diff) | |
download | meson-658a82651897676ab036d922b9603e81a5ba7333.zip meson-658a82651897676ab036d922b9603e81a5ba7333.tar.gz meson-658a82651897676ab036d922b9603e81a5ba7333.tar.bz2 |
Can check if headers have functions of a given name.
-rw-r--r-- | environment.py | 13 | ||||
-rw-r--r-- | interpreter.py | 23 |
2 files changed, 34 insertions, 2 deletions
diff --git a/environment.py b/environment.py index 03fa21b..3ccd385 100644 --- a/environment.py +++ b/environment.py @@ -188,6 +188,19 @@ int main(int argc, char **argv) { raise EnvironmentException('Could not run sizeof test binary.') return int(res.stdout) + def has_function(self, funcname, prefix): + # This fails (returns true) if funcname is a ptr or a variable. + # The correct check is a lot more difficult. + # Fix this to do that eventually. + templ = '''%s +int main(int argc, char **argv) { + void *ptr = (void*)(%s); + return 0; +}; +''' + res = self.run(templ % (prefix, funcname)) + return res.compiled + class CPPCompiler(CCompiler): def __init__(self, exelist): CCompiler.__init__(self, exelist) diff --git a/interpreter.py b/interpreter.py index 318f7b3..0025ec0 100644 --- a/interpreter.py +++ b/interpreter.py @@ -650,6 +650,7 @@ class CompilerHolder(InterpreterObject): 'sizeof': self.sizeof_method, 'has_header': self.has_header_method, 'run' : self.run_method, + 'has_function' : self.has_function_method, }) def run_method(self, args, kwargs): @@ -665,7 +666,25 @@ class CompilerHolder(InterpreterObject): def get_id_method(self, args, kwargs): return self.compiler.get_id() - + + + def has_function_method(self, args, kwargs): + if len(args) != 1: + raise InterpreterException('Has_function takes exactly one argument.') + funcname = args[0] + if not isinstance(funcname, str): + raise InterpreterException('Argument to has_function must be a string.') + prefix = kwargs.get('prefix', '') + if not isinstance(prefix, str): + raise InterpreterException('Prefix argument of has_function must be a string.') + had = self.compiler.has_function(funcname, prefix) + if had: + hadtxt = mlog.green('YES') + else: + hadtxt = mlog.red('NO') + mlog.log('Checking for function "', mlog.bold(funcname), '": ', hadtxt, sep='') + return had + def sizeof_method(self, args, kwargs): if len(args) != 1: raise InterpreterException('Sizeof takes exactly one argument.') @@ -688,7 +707,7 @@ class CompilerHolder(InterpreterObject): if not isinstance(string, str): raise InterpreterException('Argument to compiles() must be a string') return self.compiler.compiles(string) - + def has_header_method(self, args, kwargs): if len(args) != 1: raise InterpreterException('has_header method takes exactly one argument.') |