gh-76785: Fixes for test.support.interpreters (gh-112982)

This involves a number of changes for PEP 734.
This commit is contained in:
Eric Snow 2023-12-12 08:24:31 -07:00 committed by GitHub
parent f26bfe4b25
commit 86a77f4e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 2506 additions and 1507 deletions

View file

@ -12,6 +12,53 @@
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
/**************/
/* exceptions */
/**************/
/* InterpreterError extends Exception */
static PyTypeObject _PyExc_InterpreterError = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "InterpreterError",
.tp_doc = PyDoc_STR("An interpreter was not found."),
//.tp_base = (PyTypeObject *)PyExc_BaseException,
};
PyObject *PyExc_InterpreterError = (PyObject *)&_PyExc_InterpreterError;
/* InterpreterNotFoundError extends InterpreterError */
static PyTypeObject _PyExc_InterpreterNotFoundError = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "InterpreterNotFoundError",
.tp_doc = PyDoc_STR("An interpreter was not found."),
.tp_base = &_PyExc_InterpreterError,
};
PyObject *PyExc_InterpreterNotFoundError = (PyObject *)&_PyExc_InterpreterNotFoundError;
/* lifecycle */
static int
init_exceptions(PyInterpreterState *interp)
{
_PyExc_InterpreterError.tp_base = (PyTypeObject *)PyExc_BaseException;
if (_PyStaticType_InitBuiltin(interp, &_PyExc_InterpreterError) < 0) {
return -1;
}
if (_PyStaticType_InitBuiltin(interp, &_PyExc_InterpreterNotFoundError) < 0) {
return -1;
}
return 0;
}
static void
fini_exceptions(PyInterpreterState *interp)
{
_PyStaticType_Dealloc(interp, &_PyExc_InterpreterNotFoundError);
_PyStaticType_Dealloc(interp, &_PyExc_InterpreterError);
}
/***************************/
/* cross-interpreter calls */
/***************************/
@ -2099,3 +2146,18 @@ _PyXI_Fini(PyInterpreterState *interp)
_xidregistry_fini(_get_global_xidregistry(interp->runtime));
}
}
PyStatus
_PyXI_InitTypes(PyInterpreterState *interp)
{
if (init_exceptions(interp) < 0) {
return _PyStatus_ERR("failed to initialize an exception type");
}
return _PyStatus_OK();
}
void
_PyXI_FiniTypes(PyInterpreterState *interp)
{
fini_exceptions(interp);
}