aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-12-12 08:24:31 -0700
committerGitHub <noreply@github.com>2023-12-12 08:24:31 -0700
commit86a77f4e1a5ceaff1036b0072521e12752b5df47 (patch)
treececc78dab93112a3a92ae66fc0156630408063b3 /Python
parentf26bfe4b25f7e5a4f68fcac26207b7175abad208 (diff)
downloadcpython-86a77f4e1a5ceaff1036b0072521e12752b5df47.tar.gz
cpython-86a77f4e1a5ceaff1036b0072521e12752b5df47.zip
gh-76785: Fixes for test.support.interpreters (gh-112982)
This involves a number of changes for PEP 734.
Diffstat (limited to 'Python')
-rw-r--r--Python/crossinterp.c62
-rw-r--r--Python/pylifecycle.c6
-rw-r--r--Python/pystate.c2
3 files changed, 69 insertions, 1 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index f74fee38648..a31b5ef4613 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -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);
+}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 45a119fcca7..b5c7dc5da59 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -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);
diff --git a/Python/pystate.c b/Python/pystate.c
index 1a7c0c96850..f0c5259967d 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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;