Can add extra #includes to sizeof checks.

pull/15/head
Jussi Pakkanen 12 years ago
parent ae62e8ca11
commit e453c408da
  1. 7
      environment.py
  2. 9
      interpreter.py
  3. 1
      test cases/common/35 sizeof/config.h.in
  4. 2
      test cases/common/35 sizeof/meson.build
  5. 5
      test cases/common/35 sizeof/prog.c

@ -133,8 +133,10 @@ class CCompiler():
pass
return p.returncode == 0
def sizeof(self, element):
def sizeof(self, element, prefix):
templ = '''#include<stdio.h>
%s
int main(int argc, char **argv) {
printf("%%ld\\n", (long)(sizeof(%s)));
return 0;
@ -144,7 +146,8 @@ int main(int argc, char **argv) {
exename = srcname + '.exe' # Is guaranteed to be executable on every platform.
os.close(fd)
ofile = open(srcname, 'w')
code = templ % element
code = templ % (prefix, element)
print(code)
ofile.write(code)
ofile.close()
commands = self.get_exelist()

@ -546,10 +546,13 @@ class CompilerHolder(InterpreterObject):
def sizeof_method(self, args, kwargs):
if len(args) != 1:
raise InterpreterException('Sizeof takes exactly one argument.')
string = args[0]
if not isinstance(string, str):
element = args[0]
if not isinstance(element, str):
raise InterpreterException('Argument to sizeof must be a string.')
return self.compiler.sizeof(string)
prefix = kwargs.get('prefix', '')
if not isinstance(prefix, str):
raise InterpreterException('Prefix argument of sizeof must be a string.')
return self.compiler.sizeof(element, prefix)
def compiles_method(self, args, kwargs):
if len(args) != 1:

@ -1 +1,2 @@
#define INTSIZE @INTSIZE@
#define WCHARSIZE @WCHARSIZE@

@ -2,9 +2,11 @@ project('sizeof', 'c')
cc = meson.get_compiler('c')
intsize = cc.sizeof('int')
wcharsize = cc.sizeof('wchar_t', prefix : '#include<wchar.h>')
cd = configuration_data()
cd.set('INTSIZE', intsize)
cd.set('WCHARSIZE', wcharsize)
configure_file(input : 'config.h.in', output : 'config.h', configuration : cd)
e = executable('prog', 'prog.c', include_dirs : include_directories('.'))

@ -1,10 +1,15 @@
#include"config.h"
#include<stdio.h>
#include<wchar.h>
int main(int argc, char **argv) {
if(INTSIZE != sizeof(int)) {
fprintf(stderr, "Mismatch: detected int size %d, actual size %d.\n", INTSIZE, (int)sizeof(int));
return 1;
}
if(WCHARSIZE != sizeof(wchar_t)) {
fprintf(stderr, "Mismatch: detected wchar size %d, actual size %d.\n", WCHARSIZE, (int)sizeof(wchar_t));
return 1;
}
return 0;
}

Loading…
Cancel
Save