-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not throw for Marshal.SizeOf(typeof(delegate*<void>))
#113603
Conversation
Tagging subscribers to this area: @dotnet/interop-contrib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request addresses the issue of throwing exceptions when calling Marshal.SizeOf on function pointers by adding an appropriate test and updating the AOT helper method.
- Added a test in SizeOfTests.cs to validate delegate* functionality.
- Updated the NativeAot implementation to correctly recognize function pointers in the type-check condition.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs | Added test for function pointer size computation |
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NativeAot.cs | Updated condition to handle function pointers in Marshal.SizeOf |
Comments suppressed due to low confidence (1)
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/SizeOfTests.cs:37
- [nitpick] Consider expanding test coverage to include additional function pointer variations, ensuring that the behavior remains consistent across different use cases.
Assert.Equal(IntPtr.Size, Marshal.SizeOf(typeof(delegate*<void>)));
@@ -20,7 +20,7 @@ internal static int SizeOfHelper(RuntimeType t, bool throwIfNotMarshalable) | |||
{ | |||
Debug.Assert(throwIfNotMarshalable); | |||
|
|||
if (t.IsPointer /* or IsFunctionPointer */) | |||
if (t.IsPointer || t.IsFunctionPointer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing the outdated comment fragment 'or IsFunctionPointer' since the condition now explicitly includes it, which would improve clarity.
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
/ba-g unrelated failures (wasm) |
Noticed as I was looking at this code.