Repository navigation
[Foundation] Add synchronous span byte-buffer APIs - #26873
Conversation
Add copying ReadOnlySpan<byte> input and Span<byte> output APIs for NSData, NSMutableData, and NSUuid. Preserve existing array overloads and UUID first-16-byte semantics while allowing callers to use stack buffers and slices without intermediate arrays. Validate destination sizes and ranges before native calls, preserve destination suffixes, and fix tightly coupled mutable-array slice checks for negative lengths, overflow, and empty ranges at the end. Document affected overload families and add monotouch-test coverage for copying, bounds, empty input, and native overloads. Contributes to #3590; this pilot only covers the three Foundation types. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2f930abd-d540-48a1-95d5-42fd7a7368b3
There was a problem hiding this comment.
🟡 Changes recommended
The documentation test will fail until seven newly documented APIs are removed from its known-failures list.
2 open findings
What changed in this PR
Adds allocation-free span-based byte-buffer APIs to Foundation data and UUID types while preserving existing array semantics.
Changes:
- Adds
ReadOnlySpan<byte>inputs andSpan<byte>outputs. - Strengthens range and destination validation.
- Adds XML documentation and comprehensive tests.
| File | Description |
|---|---|
src/Foundation/NSData.cs |
Adds span creation and copying APIs. |
src/Foundation/NSMutableData.cs |
Adds span append/replace APIs and safer bounds checks. |
src/Foundation/NSUuid.cs |
Adds span construction and output. |
src/foundation.cs |
Documents native pointer overloads. |
tests/monotouch-test/Foundation/NSDataTest.cs |
Tests span copying, ranges, and failures. |
tests/monotouch-test/Foundation/MutableDataTest.cs |
Tests mutable span operations and validation. |
tests/monotouch-test/Foundation/UuidTest.cs |
Tests UUID span semantics. |
🧠 Review effort: Balanced
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Remove the seven missing-documentation known failures made stale by the Foundation span pilot. The full Cecil suite reproduced exactly those seven fixed failures after a clean all-platform cb build, and passes after regenerating the baseline. Clarify that NSData.GetBytes(IntPtr, nuint) requires a destination with at least the requested length in writable bytes, even when fewer bytes are copied. This addresses both review findings without changing runtime behavior or the existing monotouch coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2f930abd-d540-48a1-95d5-42fd7a7368b3
✅ 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 |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #40f87d0] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 221 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |


Add copying
ReadOnlySpan<byte>input andSpan<byte>output APIs for NSData, NSMutableData, and NSUuid. Preserve existing array overloads and UUID first-16-byte semantics while allowing callers to use stack buffers and slices without intermediate arrays.Validate destination sizes and ranges before native calls, preserve destination suffixes, and fix tightly coupled mutable-array slice checks for negative lengths, overflow, and empty ranges at the end. Document affected overload families and add monotouch-test coverage for copying, bounds, empty input, and native overloads.
Contributes to #3590; this pilot only covers the three Foundation types.
Note
Implementation and pull request description generated with GitHub Copilot.