mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
gh-76785: Fixes for test.support.interpreters (gh-112982)
This involves a number of changes for PEP 734.
This commit is contained in:
parent
f26bfe4b25
commit
86a77f4e1a
30 changed files with 2506 additions and 1507 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -734,6 +734,11 @@ pycore_init_types(PyInterpreterState *interp)
|
|||
return status;
|
||||
}
|
||||
|
||||
status = _PyXI_InitTypes(interp);
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
@ -1742,6 +1747,7 @@ finalize_interp_types(PyInterpreterState *interp)
|
|||
{
|
||||
_PyUnicode_FiniTypes(interp);
|
||||
_PySys_FiniTypes(interp);
|
||||
_PyXI_FiniTypes(interp);
|
||||
_PyExc_Fini(interp);
|
||||
_PyAsyncGen_Fini(interp);
|
||||
_PyContext_Fini(interp);
|
||||
|
|
|
@ -1216,7 +1216,7 @@ _PyInterpreterState_LookUpID(int64_t requested_id)
|
|||
HEAD_UNLOCK(runtime);
|
||||
}
|
||||
if (interp == NULL && !PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
PyErr_Format(PyExc_InterpreterNotFoundError,
|
||||
"unrecognized interpreter ID %lld", requested_id);
|
||||
}
|
||||
return interp;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue