diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-12-17 11:45:29 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-17 11:45:29 (GMT) |
| commit | fe08cdf2657bfde80aeed436fe49fee233651837 (patch) | |
| tree | 3cc805f442713bcf4c92a1044e35da353ba471cd /Python/errors.c | |
| parent | 367ea893847439502e155708539917bf655beb40 (diff) | |
| download | cpython-fe08cdf2657bfde80aeed436fe49fee233651837.zip cpython-fe08cdf2657bfde80aeed436fe49fee233651837.tar.gz cpython-fe08cdf2657bfde80aeed436fe49fee233651837.tar.bz2 | |
[3.13] gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746) (GH-128023)
- Add a helper to set an error from locale-encoded `char*`
- Use the helper for gdbm & dlerror messages
(cherry picked from commit 7303f06846b69016a075bca7ad7c6055f29ad024)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Python/errors.c')
| -rw-r--r-- | Python/errors.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c index bf1ddfa..f19c030 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -299,6 +299,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) |
