Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

Noticed as I was looking at this code.

Copilot AI review requested due to automatic review settings March 17, 2025 08:22
@dotnet-policy-service
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 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>)));

Debug.Assert(throwIfNotMarshalable);

if (t.IsPointer /* or IsFunctionPointer */)
if (t.IsPointer || t.IsFunctionPointer)
Copy link

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 uses AI. Check for mistakes.
@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
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants