summaryrefslogtreecommitdiff
path: root/numpy/f2py/rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/f2py/rules.py')
-rwxr-xr-xnumpy/f2py/rules.py57
1 files changed, 12 insertions, 45 deletions
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py
index f2f713bde..6750bf705 100755
--- a/numpy/f2py/rules.py
+++ b/numpy/f2py/rules.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
Rules for building C/API module with f2py2e.
@@ -50,8 +50,6 @@ $Date: 2005/08/30 08:58:42 $
Pearu Peterson
"""
-from __future__ import division, absolute_import, print_function
-
__version__ = "$Revision: 1.129 $"[10:-1]
from . import __version__
@@ -180,7 +178,6 @@ static PyMethodDef f2py_module_methods[] = {
\t{NULL,NULL}
};
-#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef moduledef = {
\tPyModuleDef_HEAD_INIT,
\t"#modulename#",
@@ -192,35 +189,20 @@ static struct PyModuleDef moduledef = {
\tNULL,
\tNULL
};
-#endif
-#if PY_VERSION_HEX >= 0x03000000
-#define RETVAL m
PyMODINIT_FUNC PyInit_#modulename#(void) {
-#else
-#define RETVAL
-PyMODINIT_FUNC init#modulename#(void) {
-#endif
\tint i;
\tPyObject *m,*d, *s, *tmp;
-#if PY_VERSION_HEX >= 0x03000000
\tm = #modulename#_module = PyModule_Create(&moduledef);
-#else
-\tm = #modulename#_module = Py_InitModule(\"#modulename#\", f2py_module_methods);
-#endif
\tPy_TYPE(&PyFortran_Type) = &PyType_Type;
\timport_array();
\tif (PyErr_Occurred())
-\t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return RETVAL;}
+\t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return m;}
\td = PyModule_GetDict(m);
\ts = PyString_FromString(\"$R""" + """evision: $\");
\tPyDict_SetItemString(d, \"__version__\", s);
\tPy_DECREF(s);
-#if PY_VERSION_HEX >= 0x03000000
\ts = PyUnicode_FromString(
-#else
-\ts = PyString_FromString(
-#endif
\t\t\"This module '#modulename#' is auto-generated with f2py (version:#f2py_version#).\\nFunctions:\\n\"\n#docs#\".\");
\tPyDict_SetItemString(d, \"__doc__\", s);
\tPy_DECREF(s);
@@ -245,7 +227,7 @@ PyMODINIT_FUNC init#modulename#(void) {
\tif (! PyErr_Occurred())
\t\ton_exit(f2py_report_on_exit,(void*)\"#modulename#\");
#endif
-\treturn RETVAL;
+\treturn m;
}
#ifdef __cplusplus
}
@@ -294,7 +276,7 @@ static PyObject *#apiname#(const PyObject *capi_self,
f2py_start_clock();
#endif
\tif (!PyArg_ParseTupleAndKeywords(capi_args,capi_keywds,\\
-\t\t\"#argformat##keyformat##xaformat#:#pyname#\",\\
+\t\t\"#argformat#|#keyformat##xaformat#:#pyname#\",\\
\t\tcapi_kwlist#args_capi##keys_capi##keys_xa#))\n\t\treturn NULL;
#frompyobj#
/*end of frompyobj*/
@@ -448,11 +430,7 @@ rout_rules = [
tmp = F2PyCapsule_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL);
PyObject_SetAttrString(o,"_cpointer", tmp);
Py_DECREF(tmp);
-#if PY_VERSION_HEX >= 0x03000000
s = PyUnicode_FromString("#name#");
-#else
- s = PyString_FromString("#name#");
-#endif
PyObject_SetAttrString(o,"__name__", s);
Py_DECREF(s);
}
@@ -490,11 +468,7 @@ rout_rules = [
tmp = F2PyCapsule_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL);
PyObject_SetAttrString(o,"_cpointer", tmp);
Py_DECREF(tmp);
-#if PY_VERSION_HEX >= 0x03000000
s = PyUnicode_FromString("#name#");
-#else
- s = PyString_FromString("#name#");
-#endif
PyObject_SetAttrString(o,"__name__", s);
Py_DECREF(s);
}
@@ -1064,8 +1038,10 @@ if (#varname#_capi==Py_None) {
'\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,#varname#_capi);'},
"""\
\tif (capi_#varname#_tmp == NULL) {
-\t\tif (!PyErr_Occurred())
-\t\t\tPyErr_SetString(#modulename#_error,\"failed in converting #nth# `#varname#\' of #pyname# to C/Fortran array\" );
+\t\tPyObject *exc, *val, *tb;
+\t\tPyErr_Fetch(&exc, &val, &tb);
+\t\tPyErr_SetString(exc ? exc : #modulename#_error,\"failed in converting #nth# `#varname#\' of #pyname# to C/Fortran array\" );
+\t\tnpy_PyErr_ChainExceptionsCause(exc, val, tb);
\t} else {
\t\t#varname# = (#ctype# *)(PyArray_DATA(capi_#varname#_tmp));
""",
@@ -1081,8 +1057,10 @@ if (#varname#_capi==Py_None) {
\t\t\twhile ((_i = nextforcomb()))
\t\t\t\t#varname#[capi_i++] = #init#; /* fortran way */
\t\t} else {
-\t\t\tif (!PyErr_Occurred())
-\t\t\t\tPyErr_SetString(#modulename#_error,\"Initialization of #nth# #varname# failed (initforcomb).\");
+\t\t\tPyObject *exc, *val, *tb;
+\t\t\tPyErr_Fetch(&exc, &val, &tb);
+\t\t\tPyErr_SetString(exc ? exc : #modulename#_error,\"Initialization of #nth# #varname# failed (initforcomb).\");
+\t\t\tnpy_PyErr_ChainExceptionsCause(exc, val, tb);
\t\t\tf2py_success = 0;
\t\t}
\t}
@@ -1179,7 +1157,6 @@ def buildmodule(m, um):
"""
Return
"""
- global f2py_version, options
outmess('\tBuilding module "%s"...\n' % (m['name']))
ret = {}
mod_rules = defmod_rules[:]
@@ -1467,16 +1444,6 @@ def buildapi(rout):
['\\begin{description}'] + rd[k][1:] +\
['\\end{description}']
- # Workaround for Python 2.6, 2.6.1 bug: https://bugs.python.org/issue4720
- if rd['keyformat'] or rd['xaformat']:
- argformat = rd['argformat']
- if isinstance(argformat, list):
- argformat.append('|')
- else:
- assert isinstance(argformat, str), repr(
- (argformat, type(argformat)))
- rd['argformat'] += '|'
-
ar = applyrules(routine_rules, rd)
if ismoduleroutine(rout):
outmess('\t\t\t %s\n' % (ar['docshort']))