diff options
| author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2024-12-17 12:53:16 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-17 12:53:16 (GMT) |
| commit | e0b61ffa3806cea2739172adf6e2bcbba3d5fba4 (patch) | |
| tree | 9ca0dc2475a275fb2b7904333106fd6d45f33abf /Python/errors.c | |
| parent | 6ac578cf535666283c95dff17d70e4d7de0150e7 (diff) | |
| download | cpython-e0b61ffa3806cea2739172adf6e2bcbba3d5fba4.zip cpython-e0b61ffa3806cea2739172adf6e2bcbba3d5fba4.tar.gz cpython-e0b61ffa3806cea2739172adf6e2bcbba3d5fba4.tar.bz2 | |
[3.12] gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746) (GH-128027)
- 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>
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 cbfc2fa..bfc37f3 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -305,6 +305,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) |
