[Foundation] Improve NSArray.ArrayFromHandle significantly.#24808
[Foundation] Improve NSArray.ArrayFromHandle significantly.#24808rolfbjarne merged 5 commits intomainfrom
Conversation
* Enable nullability.
* Introduce numerous variations of ArrayFromHandle to handle various scenarios
related to nullability:
* NonNullArrayFromHandle: returns an empty array if the native array is null.
* ArrayFromHandleDropNullElements: returns an array that will never have any null elements.ç
* NonNullArrayFromHandleDropNullElements: both of the above.
* Update consumers to use the best variation.
Theoretically these changes may end up changing behavior, if there are native arrays
with NSNull elements, in which case we'll now convert them to managed arrays without
null elements for some APIs.
Contributes towards #17285.
Add test coverage for modified methods that previously lacked tests: - CAGradientLayer.Colors (get/set) - MLModel.AllComputeDevices - GKObstacleGraph.GetNodes - NSArray_GameplayKit.GetShuffledArray - VNRequest.GetResults<T> - CTFont.GetAvailableTables - SecIdentity2.Certificates Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates Foundation’s NSArray.ArrayFromHandle family to be nullability-aware and adds helper variants to control behavior for null native arrays and NSNull elements, then updates a set of framework consumers and adds regression tests for the adjusted APIs.
Changes:
- Enable/expand
NSArray.ArrayFromHandleAPIs to support nullable returns and configurable handling ofNSNull/null elements (including “drop null elements” and “non-null array” variants). - Update multiple framework APIs to use the most appropriate
NSArray.*FromHandle*variant and adjust public signatures where needed (e.g.,T[]?). - Add new unit tests for affected APIs and adjust cecil known-failure baselines.
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/monotouch-test/Vision/VNRequestGetResultsTest.cs | Adds tests for VNRequest.GetResults<T> null vs non-null behavior. |
| tests/monotouch-test/Security/IdentityTest.cs | Adds a test for SecIdentity2.Certificates. |
| tests/monotouch-test/GameplayKit/NSArrayGameplayKitTest.cs | Adds tests for NSArray_GameplayKit.GetShuffledArray. |
| tests/monotouch-test/GameplayKit/GKObstacleGraphTest.cs | Adds test coverage for GKObstacleGraph.GetNodes behavior. |
| tests/monotouch-test/CoreText/CTFontGetAvailableTablesTest.cs | Adds test for CTFont.GetAvailableTables. |
| tests/monotouch-test/CoreML/MLModelTest.cs | Adds test for MLModel.AllComputeDevices. |
| tests/monotouch-test/CoreAnimation/CAGradientLayerTest.cs | Adds test for CAGradientLayer.Colors get/set semantics. |
| tests/cecil-tests/HandleSafety.KnownFailures.cs | Removes a known failure entry now presumably fixed by handle-safety changes. |
| tests/cecil-tests/Documentation.KnownFailures.txt | Updates doc known failures to reflect updated NSArray API surface. |
| src/frameworks.sources | Includes new Foundation/NSNullBehavior.cs in the build. |
| src/Vision/VNRequest.cs | Makes GetResults<T> nullable and switches to dropping null elements. |
| src/VideoToolbox/VTRawProcessingSession.cs | Switches to null-dropping array conversions and uses releaseHandle: true. |
| src/UIKit/UICellAccessory.cs | Uses non-null + drop-null-elements conversion for accessories array. |
| src/Security/Trust.cs | Makes GetCertificateChain nullable and drops null elements. |
| src/Security/SecTrust.cs | Makes GetPolicies/GetCustomAnchorCertificates nullable and drops null elements. |
| src/Security/SecIdentity2.cs | Makes Certificates nullable and uses releaseHandle: true conversion. |
| src/Security/ImportExport.cs | Makes PKCS#12 out-array nullable and uses drop-null-elements conversion with release. |
| src/Security/Certificate.cs | Updates PKCS#12 import consumption for new nullable out-array. |
| src/Photos/PHFetchResult.cs | Returns non-null array (nullable elements) for ObjectsAt<T>. |
| src/ObjCRuntime/RegistrarHelper.cs | Adjusts marshaling helper array nullability annotations. |
| src/Network/NWEndpoint.cs | Removes unused FromNSArrayHandle helper. |
| src/NaturalLanguage/NLVectorDictionary.cs | Makes indexers nullable and drops null elements during float extraction. |
| src/Metal/MTLDevice.cs | Makes GetAllDevices nullable and uses new array conversion helpers; fixes observer ownership. |
| src/MediaPlayer/MPNowPlayingInfoCenter.cs | Drops null elements when converting language option arrays. |
| src/GameplayKit/NSArray_GameplayKit.cs | Uses non-null + drop-null-elements conversions for shuffled arrays. |
| src/GameplayKit/GKObstacleGraph.cs | Makes GetNodes nullable and drops null elements for results. |
| src/Foundation/NSUrlSessionHandler.cs | Handles nullable certificate chain results under Xcode 13+ path. |
| src/Foundation/NSSet.cs | Uses non-null + drop-if-incompatible conversion for ToArray<T>. |
| src/Foundation/NSOrderedSet.cs | Uses non-null + drop-if-incompatible conversion for ToArray<T>. |
| src/Foundation/NSNullBehavior.cs | Introduces internal enum to configure NSNull handling. |
| src/Foundation/NSMutableDictionary_2.cs | Uses non-null + drop-if-incompatible conversions for Keys/Values-related APIs. |
| src/Foundation/NSDictionary_2.cs | Uses non-null + drop-if-incompatible conversions for Keys/Values-related APIs. |
| src/Foundation/NSArray.cs | Core change: expands ArrayFromHandle APIs for nullability and NSNull handling variants. |
| src/Foundation/DictionaryContainer.cs | Switches array extraction to drop null elements. |
| src/CoreVideo/CVPixelFormatDescription.cs | Uses non-null + drop-null-elements conversion for AllTypes. |
| src/CoreText/CTFontManager.cs | Replaces local helper with new array conversion helpers, including non-null variants for callbacks. |
| src/CoreText/CTFont.cs | Uses non-null conversion helper for GetAvailableTables. |
| src/CoreText/Adapter.cs | Uses non-null + drop-null-elements conversion for array extraction from dictionaries. |
| src/CoreServices/LaunchServices.cs | Uses non-null + drop-null-elements conversions for URL lists. |
| src/CoreML/MLMultiArray.cs | Uses non-null + drop-null-elements for NSNumber→nint conversion. |
| src/CoreML/MLModel.cs | Uses non-null + drop-null-elements for AllComputeDevices. |
| src/CoreGraphics/CGPath.cs | Uses non-null + drop-null-elements conversion for GetSeparateComponents. |
| src/CoreAnimation/CADefs.cs | Updates CAGradientLayer.Colors nullability and setter implementation. |
| src/AuthenticationServices/PublicPrivateKeyAuthentication.cs | Uses string-array conversion and removes Linq dependency for transport mapping. |
| src/AppKit/NSAccessibility.cs | Drops null elements when converting unignored children arrays. |
| src/AddressBook/ABMultiValue.cs | Uses non-null + drop-null-elements conversion for values extraction. |
| src/AddressBook/ABGroup.cs | Uses non-null + drop-null-elements conversions for member enumeration. |
| src/AddressBook/ABAddressBook.cs | Uses non-null + drop-null-elements conversions for people/group/source retrieval. |
| src/Accessibility/AXHearingUtilities.cs | Uses non-null + drop-null-elements conversion for paired UUIDs. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #e896c7e] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 12 tests failed, 139 tests passed. Failures❌ linker tests11 tests failed, 33 tests passed.Failed tests
|
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ullability-44-nsarray-arrayfromhandle
✅ [CI Build #6db5a63] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #6db5a63] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #6db5a63] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #6db5a63] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 156 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Theoretically these changes may end up changing behavior, if there are native
arrays with NSNull elements, in which case we'll now convert them to managed
arrays without null elements for some APIs, but this should be exceedingly rare.
Contributes towards #17285.