Skip to content

[FFI] Make Object::unique() require no weak references - #731

Merged
tqchen merged 1 commit into
apache:mainfrom
tqchen:ffi-object-unique-no-weak-refs
Sep 2, 2026
Merged

[FFI] Make Object::unique() require no weak references#731
tqchen merged 1 commit into
apache:mainfrom
tqchen:ffi-object-unique-no-weak-refs

Conversation

@tqchen

@tqchen tqchen commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Make Object::unique() require one strong reference and no external weak references by comparing the packed count with kCombinedRefCountBothOne.
  • Delegate ObjectPtr<T>::unique() to the object-level implementation while leaving strong-only use_count() semantics unchanged.
  • Add focused coverage for uniqueness while a WeakObjectPtr is live.

Rationale

unique() gates copy-on-write and in-place mutation. A live weak pointer can still upgrade while the object has a strong owner, so strong-only uniqueness is insufficient for safely choosing in-place mutation. Comparing the combined counter also observes both halves in one atomic load.

Compatibility

Out-of-tree users that retain weak references may now copy instead of mutating in place. Current production call sites without weak references retain their existing behavior.

@tqchen
tqchen merged commit 0cfb9a9 into apache:main Sep 2, 2026
9 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