|
11 | 11 | from distutils.command.config import LANG_EXT |
12 | 12 | from distutils import log |
13 | 13 | from distutils.file_util import copy_file |
| 14 | +from distutils.ccompiler import CompileError, LinkError |
14 | 15 | import distutils |
15 | 16 | from numpy.distutils.exec_command import exec_command |
16 | 17 | from numpy.distutils.mingw32ccompiler import generate_manifest |
@@ -158,6 +159,81 @@ def check_decl(self, symbol, |
158 | 159 |
|
159 | 160 | return self.try_compile(body, headers, include_dirs) |
160 | 161 |
|
| 162 | + def check_type_size(self, type_name, headers=None, include_dirs=None): |
| 163 | + """Check size of a given type.""" |
| 164 | + # XXX: should also implement the cross-compiling version (using binary |
| 165 | + # search + array indexing, see AC_CHECK_SIZEOF). |
| 166 | + self._check_compiler() |
| 167 | + |
| 168 | + # We declare the functions to avoid warnings with -Wstrict-prototypes |
| 169 | + body = r""" |
| 170 | +typedef %(type)s _dist_type_sizeof_; |
| 171 | +
|
| 172 | +static long int longval (void) |
| 173 | +{ |
| 174 | + return (long int) (sizeof (_dist_type_sizeof_)); |
| 175 | +} |
| 176 | +static unsigned long int ulongval (void) |
| 177 | +{ |
| 178 | + return (long int) (sizeof (_dist_type_sizeof_)); |
| 179 | +} |
| 180 | +
|
| 181 | +#include <stdio.h> |
| 182 | +#include <stdlib.h> |
| 183 | +int |
| 184 | +main (void) |
| 185 | +{ |
| 186 | +
|
| 187 | + if (((long int) (sizeof (_dist_type_sizeof_))) < 0) { |
| 188 | + long int i = longval (); |
| 189 | + if (i != ((long int) (sizeof (_dist_type_sizeof_)))) |
| 190 | + return 1; |
| 191 | + printf("%%ld\n", i); |
| 192 | + } else { |
| 193 | + unsigned long int i = ulongval (); |
| 194 | + if (i != ((long int) (sizeof (_dist_type_sizeof_)))) |
| 195 | + return 1; |
| 196 | + printf("%%lu\n", i); |
| 197 | + } |
| 198 | +
|
| 199 | + return 0; |
| 200 | +} |
| 201 | +""" % {'type': type_name} |
| 202 | + |
| 203 | + # XXX: this should be refactored (same code as get_output) |
| 204 | + exitcode, output = 255, '' |
| 205 | + size = None |
| 206 | + try: |
| 207 | + src, obj, exe = self._link(body, headers, include_dirs, |
| 208 | + [], [], 'c') |
| 209 | + exe = os.path.join('.', exe) |
| 210 | + exitstatus, output = exec_command(exe, execute_in='.') |
| 211 | + if hasattr(os, 'WEXITSTATUS'): |
| 212 | + exitcode = os.WEXITSTATUS(exitstatus) |
| 213 | + if os.WIFSIGNALED(exitstatus): |
| 214 | + sig = os.WTERMSIG(exitstatus) |
| 215 | + log.error('subprocess exited with signal %d' % (sig,)) |
| 216 | + if sig == signal.SIGINT: |
| 217 | + # control-C |
| 218 | + raise KeyboardInterrupt |
| 219 | + else: |
| 220 | + exitcode = exitstatus |
| 221 | + log.info("success!") |
| 222 | + |
| 223 | + try: |
| 224 | + size = int(output) |
| 225 | + except ValueError: |
| 226 | + log.error("Unexpected output %s" % output) |
| 227 | + log.info("failure") |
| 228 | + except (CompileError, LinkError): |
| 229 | + log.info("failure.") |
| 230 | + |
| 231 | + self._clean() |
| 232 | + if size is not None: |
| 233 | + return size |
| 234 | + else: |
| 235 | + return -1 |
| 236 | + |
161 | 237 | def check_func(self, func, |
162 | 238 | headers=None, include_dirs=None, |
163 | 239 | libraries=None, library_dirs=None, |
|
0 commit comments