Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 3 additions & 2 deletions Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_default_shareables(self):
shareables = [
# singletons
None,
NotImplemented,
# builtin objects
b'spam',
'spam',
Expand Down Expand Up @@ -126,7 +127,6 @@ class SubBytes(bytes):

not_shareables = [
# singletons
NotImplemented,
...,
# builtin types and objects
type,
Expand Down Expand Up @@ -156,13 +156,14 @@ def _assert_values(self, values):
self.assertIs(type(got), type(obj))

def test_singletons(self):
for obj in [None]:
for obj in [None, NotImplemented]:
with self.subTest(obj):
xid = _testinternalcapi.get_crossinterp_data(obj)
got = _testinternalcapi.restore_crossinterp_data(xid)

# XXX What about between interpreters?
self.assertIs(got, obj)
self.assertIs(type(got), type(obj))

def test_types(self):
self._assert_values([
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ def test_default_shareables(self):
shareables = [
# singletons
None,
NotImplemented,
# builtin objects
b'spam',
'spam',
Expand Down Expand Up @@ -1127,7 +1128,6 @@ class SubBytes(bytes):

not_shareables = [
# singletons
NotImplemented,
...,
# builtin types and objects
type,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for sharing ``NotImplemented`` singleton with subinterpreters.
24 changes: 24 additions & 0 deletions Python/crossinterp_data_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ _none_shared(PyThreadState *tstate, PyObject *obj,
return 0;
}

// NotImplemented

static PyObject *
_new_notimplemented_object(_PyCrossInterpreterData *data)
{
return Py_NewRef(Py_NotImplemented);
}

static int
_notimplemented_shared(PyThreadState *tstate, PyObject *obj,
_PyCrossInterpreterData *data)
{
_PyCrossInterpreterData_Init(data, tstate->interp, NULL, NULL,
_new_notimplemented_object);
return 0;
}

// bool

static PyObject *
Expand Down Expand Up @@ -562,6 +579,13 @@ _register_builtins_for_crossinterpreter_data(struct _xidregistry *xidregistry)
Py_FatalError("could not register None for cross-interpreter sharing");
}

// NotImplemented
if (_xidregistry_add_type(xidregistry,
(PyTypeObject *)PyObject_Type(Py_NotImplemented),
_notimplemented_shared) != 0) {
Py_FatalError("could not register NotImplemented for cross-interpreter sharing");
}
Comment on lines +588 to +593
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we generalize this with a macro? (Future refactoring)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Last I heard, Eric's plan was to eventually get a dedicated type slot for crossinterpreter registry things, so this will (hopefully) be obsolete sooner than later.


// int
if (_xidregistry_add_type(xidregistry, &PyLong_Type, _long_shared) != 0) {
Py_FatalError("could not register int for cross-interpreter sharing");
Expand Down