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
Incorrect error handling for APIs that can raise exceptions #105375
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Check for error after each call to PyUnicode_FromStringAndSize().
…pythonGH-105412) Check for error after each call to PyUnicode_FromStringAndSize(). (cherry picked from commit a24a780) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
…pythonGH-105412) Check for error after each call to PyUnicode_FromStringAndSize(). (cherry picked from commit a24a780) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Error handling was deferred in some cases, which could potentially lead to exceptions being overwritten.
There were many "init" functions of C extensions calling all C functions without checking for exceptions, and only checking for exceptions once at the end. Most of them have been fixed with better error checking, but not all of them yet. |
See issue #105374 about C API being error prone: when it's unclear if passing NULL was done on purpose or by mistake |
See also capi-workgroup/problems#47 |
Improve error handling so init bails on the first exception.
Fix a bug where an exception could end up being overwritten.
Bail on first error in heapctypesubclasswithfinalizer_finalize()
Bail on first error to prevent exceptions from possibly being overwritten.
Bail on first error to prevent exceptions from possibly being overwritten.
Bail on first error in heapctypesubclasswithfinalizer_finalize()
…honGH-105608) Bail on first error in heapctypesubclasswithfinalizer_finalize() (cherry picked from commit d636d7dfe714e7168b342c7ea5f9f9d3b3569ed0) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Wow, it was a productive night! Great work! |
For example, in the collation callback two
str
objects (string1
andstring2
) are created usingPyUnicode_FromStringAndSize
. Error handling should happen directly after each call toPyUnicode_FromStringAndSize
:cpython/Modules/_sqlite/connection.c
Lines 1870 to 1875 in 0cb6b9b
Other cases where error handling is not done immediately after the API has been used:
cpython/Modules/_pickle.c
Lines 1680 to 1682 in 264a011
zoneinfo
module #105586_testcapi/heaptype.c
#105608I might have missed some; I did not do a complete audit yet.
Linked PRs
zoneinfo
module #105586_testcapi/heaptype.c
#105608zoneinfo
module (GH-105586) #105612zoneinfo
module (GH-105586) #105613_testcapi/heaptype.c
(GH-105608) #105615The text was updated successfully, but these errors were encountered: