Skip to content

Commit

Permalink
gh-126223: Propagate unicode errors in _interpreters.create() (#126224
Browse files Browse the repository at this point in the history
)

Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent 8c22eba commit 0141521
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def test_in_main(self):
self.assertIsInstance(interp, interpreters.Interpreter)
self.assertIn(interp, interpreters.list_all())

# GH-126221: Passing an invalid Unicode character used to cause a SystemError
self.assertRaises(UnicodeEncodeError, _interpreters.create, '\udc80')

def test_in_thread(self):
lock = threading.Lock()
interp = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise a :exc:`UnicodeEncodeError` instead of a :exc:`SystemError` upon
calling :func:`!_interpreters.create` with an invalid Unicode character.
6 changes: 5 additions & 1 deletion Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ config_from_object(PyObject *configobj, PyInterpreterConfig *config)
}
}
else if (PyUnicode_Check(configobj)) {
if (init_named_config(config, PyUnicode_AsUTF8(configobj)) < 0) {
const char *utf8name = PyUnicode_AsUTF8(configobj);
if (utf8name == NULL) {
return -1;
}
if (init_named_config(config, utf8name) < 0) {
return -1;
}
}
Expand Down

0 comments on commit 0141521

Please sign in to comment.