[Numpy-svn] r4189 - in branches/numpy.scons: . numpy/core numpy/distutils/scons
numpy-svn at scipy.org
numpy-svn at scipy.org
Sun Oct 14 12:14:47 EDT 2007
Author: cdavid
Date: 2007-10-14 11:14:28 -0500 (Sun, 14 Oct 2007)
New Revision: 4189
Modified:
branches/numpy.scons/
branches/numpy.scons/numpy/core/SConstruct
branches/numpy.scons/numpy/distutils/scons/__init__.py
branches/numpy.scons/numpy/distutils/scons/custom_checkers.py
Log:
* (scons) Better checker to get size of types
Property changes on: branches/numpy.scons
___________________________________________________________________
Name: bzr:revision-info
- timestamp: 2007-10-14 15:49:00.111000061 +0900
committer: david <david at david-laptop>
properties:
branch-nick: numpy.scons
+ timestamp: 2007-10-14 21:44:01.213000059 +0900
committer: david <david at david-laptop>
properties:
branch-nick: numpy.scons
Name: bzr:file-ids
-
+ numpy/core/config.h.in config.h.in-20071014064907-muiokkgfs5im6243-1
Name: bzr:revision-id:v3-trunk0
- 3737 david at david-laptop-20070920080908-n8pj8vmszdir3zoa
3738 david at david-laptop-20070920081509-58kkojgmml3t7jxs
3739 david at david-laptop-20070920081910-phlk1ujthksgpm0z
3740 david at david-laptop-20070920082641-bdhrt6eafeoli50i
3741 david at ar.media.kyoto-u.ac.jp-20070920130730-satdeppbh1k0bq2p
3743 david at ar.media.kyoto-u.ac.jp-20070921073742-vpv8pwv0j8fbd93m
3744 david at david-laptop-20070922101656-61kfi2faucemr2rl
3745 david at david-laptop-20070922113708-ror18thshang1cpu
3747 david at david-laptop-20070922140534-n9xsl096tjrzmct1
3749 david at david-laptop-20070922154007-usit009fr6vp377j
3750 david at david-laptop-20070923070011-leu2ozc2fy1q5cht
3751 david at david-laptop-20070924015925-dhsiao40jp7zsfp9
3752 david at ar.media.kyoto-u.ac.jp-20070924070657-nbw23j0ayan30cli
3753 david at ar.media.kyoto-u.ac.jp-20070924082918-i1lc1zikywi8czj4
3754 david at ar.media.kyoto-u.ac.jp-20070924083008-c0edtt8zs31yeh1q
3755 david at ar.media.kyoto-u.ac.jp-20070924112351-pnnho638cohz6lj1
3756 david at david-laptop-20070924153247-yftud00bynilxv69
3757 david at david-laptop-20070924163545-pish34x9fq2h66aj
3758 david at david-laptop-20070924164633-iiyygcaw81ji3n34
3759 david at david-laptop-20070924170201-y14v2yzikdpvamfp
3760 david at david-laptop-20070924171208-5bmitorzf49d1aa2
3761 david at david-laptop-20070925014444-ns9v90gotnxt39mq
3769 david at david-laptop-20070925145952-4osi81tvch7v6luj
3773 david at ar.media.kyoto-u.ac.jp-20070926073429-2kdc6yf1o210aer0
3774 david at ar.media.kyoto-u.ac.jp-20070926084356-938djoytjap90rmo
3775 david at ar.media.kyoto-u.ac.jp-20070926085329-3gquq3gu2k8rgzb0
3776 david at ar.media.kyoto-u.ac.jp-20071009084906-9kradhwpu7su633x
3777 david at ar.media.kyoto-u.ac.jp-20071009093339-q5nf5me6ikdi48k6
3778 david at david-laptop-20071009152108-xh5cltii0h6zjk9b
3779 david at david-laptop-20071009154954-v5se05gbq60opo1z
3780 david at david-laptop-20071009223102-vz2sgf5i6pncxsd8
3781 david at david-laptop-20071009225259-13m6enwqk4w9uihe
3782 david at ar.media.kyoto-u.ac.jp-20071010021710-liz2jvw0ggbxrtgi
3783 david at ar.media.kyoto-u.ac.jp-20071010032218-8qzxvdmith85a056
3784 david at ar.media.kyoto-u.ac.jp-20071010032323-lgbxfd788h402kn0
3792 david at ar.media.kyoto-u.ac.jp-20071011033223-s14976refgeaw00h
3793 david at ar.media.kyoto-u.ac.jp-20071011033241-rrzlo2vu6w0tkdwf
3794 david at ar.media.kyoto-u.ac.jp-20071011071251-c5pxigyynpck262d
3795 david at ar.media.kyoto-u.ac.jp-20071012040323-8ka0mgkx1t8r9fcl
3796 david at ar.media.kyoto-u.ac.jp-20071012042801-44pmvc5o1u6p6wi7
3797 david at ar.media.kyoto-u.ac.jp-20071012071207-nfpsuyfoq0ooy7xf
3798 david at ar.media.kyoto-u.ac.jp-20071012073426-8o9tejzovgk7qzi4
3799 david at ar.media.kyoto-u.ac.jp-20071012074103-1fzviuk1sunv0b9n
3800 david at ar.media.kyoto-u.ac.jp-20071012074129-t5nu6f96wie8fd1y
3801 david at ar.media.kyoto-u.ac.jp-20071012100715-sq8hhctu5tynlx4m
3802 david at david-laptop-20071013043839-hc3yfsbn0t7gsuhe
3803 david at david-laptop-20071013123319-vf4b7yhadz9nxasc
3804 david at david-laptop-20071014063148-0bsktlh609c3rpv7
3805 david at david-laptop-20071014064841-liamaqiv3af71r3g
3806 david at david-laptop-20071014064900-j4yzxzuveukuyj2l
+ 3737 david at david-laptop-20070920080908-n8pj8vmszdir3zoa
3738 david at david-laptop-20070920081509-58kkojgmml3t7jxs
3739 david at david-laptop-20070920081910-phlk1ujthksgpm0z
3740 david at david-laptop-20070920082641-bdhrt6eafeoli50i
3741 david at ar.media.kyoto-u.ac.jp-20070920130730-satdeppbh1k0bq2p
3743 david at ar.media.kyoto-u.ac.jp-20070921073742-vpv8pwv0j8fbd93m
3744 david at david-laptop-20070922101656-61kfi2faucemr2rl
3745 david at david-laptop-20070922113708-ror18thshang1cpu
3747 david at david-laptop-20070922140534-n9xsl096tjrzmct1
3749 david at david-laptop-20070922154007-usit009fr6vp377j
3750 david at david-laptop-20070923070011-leu2ozc2fy1q5cht
3751 david at david-laptop-20070924015925-dhsiao40jp7zsfp9
3752 david at ar.media.kyoto-u.ac.jp-20070924070657-nbw23j0ayan30cli
3753 david at ar.media.kyoto-u.ac.jp-20070924082918-i1lc1zikywi8czj4
3754 david at ar.media.kyoto-u.ac.jp-20070924083008-c0edtt8zs31yeh1q
3755 david at ar.media.kyoto-u.ac.jp-20070924112351-pnnho638cohz6lj1
3756 david at david-laptop-20070924153247-yftud00bynilxv69
3757 david at david-laptop-20070924163545-pish34x9fq2h66aj
3758 david at david-laptop-20070924164633-iiyygcaw81ji3n34
3759 david at david-laptop-20070924170201-y14v2yzikdpvamfp
3760 david at david-laptop-20070924171208-5bmitorzf49d1aa2
3761 david at david-laptop-20070925014444-ns9v90gotnxt39mq
3769 david at david-laptop-20070925145952-4osi81tvch7v6luj
3773 david at ar.media.kyoto-u.ac.jp-20070926073429-2kdc6yf1o210aer0
3774 david at ar.media.kyoto-u.ac.jp-20070926084356-938djoytjap90rmo
3775 david at ar.media.kyoto-u.ac.jp-20070926085329-3gquq3gu2k8rgzb0
3776 david at ar.media.kyoto-u.ac.jp-20071009084906-9kradhwpu7su633x
3777 david at ar.media.kyoto-u.ac.jp-20071009093339-q5nf5me6ikdi48k6
3778 david at david-laptop-20071009152108-xh5cltii0h6zjk9b
3779 david at david-laptop-20071009154954-v5se05gbq60opo1z
3780 david at david-laptop-20071009223102-vz2sgf5i6pncxsd8
3781 david at david-laptop-20071009225259-13m6enwqk4w9uihe
3782 david at ar.media.kyoto-u.ac.jp-20071010021710-liz2jvw0ggbxrtgi
3783 david at ar.media.kyoto-u.ac.jp-20071010032218-8qzxvdmith85a056
3784 david at ar.media.kyoto-u.ac.jp-20071010032323-lgbxfd788h402kn0
3792 david at ar.media.kyoto-u.ac.jp-20071011033223-s14976refgeaw00h
3793 david at ar.media.kyoto-u.ac.jp-20071011033241-rrzlo2vu6w0tkdwf
3794 david at ar.media.kyoto-u.ac.jp-20071011071251-c5pxigyynpck262d
3795 david at ar.media.kyoto-u.ac.jp-20071012040323-8ka0mgkx1t8r9fcl
3796 david at ar.media.kyoto-u.ac.jp-20071012042801-44pmvc5o1u6p6wi7
3797 david at ar.media.kyoto-u.ac.jp-20071012071207-nfpsuyfoq0ooy7xf
3798 david at ar.media.kyoto-u.ac.jp-20071012073426-8o9tejzovgk7qzi4
3799 david at ar.media.kyoto-u.ac.jp-20071012074103-1fzviuk1sunv0b9n
3800 david at ar.media.kyoto-u.ac.jp-20071012074129-t5nu6f96wie8fd1y
3801 david at ar.media.kyoto-u.ac.jp-20071012100715-sq8hhctu5tynlx4m
3802 david at david-laptop-20071013043839-hc3yfsbn0t7gsuhe
3803 david at david-laptop-20071013123319-vf4b7yhadz9nxasc
3804 david at david-laptop-20071014063148-0bsktlh609c3rpv7
3805 david at david-laptop-20071014064841-liamaqiv3af71r3g
3806 david at david-laptop-20071014064900-j4yzxzuveukuyj2l
3807 david at david-laptop-20071014124401-n3a37y67u5imyo83
Modified: branches/numpy.scons/numpy/core/SConstruct
===================================================================
--- branches/numpy.scons/numpy/core/SConstruct 2007-10-14 16:14:10 UTC (rev 4188)
+++ branches/numpy.scons/numpy/core/SConstruct 2007-10-14 16:14:28 UTC (rev 4189)
@@ -5,7 +5,7 @@
import sys
from numpy.distutils.scons import get_python_inc
-from numpy.distutils.scons import GetNumpyEnvironment, CheckSizeof
+from numpy.distutils.scons import GetNumpyEnvironment, CheckTypeSize
import SCons.Util
@@ -19,7 +19,7 @@
if value == 1:
return "#define %s\n\n" % define
elif value == 0:
- return "#under %s\n\n" % define
+ return "#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])
@@ -65,7 +65,7 @@
config_sym.append(('NPY_ALLOW_THREADS', '1'))
env.Append(CPPPATH = [get_python_inc()])
-config = env.NumpyConfigure(custom_tests = {'CheckSizeof' : CheckSizeof})
+config = env.NumpyConfigure(custom_tests = {'CheckTypeSize' : CheckTypeSize})
# TODO: check python extension can be built (in root or here ?)
@@ -75,7 +75,7 @@
def check_type(type, include = None):
# XXX: handle space in type string
# Implement type size info in CheckSizeof
- if config.CheckSizeof(type, include = include):
+ if config.CheckTypeSize(type, includes = include):
config_sym.append(('SIZEOF_%s' % type.upper(), 1))
else:
config_sym.append(('SIZEOF_%s' % type.upper(), 0))
Modified: branches/numpy.scons/numpy/distutils/scons/__init__.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/__init__.py 2007-10-14 16:14:10 UTC (rev 4188)
+++ branches/numpy.scons/numpy/distutils/scons/__init__.py 2007-10-14 16:14:28 UTC (rev 4189)
@@ -1,4 +1,4 @@
from numpyenv import GetNumpyEnvironment, GetNumpyOptions
from libinfo_scons import NumpyCheckLib
-from custom_checkers import CheckSizeof
+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-14 16:14:10 UTC (rev 4188)
+++ branches/numpy.scons/numpy/distutils/scons/custom_checkers.py 2007-10-14 16:14:28 UTC (rev 4189)
@@ -1,59 +1,102 @@
-# size to try first for built-in types
-_PREF_SIZE = {
- 'short' : (2,),
- 'int' : (4,),
- 'long' : (4,8),
- 'long long' : (8,4),
- 'float' : (4,),
- 'double' : (8,),
- 'long double' : (12,),
- 'size_t' : (4,),
- 'Py_intptr_t' : (4,),
+# 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 CheckSizeof(context, type, include = None, language = None):
- """include should be a list of header."""
- if language:
- raise NotImplementedError("language arg not supported yet!")
+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.
- msg = context.Message('Checking size of type %s ... ' % type)
- if include:
- strinc = ["#include <%s>" % s for s in include]
- src = "\n".join(strinc)
- else:
- src = ""
- src += """
-typedef %s check_sizeof;
+ 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(check_sizeof)) <= %d)];
- test_array[0] = 0;
+ static int test_array[1 - 2 * !(((long int) (sizeof(scons_check_type))) <= %d)];
+ test_array[0] = 0;
- return 0;
+ return 0;
}
"""
- st = 0
- # First try sensible default
- if _PREF_SIZE.has_key(type):
- fs = _PREF_SIZE[type]
- for i in fs:
- st = context.TryCompile(src % (type, i), '.c')
- if st:
- break
- # General
- maxsize = 16
- if not st:
- for i in xrange(0, maxsize):
- st = context.TryCompile(src % (type, i), '.c')
- if st:
- break
+ 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:
- context.Result('%d bytes' % i)
- else:
- context.Result('Failed !')
+ if st:
+ return size
+ else:
+ return 0
+ else:
+ # Check against a list of sizes.
+ context.Message('Checking size of %s ... ' % type)
- return st
+ # 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
More information about the Numpy-svn
mailing list