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

Commitbc408c1

Browse files
committed
Convert _simd.c to multi-phase init (PEP 489)
1 parentbbdebae commitbc408c1

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

‎numpy/_core/src/_simd/_simd.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,11 @@ static PyMethodDef _simd_methods[] = {
2121
{NULL,NULL,0,NULL}
2222
};
2323

24-
PyMODINIT_FUNCPyInit__simd(void)
24+
staticint
25+
_simd_exec(PyObject*m)
2526
{
26-
staticstructPyModuleDefdefs= {
27-
.m_base=PyModuleDef_HEAD_INIT,
28-
.m_name="numpy._core._simd",
29-
.m_size=-1,
30-
.m_methods=_simd_methods
31-
};
3227
if (npy_cpu_init()<0) {
33-
returnNULL;
34-
}
35-
PyObject*m=PyModule_Create(&defs);
36-
if (m==NULL) {
37-
returnNULL;
28+
return-1;
3829
}
3930
PyObject*targets=PyDict_New();
4031
if (targets==NULL) {
@@ -88,13 +79,31 @@ PyMODINIT_FUNC PyInit__simd(void)
8879
NPY_MTARGETS_CONF_DISPATCH(NPY_CPU_HAVE,ATTACH_MODULE,MAKE_MSVC_HAPPY)
8980
NPY_MTARGETS_CONF_BASELINE(ATTACH_BASELINE_MODULE,MAKE_MSVC_HAPPY)
9081

91-
#ifPy_GIL_DISABLED
92-
// signal this module supports running with the GIL disabled
93-
PyUnstable_Module_SetGIL(m,Py_MOD_GIL_NOT_USED);
82+
return0;
83+
err:
84+
return-1;
85+
}
86+
87+
staticstructPyModuleDef_Slot_simd_slots[]= {
88+
{Py_mod_exec,_simd_exec},
89+
#ifPY_VERSION_HEX >=0x030c00f0// Python 3.12+
90+
{Py_mod_multiple_interpreters,Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
91+
#endif
92+
#ifPY_VERSION_HEX >=0x030d00f0// Python 3.13+
93+
// signal that this module supports running without an active GIL
94+
{Py_mod_gil,Py_MOD_GIL_NOT_USED},
9495
#endif
96+
{0,NULL},
97+
};
9598

96-
returnm;
97-
err:
98-
Py_DECREF(m);
99-
returnNULL;
99+
staticstructPyModuleDefdefs= {
100+
.m_base=PyModuleDef_HEAD_INIT,
101+
.m_name="numpy._core._simd",
102+
.m_size=0,
103+
.m_methods=_simd_methods,
104+
.m_slots=_simd_slots,
105+
};
106+
107+
PyMODINIT_FUNCPyInit__simd(void) {
108+
returnPyModuleDef_Init(&defs);
100109
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp