Skip to content
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

Merged
merged 1 commit into from
Mar 18, 2025

Conversation

MichalStrehovsky
Copy link
Member

Noticed as I was looking at this code.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a 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)
Copy link
Preview

Copilot AI Mar 17, 2025

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.

@jkotas
Copy link
Member

jkotas commented Mar 18, 2025

/ba-g unrelated failures (wasm)

@jkotas jkotas merged commit 9d742b6 into dotnet:main Mar 18, 2025
125 of 133 checks passed
@MichalStrehovsky MichalStrehovsky deleted the marshalsizefptr branch March 18, 2025 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants