mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
gh-127791: Fix, document, and test PyUnstable_AtExit
(#127793)
This commit is contained in:
parent
2cdeb61b57
commit
d5d84c3f13
7 changed files with 71 additions and 39 deletions
|
@ -27,7 +27,10 @@ int
|
|||
PyUnstable_AtExit(PyInterpreterState *interp,
|
||||
atexit_datacallbackfunc func, void *data)
|
||||
{
|
||||
assert(interp == _PyInterpreterState_GET());
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
assert(tstate->interp == interp);
|
||||
|
||||
atexit_callback *callback = PyMem_Malloc(sizeof(atexit_callback));
|
||||
if (callback == NULL) {
|
||||
PyErr_NoMemory();
|
||||
|
@ -38,12 +41,13 @@ PyUnstable_AtExit(PyInterpreterState *interp,
|
|||
callback->next = NULL;
|
||||
|
||||
struct atexit_state *state = &interp->atexit;
|
||||
if (state->ll_callbacks == NULL) {
|
||||
atexit_callback *top = state->ll_callbacks;
|
||||
if (top == NULL) {
|
||||
state->ll_callbacks = callback;
|
||||
state->last_ll_callback = callback;
|
||||
}
|
||||
else {
|
||||
state->last_ll_callback->next = callback;
|
||||
callback->next = top;
|
||||
state->ll_callbacks = callback;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue