Skip to content

[FFI] Enhance FFI Object exception safety during init #18050

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

Merged
merged 1 commit into from
Jun 8, 2025

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Jun 7, 2025

This PR enhances the exception safety of FFI Object during init. Specifically, when an error is thrown during init before __init_by_constructor chandle can be in a undefined state. Additionally, tools like pytest may try to call repr to get a string repr the object, causing segfault.

This PR fixes the issue by always first initialize chandle to NULL and provide chandle=None special handling so pytest can be happy in such cases.

This PR enhances the exception safety of FFI Object during init.
Specifically, when an error is thrown during init before __init_by_constructor
chandle can be in a undefined state. Additionally, tools like pytest may
try to call repr to get a string repr the object, causing segfault.

This PR fixes the issue by always first initialize chandle to NULL
and provide chandle=None special handling so pytest can be happy
in such cases.
@spectrometerHBH spectrometerHBH merged commit 9cb6705 into apache:main Jun 8, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants