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

Model relinquished instances as a separate state from not-ready #591

Merged
merged 1 commit into from
May 23, 2024

Conversation

oremanj
Copy link
Contributor

@oremanj oremanj commented May 23, 2024

Instances become relinquished when the object they wrap has its ownership transferred to a C++ unique_ptr. Unlike ready instances, they can't be validly accessed (because the C++ object might have been destroyed without our knowledge). Unlike non-ready instances, they can't be validly constructed (because the C++ object might still be within its lifetime). They need a new state. This PR handles them by expanding the previous nb_inst::ready flag into a two-bit field nb_inst::state. Due to a careful choice of which number represents which state, this should have negligible overhead.

Fixes #550.

@wjakob
Copy link
Owner

wjakob commented May 23, 2024

Awesome, this looks great!

@wjakob wjakob merged commit 16a48d2 into wjakob:master May 23, 2024
24 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.

[BUG]: instance relinquished to unique_ptr can be reinitialized from Python, leading to state confusion
2 participants