-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() #107918
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-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() #107918
Conversation
18896cd
to
3524508
Compare
…Err_Format() Such C API functions as PyErr_SetString(), PyErr_Format(), PyErr_SetFromErrnoWithFilename() and many others no longer crash or ignore errors if it failed to format the error message or decode the filename. Instead, they keep a corresponding error.
3524508
to
b986253
Compare
with self.assertRaises(UnicodeDecodeError): | ||
setstring(ZeroDivisionError, b'\xff') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails without the fix.
with self.assertRaisesRegex(OverflowError, 'not in range'): | ||
PyErr_Format(ZeroDivisionError, b'%c', c_int(-1)) | ||
with self.assertRaisesRegex(ValueError, 'format string'): | ||
PyErr_Format(ZeroDivisionError, b'\xff') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails without the fix.
@methane do you know how to make |
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
…Err_Format() (pythonGH-107918) Such C API functions as PyErr_SetString(), PyErr_Format(), PyErr_SetFromErrnoWithFilename() and many others no longer crash or ignore errors if it failed to format the error message or decode the filename. Instead, they keep a corresponding error. (cherry picked from commit 633ea21) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-108134 is a backport of this pull request to the 3.12 branch. |
… and PyErr_Format() (pythonGH-107918) Such C API functions as PyErr_SetString(), PyErr_Format(), PyErr_SetFromErrnoWithFilename() and many others no longer crash or ignore errors if it failed to format the error message or decode the filename. Instead, they keep a corresponding error.. (cherry picked from commit 633ea21) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-108135 is a backport of this pull request to the 3.11 branch. |
…yErr_Format() (GH-107918) (GH-108135) Such C API functions as PyErr_SetString(), PyErr_Format(), PyErr_SetFromErrnoWithFilename() and many others no longer crash or ignore errors if it failed to format the error message or decode the filename. Instead, they keep a corresponding error. (cherry picked from commit 633ea21)
…yErr_Format() (GH-107918) (#108134) * gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918) Such C API functions as PyErr_SetString(), PyErr_Format(), PyErr_SetFromErrnoWithFilename() and many others no longer crash or ignore errors if it failed to format the error message or decode the filename. Instead, they keep a corresponding error. (cherry picked from commit 633ea21) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> * Define PY_SSIZE_T_CLEAN. --------- Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Such C API functions as PyErr_SetString(), PyErr_Format(), PyErr_SetFromErrnoWithFilename() and many others no longer crash or ignore errors if it failed to format the error message or decode the filename. Instead, they keep a corresponding error.
PyErr_Set*()
functions #107915