From 990757a7b1d2b21715a9593db580dec6a7299579 Mon Sep 17 00:00:00 2001 From: An Long Date: Sun, 31 May 2020 23:46:25 +0800 Subject: [PATCH 1/2] bpo-40834: Fix truncate when sending str object with channel --- Lib/test/test__xxsubinterpreters.py | 3 +++ Python/pystate.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index e17bfde2c2f75a..7aec021fb19a5e 100644 --- a/Lib/test/test__xxsubinterpreters.py +++ b/Lib/test/test__xxsubinterpreters.py @@ -378,6 +378,9 @@ def test_bytes(self): 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])) diff --git a/Python/pystate.c b/Python/pystate.c index 119fe31a84ba12..df6250f38aedfe 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1735,7 +1735,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. From caf432c86e9fee2be9aec3fe8f3a3b127a3b87c8 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 31 May 2020 15:52:20 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst diff --git a/Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst b/Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst new file mode 100644 index 00000000000000..272783773ff940 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst @@ -0,0 +1 @@ +Fix truncate when sending str object with_xxsubinterpreters.channel_send. \ No newline at end of file