Skip to content

fix: Centralize ManagedResources lifecycle handling#294

Open
tmathern wants to merge 30 commits into
mainfrom
mathern/open-up-api
Open

fix: Centralize ManagedResources lifecycle handling#294
tmathern wants to merge 30 commits into
mainfrom
mathern/open-up-api

Conversation

@tmathern

@tmathern tmathern commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Changes in this pull request

Centralizes ManagedResources lifecycle plumbing (the managed resources holding a native handle) natively and handle their lifecycle. This change introduces a set of new (private) functions on the ManagedResource class for lifecycle management. Some notable additions are:

  • _activate(handle): take ownership of a validated non-null pointer and mark the resource active. Rejects null and double-activation, so a handle can't be activated twice and a closed resource can't be reopened.
  • _swap_handle(new_handle): replace the handle after an FFI call consumed the old one and returned a replacement.
  • _consume_* (family of functions): runs an FFI call that consumes this handle and manages the handle lifecycle as part of the object's lifecycle.
  • _wrap_native_handle(handle): build an instance around an already-owned pointer, bypassing init.
  • _init_attrs(): subclass hook for attribute defaults, called by both init and _wrap_native_handle so an instance built around an existing handle can't be missing state the class reads.

Those are all private APIs for native handling (hence underscore in function name, using and calling them must be very explicit).

Note on fork safety: the owner PID is still stamped on all paths, and the native free is skipped in a foreign process on all teardown paths.

Other changes:

  • Improve error handling by removing function that did not clear previous error (C FFI doesn't clear/do a take on the error either).
  • Switch examples to print crJson (instead of "just JSON").

Checklist

  • This PR represents a single feature, fix, or change.
  • All applicable changes have been documented.
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

Comment thread tests/perf/entrypoint.sh
@tmathern tmathern changed the title (WIP) fix: Centralize ManagedResources lifecycle handling Jul 21, 2026
@tmathern
tmathern requested review from gpeacock and ok-nick July 21, 2026 21:09
@tmathern
tmathern requested a review from ale-adobe July 21, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant