internal override void EmitElementCleanup(ILCodeStream codeStream, ILEmitter emitter)
{
codeStream.Emit(ILOpcode.call, emitter.NewToken(
- Context.GetHelperEntryPoint("InteropHelpers", "CoTaskMemFree")));
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
}
protected override void AllocNativeToManaged(ILCodeStream codeStream)
protected override void EmitCleanupManaged(ILCodeStream codeStream)
{
+ ILEmitter emitter = _ilCodeStreams.Emitter;
LoadNativeValue(codeStream);
- codeStream.Emit(ILOpcode.call, _ilCodeStreams.Emitter.NewToken(
- Context.GetHelperEntryPoint("InteropHelpers", "CoTaskMemFree")));
+ codeStream.Emit(ILOpcode.call, emitter.NewToken(
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
}
}
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
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
}
protected override void TransformManagedToNative(ILCodeStream codeStream)
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
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
}
protected override void TransformManagedToNative(ILCodeStream codeStream)
LoadNativeValue(codeStream);
codeStream.Emit(ILOpcode.call, emitter.NewToken(
- Context.GetHelperEntryPoint("InteropHelpers", "CoTaskMemFree")));
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
codeStream.EmitLabel(lNullCheck);
#endif
Debug.Assert(_marshallerInstance is null);
codeStream.Emit(ILOpcode.call, emitter.NewToken(
- InteropTypes.GetMarshal(Context).GetKnownMethod("CoTaskMemFree", null)));
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
}
protected override void TransformManagedToNative(ILCodeStream codeStream)
{
ILEmitter emitter = _ilCodeStreams.Emitter;
- Debug.Assert(_marshallerInstance != null);
+ if (In && !Out && !IsManagedByRef)
+ {
+ Debug.Assert(_marshallerInstance != null);
- codeStream.EmitLdLoca(_marshallerInstance.Value);
- codeStream.Emit(ILOpcode.call, emitter.NewToken(
- Marshaller.GetKnownMethod("FreeNative", null)));
+ codeStream.EmitLdLoca(_marshallerInstance.Value);
+ codeStream.Emit(ILOpcode.call, emitter.NewToken(
+ Marshaller.GetKnownMethod("FreeNative", null)));
+ }
+ else
+ {
+ // The marshaller instance is not guaranteed to be initialized with the latest native value.
+ // Free the native value directly.
+ LoadNativeValue(codeStream);
+ codeStream.Emit(ILOpcode.call, emitter.NewToken(
+ InteropTypes.GetMarshal(Context).GetKnownMethod("FreeCoTaskMem", null)));
+ }
}
}
{
STANDARD_VM_CONTRACT;
- _ASSERTE(m_dwInstance != LOCAL_NUM_UNUSED);
+ bool bPassByValueInOnly = IsIn(m_dwMarshalFlags) && !IsOut(m_dwMarshalFlags) && !IsByref(m_dwMarshalFlags);
+ if (bPassByValueInOnly)
+ {
+ _ASSERTE(m_dwInstance != LOCAL_NUM_UNUSED);
- pslILEmit->EmitLDLOCA(m_dwInstance);
- pslILEmit->EmitCALL(METHOD__UTF8STRINGMARSHALLER__FREE_NATIVE, 1, 0);
+ pslILEmit->EmitLDLOCA(m_dwInstance);
+ pslILEmit->EmitCALL(METHOD__UTF8STRINGMARSHALLER__FREE_NATIVE, 1, 0);
+ }
+ else
+ {
+ // The marshaller instance is not guaranteed to be initialized with the latest native value.
+ // Free the native value directly.
+ EmitLoadNativeValue(pslILEmit);
+ pslILEmit->EmitCALL(METHOD__MARSHAL__FREE_CO_TASK_MEM, 1, 0);
+ }
}
LocalDesc ILCSTRMarshaler::GetManagedType()