[Numpy-svn] r4214 - branches/cleanconfig/numpy/core

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Oct 17 23:15:49 EDT 2007


Author: cdavid
Date: 2007-10-17 22:15:45 -0500 (Wed, 17 Oct 2007)
New Revision: 4214

Modified:
   branches/cleanconfig/numpy/core/setup.py
Log:
Add a function to generate code for numpyconfig.h, meant to become the public configuration header.

Modified: branches/cleanconfig/numpy/core/setup.py
===================================================================
--- branches/cleanconfig/numpy/core/setup.py	2007-10-18 03:10:24 UTC (rev 4213)
+++ branches/cleanconfig/numpy/core/setup.py	2007-10-18 03:15:45 UTC (rev 4214)
@@ -18,6 +18,11 @@
     ('rint', 'HAVE_RINT'),
     ]
 
+def is_npy_no_signal():
+    """Return True if the NPY_NO_SIGNAL symbol must be defined in configuration
+    header."""
+    return sys.platform == 'win32'
+
 def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration,dot_join
     from numpy.distutils.system_info import get_info, default_lib_dirs
@@ -101,7 +106,7 @@
                 if check_func(func_name):
                     moredefs.append(defsymbol)
 
-            if sys.platform == 'win32':
+            if is_npy_no_signal():
                 moredefs.append('NPY_NO_SIGNAL')
 
             if sys.platform=='win32' or os.name=='nt':
@@ -345,6 +350,62 @@
     testcode = '\n'.join(testcode)
     return testcode
 
+def generate_numpyconfig_code(target):
+    """Return the source code as a string of the code to generate the
+    numpyconfig header file."""
+    # Config symbols to prepend
+    prepends = [('NPY_SIZEOF_SHORT', 'SIZEOF_SHORT'),
+            ('NPY_SIZEOF_INT', 'SIZEOF_INT'),
+            ('NPY_SIZEOF_LONG', 'SIZEOF_LONG'),
+            ('NPY_SIZEOF_FLOAT', 'SIZEOF_FLOAT'),
+            ('NPY_SIZEOF_DOUBLE', 'SIZEOF_DOUBLE'),
+            ('NPY_SIZEOF_LONGDOUBLE', 'SIZEOF_LONG_DOUBLE'),
+            ('NPY_SIZEOF_PY_INTPTR_T', 'SIZEOF_PY_INTPTR_T'),
+            ('NPY_NOSMP', 'NPY_NOSMP'),]
+
+    testcode = ["""
+#include <Python.h>
+#include "config.h"
+
+int main()
+{   
+    FILE* f;
+   
+    f = fopen("%s", "w");
+    if (f == NULL) {
+        return -1;
+    }
+""" % target]
+
+    testcode.append(r"""
+    fprintf(f, "/*\n * This file is generated by %s. DO NOT EDIT \n */\n");
+""" % __file__)
+
+    # Prepend NPY_ to any SIZEOF defines
+    testcode.extend([r'    fprintf(f, "#define ' + i + r' %%d \n", %s);' % j for i, j in prepends])
+
+    # Conditionally define NPY_NO_SIGNAL
+    if is_npy_no_signal():
+        testcode.append(r'    fprintf(f, "\n#define NPY_NO_SIGNAL\n");')
+
+    tmpcode = r"""
+    #ifdef PY_LONG_LONG
+        fprintf(f, "\n#define %s %%d \n", %s);
+        fprintf(f, "#define %s %%d \n", %s);
+    #else
+        fprintf(f, "/* PY_LONG_LONG not defined  */ \n");
+    #endif"""
+    testcode.append(tmpcode % ('NPY_SIZEOF_LONGLONG', 'SIZEOF_LONG_LONG',
+                               'NPY_SIZEOF_PY_LONG_LONG', 'SIZEOF_PY_LONG_LONG'))
+
+    testcode.append("""
+    fclose(f);
+
+    return 0;
+}
+""")
+    return "\n".join(testcode)
+
 if __name__=='__main__':
     from numpy.distutils.core import setup
     setup(configuration=configuration)




More information about the Numpy-svn mailing list