Skip to content
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

gh-126742: allow to use non-UTF8 exception messages #126746

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Contributor

@picnixz picnixz commented Nov 12, 2024

@picnixz picnixz changed the title gh-126742: allow to use translated exception messages gh-126742: allow to use non-UTF8 exception messages Nov 12, 2024
Python/errors.c Outdated
_PyErr_SetLocaleStringTstate(PyThreadState *tstate, PyObject *exception,
const char *string)
{
PyObject *value = PyUnicode_DecodeLocale(string, "strict");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be surrogateescape, not strict:

Suggested change
PyObject *value = PyUnicode_DecodeLocale(string, "strict");
PyObject *value = PyUnicode_DecodeLocale(string, "surrogateescape");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are acceptable and I think it's preferrable to use a strict decoding since a message that is not acceptable by the current locale feels wrong. In addition, using surrogateescape means that for re-encoding the message you need to also pass the "surrogateescape" handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looking around, other usages in the context of error rendering use the "surrogateescape" handler, so I've decided to use it as well.

Python/errors.c Show resolved Hide resolved
@ZeroIntensity
Copy link
Member

Technically, since this is a bugfix, let's wait until #126555 has landed before we merge this, and then address all the uses of dlerror() in this PR.

@ZeroIntensity ZeroIntensity added DO-NOT-MERGE needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Nov 12, 2024
@picnixz
Copy link
Contributor Author

picnixz commented Nov 12, 2024

then address all the uses of dlerror() in this PR.

I actually thought of doing it two PRs. Technically, this specific PR can be merged without waiting for the other and then you can use this interface in the other (rather the other way around).

@ZeroIntensity
Copy link
Member

Eh, I would rather not. Let's not overwhelm someone with thread states and the private API on their first PR :)

@ZeroIntensity ZeroIntensity removed needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes DO-NOT-MERGE labels Nov 13, 2024
@ZeroIntensity
Copy link
Member

I've removed backport labels, per what Petr said in the issue. I think he's right--let's just focus on main with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants