gh-76785: Improved Subinterpreters Compatibility with 3.12 (2/2) (gh-126707)

These changes makes it easier to backport the _interpreters, _interpqueues, and _interpchannels modules to Python 3.12.

This involves the following:

* add the _PyXI_GET_STATE() and _PyXI_GET_GLOBAL_STATE() macros
* add _PyXIData_lookup_context_t and _PyXIData_GetLookupContext()
* add _Py_xi_state_init() and _Py_xi_state_fini()
This commit is contained in:
Eric Snow 2024-11-12 10:41:51 -07:00 committed by GitHub
parent 6b2a19681e
commit 73cf069099
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 248 additions and 92 deletions

View file

@ -8,15 +8,24 @@
static int
ensure_xid_class(PyTypeObject *cls, xidatafunc getdata)
{
//assert(cls->tp_flags & Py_TPFLAGS_HEAPTYPE);
return _PyXIData_RegisterClass(cls, getdata);
PyInterpreterState *interp = PyInterpreterState_Get();
_PyXIData_lookup_context_t ctx;
if (_PyXIData_GetLookupContext(interp, &ctx) < 0) {
return -1;
}
return _PyXIData_RegisterClass(&ctx, cls, getdata);
}
#ifdef REGISTERS_HEAP_TYPES
static int
clear_xid_class(PyTypeObject *cls)
{
return _PyXIData_UnregisterClass(cls);
PyInterpreterState *interp = PyInterpreterState_Get();
_PyXIData_lookup_context_t ctx;
if (_PyXIData_GetLookupContext(interp, &ctx) < 0) {
return -1;
}
return _PyXIData_UnregisterClass(&ctx, cls);
}
#endif