]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40834: Fix truncate when sending str object with channel (GH-20555)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 13 Jun 2020 12:44:38 +0000 (05:44 -0700)
committerGitHub <noreply@github.com>
Sat, 13 Jun 2020 12:44:38 +0000 (05:44 -0700)
(cherry picked from commit 29c117202e386bad1d66ae336e2fefa1a1809ee0)

Co-authored-by: An Long <aisk@users.noreply.github.com>
Lib/test/test__xxsubinterpreters.py
Misc/NEWS.d/next/Library/2020-05-31-15-52-18.bpo-40834.MO9_hb.rst [new file with mode: 0644]
Python/pystate.c

index e17bfde2c2f75accfbf17bbd75652c9c50337d66..7aec021fb19a5e6707c129a5cb9c6aad8a0ce441 100644 (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]))
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 (file)
index 0000000..2727837
--- /dev/null
@@ -0,0 +1 @@
+Fix truncate when sending str object with_xxsubinterpreters.channel_send.
\ No newline at end of file
index 071b976ff634f66c062a6a17f7ac4e9d67e18082..9beefa8e20c444d1664f65c70782bf1239e61bdf 100644 (file)
@@ -1708,7 +1708,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.