8000 MAINT: Remove Python2 specific C module setup [part2] by sethtroisi · Pull Request #15231 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Remove Python2 specific C module setup [part2] #15231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Removed Python2 specific C module code
  • Loading branch information
sethtroisi committed Jan 3, 2020
commit f01982aa11b298c5a65a7752eec33c57f38674e9
8 changes: 1 addition & 7 deletions numpy/core/code_generators/generate_numpy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@
return 0;
}

#if PY_VERSION_HEX >= 0x03000000
#define NUMPY_IMPORT_ARRAY_RETVAL NULL
#else
#define NUMPY_IMPORT_ARRAY_RETVAL
#endif

#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NULL; } }

#define import_array1(ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return ret; } }

Expand Down
8 changes: 1 addition & 7 deletions numpy/core/code_generators/generate_ufunc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,14 @@
return 0;
}

#if PY_VERSION_HEX >= 0x03000000
#define NUMPY_IMPORT_UMATH_RETVAL NULL
#else
#define NUMPY_IMPORT_UMATH_RETVAL
#endif

#define import_umath() \
do {\
UFUNC_NOFPE\
if (_import_umath() < 0) {\
PyErr_Print();\
PyErr_SetString(PyExc_ImportError,\
"numpy.core.umath failed to import");\
return NUMPY_IMPORT_UMATH_RETVAL;\
return NULL;\
}\
} while(0)

Expand Down
5 changes: 2 additions & 3 deletions numpy/core/src/multiarray/_multiarray_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -2138,21 +2138,20 @@ static struct PyModuleDef moduledef = {
NULL
};

#define RETVAL m
PyMODINIT_FUNC PyInit__multiarray_tests(void)
{
PyObject *m;

m = PyModule_Create(&moduledef);
if (m == NULL) {
return RETVAL;
return m;
}
import_array();
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"cannot load _multiarray_tests module.");
}
return RETVAL;
return m;
}

NPY_NO_EXPORT int
8000 Expand Down
5 changes: 2 additions & 3 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4564,7 +4564,6 @@ static struct PyModuleDef moduledef = {
};

/* Initialization function for the module */
#define RETVAL(x) x
PyMODINIT_FUNC PyInit__multiarray_umath(void) {
PyObject *m, *d, *s;
PyObject *c_api;
Expand Down Expand Up @@ -4755,12 +4754,12 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) {
if (initumath(m) != 0) {
goto err;
}
return RETVAL(m);
return m;

err:
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"cannot load multiarray module.");
}
return RETVAL(NULL);
return NULL;
}
8 changes: 2 additions & 6 deletions numpy/core/src/umath/_operand_flag_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ static struct PyModuleDef moduledef = {
NULL
};

#define RETVAL m
PyMODINIT_FUNC PyInit__operand_flag_tests(void)
{
PyObject *m = NULL;
Expand All @@ -77,19 +76,16 @@ PyMODINIT_FUNC PyInit__operand_flag_tests(void)
((PyUFuncObject*)ufunc)->iter_flags = NPY_ITER_REDUCE_OK;
PyModule_AddObject(m, "inplace_add", (PyObject*)ufunc);

return RETVAL;
return m;

fail:
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"cannot load _operand_flag_tests module.");
}
#if defined(NPY_PY3K)
if (m) {
Py_DECREF(m);
m = NULL;
}
#endif
return RETVAL;

return m;
}
5 changes: 2 additions & 3 deletions numpy/core/src/umath/_rational_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,6 @@ static struct PyModuleDef moduledef = {
NULL
};

#define RETVAL m
PyMODINIT_FUNC PyInit__rational_tests(void) {
PyObject *m = NULL;
PyObject* numpy_str;
Expand Down Expand Up @@ -1380,7 +1379,7 @@ PyMODINIT_FUNC PyInit__rational_tests(void) {
GCD_LCM_UFUNC(gcd,NPY_INT64,"greatest common denominator of two integers");
GCD_LCM_UFUNC(lcm,NPY_INT64,"least common multiple of two integers");

return RETVAL;
return m;

fail:
if (!PyErr_Occurred()) {
Expand All @@ -1391,5 +1390,5 @@ fail:
Py_DECREF(m);
m = NULL;
}
return RETVAL;
return m;
}
7 changes: 3 additions & 4 deletions numpy/core/src/umath/_umath_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -599,15 +599,14 @@ static struct PyModuleDef moduledef = {
};

/* Initialization function for the module */
#define RETVAL(x) x
PyMODINIT_FUNC PyInit__umath_tests(void) {
PyObject *m;
PyObject *d;
PyObject *version;

m = PyModule_Create(&moduledef);
if (m == NULL) {
return RETVAL(NULL);
return NULL;
}

import_array();
Expand All @@ -625,8 +624,8 @@ PyMODINIT_FUNC PyInit__umath_tests(void) {
PyErr_Print();
PyErr_SetString(PyExc_RuntimeError,
"cannot load _umath_tests module.");
return RETVAL(NULL);
return NULL;
}

return RETVAL(m);
return m;
}
10 changes: 2 additions & 8 deletions numpy/f2py/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,7 @@
};
#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
Expand All @@ -211,7 +205,7 @@
\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;}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be return NULL, but let's leave that to a follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pattern repeats in a number of places I have a draft pull to try something new..

\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);
Expand Down Expand Up @@ -245,7 +239,7 @@
\tif (! PyErr_Occurred())
\t\ton_exit(f2py_report_on_exit,(void*)\"#modulename#\");
#endif
\treturn RETVAL;
\treturn m;
}
#ifdef __cplusplus
}
Expand Down
12 changes: 1 addition & 11 deletions numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,9 @@ static struct PyModuleDef moduledef = {
};
#endif

#if PY_VERSION_HEX >= 0x03000000
#define RETVAL m
PyMODINIT_FUNC PyInit_test_array_from_pyobj_ext(void) {
#else
#define RETVAL
PyMODINIT_FUNC inittest_array_from_pyobj_ext(void) {
#endif
PyObject *m,*d, *s;
#if PY_VERSION_HEX >= 0x03000000
m = wrap_module = PyModule_Create(&moduledef);
#else
m = wrap_module = Py_InitModule("test_array_from_pyobj_ext", f2py_module_methods);
#endif
Py_TYPE(&PyFortran_Type) = &PyType_Type;
import_array();
if (PyErr_Occurred())
Expand Down Expand Up @@ -238,7 +228,7 @@ PyMODINIT_FUNC inittest_array_from_pyobj_ext(void) {
on_exit(f2py_report_on_exit,(void*)"array_from_pyobj.wrap.call");
#endif

return RETVAL;
return m;
}
#ifdef __cplusplus
}
Expand Down
21 changes: 2 additions & 19 deletions numpy/fft/_pocketfft.c
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,6 @@ static struct PyMethodDef methods[] = {
{NULL, NULL, 0, NULL} /* sentinel */
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_pocketfft_internal",
Expand All @@ -2371,36 +2370,20 @@ static struct PyModuleDef moduledef = {
NULL,
NULL
};
#endif

/* Initialization function for the module */
#if PY_MAJOR_VERSION >= 3
#define RETVAL(x) x
PyMODINIT_FUNC PyInit__pocketfft_internal(void)
#else
#define RETVAL(x)
PyMODINIT_FUNC
init_pocketfft_internal(void)
#endif
{
PyObject *m;
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
#else
static const char module_documentation[] = "";

m = Py_InitModule4("_pocketfft_internal", methods,
module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
#endif
if (m == NULL) {
return RETVAL(NULL);
return NULL;
}

/* Import the array object */
import_array();

/* XXXX Add constants here */

return RETVAL(m);
return m;
}
18 changes: 2 additions & 16 deletions numpy/linalg/lapack_litemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ static struct PyMethodDef lapack_lite_module_methods[] = {
};


#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"lapack_lite",
Expand All @@ -389,27 +388,14 @@ static struct PyModuleDef moduledef = {
NULL,
NULL
};
#endif

/* Initialization function for the module */
#if PY_MAJOR_VERSION >= 3
#define RETVAL(x) x
PyMODINIT_FUNC PyInit_lapack_lite(void)
#else
#define RETVAL(x)
PyMODINIT_FUNC
initlapack_lite(void)
#endif
{
PyObject *m,*d;
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule4("lapack_lite", lapack_lite_module_methods,
"", (PyObject*)NULL,PYTHON_API_VERSION);
#endif
if (m == NULL) {
return RETVAL(NULL);
return NULL;
}
import_array();
d = PyModule_GetDict(m);
Expand All @@ -422,5 +408,5 @@ initlapack_lite(void)
PyDict_SetItemString(d, "_ilp64", Py_False);
#endif

return RETVAL(m);
return m;
}
7 changes: 3 additions & 4 deletions numpy/linalg/umath_linalg.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -3638,7 +3638,6 @@ static struct PyModuleDef moduledef = {
NULL
};

#define RETVAL(x) x
PyObject *PyInit__umath_linalg(void)
{
PyObject *m;
Expand All @@ -3648,7 +3647,7 @@ PyObject *PyInit__umath_linalg(void)
init_constants();
m = PyModule_Create(&moduledef);
if (m == NULL) {
return RETVAL(NULL);
return NULL;
}

import_array();
Expand All @@ -3666,8 +3665,8 @@ PyObject *PyInit__umath_linalg(void)
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"cannot load _umath_linalg module.");
return RETVAL(NULL);
return NULL;
}

return RETVAL(m);
return m;
}
0