Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c01323

Browse files
committed
Convert multiarray to multi-phase init (PEP 489)
1 parentb2b54a9 commit1c01323

File tree

2 files changed

+48
-62
lines changed

2 files changed

+48
-62
lines changed

‎numpy/_core/src/multiarray/_multiarray_tests.c.src

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,41 +2413,36 @@ static PyMethodDef Multiarray_TestsMethods[] = {
24132413
};
24142414

24152415

2416-
staticstructPyModuleDefmoduledef= {
2417-
PyModuleDef_HEAD_INIT,
2418-
"_multiarray_tests",
2419-
NULL,
2420-
-1,
2421-
Multiarray_TestsMethods,
2422-
NULL,
2423-
NULL,
2424-
NULL,
2425-
NULL
2426-
};
2427-
2428-
PyMODINIT_FUNCPyInit__multiarray_tests(void)
2416+
staticint
2417+
_multiarray_tests_exec(PyObject*m)
24292418
{
2430-
PyObject*m;
2431-
2432-
m=PyModule_Create(&moduledef);
2433-
if (m==NULL) {
2434-
returnm;
2435-
}
2436-
import_array();
2419+
import_array1(-1);
24372420
if (init_argparse_mutex()<0) {
2438-
returnNULL;
2439-
}
2440-
if (PyErr_Occurred()) {
2441-
PyErr_SetString(PyExc_RuntimeError,
2442-
"cannot load _multiarray_tests module.");
2421+
return-1;
24432422
}
24442423

2445-
#ifPy_GIL_DISABLED
2424+
return0;
2425+
}
2426+
2427+
staticstructPyModuleDef_Slot_multiarray_tests_slots[]= {
2428+
{Py_mod_exec,_multiarray_tests_exec},
2429+
{Py_mod_multiple_interpreters,Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
24462430
// signal this module supports running with the GIL disabled
2447-
PyUnstable_Module_SetGIL(m,Py_MOD_GIL_NOT_USED);
2448-
#endif
2431+
{Py_mod_gil,Py_MOD_GIL_NOT_USED},
2432+
{0,NULL},
2433+
};
24492434

2450-
returnm;
2435+
staticstructPyModuleDefmoduledef= {
2436+
.m_base=PyModuleDef_HEAD_INIT,
2437+
.m_name="_multiarray_tests",
2438+
.m_size=0,
2439+
.m_methods=Multiarray_TestsMethods,
2440+
.m_slots=_multiarray_tests_slots,
2441+
};
2442+
2443+
PyMODINIT_FUNCPyInit__multiarray_tests(void)
2444+
{
2445+
returnPyModuleDef_Init(&moduledef);
24512446
}
24522447

24532448
NPY_NO_EXPORTint

‎numpy/_core/src/multiarray/multiarraymodule.c

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4773,28 +4773,9 @@ initialize_thread_unsafe_state(void) {
47734773
return0;
47744774
}
47754775

4776-
staticstructPyModuleDefmoduledef= {
4777-
PyModuleDef_HEAD_INIT,
4778-
"_multiarray_umath",
4779-
NULL,
4780-
-1,
4781-
array_module_methods,
4782-
NULL,
4783-
NULL,
4784-
NULL,
4785-
NULL
4786-
};
4787-
4788-
/* Initialization function for the module */
4789-
PyMODINIT_FUNCPyInit__multiarray_umath(void) {
4790-
PyObject*m,*d,*s;
4791-
PyObject*c_api;
4792-
4793-
/* Create the module and add the functions */
4794-
m=PyModule_Create(&moduledef);
4795-
if (!m) {
4796-
returnNULL;
4797-
}
4776+
staticint
4777+
_multiarray_umath_exec(PyObject*m) {
4778+
PyObject*d,*s,*c_api;
47984779

47994780
/* Initialize CPU features */
48004781
if (npy_cpu_init()<0) {
@@ -5135,18 +5116,28 @@ PyMODINIT_FUNC PyInit__multiarray_umath(void) {
51355116
gotoerr;
51365117
}
51375118

5138-
#ifPy_GIL_DISABLED
5119+
return0;
5120+
5121+
err:
5122+
return-1;
5123+
}
5124+
5125+
staticstructPyModuleDef_Slot_multiarray_umath_slots[]= {
5126+
{Py_mod_exec,_multiarray_umath_exec},
5127+
{Py_mod_multiple_interpreters,Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
51395128
// signal this module supports running with the GIL disabled
5140-
PyUnstable_Module_SetGIL(m,Py_MOD_GIL_NOT_USED);
5141-
#endif
5129+
{Py_mod_gil,Py_MOD_GIL_NOT_USED},
5130+
{0,NULL},
5131+
};
51425132

5143-
returnm;
5133+
staticstructPyModuleDefmoduledef= {
5134+
.m_base=PyModuleDef_HEAD_INIT,
5135+
.m_name="_multiarray_umath",
5136+
.m_size=0,
5137+
.m_methods=array_module_methods,
5138+
.m_slots=_multiarray_umath_slots,
5139+
};
51445140

5145-
err:
5146-
if (!PyErr_Occurred()) {
5147-
PyErr_SetString(PyExc_RuntimeError,
5148-
"cannot load multiarray module.");
5149-
}
5150-
Py_DECREF(m);
5151-
returnNULL;
5141+
PyMODINIT_FUNCPyInit__multiarray_umath(void) {
5142+
returnPyModuleDef_Init(&moduledef);
51525143
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp