summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2022-05-28 15:28:19 +0200
committerRalf Gommers <ralf.gommers@gmail.com>2022-05-28 15:28:19 +0200
commite68c7064ce92d517e54b0188ca050491ed2069ff (patch)
tree17349806c744de9ff69c47229fd5bb1572bd23c9
parent1b76ff5b5e1254c95c033fc449553ab67c5d96fe (diff)
downloadnumpy-e68c7064ce92d517e54b0188ca050491ed2069ff.tar.gz
DOC: move `import_array` and `import_umath` above `PyModule_Create`
This seems to be a slightly better order, because these initializations are independent of module creation, and if initialization fails then there's no reference to the new module floating around. See https://github.com/scipy/scipy/issues/16231 [skip actions]
-rw-r--r--doc/source/user/c-info.ufunc-tutorial.rst28
1 files changed, 15 insertions, 13 deletions
diff --git a/doc/source/user/c-info.ufunc-tutorial.rst b/doc/source/user/c-info.ufunc-tutorial.rst
index 3a406479b..47d306f80 100644
--- a/doc/source/user/c-info.ufunc-tutorial.rst
+++ b/doc/source/user/c-info.ufunc-tutorial.rst
@@ -323,14 +323,15 @@ the primary thing that must be changed to create your own ufunc.
PyMODINIT_FUNC PyInit_npufunc(void)
{
PyObject *m, *logit, *d;
+
+ import_array();
+ import_umath();
+
m = PyModule_Create(&moduledef);
if (!m) {
return NULL;
}
- import_array();
- import_umath();
-
logit = PyUFunc_FromFuncAndData(funcs, NULL, types, 1, 1, 1,
PyUFunc_None, "logit",
"logit_docstring", 0);
@@ -576,14 +577,15 @@ is the primary thing that must be changed to create your own ufunc.
PyMODINIT_FUNC PyInit_npufunc(void)
{
PyObject *m, *logit, *d;
+
+ import_array();
+ import_umath();
+
m = PyModule_Create(&moduledef);
if (!m) {
return NULL;
}
- import_array();
- import_umath();
-
logit = PyUFunc_FromFuncAndData(funcs, NULL, types, 4, 1, 1,
PyUFunc_None, "logit",
"logit_docstring", 0);
@@ -767,14 +769,15 @@ as well as all other properties of a ufunc.
PyMODINIT_FUNC PyInit_npufunc(void)
{
PyObject *m, *logit, *d;
+
+ import_array();
+ import_umath();
+
m = PyModule_Create(&moduledef);
if (!m) {
return NULL;
}
- import_array();
- import_umath();
-
logit = PyUFunc_FromFuncAndData(funcs, NULL, types, 1, 2, 2,
PyUFunc_None, "logit",
"logit_docstring", 0);
@@ -896,15 +899,14 @@ The C file is given below.
PyArray_Descr *dtype;
PyArray_Descr *dtypes[3];
- m = PyModule_Create(&moduledef);
+ import_array();
+ import_umath();
+ m = PyModule_Create(&moduledef);
if (m == NULL) {
return NULL;
}
- import_array();
- import_umath();
-
/* Create a new ufunc object */
add_triplet = PyUFunc_FromFuncAndData(NULL, NULL, NULL, 0, 2, 1,
PyUFunc_None, "add_triplet",