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
Support decimal marshalling #1101
Conversation
Oops seems that it only works on Windows. Maybe caused by paddings or endians, need to figure out why it doesn't work on other platforms. |
The alignment requirements of the managed Decimal and the unmanaged DECIMAL are different. CoreCLR solves it using https://github.com/dotnet/runtime/blob/main/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs#L1082 |
You can try modify https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/src/tests/Common/dirs.proj#L36-L38 with
and run |
@jkotas PTAL. CI failure is unrelated to this PR. |
var mid32 = (int)((lo64 & 0xFFFFFFFF00000000) >> 32); | ||
var lo32 = (int)(lo64 & 0xFFFFFFFF); | ||
|
||
return new decimal(lo32, mid32, (int)hi32, sign != 0, scale); |
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.
Calling this constructor will do some extra argument validation for scale
. I do not see it in the CoreCLR decimal marshalers. CoreCLR marshalers just blasts the bits over. It would be nice to match what CoreCLR does.
I would expect the NativeDecimal type to show up in more places (e.g. also in I am actually not sure anymore whether the NativeDecimal type is actually required to deal with the alignment issues. It was required for the old decimal implementation: https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/mscorlib/system/decimal.cs#L145-L148 , but it may not be required for the current one: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Decimal.cs#L106-L108. What is not going to work if https://github.com/dotnet/runtimelab/pull/1101/files#diff-f8ce84af95c61383c81c774a30efbded7030042bc018027326e1f2c33ad00b22R83 is just changed to return |
Actually I don't see the need of |
Yes, I think it should be ok to use |
Updated. |
@jkotas I think it's ready for another look. |
Could you please also re-enable the decimal tests by deleting https://github.com/dotnet/runtimelab/blob/feature/NativeAOT/src/tests/issues.targets#L1139-L1141 ? |
Done. |
The CI failure seems to be an I/O issue while copying files.
|
This reverts commit 3e89624.
Unfortunately, this is not fully fixed yet. (It fails on BlittableStructPtrMarshaller now.) |
@@ -353,7 +353,7 @@ public static partial class MarshalHelpers | |||
{ | |||
if (nativeType == NativeTypeKind.Struct || nativeType == NativeTypeKind.Default) | |||
return MarshallerKind.Decimal; | |||
else if (nativeType == NativeTypeKind.LPStruct && !isField && !isReturn) | |||
else if (nativeType == NativeTypeKind.LPStruct && !isField) |
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.
Minor fix to match CoreCLR behavior that gets us a bit closer.
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.
Thank you!
Support decimal marshalling.
Contributes to #175
Fixes #969