summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2024-12-17 11:12:45 (GMT)
committerGitHub <noreply@github.com>2024-12-17 11:12:45 (GMT)
commit7303f06846b69016a075bca7ad7c6055f29ad024 (patch)
treefa3abb9f0a3b3b18bbd60590cbfb1c3c6a91d70f /Python
parentb9a492b809d8765ee365a5dd3c6ba4e5130a80af (diff)
downloadcpython-7303f06846b69016a075bca7ad7c6055f29ad024.zip
cpython-7303f06846b69016a075bca7ad7c6055f29ad024.tar.gz
cpython-7303f06846b69016a075bca7ad7c6055f29ad024.tar.bz2
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>
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 7f3b4aa..2d362c1 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -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)