[MLIR] Fix thread safety of the deleter in PyDenseResourceElementsAttribute (#124832)
In general, `PyDenseResourceElementsAttribute` can get deleted at any time and any thread, where unlike the `getFromBuffer` call, the Python interpreter may not be initialized and the GIL may not be held. This PR fixes segfaults caused by `PyBuffer_Release` when the GIL is not being held by the thread calling the deleter.
This commit is contained in:
parent
b8cdc5ea27
commit
28507ac629
@ -1468,7 +1468,10 @@ public:
|
||||
// The userData is a Py_buffer* that the deleter owns.
|
||||
auto deleter = [](void *userData, const void *data, size_t size,
|
||||
size_t align) {
|
||||
if (!Py_IsInitialized())
|
||||
Py_Initialize();
|
||||
Py_buffer *ownedView = static_cast<Py_buffer *>(userData);
|
||||
nb::gil_scoped_acquire gil;
|
||||
PyBuffer_Release(ownedView);
|
||||
delete ownedView;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user