bpo-40834: Fix truncate when sending str object with channel (GH-20555)

This commit is contained in:
An Long 2020-06-13 20:26:01 +08:00 committed by GitHub
parent 1c209e3b53
commit 29c117202e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 1 deletions

View File

@ -378,6 +378,9 @@ class ShareableTypeTests(unittest.TestCase):
self._assert_values(i.to_bytes(2, 'little', signed=True)
for i in range(-1, 258))
def test_strs(self):
self._assert_values(['hello world', '你好世界', ''])
def test_int(self):
self._assert_values(itertools.chain(range(-1, 258),
[sys.maxsize, -sys.maxsize - 1]))

View File

@ -0,0 +1 @@
Fix truncate when sending str object with_xxsubinterpreters.channel_send.

View File

@ -1726,7 +1726,7 @@ _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;
shared->len = PyUnicode_GET_LENGTH(obj);
data->data = (void *)shared;
Py_INCREF(obj);
data->obj = obj; // Will be "released" (decref'ed) when data released.