gh-126223: Propagate unicode errors in `_interpreters.create()` (#126224)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Peter Bierma 2024-10-31 10:14:37 -04:00 committed by GitHub
parent 8c22eba877
commit 01415213d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -54,6 +54,9 @@ class CreateTests(TestBase):
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

View File

@ -0,0 +1,2 @@
Raise a :exc:`UnicodeEncodeError` instead of a :exc:`SystemError` upon
calling :func:`!_interpreters.create` with an invalid Unicode character.

View File

@ -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;
}
}