Skip to content

Commit 074fb12

Browse files
committed
Convert pocketfft_umath to multi-phase init (PEP 489)
1 parent bbdebae commit 074fb12

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

numpy/fft/_pocketfft_umath.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -388,41 +388,42 @@ add_gufuncs(PyObject *dictionary) {
388388
return 0;
389389
}
390390

391-
static struct PyModuleDef moduledef = {
392-
PyModuleDef_HEAD_INIT,
393-
"_multiarray_umath",
394-
NULL,
395-
-1,
396-
NULL,
397-
NULL,
398-
NULL,
399-
NULL,
400-
NULL
401-
};
402-
403-
/* Initialization function for the module */
404-
PyMODINIT_FUNC PyInit__pocketfft_umath(void)
391+
static int
392+
_pocketfft_umath_exec(PyObject *m)
405393
{
406-
PyObject *m = PyModule_Create(&moduledef);
407-
if (m == NULL) {
408-
return NULL;
409-
}
410-
411394
/* Import the array and ufunc objects */
412-
import_array();
413-
import_ufunc();
395+
import_array1(-1);
396+
import_umath1(-1);
414397

415398
PyObject *d = PyModule_GetDict(m);
416399
if (add_gufuncs(d) < 0) {
417400
Py_DECREF(d);
418401
Py_DECREF(m);
419-
return NULL;
402+
return -1;
420403
}
421404

422-
#if Py_GIL_DISABLED
423-
// signal this module supports running with the GIL disabled
424-
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
405+
return 0;
406+
}
407+
408+
static struct PyModuleDef_Slot _pocketfft_umath_slots[] = {
409+
{Py_mod_exec, (void*)_pocketfft_umath_exec},
410+
#if PY_VERSION_HEX >= 0x030c00f0 // Python 3.12+
411+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
425412
#endif
413+
#if PY_VERSION_HEX >= 0x030d00f0 // Python 3.13+
414+
// signal that this module supports running without an active GIL
415+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
416+
#endif
417+
{0, NULL},
418+
};
419+
420+
static struct PyModuleDef moduledef = {
421+
.m_base = PyModuleDef_HEAD_INIT,
422+
.m_name = "_pocketfft_umath",
423+
.m_size = 0,
424+
.m_slots = _pocketfft_umath_slots,
425+
};
426426

427-
return m;
427+
PyMODINIT_FUNC PyInit__pocketfft_umath(void) {
428+
return PyModuleDef_Init(&moduledef);
428429
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy