8000 bpo-32604: Improve subinterpreter tests. by ericsnowcurrently · Pull Request #6914 · python/cpython · GitHub
[go: up one dir, main page]

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 str.
  • Loading branch information
ericsnowcurrently committed May 16, 2018
commit 13c51d497d8a73d9c78d3095f6688f6d2e0897a0
4 changes: 2 additions & 2 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def test_default_shareables(self):
None,
10000 # builtin objects
b'spam',
'spam',
10,
-10,
]
Expand Down Expand Up @@ -338,14 +339,13 @@ class SubBytes(bytes):
object(),
Exception(),
100.0,
'spam',
# user-defined types and objects
Cheese,
Cheese('Wensleydale'),
SubBytes(b'spam'),
]
for obj in not_shareables:
with self.subTest(obj):
with self.subTest(repr(obj)):
self.assertFalse(
interpreters.is_shareable(obj))

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

struct _shared_str_data {
int kind;
const void *buffer;
Py_ssize_t len;
};

static PyObject *
_new_str_object(_PyCrossInterpreterData *data)
{
struct _shared_str_data *shared = (struct _shared_str_data *)(data->data);
return PyUnicode_FromKindAndData(shared->kind, shared->buffer, shared->len);
}

static int
_str_shared(PyObject *obj, _PyCrossInterpreterData *data)
{
struct _shared_str_data *shared = PyMem_NEW(struct _shared_str_data, 1);
shared->kind = PyUnicode_KIND(obj);
shared->buffer = PyUnicode_DATA(obj);
shared->len = PyUnicode_GET_LENGTH(obj) - 1;
data->data = (void *)shared;
data->obj = obj; // Will be "released" (decref'ed) when data released.
data->new_object = _new_str_object;
data->free = PyMem_Free;
return 0;
}

static PyObject *
_new_long_object(_PyCrossInterpreterData *data)
{
Expand Down Expand Up @@ -1420,6 +1447,11 @@ _register_builtins_for_crossinterpreter_data(void)
if (_register_xidata(&PyBytes_Type, _bytes_shared) != 0) {
Py_FatalError("could not register bytes for cross-interpreter sharing");
}

// str
if (_register_xidata(&PyUnicode_Type, _str_shared) != 0) {
Py_FatalError("could not register str for cross-interpreter sharing");
}
}


Expand Down
0