Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix enum handling for the runtime marshalling disabled case.
  • Loading branch information
jkoritzinsky committed Feb 9, 2022
commit 1eaf8b62603f30752465ae0678ca197451b9ae0d
Original file line number Diff line number Diff line change
Expand Up @@ -872,26 +872,28 @@ private static MarshallerKind GetArrayElementMarshallerKind(
internal static MarshallerKind GetDisabledMarshallerKind(
TypeDesc type)
{
if (type.Category == TypeFlags.Void)
// Get the underlying type for enum types.
TypeDesc underlyingType = type.UnderlyingType;
if (underlyingType.Category == TypeFlags.Void)
{
return MarshallerKind.VoidReturn;
}
else if (type.IsByRef)
else if (underlyingType.IsByRef)
{
// Managed refs are not supported when runtime marshalling is disabled.
return MarshallerKind.Invalid;
}
else if (type.IsPrimitive)
else if (underlyingType.IsPrimitive)
{
return MarshallerKind.BlittableValue;
}
else if (type.IsPointer || type.IsFunctionPointer)
else if (underlyingType.IsPointer || underlyingType.IsFunctionPointer)
{
return MarshallerKind.BlittableValue;
}
else if (type.IsValueType)
else if (underlyingType.IsValueType)
{
var defType = (DefType)type;
var defType = (DefType)underlyingType;
if (!defType.ContainsGCPointers && !defType.IsAutoLayoutOrHasAutoLayoutFields)
{
return MarshallerKind.BlittableValue;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3349,6 +3349,7 @@ BOOL NDirect::MarshalingRequired(
// any types that contain gc pointers, but all "unmanaged" types are treated as blittable
// as long as they aren't auto-layout and don't have any auto-layout fields.
if (!runtimeMarshallingEnabled &&
!hndArgType.IsEnum() &&
(hndArgType.GetMethodTable()->ContainsPointers()
|| hndArgType.GetMethodTable()->IsAutoLayoutOrHasAutoLayoutField()))
{
Expand Down