gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746)

- Add a helper to set an error from locale-encoded `char*`
- Use the helper for gdbm & dlerror messages

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Bénédikt Tran 2024-12-17 12:12:45 +01:00 committed by GitHub
parent b9a492b809
commit 7303f06846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 176 additions and 69 deletions

View file

@ -301,6 +301,15 @@ PyErr_SetString(PyObject *exception, const char *string)
_PyErr_SetString(tstate, exception, string);
}
void
_PyErr_SetLocaleString(PyObject *exception, const char *string)
{
PyObject *value = PyUnicode_DecodeLocale(string, "surrogateescape");
if (value != NULL) {
PyErr_SetObject(exception, value);
Py_DECREF(value);
}
}
PyObject* _Py_HOT_FUNCTION
PyErr_Occurred(void)