[Numpy-svn] r4258 - in branches/numpy.scons/numpy: core distutils/scons distutils/scons-local/scons-local-0.97.0d20070918/SCons

numpy-svn@scip... numpy-svn@scip...
Fri Oct 19 05:44:52 CDT 2007


Author: cdavid
Date: 2007-10-19 05:44:43 -0500 (Fri, 19 Oct 2007)
New Revision: 4258

Modified:
   branches/numpy.scons/numpy/core/SConstruct
   branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/Conftest.py
   branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/SConf.py
   branches/numpy.scons/numpy/distutils/scons/__init__.py
   branches/numpy.scons/numpy/distutils/scons/custom_checkers.py
Log:

* Improve the Type checker, and put it in scons-local
* Use it instead of previous custom checker (more robust on solaris)



Modified: branches/numpy.scons/numpy/core/SConstruct
===================================================================
--- branches/numpy.scons/numpy/core/SConstruct	2007-10-19 10:14:54 UTC (rev 4257)
+++ branches/numpy.scons/numpy/core/SConstruct	2007-10-19 10:44:43 UTC (rev 4258)
@@ -6,7 +6,7 @@
 from copy import deepcopy
 
 from numpy.distutils.scons import get_python_inc
-from numpy.distutils.scons import GetNumpyEnvironment, CheckTypeSize
+from numpy.distutils.scons import GetNumpyEnvironment
 
 from scons_support import CheckBrokenMathlib, define_no_smp, \
     generate_config_header, generate_config_header_emitter
@@ -17,8 +17,7 @@
 #=======================
 # Starting Configuration
 #=======================
-config = env.NumpyConfigure(custom_tests = {'CheckTypeSize' : CheckTypeSize,
-    'CheckBrokenMathlib' : CheckBrokenMathlib})
+config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib})
 
 # Convention: list of tuples (definition, value). value:
 # - 0: #undef definition
@@ -42,8 +41,8 @@
 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"])
+check_type('Py_intptr_t', include = r"#include <Python.h>\n")
+check_type('PY_LONG_LONG', include = r"#include <Python.h>\n")
 
 # TODO: check python extension can be built (in root or here ?)
 
@@ -123,8 +122,8 @@
 
 try:
     config_file = open('config.log')
-    for i in  config_file.readlines():
-        print i
+    #for i in  config_file.readlines():
+    #    print i
 except:
     pass
 #==========

Modified: branches/numpy.scons/numpy/distutils/scons/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-10-19 10:14:54 UTC (rev 4257)
+++ branches/numpy.scons/numpy/distutils/scons/__init__.py	2007-10-19 10:44:43 UTC (rev 4258)
@@ -1,5 +1,5 @@
 from numpyenv import GetNumpyEnvironment, GetNumpyOptions
 from libinfo_scons import NumpyCheckLib
 from libinfo import get_paths as scons_get_paths
-from custom_checkers import CheckTypeSize
+#from custom_checkers import CheckTypeSize
 from extension import get_python_inc

Modified: branches/numpy.scons/numpy/distutils/scons/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/custom_checkers.py	2007-10-19 10:14:54 UTC (rev 4257)
+++ branches/numpy.scons/numpy/distutils/scons/custom_checkers.py	2007-10-19 10:44:43 UTC (rev 4258)
@@ -1,102 +0,0 @@
-# Sensible default for common types on common platforms.
-_DEFAULTS = {
-   'short' : [2,],
-   'int' : [4, 2],
-   'long' : [4, 8],
-   'long long' : [8, 4],
-   # Normally, there is no need to check unsigned types, because they are
-   # guaranteed to be of the same size than their signed counterpart.
-   'unsigned short' : [2,],
-   'unsigned int' : [4, 2],
-   'unsigned long' : [4, 8],
-   'unsigned long long' : [8, 4],
-   'float' : [4,],
-   'double' : [8,],
-   'long double' : [12,],
-   'size_t' : [4,],
-}
-
-def CheckTypeSize(context, type, includes = None, language = 'C', size = None):
-   """This check can be used to get the size of a given type, or to check whether
-   the type is of expected size.
-
-   Arguments:
-       - type : str
-           the type to check
-       - includes : sequence
-           list of headers to include in the test code before testing the type
-       - language : str
-           'C' or 'C++'
-       - size : int
-           if given, will test wether the type has the given number of bytes.
-           If not given, will test against a list of sizes (all sizes between
-           0 and 16 bytes are tested).
-
-       Returns:
-           status : int
-               0 if the check failed, or the found size of the type if
-               the check succeeded."""
-   minsz = 0
-   maxsz = 16
-
-   if includes:
-       src = "\n".join([r"#include <%s>\n" % i for i in includes])
-   else:
-       src = ""
-
-   if language == 'C':
-       ext = '.c'
-   elif language == 'C++':
-       ext = '.cpp'
-   else:
-       raise NotImplementedError("%s is not a recognized language" % language)
-
-   # test code taken from autoconf: this is a pretty clever hack to find that
-   # a type is of a given size using only compilation. This speeds things up
-   # quite a bit compared to straightforward code using TryRun
-   src += r"""
-typedef %s scons_check_type;
-
-int main()
-{
-   static int test_array[1 - 2 * !(((long int) (sizeof(scons_check_type))) <= %d)];
-   test_array[0] = 0;
-
-   return 0;
-}
-"""
-
-   if size:
-       # Only check if the given size is the right one
-       context.Message('Checking %s is %d bytes... ' % (type, size))
-       st = context.TryCompile(src % (type, size), ext)
-       context.Result(st)
-
-       if st:
-           return size
-       else:
-           return 0
-   else:
-       # Check against a list of sizes.
-       context.Message('Checking size of %s ... ' % type)
-
-       # Try sensible defaults first
-       try:
-           szrange = _DEFAULTS[type]
-       except KeyError:
-           szrange = []
-       szrange.extend(xrange(minsz, maxsz))
-       st = 0
-
-       # Actual test
-       for sz in szrange:
-           st = context.TryCompile(src % (type, sz), ext)
-           if st:
-               break
-
-       if st:
-           context.Result('%d' % sz)
-           return sz
-       else:
-           context.Result('Failed !')
-           return 0

Modified: branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/Conftest.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/Conftest.py	2007-10-19 10:14:54 UTC (rev 4257)
+++ branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/Conftest.py	2007-10-19 10:44:43 UTC (rev 4258)
@@ -422,6 +422,102 @@
 
     return ret
 
+def CheckTypeSize(context, type_name, header = None, language = None, expect = None):
+    """This check can be used to get the size of a given type, or to check whether
+    the type is of expected size.
+
+    Arguments:
+        - type : str
+            the type to check
+        - includes : sequence
+            list of headers to include in the test code before testing the type
+        - language : str
+            'C' or 'C++'
+        - expect : int
+            if given, will test wether the type has the given number of bytes.
+            If not given, will automatically find the size.
+
+        Returns:
+            status : int
+                0 if the check failed, or the found size of the type if the check succeeded."""
+    
+    # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+    if context.headerfilename:
+        includetext = '#include "%s"' % context.headerfilename
+    else:
+        includetext = ''
+
+    if not header:
+        header = ""
+
+    lang, suffix, msg = _lang2suffix(language)
+    if msg:
+        context.Display("Cannot check for %s type: %s\n" % (type_name, msg))
+        return msg
+
+    src = includetext + header 
+    if not expect is None:
+        # Only check if the given size is the right one
+        context.Display('Checking %s is %d bytes... ' % (type_name, expect))
+
+        # test code taken from autoconf: this is a pretty clever hack to find that
+        # a type is of a given size using only compilation. This speeds things up
+        # quite a bit compared to straightforward code using TryRun
+        src += r"""
+typedef %s scons_check_type;
+
+int main()
+{
+    static int test_array[1 - 2 * !(((long int) (sizeof(scons_check_type))) == %d)];
+    test_array[0] = 0;
+
+    return 0;
+}
+"""
+
+        # XXX: Try* vs CompileProg ?
+        st = context.TryCompile(src % (type_name, expect), suffix)
+        if st:
+            _Have(context, "SIZEOF_" + type_name, str(expect))
+            context.Display("yes\n")
+            return expect
+        else:
+            context.Display("no\n")
+            _LogFailed(context, src, st)
+            return 0
+    else:
+        # Only check if the given size is the right one
+        context.Message('Checking size of %s ... ' % type_name)
+
+        # We have to be careful with the program we wish to test here since
+        # compilation will be attempted using the current environment's flags.
+        # So make sure that the program will compile without any warning. For
+        # example using: 'int main(int argc, char** argv)' will fail with the
+        # '-Wall -Werror' flags since the variables argc and argv would not be
+        # used in the program...
+        #
+        src += """
+#include <stdlib.h>
+#include <stdio.h>
+int main() {
+    printf("%d", (int)sizeof(""" + type_name + """));
+    return 0;
+}
+    """
+        ret = context.TryRun(src, suffix)
+        st = ret[0]
+        try:
+            size = int(ret[1])
+            _Have(context, "SIZEOF_" + type_name, str(size))
+            context.Display("%d\n" % size)
+        except ValueError:
+            size = 0
+            _LogFailed(context, src, st)
+            context.Display(" Failed !\n")
+        if st:
+            return size
+        else:
+            return 0
 #
 # END OF PUBLIC FUNCTIONS
 #

Modified: branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/SConf.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/SConf.py	2007-10-19 10:14:54 UTC (rev 4257)
+++ branches/numpy.scons/numpy/distutils/scons-local/scons-local-0.97.0d20070918/SCons/SConf.py	2007-10-19 10:44:43 UTC (rev 4258)
@@ -395,6 +395,7 @@
         default_tests = {
                  'CheckFunc'          : CheckFunc,
                  'CheckType'          : CheckType,
+                 'CheckTypeSize'      : CheckTypeSize,
                  'CheckHeader'        : CheckHeader,
                  'CheckCHeader'       : CheckCHeader,
                  'CheckCXXHeader'     : CheckCXXHeader,
@@ -826,6 +827,13 @@
     context.did_show_result = 1
     return not res
 
+def CheckTypeSize(context, type_name, includes = "", language = None, expect = None):
+    res = SCons.Conftest.CheckTypeSize(context, type_name,
+                                       header = includes, language = language, 
+                                       expect = expect)
+    context.did_show_result = 1
+    return res
+
 def createIncludesFromHeaders(headers, leaveLast, include_quotes = '""'):
     # used by CheckHeader and CheckLibWithHeader to produce C - #include
     # statements from the specified header (list)



More information about the Numpy-svn mailing list