Repository navigation
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.
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.
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 UnsafeAccessors 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.FieldOffsetas suggested here