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

Handling errors in ctypes callbacks #129502

Closed
serhiy-storchaka opened this issue Jan 31, 2025 · 1 comment
Closed

Handling errors in ctypes callbacks #129502

serhiy-storchaka opened this issue Jan 31, 2025 · 1 comment
Labels
extension-modules C modules in the Modules dir topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jan 31, 2025

If an error happens in the callback or in converting result of the callback, it is handled by calling PyErr_FormatUnraisable(). If an error happens in preparing arguments for the callback, it is handled in different way -- some message is printed to stderr and then PyErr_Print() is called. In one case the error is not properly handled.

It is better to handle all errors in the uniform way. PyErr_Print() is not suitable for it because it treats SystemExit specially and has a side effect of setting sys.last_exc` and other variables.

Linked PRs

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jan 31, 2025
Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
serhiy-storchaka added a commit that referenced this issue Jan 31, 2025
Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 31, 2025
…9504)

Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
(cherry picked from commit 9d63ae5)

Co-authored-by: Serhiy Storchaka <[email protected]>
@picnixz picnixz added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Jan 31, 2025
Yhg1s pushed a commit that referenced this issue Feb 4, 2025
…#129517)

gh-129502: Fix handling errors in ctypes callbacks (GH-129504)

Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
(cherry picked from commit 9d63ae5)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Feb 4, 2025
…onGH-129504)

Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
(cherry picked from commit 9d63ae5)

Co-authored-by: Serhiy Storchaka <[email protected]>
Yhg1s pushed a commit that referenced this issue Feb 4, 2025
…#129639)

Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
(cherry picked from commit 9d63ae5)
@hugovk
Copy link
Member

hugovk commented Feb 5, 2025

Triage: PR merged and backported. Please re-open if there's more to do.

@hugovk hugovk closed this as completed Feb 5, 2025
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Feb 7, 2025
…9504)

Unlikely errors in preparing arguments for ctypes callback are now
handled in the same way as errors raised in the callback of in converting
the result of the callback -- using sys.unraisablehook() instead of
sys.excepthook() and not setting sys.last_exc and other variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir topic-ctypes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants