Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-76785: Crossinterp utils additions #111530

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
67a88c2
Factor out _Py_excinfo.
ericsnowcurrently Oct 24, 2023
a9ea9ac
Extract _PyXI_errcode.
ericsnowcurrently Oct 25, 2023
33d91af
Extract _PyXI_exception_info.
ericsnowcurrently Oct 25, 2023
2424e33
Extract _PyXI_namespace.
ericsnowcurrently Oct 25, 2023
23d6959
Factor out _enter_interpreter(), _exit_interpreter(), etc.
ericsnowcurrently Oct 23, 2023
b08249f
Move enter/exit to crossinterp.c.
ericsnowcurrently Oct 27, 2023
773f5ab
Factor out _sharednsitem_set_value().
ericsnowcurrently Oct 23, 2023
cf7354e
Add _PyXI_NamespaceFromNames().
ericsnowcurrently Oct 31, 2023
6b43620
Add a default arg to _PyXI_ApplyNamespace().
ericsnowcurrently Oct 31, 2023
caef717
Allocate xid dynamically when in target interpreter.
ericsnowcurrently Oct 31, 2023
0bd42e0
Add _PyXI_FillNamespaceFromDict().
ericsnowcurrently Oct 31, 2023
a230f77
Add xid_state structs and lifecycle funcs.
ericsnowcurrently Oct 31, 2023
5675f86
Add PyExc_NotShareableError.
ericsnowcurrently Oct 31, 2023
45488f2
Propagate the ValueError when a value is not shareable.
ericsnowcurrently Oct 31, 2023
6f07364
Propagate errors in _PyXI_Enter() directly.
ericsnowcurrently Oct 31, 2023
0201b7f
Factor out _init_not_shareable_error_type() and _fini_not_shareable_e…
ericsnowcurrently Nov 1, 2023
d32a918
Drop some duplicate lines.
ericsnowcurrently Nov 1, 2023
1d4fc87
Fix a comment.
ericsnowcurrently Nov 1, 2023
88c9d54
Call _PyXI_Fini() *before* the interpreter is cleared.
ericsnowcurrently Nov 1, 2023
2edcb49
Fix init/fini.
ericsnowcurrently Nov 1, 2023
8e53752
Add _get_not_shareable_error_type().
ericsnowcurrently Nov 1, 2023
53764c1
Export fewer symbols.
ericsnowcurrently Nov 1, 2023
cacf969
Merge branch 'main' into crossinterp-utils-additions
ericsnowcurrently Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add PyExc_NotShareableError.
  • Loading branch information
ericsnowcurrently committed Oct 31, 2023
commit 5675f86ecce18baaaf33433c4ae1c0f8a7f151fb
3 changes: 3 additions & 0 deletions 3 Include/internal/pycore_crossinterp.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ struct _xi_state {
// heap types
// XXX Remove this field once we have a tp_* slot.
struct _xidregistry registry;

// heap types
PyObject *PyExc_NotShareableError;
};

extern PyStatus _PyXI_Init(PyInterpreterState *interp);
Expand Down
69 changes: 50 additions & 19 deletions 69 Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,49 @@ _check_xidata(PyThreadState *tstate, _PyCrossInterpreterData *data)
return 0;
}

crossinterpdatafunc _PyCrossInterpreterData_Lookup(PyObject *);
static crossinterpdatafunc _lookup_getdata_from_registry(
PyInterpreterState *, PyObject *);

/* This is a separate func from _PyCrossInterpreterData_Lookup in order
to keep the registry code separate. */
static crossinterpdatafunc
_lookup_getdata(PyObject *obj)
_lookup_getdata(PyInterpreterState *interp, PyObject *obj)
{
crossinterpdatafunc getdata = _PyCrossInterpreterData_Lookup(obj);
if (getdata == NULL && PyErr_Occurred() == 0)
PyErr_Format(PyExc_ValueError,
/* Cross-interpreter objects are looked up by exact match on the class.
We can reassess this policy when we move from a global registry to a
tp_* slot. */
return _lookup_getdata_from_registry(interp, obj);
}

crossinterpdatafunc
_PyCrossInterpreterData_Lookup(PyObject *obj)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
return _lookup_getdata(interp, obj);
}

static inline void
_set_xid_lookup_failure(PyInterpreterState *interp, PyObject *obj)
{
PyObject *exctype = interp->xi.PyExc_NotShareableError;
assert(exctype != NULL);
if (obj == NULL) {
PyErr_SetString(exctype,
"object does not support cross-interpreter data");
}
else {
PyErr_Format(exctype,
"%S does not support cross-interpreter data", obj);
return getdata;
}
}

int
_PyObject_CheckCrossInterpreterData(PyObject *obj)
{
crossinterpdatafunc getdata = _lookup_getdata(obj);
PyInterpreterState *interp = _PyInterpreterState_GET();
crossinterpdatafunc getdata = _lookup_getdata(interp, obj);
if (getdata == NULL) {
if (!PyErr_Occurred()) {
_set_xid_lookup_failure(interp, obj);
}
return -1;
}
return 0;
Expand All @@ -212,9 +236,12 @@ _PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)

// Call the "getdata" func for the object.
Py_INCREF(obj);
crossinterpdatafunc getdata = _lookup_getdata(obj);
crossinterpdatafunc getdata = _lookup_getdata(interp, obj);
if (getdata == NULL) {
Py_DECREF(obj);
if (!PyErr_Occurred()) {
_set_xid_lookup_failure(interp, obj);
}
return -1;
}
int res = getdata(tstate, obj, data);
Expand Down Expand Up @@ -474,17 +501,11 @@ _PyCrossInterpreterData_UnregisterClass(PyTypeObject *cls)
return res;
}


/* Cross-interpreter objects are looked up by exact match on the class.
We can reassess this policy when we move from a global registry to a
tp_* slot. */

crossinterpdatafunc
_PyCrossInterpreterData_Lookup(PyObject *obj)
static crossinterpdatafunc
_lookup_getdata_from_registry(PyInterpreterState *interp, PyObject *obj)
{
PyTypeObject *cls = Py_TYPE(obj);

PyInterpreterState *interp = _PyInterpreterState_GET();
struct _xidregistry *xidregistry = _get_xidregistry(interp, cls);
PyThread_acquire_lock(xidregistry->mutex, WAIT_LOCK);

Expand Down Expand Up @@ -1286,11 +1307,21 @@ _PyXI_Exit(_PyXI_session *session)
PyStatus
_PyXI_Init(PyInterpreterState *interp)
{
// Initialize NotShareableError (a heap type).
PyObject *exctype = PyErr_NewException("_interpreters.NotShareableError",
PyExc_ValueError, NULL);
if (exctype == NULL) {
PyErr_Clear();
return _PyStatus_ERR("could not initialize NotShareableError");
}
interp->xi.PyExc_NotShareableError = exctype;

return _PyStatus_OK();
}

void
_PyXI_Fini(PyInterpreterState *interp)
{
// For now we don't do anything.
// Dealloc heap type exceptions.
Py_CLEAR(interp->xi.PyExc_NotShareableError);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.