Skip to content

bpo-32604: Improve subinterpreter tests. #6914

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 18 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add support for int.
  • Loading branch information
ericsnowcurrently committed May 16, 2018
commit 49e80652bf1cf604b8b589823de91109b61f28a5
44 changes: 43 additions & 1 deletion Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def test_default_shareables(self):
None,
# builtin objects
b'spam',
10,
-10,
]
for obj in shareables:
with self.subTest(obj):
Expand Down Expand Up @@ -110,7 +112,6 @@ class SubBytes(bytes):
object,
object(),
Exception(),
42,
100.0,
'spam',
# user-defined types and objects
Expand All @@ -124,6 +125,47 @@ class SubBytes(bytes):
interpreters.is_shareable(obj))


class ShareableTypeTests(unittest.TestCase):

def setUp(self):
super().setUp()
self.cid = interpreters.channel_create()

def tearDown(self):
interpreters.channel_destroy(self.cid)
super().tearDown()

def _assert_values(self, values):
for obj in values:
with self.subTest(obj):
interpreters.channel_send(self.cid, obj)
got = interpreters.channel_recv(self.cid)

self.assertEqual(got, obj)
self.assertIs(type(got), type(obj))
# XXX Check the following in the channel tests?
#self.assertIsNot(got, obj)

def test_singletons(self):
for obj in [None]:
with self.subTest(obj):
interpreters.channel_send(self.cid, obj)
got = interpreters.channel_recv(self.cid)

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

def test_types(self):
self._assert_values([
b'spam',
9999,
self.cid,
])

def test_int(self):
self._assert_values(range(-1, 258))


##################################
# interpreter tests

Expand Down
28 changes: 28 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,29 @@ _bytes_shared(PyObject *obj, _PyCrossInterpreterData *data)
return 0;
}

static PyObject *
_new_long_object(_PyCrossInterpreterData *data)
{
return PyLong_FromLongLong((int64_t)(data->data));
}

static int
_long_shared(PyObject *obj, _PyCrossInterpreterData *data)
{
int64_t value = PyLong_AsLongLong(obj);
if (value == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_SetString(PyExc_OverflowError, "try sending as bytes");
}
return -1;
}
data->data = (void *)value;
data->obj = NULL;
data->new_object = _new_long_object;
data->free = NULL;
return 0;
}

static PyObject *
_new_none_object(_PyCrossInterpreterData *data)
{
Expand All @@ -1374,6 +1397,11 @@ _register_builtins_for_crossinterpreter_data(void)
Py_FatalError("could not register None for cross-interpreter sharing");
}

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

// bytes
if (_register_xidata(&PyBytes_Type, _bytes_shared) != 0) {
Py_FatalError("could not register bytes for cross-interpreter sharing");
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy