Content-Length: 364299 | pFad | http://github.com/python/cpython/pull/126704/commits/de75cb492bc7dc40fc6d8e9ad52e2f197409c22e

7B gh-76785: Improved Subinterpreters Compatibility with 3.12 (1/2) by ericsnowcurrently · Pull Request #126704 · python/cpython · GitHub
Skip to content

gh-76785: Improved Subinterpreters Compatibility with 3.12 (1/2) #126704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Use struct _xi_state to look up PyExc_NotShareableError.
  • Loading branch information
ericsnowcurrently committed Nov 11, 2024
commit de75cb492bc7dc40fc6d8e9ad52e2f197409c22e
33 changes: 20 additions & 13 deletions Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ _check_xidata(PyThreadState *tstate, _PyXIData_t *data)
}

static inline void
_set_xid_lookup_failure(PyInterpreterState *interp,
PyObject *obj, const char *msg)
_set_xid_lookup_failure(_PyXI_state_t *state, PyObject *obj, const char *msg)
{
exceptions_t *state = &_PyInterpreterState_GetXIState(interp)->exceptions;
PyObject *exctype = state->PyExc_NotShareableError;
PyObject *exctype = state->exceptions.PyExc_NotShareableError;
assert(exctype != NULL);
if (msg != NULL) {
assert(obj == NULL);
Expand All @@ -226,10 +224,11 @@ int
_PyObject_CheckXIData(PyObject *obj)
{
PyInterpreterState *interp = PyInterpreterState_Get();
_PyXI_state_t *state = _PyXI_GET_STATE(interp);
xidatafunc getdata = lookup_getdata(interp, obj);
if (getdata == NULL) {
if (!PyErr_Occurred()) {
_set_xid_lookup_failure(interp, obj, NULL);
_set_xid_lookup_failure(state, obj, NULL);
}
return -1;
}
Expand All @@ -241,6 +240,7 @@ _PyObject_GetXIData(PyObject *obj, _PyXIData_t *data)
{
PyThreadState *tstate = PyThreadState_Get();
PyInterpreterState *interp = tstate->interp;
_PyXI_state_t *state = _PyXI_GET_STATE(interp);

// Reset data before re-populating.
*data = (_PyXIData_t){0};
Expand All @@ -252,7 +252,7 @@ _PyObject_GetXIData(PyObject *obj, _PyXIData_t *data)
if (getdata == NULL) {
Py_DECREF(obj);
if (!PyErr_Occurred()) {
_set_xid_lookup_failure(interp, obj, NULL);
_set_xid_lookup_failure(state, obj, NULL);
}
return -1;
}
Expand Down Expand Up @@ -969,6 +969,7 @@ _PyXI_ClearExcInfo(_PyXI_excinfo *info)
static int
_PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState *interp)
{
_PyXI_state_t *state;
assert(!PyErr_Occurred());
switch (code) {
case _PyXI_ERR_NO_ERROR: _Py_FALLTHROUGH;
Expand Down Expand Up @@ -999,7 +1000,8 @@ _PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState *interp)
"failed to apply namespace to __main__");
break;
case _PyXI_ERR_NOT_SHAREABLE:
_set_xid_lookup_failure(interp, NULL, NULL);
state = _PyXI_GET_STATE(interp);
_set_xid_lookup_failure(state, NULL, NULL);
break;
default:
#ifdef Py_DEBUG
Expand Down Expand Up @@ -1061,7 +1063,8 @@ _PyXI_ApplyError(_PyXI_error *error)
}
else if (error->code == _PyXI_ERR_NOT_SHAREABLE) {
// Propagate the exception directly.
_set_xid_lookup_failure(error->interp, NULL, error->uncaught.msg);
_PyXI_state_t *state = _PyXI_GET_STATE(error->interp);
_set_xid_lookup_failure(state, NULL, error->uncaught.msg);
}
else {
// Raise an exception corresponding to the code.
Expand Down Expand Up @@ -1606,9 +1609,9 @@ _propagate_not_shareable_error(_PyXI_session *session)
return;
}
PyInterpreterState *interp = PyInterpreterState_Get();
exceptions_t *state = &_PyInterpreterState_GetXIState(interp)->exceptions;
assert(state->PyExc_NotShareableError != NULL);
if (PyErr_ExceptionMatches(state->PyExc_NotShareableError)) {
_PyXI_state_t *state = _PyXI_GET_STATE(interp);
assert(state->exceptions.PyExc_NotShareableError != NULL);
if (PyErr_ExceptionMatches(state->exceptions.PyExc_NotShareableError)) {
// We want to propagate the exception directly.
session->_error_override = _PyXI_ERR_NOT_SHAREABLE;
session->error_override = &session->_error_override;
Expand Down Expand Up @@ -1779,11 +1782,13 @@ _PyXI_Exit(_PyXI_session *session)
PyStatus
_PyXI_Init(PyInterpreterState *interp)
{
_PyXI_state_t *state = _PyXI_GET_STATE(interp);

// Initialize the XID lookup state (e.g. registry).
if (_Py_IsMainInterpreter(interp)) {
xid_lookup_init(&_PyXI_GET_GLOBAL_STATE(interp)->data_lookup);
}
xid_lookup_init(&_PyXI_GET_STATE(interp)->data_lookup);
xid_lookup_init(&state->data_lookup);

// Initialize exceptions.(heap types).
// See _PyXI_InitTypes() for the static types.
Expand All @@ -1801,12 +1806,14 @@ _PyXI_Init(PyInterpreterState *interp)
void
_PyXI_Fini(PyInterpreterState *interp)
{
_PyXI_state_t *state = _PyXI_GET_STATE(interp);

// Finalize exceptions (heap types).
// See _PyXI_FiniTypes() for the static types.
fini_heap_exctypes(&_PyXI_GET_STATE(interp)->exceptions);

// Finalize the XID lookup state (e.g. registry).
xid_lookup_fini(&_PyXI_GET_STATE(interp)->data_lookup);
xid_lookup_fini(&state->data_lookup);
if (_Py_IsMainInterpreter(interp)) {
xid_lookup_fini(&_PyXI_GET_GLOBAL_STATE(interp)->data_lookup);
}
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/126704/commits/de75cb492bc7dc40fc6d8e9ad52e2f197409c22e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy