Can check if headers have functions of a given name.
This commit is contained in:
parent
08d18671ae
commit
658a826518
|
@ -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)
|
||||
|
|
|
@ -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.')
|
||||
|
|
Loading…
Reference in New Issue