Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion numpy/_core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5170,7 +5170,13 @@ _multiarray_umath_exec(PyObject *m) {
if (PyDataMem_DefaultHandler == NULL) {
return -1;
}

#ifdef Py_GIL_DISABLED
if (PyUnstable_SetImmortal(PyDataMem_DefaultHandler) == 0) {
PyErr_SetString(PyExc_RuntimeError,
"Could not mark memory handler capsule as immortal");
return -1;
}
#endif
/*
* Initialize the context-local current handler
* with the default PyDataMem_Handler capsule.
Expand Down
8 changes: 8 additions & 0 deletions numpy/_core/src/umath/extobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "numpy/ufuncobject.h"

#include "common.h"
#include "npy_pycompat.h"


#define UFUNC_ERR_IGNORE 0
Expand Down Expand Up @@ -145,6 +146,13 @@ init_extobj(void)
if (npy_static_pydata.default_extobj_capsule == NULL) {
return -1;
}
#ifdef Py_GIL_DISABLED
if (PyUnstable_SetImmortal(npy_static_pydata.default_extobj_capsule) == 0) {
PyErr_SetString(PyExc_RuntimeError, "Could not mark extobj capsule as immortal");
Py_CLEAR(npy_static_pydata.default_extobj_capsule);
return -1;
}
#endif
npy_static_pydata.npy_extobj_contextvar = PyContextVar_New(
"numpy.ufunc.extobj", npy_static_pydata.default_extobj_capsule);
if (npy_static_pydata.npy_extobj_contextvar == NULL) {
Expand Down