Skip to content

[Foundation] Add synchronous span byte-buffer APIs - #26873

Merged
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/foundation-span-buffers
Oct 20, 2026
Merged

rolfbjarne merged 2 commits into
mainfrom
dev/rolf/foundation-span-buffers

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

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.

Note

Implementation and pull request description generated with GitHub Copilot.

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
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 14, 2026 16:49
Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 and Span<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

Comment thread src/foundation.cs Resolved
Comment thread src/foundation.cs Resolved
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

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
Copilot AI balanced review requested due to automatic review settings October 15, 2026 16:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Apple-platform runtime validation remains unverified for the new native-buffer paths.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 40f87d0eea5de43858dba107ea5f40d3a1f255d9 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne enabled auto-merge (squash) October 20, 2026 13:10
@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Oct 20, 2026
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [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
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 21 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 40f87d0eea5de43858dba107ea5f40d3a1f255d9 [PR build]

@rolfbjarne
rolfbjarne merged commit 5a1a6c5 into main Oct 20, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/foundation-span-buffers branch October 20, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants