Skip to content

Commit cbfb2ea

Browse files
committed
MAINT: Remove unnecessarily defensive code from dlpack deleter
This is a tp_dealloc, they don't need to care about errors. Even the assert is absurdly defensive: Python will already set a SystemError anyway!
1 parent 20185fd commit cbfb2ea

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

numpy/_core/src/multiarray/dlpack.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,19 @@ static void dlpack_capsule_deleter(PyObject *self) {
3838
return;
3939
}
4040

41-
/* an exception may be in-flight, we must save it in case we create another one */
42-
PyObject *type, *value, *traceback;
43-
PyErr_Fetch(&type, &value, &traceback);
44-
4541
DLManagedTensor *managed =
4642
(DLManagedTensor *)PyCapsule_GetPointer(self, NPY_DLPACK_CAPSULE_NAME);
4743
if (managed == NULL) {
4844
PyErr_WriteUnraisable(self);
49-
goto done;
45+
return;
5046
}
5147
/*
52-
* the spec says the deleter can be NULL if there is no way for the caller
48+
* The spec says the deleter can be NULL if there is no way for the caller
5349
* to provide a reasonable destructor.
5450
*/
5551
if (managed->deleter) {
5652
managed->deleter(managed);
57-
/* TODO: is the deleter allowed to set a python exception? */
58-
assert(!PyErr_Occurred());
5953
}
60-
61-
done:
62-
PyErr_Restore(type, value, traceback);
6354
}
6455

6556
/* used internally, almost identical to dlpack_capsule_deleter() */

0 commit comments

Comments
 (0)