Skip to content

Commit

Permalink
exclude UTF8 string marshallers from cg2 (dotnet#55624)
Browse files Browse the repository at this point in the history
* exclude UTF8 and Unicode string marshallers from cg2

* keep unicodestringmarshaller

The non-pinned cases which are not supported will throw

* excluding one non-r2r case

All calls to InteropHelpers should now be under !READYTORUN
  • Loading branch information
mangod9 authored Jul 15, 2021
1 parent 546604c commit 54c3db5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Interop/IL/Marshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,12 @@ internal override bool CleanupRequired

internal override void EmitElementCleanup(ILCodeStream codeStream, ILEmitter emitter)
{
#if READYTORUN
throw new NotSupportedException();
#else
codeStream.Emit(ILOpcode.call, emitter.NewToken(
Context.GetHelperEntryPoint("InteropHelpers", "CoTaskMemFree")));
#endif
}

protected override void TransformManagedToNative(ILCodeStream codeStream)
Expand Down Expand Up @@ -1536,12 +1540,16 @@ protected override void TransformManagedToNative(ILCodeStream codeStream)
}
else
{
#if READYTORUN
throw new NotSupportedException();
#else
var helper = Context.GetHelperEntryPoint("InteropHelpers", "StringToUnicodeBuffer");
LoadManagedValue(codeStream);

codeStream.Emit(ILOpcode.call, emitter.NewToken(helper));

StoreNativeValue(codeStream);
#endif
}
}

Expand Down Expand Up @@ -1597,8 +1605,12 @@ internal override bool CleanupRequired

internal override void EmitElementCleanup(ILCodeStream codeStream, ILEmitter emitter)
{
#if READYTORUN
throw new NotSupportedException();
#else
codeStream.Emit(ILOpcode.call, emitter.NewToken(
Context.GetHelperEntryPoint("InteropHelpers", "CoTaskMemFree")));
#endif
}

protected override void TransformManagedToNative(ILCodeStream codeStream)
Expand Down Expand Up @@ -1752,6 +1764,7 @@ protected override void EmitCleanupManaged(ILCodeStream codeStream)
}
}

#if !READYTORUN
class UTF8StringMarshaller : Marshaller
{
internal override bool CleanupRequired
Expand Down Expand Up @@ -1806,6 +1819,7 @@ protected override void EmitCleanupManaged(ILCodeStream codeStream)
codeStream.EmitLabel(lNullCheck);
}
}
#endif

class SafeHandleMarshaller : Marshaller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ protected static Marshaller CreateMarshaller(MarshallerKind kind)
return new BooleanMarshaller();
case MarshallerKind.AnsiString:
return new AnsiStringMarshaller();
case MarshallerKind.UTF8String:
return new UTF8StringMarshaller();
case MarshallerKind.SafeHandle:
return new SafeHandleMarshaller();
case MarshallerKind.UnicodeString:
Expand Down

0 comments on commit 54c3db5

Please sign in to comment.