summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Jones <eric@enthought.com>2002-09-19 07:08:30 +0000
committerEric Jones <eric@enthought.com>2002-09-19 07:08:30 +0000
commit200bff5384ca06d4d61570a576f94ff63b6c335d (patch)
tree780842aff1bceab242543194ef9bbb6b0044b5c8
parent9dec5004a2593a123fb80eefcb5d73a229cb7501 (diff)
downloadnumpy-200bff5384ca06d4d61570a576f94ff63b6c335d.tar.gz
added yet another directory into the path of intermediate files generated by
weave. This is needed so that people switching between compilers don't end up trying to link c++ object files built with incompatible compilers together. changed Py_INCREF to a Py_XINCREF to guard against NULL pointer problems in convert_to_xxx routines. lengthened the type_names strings for Numeric type names in standard_array_spec. It was shorter than some of the names. yikes! choose_compiler stuff is no longer done by ext_modules. This was used to allow xxx_convterters and xxx_info objects to generate different code depending on which compiler was used. This is no longer done, and I don't think it should be necessary going forward. I've left a little of the code in case I'm wrong, but will probably hack it out soon.
-rw-r--r--weave/blitz-20001213/blitz/config.h2
-rw-r--r--weave/blitz_spec.py7
-rw-r--r--weave/build_tools.py38
-rw-r--r--weave/c_spec.py5
-rw-r--r--weave/common_info.py2
-rw-r--r--weave/ext_tools.py26
-rw-r--r--weave/standard_array_spec.py2
7 files changed, 65 insertions, 17 deletions
diff --git a/weave/blitz-20001213/blitz/config.h b/weave/blitz-20001213/blitz/config.h
index 125219035..6527e9d1a 100644
--- a/weave/blitz-20001213/blitz/config.h
+++ b/weave/blitz-20001213/blitz/config.h
@@ -52,7 +52,7 @@
#define BZ_ENUM_COMPUTATIONS_WITH_CAST
#define BZ_HAVE_COMPLEX
-#ifdef __GNUC__ && __GNUC__==3
+#if (__GNUC__ && __GNUC__ == 3)
#define BZ_HAVE_NUMERIC_LIMITS
#else
#undef BZ_HAVE_NUMERIC_LIMITS
diff --git a/weave/blitz_spec.py b/weave/blitz_spec.py
index e0200f9eb..7527bcbf4 100644
--- a/weave/blitz_spec.py
+++ b/weave/blitz_spec.py
@@ -89,7 +89,12 @@ class array_converter(standard_array_spec.array_converter):
self.headers.extend(blitz_headers)
self.include_dirs = [blitz_dir]
self.support_code.append(blitz_support_code)
- self.type_name = 'blitz'
+
+ # type_name is used to setup the initial type conversion. Even
+ # for blitz conversion, the first step is to convert it to a
+ # standard numpy array.
+ #self.type_name = 'blitz'
+ self.type_name = 'numpy'
def info_object(self):
return array_info()
diff --git a/weave/build_tools.py b/weave/build_tools.py
index 1e931dd96..23385fa6f 100644
--- a/weave/build_tools.py
+++ b/weave/build_tools.py
@@ -24,6 +24,7 @@ import exceptions
# If linker is 'gcc', this will convert it to 'g++'
# necessary to make sure stdc++ is linked in cross-platform way.
import distutils.sysconfig
+import distutils.dir_util
old_init_posix = distutils.sysconfig._init_posix
@@ -146,12 +147,22 @@ def build_extension(module_path,compiler_name = '',build_dir = None,
# get the name of the module and the extension directory it lives in.
module_dir,cpp_name = os.path.split(os.path.abspath(module_path))
module_name,ext = os.path.splitext(cpp_name)
-
+
# configure temp and build directories
temp_dir = configure_temp_dir(temp_dir)
build_dir = configure_build_dir(module_dir)
+ # dag. We keep having to add directories to the path to keep
+ # object files separated from each other. gcc2.x and gcc3.x C++
+ # object files are not compatible, so we'll stick them in a sub
+ # dir based on their version. This will add gccX.X to the
+ # path.
+ compiler_dir = get_compiler_dir(compiler_name)
+ temp_dir = os.path.join(temp_dir,compiler_dir)
+ distutils.dir_util.mkpath(temp_dir)
+
compiler_name = choose_compiler(compiler_name)
+
configure_sys_argv(compiler_name,temp_dir,build_dir)
# the business end of the function
@@ -298,6 +309,29 @@ def msvc_exists():
result = 1
return result
+if os.name == 'nt':
+ def run_command(command):
+ """ not sure how to get exit status on nt. """
+ in_pipe,out_pipe = os.popen4(command)
+ in_pipe.close()
+ text = out_pipe.read()
+ return 0, text
+else:
+ run_command = commands.getstatusoutput
+
+def get_compiler_dir(compiler_name):
+ if compiler_name == 'gcc':
+ status, text = run_command(compiler_name + ' --version')
+ try:
+ import re
+ version = re.findall('\d\.\d',text)[0]
+ except IndexError:
+ version = ''
+ compiler_dir = compiler_name + version
+ else:
+ compiler_dir = compiler_name
+ return compiler_dir
+
def configure_temp_dir(temp_dir=None):
if temp_dir is None:
temp_dir = tempfile.gettempdir()
@@ -418,7 +452,7 @@ if sys.platform == 'win32':
def build_import_library():
""" Build the import libraries for Mingw32-gcc on Windows
"""
- import scipy_distutils import lib2def
+ from scipy_distutils import lib2def
#libfile, deffile = parse_cmd()
#if deffile is None:
# deffile = sys.stdout
diff --git a/weave/c_spec.py b/weave/c_spec.py
index eec1d6d27..ecb1d24df 100644
--- a/weave/c_spec.py
+++ b/weave/c_spec.py
@@ -135,7 +135,7 @@ class common_base_converter(base_converter):
code = 'convert_to_%(type_name)s(%(py_var)s,"%(name)s")' % d
d['var_convert'] = code
if self.use_ref_count:
- d['inc_ref_count'] = "Py_INCREF(py_obj);"
+ d['inc_ref_count'] = "Py_XINCREF(py_obj);"
else:
d['inc_ref_count'] = ""
return d
@@ -154,7 +154,8 @@ class common_base_converter(base_converter):
def cleanup_code(self):
if self.use_ref_count:
- code = "Py_XDECREF(%(py_var)s);\n" % self.template_vars()
+ code = 'Py_XDECREF(%(py_var)s);\n' % self.template_vars()
+ #code += 'printf("cleaning up %(py_var)s\\n");\n' % self.template_vars()
else:
code = ""
return code
diff --git a/weave/common_info.py b/weave/common_info.py
index 8b792087f..67be8d61a 100644
--- a/weave/common_info.py
+++ b/weave/common_info.py
@@ -32,7 +32,9 @@ char* find_type(PyObject* py_obj)
void throw_error(PyObject* exc, const char* msg)
{
+ //printf("setting python error: %s\\n",msg);
PyErr_SetString(exc, msg);
+ //printf("throwing error\\n");
throw 1;
}
diff --git a/weave/ext_tools.py b/weave/ext_tools.py
index 326e7238d..11f9777a4 100644
--- a/weave/ext_tools.py
+++ b/weave/ext_tools.py
@@ -134,13 +134,13 @@ class ext_function_from_specs:
return_code = " /*cleanup code*/ \n" + \
cleanup_code + \
- " if(!return_val && !exception_occured)\n" \
- " {\n \n" \
- " Py_INCREF(Py_None); \n" \
- " return_val = Py_None; \n" \
- " }\n \n" \
- " return return_val; \n" \
- "} \n"
+ ' if(!return_val && !exception_occured)\n' \
+ ' {\n \n' \
+ ' Py_INCREF(Py_None); \n' \
+ ' return_val = Py_None; \n' \
+ ' }\n \n' \
+ ' return return_val; \n' \
+ '} \n'
all_code = self.function_declaration_code() + \
indent(self.parse_tuple_code(),4) + \
@@ -276,6 +276,7 @@ class ext_module:
return generate_module(code,name)
def set_compiler(self,compiler):
+ # This is not used anymore -- I think we should ditch it.
#for i in self.arg_specs()
# i.set_compiler(compiler)
for i in self.build_information():
@@ -288,10 +289,14 @@ class ext_module:
if compiler is not None:
self.compiler = compiler
+
+ # !! removed -- we don't have any compiler dependent code
+ # currently in spec or info classes
# hmm. Is there a cleaner way to do this? Seems like
- # choosing the compiler spagettis around a little.
- compiler = build_tools.choose_compiler(self.compiler)
- self.set_compiler(compiler)
+ # choosing the compiler spagettis around a little.
+ #compiler = build_tools.choose_compiler(self.compiler)
+ #self.set_compiler(compiler)
+
arg_specs = self.arg_specs()
info = self.build_information()
_source_files = info.sources()
@@ -316,6 +321,7 @@ class ext_module:
#temp = catalog.default_temp_dir()
# for speed, build in the machines temp directory
temp = catalog.intermediate_dir()
+
success = build_tools.build_extension(file, temp_dir = temp,
sources = source_files,
compiler_name = compiler,
diff --git a/weave/standard_array_spec.py b/weave/standard_array_spec.py
index c8c8e61dc..9c32bafda 100644
--- a/weave/standard_array_spec.py
+++ b/weave/standard_array_spec.py
@@ -34,7 +34,7 @@ public:
!(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&
!(numeric_type == PyArray_LONG && arr_type == PyArray_INT))
{
- char* type_names[13] = {"char","unsigned byte","byte", "short", "int",
+ char* type_names[20] = {"char","unsigned byte","byte", "short", "int",
"long", "float", "double", "complex float",
"complex double", "object","ntype","unkown"};
char msg[500];