-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add support for UnsafeAccessorKind.FieldOffset (#45152) #93946
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices Issue DetailsDraft PR to add support for This PR is for now just a proof of concept of the suggestion of implementing field offset computation via
|
@xoofx Do you want to file an API proposal for this? That would be the next step. |
Console.WriteLine($"Running {nameof(Verify_AccessFieldOffsetClass)}"); | ||
|
||
// Offset = method table pointer + first string pointer | ||
Assert.Equal(IntPtr.Size + IntPtr.Size, GetPrivateFieldOffset()); |
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.
This should just be IntPtr.Size
I think, since you cannot legitimately obtain a ref before the first field iirc.
Presumably the GetRawData
API will give the offset of the 0th field.
Also, should we have tests for structs and for ref fields?
(edit: I'm editing this because my edge crashed after posting my comments and undid all my changes & deleted a comment?!)
Assert.Equal(IntPtr.Size + IntPtr.Size, GetPrivateFieldOffset()); | ||
|
||
[UnsafeAccessor(UnsafeAccessorKind.FieldOffset, Name=UserDataClass.FieldSecondName)] | ||
extern static nint GetPrivateFieldOffset(UserDataClass? d = null); |
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.
Not sure what others' opinions on this are, but I like to be explicit with these sorts of APIs - I'd like it if we could also specify a second parameter which is the type of the field - it would first check for fields with same type (including modifiers), and then same type (ignoring modifiers) (same as other checks for the UnsafeAccessor
s iirc).
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Draft PR to add support for
UnsafeAccessorKind.FieldOffset
.This PR is for now just a proof of concept of the suggestion of implementing field offset computation via
UnsafeAccessorKind.FieldOffset
as suggested here