compiler: Ensure prefix and dependencies are used for alignment.

This is now similar to how prefix and dependencies are used in all
the other similar checks performed by the compiler.
pull/1456/head
Haakon Sporsheim 8 years ago
parent 1e2c914b3c
commit c9fe3a3ad4
  1. 13
      mesonbuild/compilers.py
  2. 6
      mesonbuild/interpreter.py

@ -1076,31 +1076,34 @@ class CCompiler(Compiler):
raise EnvironmentException('Could not run sizeof test binary.') raise EnvironmentException('Could not run sizeof test binary.')
return int(res.stdout) return int(res.stdout)
def cross_alignment(self, typename, env, extra_args=None, dependencies=None): def cross_alignment(self, typename, prefix, env, extra_args=None, dependencies=None):
if extra_args is None: if extra_args is None:
extra_args = [] extra_args = []
fargs = {'type': typename} fargs = {'prefix': prefix, 'type': typename}
t = '''#include <stdio.h> t = '''#include <stdio.h>
{prefix}
int main(int argc, char **argv) {{ int main(int argc, char **argv) {{
{type} something; {type} something;
}}''' }}'''
if not self.compiles(t.format(**fargs), env, extra_args, dependencies): if not self.compiles(t.format(**fargs), env, extra_args, dependencies):
return -1 return -1
t = '''#include <stddef.h> t = '''#include <stddef.h>
{prefix}
struct tmp {{ struct tmp {{
char c; char c;
{type} target; {type} target;
}};''' }};'''
return self.cross_compute_int('offsetof(struct tmp, target)', 1, 1024, None, t.format(**fargs), env, extra_args, dependencies) return self.cross_compute_int('offsetof(struct tmp, target)', 1, 1024, None, t.format(**fargs), env, extra_args, dependencies)
def alignment(self, typename, env, extra_args=None, dependencies=None): def alignment(self, typename, prefix, env, extra_args=None, dependencies=None):
if extra_args is None: if extra_args is None:
extra_args = [] extra_args = []
if self.is_cross: if self.is_cross:
return self.cross_alignment(typename, env, extra_args, dependencies) return self.cross_alignment(typename, prefix, env, extra_args, dependencies)
fargs = {'type': typename} fargs = {'prefix': prefix, 'type': typename}
t = '''#include <stdio.h> t = '''#include <stdio.h>
#include <stddef.h> #include <stddef.h>
{prefix}
struct tmp {{ struct tmp {{
char c; char c;
{type} target; {type} target;

@ -700,8 +700,12 @@ class CompilerHolder(InterpreterObject):
raise InterpreterException('Alignment method takes exactly one positional argument.') raise InterpreterException('Alignment method takes exactly one positional argument.')
check_stringlist(args) check_stringlist(args)
typename = args[0] typename = args[0]
prefix = kwargs.get('prefix', '')
if not isinstance(prefix, str):
raise InterpreterException('Prefix argument of sizeof must be a string.')
extra_args = mesonlib.stringlistify(kwargs.get('args', [])) extra_args = mesonlib.stringlistify(kwargs.get('args', []))
result = self.compiler.alignment(typename, self.environment, extra_args) deps = self.determine_dependencies(kwargs)
result = self.compiler.alignment(typename, prefix, self.environment, extra_args, deps)
mlog.log('Checking for alignment of "', mlog.bold(typename), '": ', result, sep='') mlog.log('Checking for alignment of "', mlog.bold(typename), '": ', result, sep='')
return result return result

Loading…
Cancel
Save