mirror of
https://github.com/python/cpython
synced 2024-09-19 21:01:47 +00:00
gh-104028: Reduce object creation while calling callback function from gc (gh-104030)
This commit is contained in:
parent
4181d078fc
commit
e147694252
|
@ -0,0 +1,2 @@
|
|||
Reduce object creation while calling callback function from gc.
|
||||
Patch by Dong-hee Na.
|
|
@ -1388,10 +1388,19 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *phase_obj = PyUnicode_FromString(phase);
|
||||
if (phase_obj == NULL) {
|
||||
Py_XDECREF(info);
|
||||
PyErr_WriteUnraisable(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
PyObject *stack[] = {phase_obj, info};
|
||||
for (Py_ssize_t i=0; i<PyList_GET_SIZE(gcstate->callbacks); i++) {
|
||||
PyObject *r, *cb = PyList_GET_ITEM(gcstate->callbacks, i);
|
||||
Py_INCREF(cb); /* make sure cb doesn't go away */
|
||||
r = PyObject_CallFunction(cb, "sO", phase, info);
|
||||
r = PyObject_Vectorcall(cb, stack, 2, NULL);
|
||||
if (r == NULL) {
|
||||
PyErr_WriteUnraisable(cb);
|
||||
}
|
||||
|
@ -1400,6 +1409,7 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
|
|||
}
|
||||
Py_DECREF(cb);
|
||||
}
|
||||
Py_DECREF(phase_obj);
|
||||
Py_XDECREF(info);
|
||||
assert(!_PyErr_Occurred(tstate));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue