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.')
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:
extra_args = []
fargs = {'type': typename}
fargs = {'prefix': prefix, 'type': typename}
t = '''#include <stdio.h>
{prefix}
int main(int argc, char **argv) {{
{type} something;
}}'''
if not self.compiles(t.format(**fargs), env, extra_args, dependencies):
return -1
t = '''#include <stddef.h>
{prefix}
struct tmp {{
char c;
{type} target;
}};'''
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:
extra_args = []
if self.is_cross:
return self.cross_alignment(typename, env, extra_args, dependencies)
fargs = {'type': typename}
return self.cross_alignment(typename, prefix, env, extra_args, dependencies)
fargs = {'prefix': prefix, 'type': typename}
t = '''#include <stdio.h>
#include <stddef.h>
{prefix}
struct tmp {{
char c;
{type} target;

@ -700,8 +700,12 @@ class CompilerHolder(InterpreterObject):
raise InterpreterException('Alignment method takes exactly one positional argument.')
check_stringlist(args)
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', []))
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='')
return result

Loading…
Cancel
Save