mirror of
https://github.com/python/cpython.git
synced 2025-11-11 02:52:04 +00:00
[3.13] gh-132171: Fix _interpreters.run_string crash on string subclass (GH-132173) (#132219)
gh-132171: Fix `_interpreters.run_string` crash on string subclass (GH-132173)
(cherry picked from commit 3980718710)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
71b537572a
commit
6afab81f72
3 changed files with 8 additions and 1 deletions
|
|
@ -745,6 +745,12 @@ def test_bytes_for_script(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
_interpreters.run_string(self.id, b'print("spam")')
|
_interpreters.run_string(self.id, b'print("spam")')
|
||||||
|
|
||||||
|
def test_str_subclass_string(self):
|
||||||
|
class StrSubclass(str): pass
|
||||||
|
|
||||||
|
output = _run_output(self.id, StrSubclass('print(1 + 2)'))
|
||||||
|
self.assertEqual(output, '3\n')
|
||||||
|
|
||||||
def test_with_shared(self):
|
def test_with_shared(self):
|
||||||
r, w = os.pipe()
|
r, w = os.pipe()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Fix crash of ``_interpreters.run_string`` on string subclasses.
|
||||||
|
|
@ -331,7 +331,7 @@ get_code_str(PyObject *arg, Py_ssize_t *len_p, PyObject **bytes_p, int *flags_p)
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
if (PyUnicode_Check(arg)) {
|
if (PyUnicode_Check(arg)) {
|
||||||
assert(PyUnicode_CheckExact(arg)
|
assert(PyUnicode_Check(arg)
|
||||||
&& (check_code_str((PyUnicodeObject *)arg) == NULL));
|
&& (check_code_str((PyUnicodeObject *)arg) == NULL));
|
||||||
codestr = PyUnicode_AsUTF8AndSize(arg, &len);
|
codestr = PyUnicode_AsUTF8AndSize(arg, &len);
|
||||||
if (codestr == NULL) {
|
if (codestr == NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue