summaryrefslogtreecommitdiff
path: root/numpy/distutils/command/config.py
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-02-26 10:41:32 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-02-26 10:41:32 +0000
commitd1573af98a34d1cb8da4aa63b9d2cab19e3c567d (patch)
treef2719f4cd8e3c6efdd0749ddeb94f7683fb91de5 /numpy/distutils/command/config.py
parentc316a60c3638aedb53d5571816d77dc2fa0a82d1 (diff)
parent0878b817981ebd66088184fa15589784aca96725 (diff)
downloadnumpy-d1573af98a34d1cb8da4aa63b9d2cab19e3c567d.tar.gz
Merge coremath.
Diffstat (limited to 'numpy/distutils/command/config.py')
-rw-r--r--numpy/distutils/command/config.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/numpy/distutils/command/config.py b/numpy/distutils/command/config.py
index 39ea5f3b1..74f96e3b0 100644
--- a/numpy/distutils/command/config.py
+++ b/numpy/distutils/command/config.py
@@ -11,6 +11,7 @@ from distutils.command.config import config as old_config
from distutils.command.config import LANG_EXT
from distutils import log
from distutils.file_util import copy_file
+from distutils.ccompiler import CompileError, LinkError
import distutils
from numpy.distutils.exec_command import exec_command
from numpy.distutils.mingw32ccompiler import generate_manifest
@@ -143,6 +144,12 @@ class was %s
(body, headers, include_dirs,
libraries, library_dirs, lang))
+ def check_header(self, header, include_dirs=None, library_dirs=None, lang='c'):
+ self._check_compiler()
+ return self.try_compile(
+ "/* we need a dummy line to make distutils happy */",
+ [header], include_dirs)
+
def check_decl(self, symbol,
headers=None, include_dirs=None):
self._check_compiler()
@@ -158,6 +165,81 @@ int main()
return self.try_compile(body, headers, include_dirs)
+ def check_type_size(self, type_name, headers=None, include_dirs=None, library_dirs=None):
+ """Check size of a given type."""
+ # XXX: should also implement the cross-compiling version (using binary
+ # search + array indexing, see AC_CHECK_SIZEOF).
+ self._check_compiler()
+
+ # We declare the functions to avoid warnings with -Wstrict-prototypes
+ body = r"""
+typedef %(type)s _dist_type_sizeof_;
+
+static long int longval (void)
+{
+ return (long int) (sizeof (_dist_type_sizeof_));
+}
+static unsigned long int ulongval (void)
+{
+ return (long int) (sizeof (_dist_type_sizeof_));
+}
+
+#include <stdio.h>
+#include <stdlib.h>
+int
+main (void)
+{
+
+ if (((long int) (sizeof (_dist_type_sizeof_))) < 0) {
+ long int i = longval ();
+ if (i != ((long int) (sizeof (_dist_type_sizeof_))))
+ return 1;
+ printf("%%ld\n", i);
+ } else {
+ unsigned long int i = ulongval ();
+ if (i != ((long int) (sizeof (_dist_type_sizeof_))))
+ return 1;
+ printf("%%lu\n", i);
+ }
+
+ return 0;
+}
+""" % {'type': type_name}
+
+ # XXX: this should be refactored (same code as get_output)
+ exitcode, output = 255, ''
+ size = None
+ try:
+ src, obj, exe = self._link(body, headers, include_dirs,
+ [], library_dirs, 'c')
+ #exe = os.path.join('.', exe)
+ exitstatus, output = exec_command(exe, execute_in='.')
+ if hasattr(os, 'WEXITSTATUS'):
+ exitcode = os.WEXITSTATUS(exitstatus)
+ if os.WIFSIGNALED(exitstatus):
+ sig = os.WTERMSIG(exitstatus)
+ log.error('subprocess exited with signal %d' % (sig,))
+ if sig == signal.SIGINT:
+ # control-C
+ raise KeyboardInterrupt
+ else:
+ exitcode = exitstatus
+ log.info("success!")
+
+ try:
+ size = int(output)
+ except ValueError:
+ log.error("Unexpected output %s" % output)
+ log.info("failure")
+ except (CompileError, LinkError):
+ log.info("failure.")
+
+ self._clean()
+ if size is not None:
+ return size
+ else:
+ return -1
+
def check_func(self, func,
headers=None, include_dirs=None,
libraries=None, library_dirs=None,