Skip to content

Commit 89664d4

Browse files
miss-islingtonZeroIntensitysobolevnpicnixz
authored
[3.13] gh-126223: Propagate unicode errors in _interpreters.create() (GH-126224) (#126242)
gh-126223: Propagate unicode errors in `_interpreters.create()` (GH-126224) (cherry picked from commit 0141521) Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: sobolevn <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent ac00bf0 commit 89664d4

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Lib/test/test_interpreters/test_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def test_in_main(self):
5555
self.assertIsInstance(interp, interpreters.Interpreter)
5656
self.assertIn(interp, interpreters.list_all())
5757

58+
# GH-126221: Passing an invalid Unicode character used to cause a SystemError
59+
self.assertRaises(UnicodeEncodeError, _interpreters.create, '\udc80')
60+
5861
def test_in_thread(self):
5962
lock = threading.Lock()
6063
interp = None
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raise a :exc:`UnicodeEncodeError` instead of a :exc:`SystemError` upon
2+
calling :func:`!_interpreters.create` with an invalid Unicode character.

Modules/_interpretersmodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ config_from_object(PyObject *configobj, PyInterpreterConfig *config)
403403
}
404404
}
405405
else if (PyUnicode_Check(configobj)) {
406-
if (init_named_config(config, PyUnicode_AsUTF8(configobj)) < 0) {
406+
const char *utf8name = PyUnicode_AsUTF8(configobj);
407+
if (utf8name == NULL) {
408+
return -1;
409+
}
410+
if (init_named_config(config, utf8name) < 0) {
407411
return -1;
408412
}
409413
}

0 commit comments

Comments
 (0)