summaryrefslogtreecommitdiff
path: root/src/vm/clsload.cpp
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2019-05-13 19:58:23 -0700
committerGitHub <noreply@github.com>2019-05-13 19:58:23 -0700
commit6881de09b3d9ba165194ba416dd0786db00c2d5d (patch)
tree97ad4f996a0052cdd3dfa4c2ad0c9e275092d559 /src/vm/clsload.cpp
parent6b19bc3fb7add4999f3ac9e1a5fb2244de2c9836 (diff)
downloadcoreclr-6881de09b3d9ba165194ba416dd0786db00c2d5d.tar.gz
coreclr-6881de09b3d9ba165194ba416dd0786db00c2d5d.tar.bz2
coreclr-6881de09b3d9ba165194ba416dd0786db00c2d5d.zip
Delete InternalCasingHelper (#24511)
The unmanaged runtime has number of different paths for case-insensitive operations, each with unique issues. This is replacing InternalCasingHelper with SString to reduce number of different paths for case-insensitive operations that need to be maintained. Contributes to #20616
Diffstat (limited to 'src/vm/clsload.cpp')
-rw-r--r--src/vm/clsload.cpp157
1 files changed, 30 insertions, 127 deletions
diff --git a/src/vm/clsload.cpp b/src/vm/clsload.cpp
index 2909c64128..479e1240dd 100644
--- a/src/vm/clsload.cpp
+++ b/src/vm/clsload.cpp
@@ -757,7 +757,7 @@ BOOL ClassLoader::IsNested(Module *pModule, mdToken token, mdToken *mdEncloser)
}
}
-BOOL ClassLoader::IsNested(NameHandle* pName, mdToken *mdEncloser)
+BOOL ClassLoader::IsNested(const NameHandle* pName, mdToken *mdEncloser)
{
CONTRACTL
{
@@ -785,7 +785,7 @@ BOOL ClassLoader::IsNested(NameHandle* pName, mdToken *mdEncloser)
}
void ClassLoader::GetClassValue(NameHandleTable nhTable,
- NameHandle *pName,
+ const NameHandle *pName,
HashDatum *pData,
EEClassHashTable **ppTable,
Module* pLookInThisModuleOnly,
@@ -1475,7 +1475,7 @@ TypeHandle ClassLoader::LookupTypeHandleForTypeKeyInner(TypeKey *pKey, BOOL fChe
//
//
BOOL ClassLoader::FindClassModuleThrowing(
- const NameHandle * pOriginalName,
+ const NameHandle * pName,
TypeHandle * pType,
mdToken * pmdClassToken,
Module ** ppModule,
@@ -1490,91 +1490,16 @@ BOOL ClassLoader::FindClassModuleThrowing(
if (FORBIDGC_LOADER_USE_ENABLED()) NOTHROW; else THROWS;
if (FORBIDGC_LOADER_USE_ENABLED()) GC_NOTRIGGER; else GC_TRIGGERS;
if (FORBIDGC_LOADER_USE_ENABLED()) FORBID_FAULT; else { INJECT_FAULT(COMPlusThrowOM()); }
- PRECONDITION(CheckPointer(pOriginalName));
+ PRECONDITION(CheckPointer(pName));
PRECONDITION(CheckPointer(ppModule));
MODE_ANY;
SUPPORTS_DAC;
}
CONTRACTL_END
- NameHandleTable nhTable = nhCaseSensitive; // just to initialize this ...
-
- // Make a copy of the original name which we can modify (to lowercase)
- NameHandle localName = *pOriginalName;
- NameHandle * pName = &localName;
-
- switch (pName->GetTable())
- {
- case nhCaseInsensitive:
- {
-#ifndef DACCESS_COMPILE
- // GC-type users should only be loading types through tokens.
-#ifdef _DEBUG_IMPL
- _ASSERTE(!FORBIDGC_LOADER_USE_ENABLED());
-#endif
-
- // Use the case insensitive table
- nhTable = nhCaseInsensitive;
-
- // Create a low case version of the namespace and name
- LPUTF8 pszLowerNameSpace = NULL;
- LPUTF8 pszLowerClassName = NULL;
- int allocLen;
-
- if (pName->GetNameSpace())
- {
- allocLen = InternalCasingHelper::InvariantToLower(
- NULL,
- 0,
- pName->GetNameSpace());
- if (allocLen == 0)
- {
- return FALSE;
- }
-
- pszLowerNameSpace = (LPUTF8)_alloca(allocLen);
- if (allocLen == 1)
- {
- *pszLowerNameSpace = '\0';
- }
- else if (!InternalCasingHelper::InvariantToLower(
- pszLowerNameSpace,
- allocLen,
- pName->GetNameSpace()))
- {
- return FALSE;
- }
- }
+ // Note that the type name is expected to be lower-cased by the caller for case-insensitive lookups
- _ASSERTE(pName->GetName() != NULL);
- allocLen = InternalCasingHelper::InvariantToLower(NULL, 0, pName->GetName());
- if (allocLen == 0)
- {
- return FALSE;
- }
-
- pszLowerClassName = (LPUTF8)_alloca(allocLen);
- if (!InternalCasingHelper::InvariantToLower(
- pszLowerClassName,
- allocLen,
- pName->GetName()))
- {
- return FALSE;
- }
-
- // Substitute the lower case version of the name.
- // The field are will be released when we leave this scope
- pName->SetName(pszLowerNameSpace, pszLowerClassName);
- break;
-#else
- DacNotImpl();
- break;
-#endif // #ifndef DACCESS_COMPILE
- }
- case nhCaseSensitive:
- nhTable = nhCaseSensitive;
- break;
- }
+ NameHandleTable nhTable = pName->GetTable();
// Remember if there are any unhashed modules. We must do this before
// the actual look to avoid a race condition with other threads doing lookups.
@@ -1752,7 +1677,7 @@ static const UINT32 const_cMaxTypeForwardingChainSize = 1024;
//
TypeHandle
ClassLoader::LoadTypeHandleThrowing(
- NameHandle * pName,
+ NameHandle * pName,
ClassLoadLevel level,
Module * pLookInThisModuleOnly /*=NULL*/)
{
@@ -1900,7 +1825,7 @@ ClassLoader::LoadTypeHandleThrowing(
else
{ //#LoadTypeHandle_TypeForwarded
// pName is a host instance so it's okay to set fields in it in a DAC build
- HashedTypeEntry& bucket = pName->GetBucket();
+ const HashedTypeEntry& bucket = pName->GetBucket();
// Reset pName's bucket entry
if (bucket.GetEntryType() == HashedTypeEntry::IsHashedClassEntry && bucket.GetClassHashBasedEntryValue()->GetEncloser())
@@ -2142,54 +2067,32 @@ VOID ClassLoader::CreateCanonicallyCasedKey(LPCUTF8 pszNameSpace, LPCUTF8 pszNam
}
CONTRACTL_END
- // We can use the NoThrow versions here because we only call this routine if we're maintaining
- // a case-insensitive hash table, and the creation of that table initialized the
- // CasingHelper system.
- INT32 iNSLength = InternalCasingHelper::InvariantToLowerNoThrow(NULL, 0, pszNameSpace);
- if (!iNSLength)
- {
- COMPlusThrowOM();
- }
+ StackSString nameSpace(SString::Utf8, pszNameSpace);
+ nameSpace.LowerCase();
- INT32 iNameLength = InternalCasingHelper::InvariantToLowerNoThrow(NULL, 0, pszName);
- if (!iNameLength)
- {
- COMPlusThrowOM();
- }
+ StackScratchBuffer nameSpaceBuffer;
+ pszNameSpace = nameSpace.GetUTF8(nameSpaceBuffer);
- {
- //Calc & allocate path length
- //Includes terminating null
- S_SIZE_T allocSize = S_SIZE_T(iNSLength) + S_SIZE_T(iNameLength);
- if (allocSize.IsOverflow())
- {
- ThrowHR(COR_E_OVERFLOW);
- }
- AllocMemHolder<char> pszOutNameSpace (GetAssembly()->GetHighFrequencyHeap()->AllocMem(allocSize));
- *ppszOutNameSpace = pszOutNameSpace;
-
- if (iNSLength == 1)
- {
- **ppszOutNameSpace = '\0';
- }
- else
- {
- if (!InternalCasingHelper::InvariantToLowerNoThrow(*ppszOutNameSpace, iNSLength, pszNameSpace))
- {
- COMPlusThrowOM();
- }
- }
+ StackSString name(SString::Utf8, pszName);
+ name.LowerCase();
- *ppszOutName = *ppszOutNameSpace + iNSLength;
-
- if (!InternalCasingHelper::InvariantToLowerNoThrow(*ppszOutName, iNameLength, pszName))
- {
- COMPlusThrowOM();
- }
+ StackScratchBuffer nameBuffer;
+ pszName = name.GetUTF8(nameBuffer);
- pszOutNameSpace.SuppressRelease();
- }
+
+ size_t iNSLength = strlen(pszNameSpace);
+ size_t iNameLength = strlen(pszName);
+
+ //Calc & allocate path length
+ //Includes terminating null
+ S_SIZE_T allocSize = S_SIZE_T(iNSLength) + S_SIZE_T(iNameLength) + S_SIZE_T(2);
+ AllocMemHolder<char> alloc(GetAssembly()->GetHighFrequencyHeap()->AllocMem(allocSize));
+
+ memcpy(*ppszOutNameSpace = (char*)alloc, pszNameSpace, iNSLength + 1);
+ memcpy(*ppszOutName = (char*)alloc + iNSLength + 1, pszName, iNameLength + 1);
+
+ alloc.SuppressRelease();
}
#endif // #ifndef DACCESS_COMPILE
@@ -2936,7 +2839,7 @@ ClassLoader::ResolveTokenToTypeDefThrowing(
BOOL
ClassLoader::ResolveNameToTypeDefThrowing(
Module * pModule,
- NameHandle * pName,
+ const NameHandle * pName,
Module ** ppTypeDefModule,
mdTypeDef * pTypeDefToken,
Loader::LoadFlag loadFlag,