Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -1101,6 +1101,7 @@ def test_default_shareables(self):
shareables = [
# singletons
None,
NotImplemented,
# builtin objects
b'spam',
'spam',
Expand Down Expand Up @@ -1129,7 +1130,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 :data:`NotImplemented` singleton between subinterpreters.
25 changes: 25 additions & 0 deletions Python/crossinterp_data_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@
return 0;
}

// NotImplemented

static PyObject *
_new_notimplemented_object(_PyCrossInterpreterData *data)

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-22.04-arm)

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 444 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

unknown type name ‘_PyCrossInterpreterData’
{
assert(_Py_IsImmortal(Py_NotImplemented));
return Py_NotImplemented;
}

static int
_notimplemented_shared(PyThreadState *tstate, PyObject *obj,
_PyCrossInterpreterData *data)

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-22.04-arm)

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'_PyCrossInterpreterData': name in formal parameter list illegal [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'_PyCrossInterpreterData': name in formal parameter list illegal [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_PyCrossInterpreterData': name in formal parameter list illegal [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

syntax error: missing ')' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'_PyCrossInterpreterData': name in formal parameter list illegal [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

syntax error: missing '{' before '*' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

expected '(' to follow 'data' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

unknown type name ‘_PyCrossInterpreterData’

Check failure on line 452 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

unknown type name ‘_PyCrossInterpreterData’
{
_PyCrossInterpreterData_Init(data, tstate->interp, NULL, NULL,
_new_notimplemented_object);
return 0;
}

// bool

static PyObject *
Expand Down Expand Up @@ -567,6 +585,13 @@
Py_FatalError("could not register None for cross-interpreter sharing");
}

// NotImplemented
if (_xidregistry_add_type(xidregistry,
(PyTypeObject *)PyObject_Type(Py_NotImplemented),
_notimplemented_shared) != 0) {

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘_notimplemented_shared’ undeclared (first use in this function)

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-22.04-arm)

‘_notimplemented_shared’ undeclared (first use in this function)

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'_notimplemented_shared': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'function': 'xidatafunc' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'_xidregistry_add_type': different types for formal and actual parameter 3 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

‘_notimplemented_shared’ undeclared (first use in this function)

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'_notimplemented_shared': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'function': 'xidatafunc' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'_xidregistry_add_type': different types for formal and actual parameter 3 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_notimplemented_shared': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'function': 'xidatafunc' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_xidregistry_add_type': different types for formal and actual parameter 3 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

‘_notimplemented_shared’ undeclared (first use in this function)

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'_notimplemented_shared': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'function': 'xidatafunc' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'_xidregistry_add_type': different types for formal and actual parameter 3 [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Cross build Linux

‘_notimplemented_shared’ undeclared (first use in this function)

Check failure on line 591 in Python/crossinterp_data_lookup.h

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

‘_notimplemented_shared’ undeclared (first use in this function)
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
Loading