Skip to content

[CoreFoundation] Fix numerous issues with CFMessagePort. - #26513

Open
rolfbjarne wants to merge 7 commits into
mainfrom
dev/rolf/corefoundation-cfmessageport
Open

[CoreFoundation] Fix numerous issues with CFMessagePort.#26513
rolfbjarne wants to merge 7 commits into
mainfrom
dev/rolf/corefoundation-cfmessageport

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member
  • Use the native CFMessagePort context retain/release contract to keep callback state alive
  • Fix returned object ownership
  • Make invalidation callbacks replaceable.
  • Add complete API documentation, a result-returning TrySetName API
  • Add test coverage.

Contributes towards #10146.

Copilot-Session: 99900f2c-d178-4e70-9068-c6c3005ef89a

* Use the native CFMessagePort context retain/release contract to keep callback state alive
* Fix returned object ownership
* Make invalidation callbacks replaceable.
* Add complete API documentation, a result-returning TrySetName API
* Add test coverage.

Contributes towards #10146.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99900f2c-d178-4e70-9068-c6c3005ef89a
Copilot AI lite review requested due to automatic review settings September 1, 2026 14: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.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the CoreFoundation.CFMessagePort managed wrapper to be safer and more correct with respect to CoreFoundation context lifetime, returned object ownership, invalidation callback behavior, and API documentation, along with adding regression tests and updating handle-safety known failures.

Changes:

  • Reworked local port callback/context lifetime management to rely on CFMessagePort’s retain/release context contract, and adjusted invalidation callback handling to be replaceable.
  • Fixed ownership semantics for SendRequest’s returned data and CreateRunLoopSource’s returned source.
  • Added new NUnit coverage for naming/invalidation/send-request/run loop source ownership scenarios, and adjusted Cecil handle-safety known failures accordingly.
File summaries
File Description
src/CoreFoundation/CFMessagePort.cs Core wrapper changes: context retain/release, invalidation callback behavior, ownership fixes, and expanded XML docs.
tests/monotouch-test/CoreFoundation/CFMessagePortTest.cs New end-to-end tests validating callback replacement, duplicate port callback behavior, send request semantics, and run loop source ownership.
tests/cecil-tests/HandleSafety.KnownFailures.cs Updates the known-failures list to reflect removed/changed implementation details in CFMessagePort.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/CoreFoundation/CFMessagePort.cs Outdated
Comment thread src/CoreFoundation/CFMessagePort.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Remove the null-forgiving operator at the unmanaged callback boundary and return no reply if Core Foundation unexpectedly supplies a null data object.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99900f2c-d178-4e70-9068-c6c3005ef89a
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne

Copy link
Copy Markdown
Member Author

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/562b7395cffe3215c6d78e33f98dc628

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

✅ Applied expected app size files from gist.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne added the ready-to-review This PR is ready to review/merge. label Sep 2, 2026
@rolfbjarne
rolfbjarne enabled auto-merge (squash) September 2, 2026 15:26
@vs-mobiletools-engineering-service2

This comment has been minimized.

dalexsoto
dalexsoto previously approved these changes Sep 2, 2026
@vs-mobiletools-engineering-service2

This comment has been minimized.

@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/a96ada4aca0653623292ba1ebc25b981
Updated files
  • MacOSX-CoreCLR-R2R-size.txt

Pipeline on Agent
Hash: a354efde93df4b8e7ad9eb15a88ebd64916b2be1 [PR build]

@rolfbjarne

Copy link
Copy Markdown
Member Author

/apply-gist https://gist.github.com/vs-mobiletools-engineering-service2/a96ada4aca0653623292ba1ebc25b981

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

✅ Applied expected app size files from gist.

@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: dc916b616979c11042468b0a11894d28ed84ea17 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #dc916b6] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 264 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 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 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

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: dc916b616979c11042468b0a11894d28ed84ea17 [PR build]

@rolfbjarne rolfbjarne removed the ready-to-review This PR is ready to review/merge. label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants