summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/f2py/lib/py_wrap.py10
-rw-r--r--numpy/f2py/lib/py_wrap_type.py15
-rw-r--r--numpy/f2py/lib/test_module_module.py12
3 files changed, 26 insertions, 11 deletions
diff --git a/numpy/f2py/lib/py_wrap.py b/numpy/f2py/lib/py_wrap.py
index e4dc82786..b35e4452c 100644
--- a/numpy/f2py/lib/py_wrap.py
+++ b/numpy/f2py/lib/py_wrap.py
@@ -43,11 +43,17 @@ static PyMethodDef f2py_module_methods[] = {
PyMODINIT_FUNC init%(modulename)s(void) {
f2py_module = Py_InitModule("%(modulename)s", f2py_module_methods);
import_array();
- %(module_init_list)s
if (PyErr_Occurred()) {
- PyErr_SetString(PyExc_ImportError, "can\'t initialize module %(modulename)s");
+ PyErr_SetString(PyExc_ImportError, "failed to load array module.");
return;
}
+ %(module_init_list)s
+ return;
+capi_err:
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_RuntimeError, "failed to initialize %(modulename)s module.");
+ }
+ return;
}
#ifdef __cplusplus
}
diff --git a/numpy/f2py/lib/py_wrap_type.py b/numpy/f2py/lib/py_wrap_type.py
index 0f4ea5a16..bb9af9a33 100644
--- a/numpy/f2py/lib/py_wrap_type.py
+++ b/numpy/f2py/lib/py_wrap_type.py
@@ -448,13 +448,24 @@ static PyTypeObject %(otype)sType = {
0, /* tp_alloc */
%(otype)s_new, /* tp_new */
};
-'''
+void *F2PY_%(otype)s_API[] = {
+ (void *) &%(otype)sType,
+ (void *) pyobj_from_%(ctype)s,
+ (void *) pyobj_to_%(ctype)s_inplace
+};
+'''
+
module_init_template = '''\
if (PyType_Ready(&%(otype)sType) < 0)
- return;
+ goto capi_err;
PyModule_AddObject(f2py_module, "%(name)s",
(PyObject *)&%(otype)sType);
+{
+ PyObject* c_api = PyCObject_FromVoidPtr((void *)F2PY_%(otype)s_API, NULL);
+ PyModule_AddObject(f2py_module, "_%(name)s_API", c_api);
+ if (PyErr_Occurred()) goto capi_err;
+}
'''
c_code_template = '''\
diff --git a/numpy/f2py/lib/test_module_module.py b/numpy/f2py/lib/test_module_module.py
index 8d3bff67d..4823276a8 100644
--- a/numpy/f2py/lib/test_module_module.py
+++ b/numpy/f2py/lib/test_module_module.py
@@ -16,7 +16,7 @@ import os
import sys
from numpy.testing import *
-def build(fortran_code, rebuild=True):
+def build(fortran_code, rebuild=True, build_dir = 'tmp'):
modulename = os.path.splitext(os.path.basename(__file__))[0] + '_ext'
try:
exec ('import %s as m' % (modulename))
@@ -25,27 +25,25 @@ def build(fortran_code, rebuild=True):
os.remove(m.__file__)
raise ImportError,'%s is newer than %s' % (__file__, m.__file__)
except ImportError,msg:
- assert str(msg)==('No module named %s' % (modulename)),str(msg)
+ assert str(msg)==('No module named %s' % (modulename)) \
+ or str(msg).startswith('%s is newer than' % (__file__)),str(msg)
print msg, ', recompiling %s.' % (modulename)
- import tempfile
- fname = tempfile.mktemp() + '.f90'
+ fname = os.path.join(build_dir, modulename + '_source.f90')
f = open(fname,'w')
f.write(fortran_code)
f.close()
sys_argv = []
- sys_argv.extend(['--build-dir','tmp'])
+ sys_argv.extend(['--build-dir',build_dir])
#sys_argv.extend(['-DF2PY_DEBUG_PYOBJ_TOFROM'])
from main import build_extension
sys_argv.extend(['-m',modulename, fname])
build_extension(sys_argv)
- os.remove(fname)
status = os.system(' '.join([sys.executable] + sys.argv))
sys.exit(status)
return m
fortran_code = '''
module test_module_module_ext2
-
type rat
integer n,d
end type rat