Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 82f0216

Browse files
authored
[release/3.1] Fix marshalling a pinnable multi-dimensional arr… (#26664)
* Use the exact methodtable of the parameter to calculate the offset into a pinned array.
1 parent 012b987 commit 82f0216

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/vm/ilmarshalers.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,7 +3808,7 @@ void ILMngdMarshaler::EmitCallMngdMarshalerMethod(ILCodeStream* pslILEmit, Metho
38083808

38093809
bool ILNativeArrayMarshaler::UsePinnedArraySpecialCase()
38103810
{
3811-
if (IsCLRToNative(m_dwMarshalFlags) && !IsByref(m_dwMarshalFlags) && (NULL == OleVariant::GetMarshalerForVarType(m_pargs->na.m_vt, TRUE)))
3811+
if (IsCLRToNative(m_dwMarshalFlags) && !IsByref(m_dwMarshalFlags) && (NULL != m_pargs->na.m_pArrayMT) && (NULL == OleVariant::GetMarshalerForVarType(m_pargs->na.m_vt, TRUE)))
38123812
{
38133813
return true;
38143814
}
@@ -3855,7 +3855,6 @@ void ILNativeArrayMarshaler::EmitCreateMngdMarshaler(ILCodeStream* pslILEmit)
38553855
pslILEmit->EmitCALL(METHOD__MNGD_NATIVE_ARRAY_MARSHALER__CREATE_MARSHALER, 3, 0);
38563856
}
38573857

3858-
38593858
void ILNativeArrayMarshaler::EmitMarshalArgumentCLRToNative()
38603859
{
38613860
CONTRACTL
@@ -3900,7 +3899,7 @@ void ILNativeArrayMarshaler::EmitMarshalArgumentCLRToNative()
39003899
m_pcsMarshal->EmitCONV_I();
39013900
// Optimize marshalling by emitting the data ptr offset directly into the IL stream
39023901
// instead of doing an FCall to recalulate it each time when possible.
3903-
m_pcsMarshal->EmitLDC(ArrayBase::GetDataPtrOffset(m_pargs->m_pMarshalInfo->GetArrayElementTypeHandle().MakeSZArray().GetMethodTable()));
3902+
m_pcsMarshal->EmitLDC(ArrayBase::GetDataPtrOffset(m_pargs->na.m_pArrayMT));
39043903
m_pcsMarshal->EmitADD();
39053904
EmitStoreNativeValue(m_pcsMarshal);
39063905

src/vm/mlinfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,8 @@ MarshalInfo::MarshalInfo(Module* pModule,
28022802
}
28032803
}
28042804

2805+
m_args.na.m_pArrayMT = arrayTypeHnd.GetMethodTable();
2806+
28052807
// Handle retrieving the information for the array type.
28062808
IfFailGoto(HandleArrayElemType(&ParamInfo, thElement, asArray->GetRank(), mtype == ELEMENT_TYPE_SZARRAY, isParam, pAssembly), lFail);
28072809
break;

src/vm/mlinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct OverrideProcArgs
8282

8383
struct
8484
{
85+
MethodTable* m_pArrayMT;
8586
VARTYPE m_vt;
8687
#ifdef FEATURE_COMINTEROP
8788
SIZE_T m_cbElementSize;

0 commit comments

Comments
 (0)