[Numpy-svn] r6377 - branches/coremath/numpy/distutils/command

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Feb 18 12:22:04 EST 2009


Author: cdavid
Date: 2009-02-18 11:21:49 -0600 (Wed, 18 Feb 2009)
New Revision: 6377

Modified:
   branches/coremath/numpy/distutils/command/config.py
Log:
Add check_type_sizeof function.

Modified: branches/coremath/numpy/distutils/command/config.py
===================================================================
--- branches/coremath/numpy/distutils/command/config.py	2009-02-18 17:21:08 UTC (rev 6376)
+++ branches/coremath/numpy/distutils/command/config.py	2009-02-18 17:21:49 UTC (rev 6377)
@@ -11,6 +11,7 @@
 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
@@ -158,6 +159,81 @@
 
         return self.try_compile(body, headers, include_dirs)
 
+    def check_type_size(self, type_name, headers=None, include_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,
+                                       [], [], '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,




More information about the Numpy-svn mailing list