mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-132776: Cleanup for XIBufferViewType (gh-132821)
* add notes * rename XIBufferViewObject to xibufferview * move memoryview XIData code to memoryobject.c
This commit is contained in:
parent
c9f3f5b4ed
commit
e54e828852
8 changed files with 339 additions and 250 deletions
|
@ -1902,7 +1902,25 @@ _PyXI_Fini(PyInterpreterState *interp)
|
|||
PyStatus
|
||||
_PyXI_InitTypes(PyInterpreterState *interp)
|
||||
{
|
||||
if (init_static_exctypes(&_PyXI_GET_STATE(interp)->exceptions, interp) < 0) {
|
||||
if (_Py_IsMainInterpreter(interp)) {
|
||||
_PyXI_global_state_t *global_state = _PyXI_GET_GLOBAL_STATE(interp);
|
||||
if (global_state == NULL) {
|
||||
PyErr_PrintEx(0);
|
||||
return _PyStatus_ERR(
|
||||
"failed to get global cross-interpreter state");
|
||||
}
|
||||
xid_lookup_init(&global_state->data_lookup);
|
||||
}
|
||||
|
||||
_PyXI_state_t *state = _PyXI_GET_STATE(interp);
|
||||
if (state == NULL) {
|
||||
PyErr_PrintEx(0);
|
||||
return _PyStatus_ERR(
|
||||
"failed to get interpreter's cross-interpreter state");
|
||||
}
|
||||
xid_lookup_init(&state->data_lookup);
|
||||
|
||||
if (init_static_exctypes(&state->exceptions, interp) < 0) {
|
||||
PyErr_PrintEx(0);
|
||||
return _PyStatus_ERR(
|
||||
"failed to initialize the cross-interpreter exception types");
|
||||
|
@ -1915,9 +1933,21 @@ _PyXI_InitTypes(PyInterpreterState *interp)
|
|||
void
|
||||
_PyXI_FiniTypes(PyInterpreterState *interp)
|
||||
{
|
||||
// We would finalize heap types here too but that leads to ref leaks.
|
||||
// Instead, we finalize them in _PyXI_Fini().
|
||||
fini_static_exctypes(&_PyXI_GET_STATE(interp)->exceptions, interp);
|
||||
_PyXI_state_t *state = _PyXI_GET_STATE(interp);
|
||||
if (state != NULL) {
|
||||
// We would finalize heap types here too but that leads to ref leaks.
|
||||
// Instead, we finalize them in _PyXI_Fini().
|
||||
fini_static_exctypes(&state->exceptions, interp);
|
||||
|
||||
xid_lookup_fini(&state->data_lookup);
|
||||
}
|
||||
|
||||
if (_Py_IsMainInterpreter(interp)) {
|
||||
_PyXI_global_state_t *global_state = _PyXI_GET_GLOBAL_STATE(interp);
|
||||
if (global_state != NULL) {
|
||||
xid_lookup_fini(&global_state->data_lookup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ _lookup_getdata_from_registry(dlcontext_t *ctx, PyObject *obj)
|
|||
PyTypeObject *cls = Py_TYPE(obj);
|
||||
|
||||
dlregistry_t *xidregistry = _get_xidregistry_for_type(ctx, cls);
|
||||
assert(xidregistry->initialized);
|
||||
_xidregistry_lock(xidregistry);
|
||||
|
||||
dlregitem_t *matched = _xidregistry_find_type(xidregistry, cls);
|
||||
|
@ -190,6 +191,7 @@ static int
|
|||
_xidregistry_add_type(dlregistry_t *xidregistry,
|
||||
PyTypeObject *cls, xidatafunc getdata)
|
||||
{
|
||||
assert(xidregistry->initialized);
|
||||
dlregitem_t *newhead = PyMem_RawMalloc(sizeof(dlregitem_t));
|
||||
if (newhead == NULL) {
|
||||
return -1;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "pycore_global_objects_fini_generated.h" // _PyStaticObjects_CheckRefcnt()
|
||||
#include "pycore_initconfig.h" // _PyStatus_OK()
|
||||
#include "pycore_long.h" // _PyLong_InitTypes()
|
||||
#include "pycore_memoryobject.h" // _PyMemoryView_InitTypes()
|
||||
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
|
||||
#include "pycore_obmalloc.h" // _PyMem_init_obmalloc()
|
||||
#include "pycore_optimizer.h" // _Py_Executors_InvalidateAll
|
||||
|
@ -754,6 +755,11 @@ pycore_init_types(PyInterpreterState *interp)
|
|||
return status;
|
||||
}
|
||||
|
||||
status = _PyMemoryView_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
@ -1845,6 +1851,7 @@ finalize_interp_types(PyInterpreterState *interp)
|
|||
_PyTypes_FiniExtTypes(interp);
|
||||
_PyUnicode_FiniTypes(interp);
|
||||
_PySys_FiniTypes(interp);
|
||||
_PyMemoryView_FiniTypes(interp);
|
||||
_PyXI_FiniTypes(interp);
|
||||
_PyExc_Fini(interp);
|
||||
_PyFloat_FiniType(interp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue