You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HandleSafety] Add a number of dictionary APIs to make it easier to safely get and set values. - #26829
These new overloads take INativeObject instances instead of plain handles, and as such they can make sure the INativeObject instances aren't collected by the GC too early (instead of each caller having to ensure this).
CFDictionary gains GetValue and GetBooleanValue overloads.
This also required a fix in the handle analyzer: recognize symbol references that occur after a handle access within the same containing statement. This prevents RBI0014 from incorrectly flagging pattern variables that are consumed in an if body after being used in the condition.
Recognize symbol references that occur after a handle access within the same containing statement. This prevents RBI0014 from incorrectly flagging pattern variables that are consumed in an if body after being used in the condition.
Add a regression case covering an INativeObject pattern variable used later in the same if statement.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0eb8114a-c6b4-4dda-9cf6-2fd3f7e5f123
…afely get and set values.
These new overloads take INativeObject instances instead of plain handles, and as such they can make sure the INativeObject instances aren't collected by the GC too early (instead of each caller having to ensure this).
* CFDictionary gains GetValue and GetBooleanValue overloads.
* CFMutableDictionary gains SetValue overloads.
* NSDictionary gains LowlevelObjectForKey overloads.
* NSMutableDictionary gains LowlevelSetObject overloads.
And then update consumers to use these to APIs to fix premature object collection by the GC.
Contributes towards #10146.
Copilot-Session: dd86cf03-297a-43e8-ae1f-3c0b22bb67c4
Adds GC-safe dictionary APIs and migrates consumers away from direct native-handle access. It also updates RBI0014 analysis for same-statement references.
Changes:
Added safe dictionary get/set overloads.
Migrated framework consumers to the new APIs.
Updated analyzer behavior, tests, and known failures.
Keep source wrappers alive through CFArray creation
src/Foundation/DictionaryContainer.cs:669
🤖 ❌ Memory management — This method still extracts raw handles from values before CFArray.FromIntPtrs; changing only the dictionary insertion does not keep the source wrappers alive while CFArrayCreate consumes those handles. Keep values alive through array creation/insertion before removing this method from the handle-safety known failures.
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
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.
These new overloads take INativeObject instances instead of plain handles, and as such they can make sure the INativeObject instances aren't collected by the GC too early (instead of each caller having to ensure this).
And then update consumers to use these to APIs to fix premature object collection by the GC.
Contributes towards #10146.
This also required a fix in the handle analyzer: recognize symbol references that occur after a handle access within the same containing statement. This prevents RBI0014 from incorrectly flagging pattern variables that are consumed in an if body after being used in the condition.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
Copilot-Session: 0eb8114a-c6b4-4dda-9cf6-2fd3f7e5f123