[Numpy-svn] r4227 - in branches/numpy.scons/numpy/core: . include/numpy

numpy-svn@scip... numpy-svn@scip...
Thu Oct 18 02:13:24 CDT 2007


Author: cdavid
Date: 2007-10-18 02:13:12 -0500 (Thu, 18 Oct 2007)
New Revision: 4227

Added:
   branches/numpy.scons/numpy/core/include/numpy/numpyconfig.h.in
Modified:
   branches/numpy.scons/numpy/core/SConstruct
   branches/numpy.scons/numpy/core/setupscons.py
Log:
Modify scons configuration to be compatible with cleanconfig changes

Modified: branches/numpy.scons/numpy/core/SConstruct
===================================================================
--- branches/numpy.scons/numpy/core/SConstruct	2007-10-18 07:11:10 UTC (rev 4226)
+++ branches/numpy.scons/numpy/core/SConstruct	2007-10-18 07:13:12 UTC (rev 4227)
@@ -1,4 +1,4 @@
-# Last Change: Thu Oct 18 02:00 PM 2007 J
+# Last Change: Thu Oct 18 03:00 PM 2007 J
 # vim:syntax=python
 import os
 from os.path import join as pjoin, basename as pbasename, dirname as pdirname
@@ -20,50 +20,46 @@
         if value == 1:
             return "#define %s\n\n" % define
         elif value == 0:
-            return "#undef %s\n\n" % define
+            return r"/* #undef %s */\n\n" % define
         elif SCons.Util.is_String(value):
             return "#define %s %s\n\n" % (define, value)
     t.writelines([write_symbol(i[0], i[1]) for i in sym])
     t.write('\n')
     t.close()
 
+    print 'File: %s' % target[0]
+    target_f = open(str(target[0]))
+    print target_f.read()
+    target_f.close()
+    print 'EOF'
     return 0
 
-# Convention: list of tuples (definition, value). value:
-# - 0: #undef definition
-# - 1: #define definition
-# - string: #define definition value
-config_sym = []
-
-env = GetNumpyEnvironment(ARGUMENTS)
-
-#--------------------------------
-# Checking SMP and thread options
-#--------------------------------
-# Python 2.3 causes a segfault when
-#  trying to re-acquire the thread-state
-#  which is done in error-handling
-#  ufunc code.  NPY_ALLOW_C_API and friends
-#  cause the segfault. So, we disable threading
-#  for now.
-if sys.version[:5] < '2.4.2':
-    nosmp = 1
-else:
-    # Perhaps a fancier check is in order here.
-    #  so that threads are only enabled if there
-    #  are actually multiple CPUS? -- but
-    #  threaded code can be nice even on a single
-    #  CPU so that long-calculating code doesn't
-    #  block.
-    try:
-        nosmp = os.environ['NPY_NOSMP']
+def define_no_smp():
+    """Returns True if we should define NPY_NOSMP, False otherwise."""
+    #--------------------------------
+    # Checking SMP and thread options
+    #--------------------------------
+    # Python 2.3 causes a segfault when
+    #  trying to re-acquire the thread-state
+    #  which is done in error-handling
+    #  ufunc code.  NPY_ALLOW_C_API and friends
+    #  cause the segfault. So, we disable threading
+    #  for now.
+    if sys.version[:5] < '2.4.2':
         nosmp = 1
-    except KeyError:
-        nosmp = 0
-if nosmp:
-    config_sym.append(('NPY_NOSMP', '0'))
-else:
-    config_sym.append(('NPY_NOSMP', '1'))
+    else:
+        # Perhaps a fancier check is in order here.
+        #  so that threads are only enabled if there
+        #  are actually multiple CPUS? -- but
+        #  threaded code can be nice even on a single
+        #  CPU so that long-calculating code doesn't
+        #  block.
+        try:
+            nosmp = os.environ['NPY_NOSMP']
+            nosmp = 1
+        except KeyError:
+            nosmp = 0
+    return nosmp == 1
 
 def CheckBrokenMathlib(context, mathlib):
     src = """
@@ -93,11 +89,20 @@
         context.Result(' broken !')
     return st[0]
 
+env = GetNumpyEnvironment(ARGUMENTS)
 env.Append(CPPPATH = [get_python_inc()])
+
+#=======================
+# Starting Configuration
+#=======================
 config = env.NumpyConfigure(custom_tests = {'CheckTypeSize' : CheckTypeSize,
     'CheckBrokenMathlib' : CheckBrokenMathlib})
 
-# TODO: check python extension can be built (in root or here ?)
+# Convention: list of tuples (definition, value). value:
+# - 0: #undef definition
+# - 1: #define definition
+# - string: #define definition value
+config_sym = []
 
 #---------------
 # Checking Types
@@ -111,13 +116,15 @@
         config_sym.append(('SIZEOF_%s' % type.upper(), 0))
 check_type('short')
 check_type('int')
-#check_type('long')
+check_type('long')
 check_type('float')
 check_type('double')
 check_type('long double')
 check_type('Py_intptr_t', include = ["Python.h"])
 check_type('PY_LONG_LONG', include = ["Python.h"])
 
+# TODO: check python extension can be built (in root or here ?)
+
 #-----------------------
 # Checking configuration
 #-----------------------
@@ -177,6 +184,11 @@
     if config.CheckFunc('strtod'):
         config_sym.append('PyOS_ascii_strtod', 'strtod')
 
+if define_no_smp():
+    config_sym.append(('NPY_NOSMP', '1'))
+else:
+    config_sym.append(('NPY_NOSMP', '0'))
+
 #--------------
 # Checking Blas
 #--------------
@@ -184,6 +196,19 @@
 
 config.Finish()
 
+#---------------------------------------
+# Generate the public configuration file
+#---------------------------------------
+config_dict = {}
+# XXX: this is ugly, make the API for config.h and numpyconfig.h similar
+for key, value in config_sym:
+    config_dict['@%s@' % key] = str(value)
+env['SUBST_DICT'] = config_dict
+
+include_dir = 'include/numpy'
+env.SubstInFile(pjoin(env['build_dir'], 'numpyconfig.h'), 
+                pjoin(env['src_dir'], include_dir, 'numpyconfig.h.in'))
+
 #---------------------------
 # Builder for generated code
 #---------------------------
@@ -273,7 +298,7 @@
     pjoin(env['src_dir'], 'code_generators', 'ufunc_api_order.txt'))
 
 # XXX
-#env.Append(CCFLAGS = "-Wall -O2")
+env.Append(CCFLAGS = "-Wall -fno-strict-aliasing")
 
 #-----------------
 # Build multiarray

Added: branches/numpy.scons/numpy/core/include/numpy/numpyconfig.h.in
===================================================================
--- branches/numpy.scons/numpy/core/include/numpy/numpyconfig.h.in	2007-10-18 07:11:10 UTC (rev 4226)
+++ branches/numpy.scons/numpy/core/include/numpy/numpyconfig.h.in	2007-10-18 07:13:12 UTC (rev 4227)
@@ -0,0 +1,21 @@
+#define NPY_SIZEOF_SHORT        @SIZEOF_SHORT@
+#define NPY_SIZEOF_INT          @SIZEOF_INT@
+#define NPY_SIZEOF_LONG         @SIZEOF_LONG@
+#define NPY_SIZEOF_FLOAT        @SIZEOF_FLOAT@
+#define NPY_SIZEOF_DOUBLE       @SIZEOF_DOUBLE@
+#define NPY_SIZEOF_LONGDOUBLE   @SIZEOF_LONG_DOUBLE@
+#define NPY_SIZEOF_PY_INTPTR_T  @SIZEOF_PY_INTPTR_T@
+
+#define NPY_NOSMP        @NPY_NOSMP@
+
+/* Conditionally define them */
+/* XXX: this has to be done outside config files !!!! */
+#ifdef PY_LONG_LONG
+        #define NPY_SIZEOF_LONGLONG @SIZEOF_PY_LONG_LONG@
+        #define NPY_SIZEOF_PY_LONG_LONG @SIZEOF_PY_LONG_LONG@
+#endif
+
+#ifndef CHAR_BIT
+        #error Configuration for undefined CHAR_BIT is not supported, contact the maintainter
+        #define CHAR_BIT      @CHAR_BIT@
+#endif

Modified: branches/numpy.scons/numpy/core/setupscons.py
===================================================================
--- branches/numpy.scons/numpy/core/setupscons.py	2007-10-18 07:11:10 UTC (rev 4226)
+++ branches/numpy.scons/numpy/core/setupscons.py	2007-10-18 07:13:12 UTC (rev 4227)
@@ -24,6 +24,17 @@
         incl_dir = os.path.dirname(target)
         if incl_dir not in config.numpy_include_dirs:
             config.numpy_include_dirs.append(incl_dir)
+        #config.add_data_files((header_dir, target)) 
+
+    def add_numpyconfig_header():
+        scons_build_dir = config.get_scons_build_dir()
+        # XXX: I really have to think about how to communicate path info
+        # between scons and distutils, and set the options at one single
+        # location.
+        target = join(scons_build_dir, local_dir, 'numpyconfig.h')
+        incl_dir = os.path.dirname(target)
+        if incl_dir not in config.numpy_include_dirs:
+            config.numpy_include_dirs.append(incl_dir)
         config.add_data_files((header_dir, target)) 
 
     def add_array_api():
@@ -48,6 +59,7 @@
 
     def add_generated_files():
         add_config_header()
+        add_numpyconfig_header()
         add_array_api()
         add_ufunc_api()
 



More information about the Numpy-svn mailing list