Repository navigation
Add interop members from #99's gap list - #491
Merged
Merged
Conversation
nint/nuint.Add and Subtract, Marshal.GetHRForException, Marshal.WriteInt16's char overloads, NativeLibrary.Load(string, Assembly, DllImportSearchPath?) and OperatingSystem.IsMacOSVersionAtLeast (kern.osproductversion on macOS, false elsewhere), each as .NET defines it. Sample 1553 is recorded from .NET.
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 86d5417. Configure here.
…searchPath) The overload went to the system loader as NativeLibrary.Load(path) does, so a native library shipped next to the executable was not found. It now takes the [DllImport] search, the program's directory first, unless searchPath leaves out DllImportSearchPath.AssemblyDirectory, through the runtime's new csrt_pinvoke_load_library_from. Windows' LoadLibrary starts in the program's directory itself. Sample 1553 is skipped on WASI, which has no dynamic libraries, as 729 and 730 are.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Part of #99.
What changed
Library members #99 lists that csharpc did not provide yet, each written as .NET defines it (corelib, plus one runtime entry point; no codegen change):
nint.Add/Subtract,nuint.Add/Subtract(NativeIntMembers.cs)Marshal.GetHRForExceptionand thecharoverloads ofMarshal.WriteInt16(SecureString.cs'sMarshalSecureStringMembers)NativeLibrary.Load(string, Assembly, DllImportSearchPath?)(Interop.cs), with .NET's argument checks and the [DllImport] search: the program's directory first unlesssearchPathleaves outAssemblyDirectory(csrt_pinvoke_load_library_frominruntime/pinvoke.c; Windows' LoadLibrary starts there itself)OperatingSystem.IsMacOSVersionAtLeast:kern.osproductversionthroughsysctlbynameon macOS, false on other systemsTests
tests/samples/1553_interop_gap_members, recorded from .NET. Locally on linux-x86_64: the sample and its neighbours (marshal|nativelibrary|nint|interop|operatingsystem) plus the dllimport/pinvoke samples pass at -O0/-O2 (36/36), via IL (18/18) and on wasm32 (8/8; 1553 is skipped on WASI, which has no dynamic libraries);size.shis within every budget;slicer.shpasses 10/10.What remains of #99
The
UnsafeAccessorconstructor case (next PR).NFloatis in filipnavara's #296. The other items on the list already work onmain; #99 gets a comment with each one's status when this merges.Note
Low Risk
Additive BCL parity with tests; the only behavioral surface is optional native library search order via the new Load overload.
Overview
Adds .NET-compatible interop and platform APIs that were missing from csharpc’s gap list (#99), without codegen changes.
Pointer arithmetic:
nint/nuint(andIntPtr/UIntPtr) now exposeAdd/Subtractwith unchecked byte offsets.Marshal:
GetHRForExceptionreturns an exception’sHResult(0 for null).WriteInt16gainscharoverloads that write the character’s code unit.NativeLibrary: New
Load(libraryName, assembly, searchPath?)validates arguments and calls a new runtime entrycsrt_pinvoke_load_library_from, which probes the application directory first whenDllImportSearchPath.AssemblyDirectoryis included (the default), matching DllImport semantics on Unix; Windows delegates to existing LoadLibrary behavior.OperatingSystem:
IsMacOSVersionAtLeastreadskern.osproductversionviasysctlbynameon macOS and returns false elsewhere.A sample test
1553_interop_gap_membersrecords behavior against .NET; WASI skips it because dynamic libraries aren’t available.Reviewed by Cursor Bugbot for commit cf3bb5d. Bugbot is set up for automated code reviews on this repo. Configure here.