Skip to content

[Foundation][CoreFoundation] Add synchronous stream Span APIs. - #26955

Merged
rolfbjarne merged 4 commits into
mainfrom
dev/rolf/stream-span-apis
Oct 23, 2026
Merged

rolfbjarne merged 4 commits into
mainfrom
dev/rolf/stream-span-apis

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Add Span<byte> reads and ReadOnlySpan<byte> writes for NSInputStream, NSOutputStream, CFReadStream, and CFWriteStream without temporary arrays. Preserve Objective-C dispatch and the virtual NSInputStream pointer overload, pin buffers only for synchronous native calls, and keep stream wrappers alive through those calls.

Validate array ranges without overflow before native access while retaining legacy CF zero-count and NS offset-at-end behavior. Invalid null buffers and lengths exceeding the array capacity now throw managed exceptions before reaching native code. Document all 14 Read/Write methods (four new overloads and ten existing overloads), and remove the two obsolete documentation baseline entries.

Add monotouch-test coverage for slices, stack buffers, empty inputs, native errors, partial transfers, EOF, subclass dispatch, and validation. Empty Foundation spans still dispatch to the native/overridden method with a nonnull buffer and zero length; empty CF spans return zero without accessing the native stream, after checking for disposal.

Contributes to #3590.

Note

Implementation and pull request description generated with GitHub Copilot.

🤖 Pull request created by Copilot

rolfbjarne and others added 2 commits October 21, 2026 14:47
Add Span<byte> reads and ReadOnlySpan<byte> writes for NSInputStream, NSOutputStream, CFReadStream, and CFWriteStream without temporary arrays. Preserve Objective-C dispatch and the virtual NSInputStream pointer overload, pin buffers only for synchronous native calls, and keep stream wrappers alive through those calls.

Validate array ranges without overflow before native access while retaining legacy CF zero-count and NS offset-at-end behavior. Document all thirteen Read/Write overloads and cover slices, stack buffers, empty inputs, native errors, partial transfers, EOF, subclass dispatch, and validation in monotouch-test. Remove the two obsolete documentation baseline entries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4a52a78a-db68-4d15-a0a2-96326e63997b
Place the new Foundation fixture members at class scope and make the CF array-range assertion distinguish copied bytes from preexisting destination contents. Keep the empty Foundation write assertion after the successful data write: a native zero-byte memory-stream write returns zero but transitions the stream to its end state, so subsequent writes return -1. Document that native state behavior for every NSOutputStream Write overload.

The completed chunk covers fourteen methods: four new Span overloads and ten existing overloads. Validation includes a clean all-platform build/install, a final incremental build/install, the full Cecil suite (126 passed, four existing skips), and all 21 tests in the three focused macOS stream fixtures.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4a52a78a-db68-4d15-a0a2-96326e63997b
Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:23
@rolfbjarne
rolfbjarne requested a review from dalexsoto as a code owner October 21, 2026 13:23

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

Native dispatch and buffer-lifetime behavior need Apple-platform validation, whose results were unavailable for this review.

1 open issue
What changed in this PR

Adds synchronous, allocation-free span APIs to Foundation and CoreFoundation streams, contributing to #3590.

Changes:

  • Adds four span overloads with native dispatch and buffer-lifetime handling.
  • Validates array ranges without overflow while preserving legacy boundary behavior.
  • Documents all Read/Write overloads and adds regression coverage.
File Description
tests/​monotouch-test/​Foundation/​OutputStreamTest.cs Tests span writes, dispatch, errors, and validation.
tests/​monotouch-test/​Foundation/​NSInputStreamTest.cs Tests span reads, overrides, EOF, and validation.
tests/​monotouch-test/​CoreFoundation/​StreamTest.cs Adds stream transfer and disposal tests.
tests/​cecil-tests/​Documentation.KnownFailures.txt Removes two newly documented API entries.
src/​Foundation/​NSOutputStream.cs Adds span writes, validation, and documentation.
src/​Foundation/​NSInputStream.cs Adds span reads while preserving virtual dispatch.
src/​CoreFoundation/​CFWriteStream.cs Adds span writes and checked array ranges.
src/​CoreFoundation/​CFReadStream.cs Adds span reads and checked array ranges.

Review effort: Balanced

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

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 23:12
@rolfbjarne
rolfbjarne enabled auto-merge (squash) October 22, 2026 23:17
@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Oct 22, 2026

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

Native dispatch, buffer lifetime, and stream edge cases need Apple-platform test confirmation that was unavailable during this review.

1 open issue
1 resolved since last review

Review effort: Balanced

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

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

⚠️ AppSizeTest expected files changed ⚠️

The AppSizeTest detected changes in the expected app size files.

To update the expected files, add a comment with the following command:

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/744e228d70163994980e4584c29e5753
Updated files
  • MacOSX-CoreCLR-R2R-size.txt

Pipeline on Agent
Hash: 827844f33ecc35311224df4f3b12fa9c5c8f6b40 [PR build]

Copilot AI balanced review requested due to automatic review settings October 23, 2026 06:46

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

Native buffer lifetimes, Objective-C subclass dispatch, and partial-transfer behavior still need Apple-platform test confirmation.

No open issues 🎉

1 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: d9988bab67f8fef82d68bf8e0a90d27be29e6db3 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #d9988ba] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 217 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 1 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. 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: d9988bab67f8fef82d68bf8e0a90d27be29e6db3 [PR build]

@rolfbjarne
rolfbjarne merged commit d77b8a4 into main Oct 23, 2026
62 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/stream-span-apis branch October 23, 2026 09:52
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