Repository navigation
[Foundation][CoreFoundation] Add synchronous stream Span APIs. - #26955
Conversation
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
There was a problem hiding this comment.
🔵 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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot Autofix powered by AI <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.
|
✅ 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 #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 macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |

Add
Span<byte>reads andReadOnlySpan<byte>writes forNSInputStream,NSOutputStream,CFReadStream, andCFWriteStreamwithout temporary arrays. Preserve Objective-C dispatch and the virtualNSInputStreampointer 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