Skip to content

Commit a3dc133

Browse files
Remove helper frames from MetadataImport class FCalls (#100939)
Co-authored-by: Jan Kotas <[email protected]>
1 parent 7e7c1f0 commit a3dc133

File tree

12 files changed

+551
-680
lines changed

12 files changed

+551
-680
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/MdImport.cs

Lines changed: 202 additions & 146 deletions
Large diffs are not rendered by default.

src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,38 +2257,7 @@ internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType? caType)
22572257
if (nativeType.Length == 0)
22582258
return null;
22592259

2260-
MetadataImport.GetMarshalAs(nativeType,
2261-
out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string? safeArrayUserDefinedTypeName, out UnmanagedType arraySubType, out int sizeParamIndex,
2262-
out int sizeConst, out string? marshalTypeName, out string? marshalCookie, out int iidParamIndex);
2263-
2264-
RuntimeType? safeArrayUserDefinedType = string.IsNullOrEmpty(safeArrayUserDefinedTypeName) ? null :
2265-
TypeNameParser.GetTypeReferencedByCustomAttribute(safeArrayUserDefinedTypeName, scope);
2266-
RuntimeType? marshalTypeRef = null;
2267-
2268-
try
2269-
{
2270-
marshalTypeRef = marshalTypeName is null ? null : TypeNameParser.GetTypeReferencedByCustomAttribute(marshalTypeName, scope);
2271-
}
2272-
catch (TypeLoadException)
2273-
{
2274-
// The user may have supplied a bad type name string causing this TypeLoadException
2275-
// Regardless, we return the bad type name
2276-
Debug.Assert(marshalTypeName is not null);
2277-
}
2278-
2279-
MarshalAsAttribute attribute = new MarshalAsAttribute(unmanagedType);
2280-
2281-
attribute.SafeArraySubType = safeArraySubType;
2282-
attribute.SafeArrayUserDefinedSubType = safeArrayUserDefinedType;
2283-
attribute.IidParameterIndex = iidParamIndex;
2284-
attribute.ArraySubType = arraySubType;
2285-
attribute.SizeParamIndex = (short)sizeParamIndex;
2286-
attribute.SizeConst = sizeConst;
2287-
attribute.MarshalType = marshalTypeName;
2288-
attribute.MarshalTypeRef = marshalTypeRef;
2289-
attribute.MarshalCookie = marshalCookie;
2290-
2291-
return attribute;
2260+
return MetadataImport.GetMarshalAs(nativeType, scope);
22922261
}
22932262

22942263
private static FieldOffsetAttribute? GetFieldOffsetCustomAttribute(RuntimeFieldInfo field)

src/coreclr/ildasm/dis.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ void OpenScope(ISymUnmanagedScope *pIScope,
727727
char* DumpUnicodeString(void* GUICookie,
728728
__inout __nullterminated char* szString,
729729
_In_reads_(cbString) WCHAR* pszString,
730-
ULONG cbString,
731-
bool SwapString )
730+
ULONG cbString)
732731
{
733732
unsigned i,L;
734733
char* szStr=NULL, *szRet = NULL;
@@ -750,8 +749,7 @@ char* DumpUnicodeString(void* GUICookie,
750749
#endif
751750

752751
#if BIGENDIAN
753-
if (SwapString)
754-
SwapStringLength(pszString, cbString);
752+
SwapStringLength(pszString, cbString);
755753
#endif
756754

757755
// first, check for embedded zeros:
@@ -782,7 +780,7 @@ char* DumpUnicodeString(void* GUICookie,
782780
strcat_s(szString,SZSTRING_SIZE," (");
783781

784782
#if BIGENDIAN
785-
SwapStringLength(pszString, cbString);
783+
SwapStringLength(pszString, cbString);
786784
#endif
787785
DumpByteArray(szString,(BYTE*)pszString,cbString*sizeof(WCHAR),GUICookie);
788786
szRet = &szString[strlen(szString)];
@@ -2546,7 +2544,7 @@ void PrettyPrintToken(__inout __nullterminated char* szString, mdToken tk, IMDIn
25462544
}
25472545
if (pszString != NULL)
25482546
{
2549-
DumpUnicodeString(GUICookie,szString,(WCHAR *)pszString,cbString, true);
2547+
DumpUnicodeString(GUICookie,szString,(WCHAR *)pszString,cbString);
25502548
}
25512549
else
25522550
{

src/coreclr/ildasm/dis.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ void DumpVtable(void* GUICookie);
7878
char* DumpUnicodeString(void* GUICookie,
7979
__inout __nullterminated char* szString,
8080
_In_reads_(cbString) WCHAR* pszString,
81-
ULONG cbString,
82-
bool SwapString = false);
81+
ULONG cbString);
8382

8483
void TokenSigInit(IMDInternalImport *pImport);
8584
void TokenSigDelete();

src/coreclr/inc/metadata.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,6 @@ struct HENUMInternal
220220
//*****************************************
221221
typedef struct _MDDefaultValue
222222
{
223-
#if BIGENDIAN
224-
_MDDefaultValue(void)
225-
{
226-
m_bType = ELEMENT_TYPE_END;
227-
}
228-
~_MDDefaultValue(void)
229-
{
230-
if (m_bType == ELEMENT_TYPE_STRING)
231-
{
232-
delete[] m_wzValue;
233-
}
234-
}
235-
#endif
236223

237224
// type of default value
238225
BYTE m_bType; // CorElementType for the default value
@@ -251,7 +238,7 @@ typedef struct _MDDefaultValue
251238
ULONGLONG m_ullValue; // ELEMENT_TYPE_UI8
252239
FLOAT m_fltValue; // ELEMENT_TYPE_R4
253240
DOUBLE m_dblValue; // ELEMENT_TYPE_R8
254-
LPCWSTR m_wzValue; // ELEMENT_TYPE_STRING
241+
LPCWSTR m_wzValue; // ELEMENT_TYPE_STRING - Little endian
255242
IUnknown *m_unkValue; // ELEMENT_TYPE_CLASS
256243
};
257244
ULONG m_cbSize; // default value size (for blob)

src/coreclr/md/runtime/mdinternalro.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,6 @@ mdModule MDInternalRO::GetModuleFromScope(void)
31473147

31483148
//*****************************************************************************
31493149
// Fill a variant given a MDDefaultValue
3150-
// This routine will create a bstr if the ELEMENT_TYPE of default value is STRING
31513150
//*****************************************************************************
31523151
__checkReturn
31533152
HRESULT _FillMDDefaultValue(
@@ -3236,19 +3235,7 @@ HRESULT _FillMDDefaultValue(
32363235
if (cbValue == 0)
32373236
pValue = NULL;
32383237

3239-
#if BIGENDIAN
3240-
{
3241-
// We need to allocate and swap the string if we're on a big endian
3242-
// This allocation will be freed by the MDDefaultValue destructor.
3243-
pMDDefaultValue->m_wzValue = new WCHAR[(cbValue + 1) / sizeof (WCHAR)];
3244-
IfNullGo(pMDDefaultValue->m_wzValue);
3245-
memcpy(const_cast<WCHAR *>(pMDDefaultValue->m_wzValue), pValue, cbValue);
3246-
_ASSERTE(cbValue % sizeof(WCHAR) == 0);
3247-
SwapStringLength(const_cast<WCHAR *>(pMDDefaultValue->m_wzValue), cbValue / sizeof(WCHAR));
3248-
}
3249-
#else
32503238
pMDDefaultValue->m_wzValue = (LPWSTR) pValue;
3251-
#endif
32523239
break;
32533240
case ELEMENT_TYPE_CLASS:
32543241
//

src/coreclr/vm/corelib.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,6 @@ DEFINE_METHOD(PROPERTY, GET_GETTER, GetGetMethod,
604604

605605
DEFINE_CLASS(PROPERTY_INFO, Reflection, PropertyInfo)
606606

607-
608-
609-
DEFINE_CLASS(METADATA_IMPORT, Reflection, MetadataImport)
610-
DEFINE_METHOD(METADATA_IMPORT, THROW_ERROR, ThrowError, SM_Int_RetVoid)
611-
612607
DEFINE_CLASS(RESOLVER, System, Resolver)
613608
DEFINE_METHOD(RESOLVER, GET_JIT_CONTEXT, GetJitContext, IM_RefInt_RetRuntimeType)
614609
DEFINE_METHOD(RESOLVER, GET_CODE_INFO, GetCodeInfo, IM_RefInt_RefInt_RefInt_RetArrByte)

src/coreclr/vm/ecalllist.h

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,30 @@ FCFuncStart(gCOMTypeHandleFuncs)
156156
FCFuncEnd()
157157

158158
FCFuncStart(gMetaDataImport)
159-
FCFuncElement("_GetDefaultValue", MetaDataImport::GetDefaultValue)
160-
FCFuncElement("_GetName", MetaDataImport::GetName)
161-
FCFuncElement("_GetUserString", MetaDataImport::GetUserString)
162-
FCFuncElement("_GetScopeProps", MetaDataImport::GetScopeProps)
163-
FCFuncElement("_GetClassLayout", MetaDataImport::GetClassLayout)
164-
FCFuncElement("_GetSignatureFromToken", MetaDataImport::GetSignatureFromToken)
165-
FCFuncElement("_GetNamespace", MetaDataImport::GetNamespace)
166-
FCFuncElement("_GetEventProps", MetaDataImport::GetEventProps)
167-
FCFuncElement("_GetFieldDefProps", MetaDataImport::GetFieldDefProps)
168-
FCFuncElement("_GetPropertyProps", MetaDataImport::GetPropertyProps)
169-
FCFuncElement("_GetParentToken", MetaDataImport::GetParentToken)
170-
FCFuncElement("_GetParamDefProps", MetaDataImport::GetParamDefProps)
171-
FCFuncElement("_GetGenericParamProps", MetaDataImport::GetGenericParamProps)
172-
173-
FCFuncElement("_Enum", MetaDataImport::Enum)
174-
FCFuncElement("_GetMemberRefProps", MetaDataImport::GetMemberRefProps)
175-
FCFuncElement("_GetCustomAttributeProps", MetaDataImport::GetCustomAttributeProps)
176-
FCFuncElement("_GetFieldOffset", MetaDataImport::GetFieldOffset)
177-
178-
FCFuncElement("_GetSigOfFieldDef", MetaDataImport::GetSigOfFieldDef)
179-
FCFuncElement("_GetSigOfMethodDef", MetaDataImport::GetSigOfMethodDef)
180-
FCFuncElement("_GetFieldMarshal", MetaDataImport::GetFieldMarshal)
181-
FCFuncElement("_GetPInvokeMap", MetaDataImport::GetPinvokeMap)
182-
FCFuncElement("_IsValidToken", MetaDataImport::IsValidToken)
183-
FCFuncElement("_GetMarshalAs", MetaDataImport::GetMarshalAs)
159+
FCFuncElement("GetDefaultValue", MetaDataImport::GetDefaultValue)
160+
FCFuncElement("GetName", MetaDataImport::GetName)
161+
FCFuncElement("GetUserString", MetaDataImport::GetUserString)
162+
FCFuncElement("GetScopeProps", MetaDataImport::GetScopeProps)
163+
FCFuncElement("GetClassLayout", MetaDataImport::GetClassLayout)
164+
FCFuncElement("GetSignatureFromToken", MetaDataImport::GetSignatureFromToken)
165+
FCFuncElement("GetNamespace", MetaDataImport::GetNamespace)
166+
FCFuncElement("GetEventProps", MetaDataImport::GetEventProps)
167+
FCFuncElement("GetFieldDefProps", MetaDataImport::GetFieldDefProps)
168+
FCFuncElement("GetPropertyProps", MetaDataImport::GetPropertyProps)
169+
FCFuncElement("GetParentToken", MetaDataImport::GetParentToken)
170+
FCFuncElement("GetParamDefProps", MetaDataImport::GetParamDefProps)
171+
FCFuncElement("GetGenericParamProps", MetaDataImport::GetGenericParamProps)
172+
173+
FCFuncElement("GetMemberRefProps", MetaDataImport::GetMemberRefProps)
174+
FCFuncElement("GetCustomAttributeProps", MetaDataImport::GetCustomAttributeProps)
175+
FCFuncElement("GetFieldOffset", MetaDataImport::GetFieldOffset)
176+
177+
FCFuncElement("GetSigOfFieldDef", MetaDataImport::GetSigOfFieldDef)
178+
FCFuncElement("GetSigOfMethodDef", MetaDataImport::GetSigOfMethodDef)
179+
FCFuncElement("GetFieldMarshal", MetaDataImport::GetFieldMarshal)
180+
FCFuncElement("GetPInvokeMap", MetaDataImport::GetPInvokeMap)
181+
FCFuncElement("IsValidToken", MetaDataImport::IsValidToken)
182+
FCFuncElement("GetMarshalAs", MetaDataImport::GetMarshalAs)
184183
FCFuncEnd()
185184

186185
FCFuncStart(gSignatureNative)

0 commit comments

Comments
 (0)