-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to set non-UTF8 exception messages #126742
Comments
Let's actually mark it as a bugfix since we'll need to backport it in order to use it later. |
Hmm, so is |
For now, but maybe we can directly expose to the C API? I want to be consistent with the naming of each function. |
Nevermind, there is a precedent: |
How many places in the code would use this helper? I don't see the advantage over calling |
There are a few occurrences of NVM: the |
I don't think it's worth it to add a project-wide helper here. Calling the 2 functions should be fine. |
My main arguments for adding a new internal function would be that a) it helps remove the risk of reference leaks (which in my experience, are all too common when dealing with string mutations) and b) makes it easier to deal with locale in the future (we have incorrect uses of |
As far as I know, this is not a bug on any supported platforms, and so can't be tested in our CI. It's also not been reported/patched on any other platform I know of. I don't know if it should be called a “bug” (that's more a question about the definition of the term), but I don't think a fix for this issue should be backported. Let's just improve As for the helper: IMO, it's better to first fix the code, and then, if it makes sense, refactor to add a helper. In clear-cut cases you'd combine the steps in one commit, but let's not do that here. |
FWIW, I did find BPO-41894 when looking through the places where we use |
I do not mind to add a private helper if it can be used in multiple files, but I am not sure about a public API. It is just a combination of two functions, and this pattern may be not so common. Some examples in the PR looks wrong. Set an error with locale-decoded error message, then clear it and set an error with utf8-decoded error message -- this pattern looks very wrong. |
This pattern is actually a way to fallback to a generic message. Otherwise, there will be no error message at all, which can be more confusing IMO. We only clear the error if the decoding fails (for whatever reason). Such pattern already existed when handling |
…ages (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>
We just merged the PR for |
…r messages (pythonGH-126746) - Add a helper to set an error from locale-encoded `char*` - Use the helper for gdbm & dlerror messages (cherry picked from commit 7303f06) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
…or 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 7303f06) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
…r messages (pythonGH-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>
I changed the labels since we decideed to eventually treat this as a bug fix. |
Avoid checking for library filename in `dlerror()` error messages of test_ctypes.
…ythonGH-128034) Avoid checking for library filename in `dlerror()` error messages of test_ctypes. (cherry picked from commit 335e24f) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…ythonGH-128034) Avoid checking for library filename in `dlerror()` error messages of test_ctypes. (cherry picked from commit 335e24f) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…ythonGH-128025) (cherry picked from commit 2610bcc) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…ythonGH-128025) (cherry picked from commit 2610bccfdf55bc6519808f8e1b5db2cfb03ae809) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Feature or enhancement
Proposal:
This is a follow-up to the discussion in #126555 (comment).
dlerror()
may return non-UTF-8 messages, possibly translated. We should be able to set exception messages according to the current locale. To that end, we'll expose some internal helper:cc @ZeroIntensity @encukou
For now, both functions would be only declared as
extern
and not part of the public C API.Linked PRs
gh-126742: allow to use non-UTF8 exception messages #126746
[3.13] gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746) #128023
[3.12] gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746) #128027
gh-126742: avoid checking for library filename in
dlerror()
error messages #128034[3.13] gh-126742: Avoid checking for library filename in test_ctypes (GH-128034) #128056
[3.12] gh-126742: Avoid checking for library filename in test_ctypes (GH-128034) #128057
gh-126742: add missing NEWS entry #128025
[3.13] gh-126742: add NEWS entry for fix of localized error messages (GH-128025) #128059
[3.12] gh-126742: add NEWS entry for fix of localized error messages (GH-128025) #128060
The text was updated successfully, but these errors were encountered: