Repository navigation
Weak collections: read-only clear, explicit WeakReference tracking, reentrant clear, and stale counts (#1497) - #1503
Merged
ctrlaltca merged 2 commits intoNov 9, 2026
Conversation
…eentrant clear, and stale counts (pradosoft#1497)
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1497. Found by the second Collections path audit.
TWeakMap:clear()had no read-only check, soclear()andcopyFrom()emptied a read-only map, andcopyFrom(['b' => 2])emptied it and then threw. It now throwsmap_readonlylikeTMapand leaves the map unchanged.WeakReference:TWeakListandTWeakMaptracked the reference, which the collection holds strongly, so a collected referent was never scrubbed. A reference to aTEventHandleralso droveTWeakList's handler count to -1 on removal. Add and remove now track the referent.clear(): all three collections crashed when a destructor removed another entry during the clear. Each now re-reads its live state on every pass and ends empty.TWeakCallableCollection: turningDiscardInvalidon threwlist_readonly, against its documentation. It now removes collected entries asTWeakListandTWeakMapdo.clear()resets the handler count, and removing a dead handler withDiscardInvalidfalse now decrements it.TWeakListandTWeakCallableCollectiontrack an item after the insert succeeds, so a failed insert leaves no bookkeeping.Behavior to review:
TWeakListwithDiscardInvalidon that holds only collected entries now clears without error, asTWeakMapdoes; it scrubs first and then has nothing to remove. It used to throwlist_readonly.WeakReferenceto aTEventHandleris treated as a plain weak object: the handler itself is tracked, and it is not counted as an event handler.Not changed: if a destructor calls
remove()on an entryclear()has already removed,TWeakListandTWeakCallableCollectionstill throwlist_item_inexistentout ofclear(), because swallowing it would hide real errors. The trait docblock records this.detachEventHandler()catches it and returns false.26 regression tests, passing with and without Xdebug develop mode. Those tests and #1498 pass together.