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

Miss Islington (bot) webhook-mailer at python.org
Sat Jun 13 08:44:55 EDT 2020


https://github.com/python/cpython/commit/26db10a431bf5b55340f4427bf015719e384d306
commit: 26db10a431bf5b55340f4427bf015719e384d306
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-06-13T05:44:50-07:00
summary:

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

(cherry picked from commit 29c117202e386bad1d66ae336e2fefa1a1809ee0)

Co-authored-by: An Long <aisk at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst
M Lib/test/test__xxsubinterpreters.py
M Python/pystate.c

diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py
index 30f8f98acc9dd..f14868ad8cb35 100644
--- a/Lib/test/test__xxsubinterpreters.py
+++ b/Lib/test/test__xxsubinterpreters.py
@@ -392,6 +392,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/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 0000000000000..272783773ff94
--- /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
diff --git a/Python/pystate.c b/Python/pystate.c
index 3e1085568b61a..b1d0f1cbec428 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1639,7 +1639,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.



More information about the Python-checkins mailing list