diff --git a/src/coreclr/inc/nsutilpriv.h b/src/coreclr/inc/nsutilpriv.h index 238b34618b661..fdd82daacbf6f 100644 --- a/src/coreclr/inc/nsutilpriv.h +++ b/src/coreclr/inc/nsutilpriv.h @@ -1,10 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. + //***************************************************************************** // NSUtilPriv.h // // Helpers for converting namespace separators. -// //***************************************************************************** #ifndef __NSUTILPRIV_H__ @@ -15,7 +15,6 @@ class SString; struct ns { - //***************************************************************************** // Determine how many chars large a fully qualified name would be given the // two parts of the name. The return value includes room for every character @@ -43,7 +42,6 @@ static int IsValidName( // true if valid, false invalid. LPCUTF8 szName); // Name to parse. - //***************************************************************************** // Scan the string from the rear looking for the first valid separator. If // found, return a pointer to it. Else return null. This code is smart enough @@ -61,34 +59,22 @@ static LPUTF8 FindSep( // Pointer to separator or null. LPCUTF8 szPath); // The path to look in. - //***************************************************************************** // Take a path and find the last separator (nsFindSep), and then replace the // separator with a '\0' and return a pointer to the name. So for example: // a.b.c // becomes two strings "a.b" and "c" and the return value points to "c". //***************************************************************************** -static -WCHAR *SplitInline( // Pointer to name portion. - __inout __inout_z WCHAR *szPath); // The path to split. - static LPUTF8 SplitInline( // Pointer to name portion. __inout __inout_z LPUTF8 szPath); // The path to split. -static -void SplitInline( - __inout __inout_z LPWSTR szPath, // Path to split. - LPCWSTR &szNameSpace, // Return pointer to namespace. - LPCWSTR &szName); // Return pointer to name. - static void SplitInline( __inout __inout_z LPUTF8 szPath, // Path to split. LPCUTF8 &szNameSpace, // Return pointer to namespace. LPCUTF8 &szName); // Return pointer to name. - //***************************************************************************** // Split the last parsable element from the end of the string as the name, // the first part as the namespace. @@ -109,7 +95,6 @@ int SplitPath( // true ok, false trunction. _Out_writes_opt_ (cchName) LPUTF8 szName, // Output for name. int cchName); // Max chars for output. - //***************************************************************************** // Take two values and put them together in a fully qualified path using the // correct separator. @@ -128,31 +113,6 @@ int MakePath( // true ok, false truncation. LPCUTF8 szNameSpace, // Namespace. LPCUTF8 szName); // Name. -static -int MakePath( // true ok, false truncation. - _Out_writes_(cchChars) WCHAR *szOut, // output path for name. - int cchChars, // max chars for output path. - LPCUTF8 szNameSpace, // Namespace. - LPCUTF8 szName); // Name. - -static -int MakePath( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - LPCUTF8 szNameSpace, // Namespace for name. - LPCUTF8 szName); // Final part of name. - -static -int MakePath( // true ok, false out of memory - CQuickArray &qa, // Where to put results. - LPCUTF8 szNameSpace, // Namespace for name. - LPCUTF8 szName); // Final part of name. - -static -int MakePath( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - const WCHAR *szNameSpace, // Namespace for name. - const WCHAR *szName); // Final part of name. - static void MakePath( // throws on out of memory SString &ssBuf, // Where to put results. @@ -176,46 +136,12 @@ bool MakeAssemblyQualifiedName( // true o int dwTypeName, // Number of characters (not including null) const WCHAR *szAssemblyName, // Final part of name. int dwAssemblyName); // Number of characters (not including null) - -static -int MakeNestedTypeName( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - LPCUTF8 szEnclosingName, // Full name for enclosing type - LPCUTF8 szNestedName); // Full name for nested type - -static -int MakeNestedTypeName( // true ok, false truncation. - _Out_writes_ (cchChars) LPUTF8 szOut, // output path for name. - int cchChars, // max chars for output path. - LPCUTF8 szEnclosingName, // Full name for enclosing type - LPCUTF8 szNestedName); // Full name for nested type - -static -void MakeNestedTypeName( // throws on out of memory - SString &ssBuf, // output path for name. - const SString &ssEnclosingName, // Full name for enclosing type - const SString &ssNestedName); // Full name for nested type }; // struct ns -#ifndef NAMESPACE_SEPARATOR_CHAR #define NAMESPACE_SEPARATOR_CHAR '.' #define NAMESPACE_SEPARATOR_WCHAR W('.') #define NAMESPACE_SEPARATOR_STR "." #define NAMESPACE_SEPARATOR_WSTR W(".") -#define NAMESPACE_SEPARATOR_LEN 1 -#define ASSEMBLY_SEPARATOR_CHAR ',' -#define ASSEMBLY_SEPARATOR_WCHAR W(',') -#define ASSEMBLY_SEPARATOR_STR ", " -#define ASSEMBLY_SEPARATOR_WSTR W(", ") -#define ASSEMBLY_SEPARATOR_LEN 2 -#define NESTED_SEPARATOR_CHAR '+' -#define NESTED_SEPARATOR_WCHAR W('+') -#define NESTED_SEPARATOR_STR "+" -#define NESTED_SEPARATOR_WSTR W("+") -#endif - -#define EMPTY_STR "" -#define EMPTY_WSTR W("") #define MAKE_FULL_PATH_ON_STACK_UTF8(toptr, pnamespace, pname) \ { \ @@ -224,20 +150,11 @@ void MakeNestedTypeName( // throws on out of memory ns::MakePath(toptr, __i##toptr, pnamespace, pname); \ } -#define MAKE_FULL_PATH_ON_STACK_UNICODE(toptr, pnamespace, pname) \ -{ \ - int __i##toptr = ns::GetFullLength(pnamespace, pname); \ - toptr = (WCHAR *) alloca(__i##toptr * sizeof(WCHAR)); \ - ns::MakePath(toptr, __i##toptr, pnamespace, pname); \ -} - -#define MAKE_FULLY_QUALIFIED_NAME(pszFullyQualifiedName, pszNameSpace, pszName) MAKE_FULL_PATH_ON_STACK_UTF8(pszFullyQualifiedName, pszNameSpace, pszName) - #define MAKE_FULLY_QUALIFIED_MEMBER_NAME(ptr, pszNameSpace, pszClassName, pszMemberName, pszSig) \ { \ int __i##ptr = ns::GetFullLength(pszNameSpace, pszClassName); \ __i##ptr += (pszMemberName ? (int) strlen(pszMemberName) : 0); \ - __i##ptr += (NAMESPACE_SEPARATOR_LEN * 2); \ + __i##ptr += (int)strlen(NAMESPACE_SEPARATOR_STR) * 2; \ __i##ptr += (pszSig ? (int) strlen(pszSig) : 0); \ ptr = (LPUTF8) alloca(__i##ptr); \ ns::MakePath(ptr, __i##ptr, pszNameSpace, pszClassName); \ @@ -252,12 +169,4 @@ void MakeNestedTypeName( // throws on out of memory } \ } -#ifdef _PREFAST_ -// need to eliminate the expansion of MAKE_FULLY_QUALIFIED_MEMBER_NAME in prefast -// builds to prevent it complaining about the potential for NULLs to strlen and strcat -#undef MAKE_FULLY_QUALIFIED_MEMBER_NAME -// need to set ptr=NULL so we don't get a build error because ptr isn't inited in a couple cases -#define MAKE_FULLY_QUALIFIED_MEMBER_NAME(ptr, pszNameSpace, pszClassName, pszMemberName, pszSig) ptr=NULL; -#endif - -#endif +#endif // __NSUTILPRIV_H__ diff --git a/src/coreclr/utilcode/namespaceutil.cpp b/src/coreclr/utilcode/namespaceutil.cpp index c606e31a7fcdd..c17b07abae3ab 100644 --- a/src/coreclr/utilcode/namespaceutil.cpp +++ b/src/coreclr/utilcode/namespaceutil.cpp @@ -20,7 +20,6 @@ #include "nsutilpriv.h" - //***************************************************************************** // Determine how many chars large a fully qualified name would be given the // two parts of the name. The return value includes room for every character @@ -63,7 +62,6 @@ int ns::GetFullLength( // Number of chars in full name. return iLen; } //int ns::GetFullLength() - //***************************************************************************** // Scan the string from the rear looking for the first valid separator. If // found, return a pointer to it. Else return null. This code is smart enough @@ -105,30 +103,12 @@ LPUTF8 ns::FindSep( // Pointer to separator or null. return ptr; } //LPUTF8 ns::FindSep() - - //***************************************************************************** // Take a path and find the last separator (nsFindSep), and then replace the // separator with a '\0' and return a pointer to the name. So for example: // a.b.c // becomes two strings "a.b" and "c" and the return value points to "c". //***************************************************************************** -WCHAR *ns::SplitInline( // Pointer to name portion. - __inout __inout_z WCHAR *szPath) // The path to split. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - - WCHAR *ptr = ns::FindSep(szPath); - if (ptr) - { - *ptr = 0; - ++ptr; - } - return ptr; -} // WCHAR *ns::SplitInline() - LPUTF8 ns::SplitInline( // Pointer to name portion. __inout __inout_z LPUTF8 szPath) // The path to split. { @@ -145,28 +125,6 @@ LPUTF8 ns::SplitInline( // Pointer to name portion. return ptr; } // LPUTF8 ns::SplitInline() -void ns::SplitInline( - __inout __inout_z LPWSTR szPath, // Path to split. - LPCWSTR &szNameSpace, // Return pointer to namespace. - LPCWSTR &szName) // Return pointer to name. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - - WCHAR *ptr = SplitInline(szPath); - if (ptr) - { - szNameSpace = szPath; - szName = ptr; - } - else - { - szNameSpace = 0; - szName = szPath; - } -} // void ns::SplitInline() - void ns::SplitInline( __inout __inout_z LPUTF8 szPath, // Path to split. LPCUTF8 &szNameSpace, // Return pointer to namespace. @@ -189,7 +147,6 @@ void ns::SplitInline( } } // void ns::SplitInline() - //***************************************************************************** // Split the last parsable element from the end of the string as the name, // the first part as the namespace. @@ -287,7 +244,6 @@ int ns::SplitPath( // true ok, false trunction. return brtn; } // int ns::SplitPath() - //***************************************************************************** // Take two values and put them together in a fully qualified path using the // correct separator. @@ -377,111 +333,6 @@ int ns::MakePath( // true ok, false truncation. } // int ns::MakePath() -int ns::MakePath( // true ok, false truncation. - _Out_writes_(cchChars) WCHAR *szOut, // output path for name. - int cchChars, // max chars for output path. - LPCUTF8 szNamespace, // Namespace. - LPCUTF8 szName) // Name. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - - if (cchChars < 1) - return false; - - if (szOut) - *szOut = 0; - else - return false; - - if (szNamespace != NULL && *szNamespace != '\0') - { - if (cchChars < 2) - return false; - - int count; - - // We use cBuffer - 2 to account for the '.' and at least a 1 character name below. - count = MultiByteToWideChar(CP_UTF8, 0, szNamespace, -1, szOut, cchChars-2); - if (count == 0) - return false; // Supply a bigger buffer! - - // buffer access is bounded: MultiByteToWideChar returns 0 if access doesn't fit in range -#ifdef _PREFAST_ - #pragma warning( suppress: 26015 ) -#endif - szOut[count-1] = NAMESPACE_SEPARATOR_WCHAR; - szOut += count; - cchChars -= count; - } - - if (((cchChars == 0) && (szName != NULL) && (*szName != '\0')) || - (MultiByteToWideChar(CP_UTF8, 0, szName, -1, szOut, cchChars) == 0)) - return false; // supply a bigger buffer! - return true; -} // int ns::MakePath() - -int ns::MakePath( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - LPCUTF8 szNameSpace, // Namespace for name. - LPCUTF8 szName) // Final part of name. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - int iLen = 2; - if (szNameSpace) - iLen += (int)strlen(szNameSpace); - if (szName) - iLen += (int)strlen(szName); - LPUTF8 szOut = (LPUTF8) qb.AllocNoThrow(iLen); - if (!szOut) - return false; - return ns::MakePath(szOut, iLen, szNameSpace, szName); -} // int ns::MakePath() - -int ns::MakePath( // true ok, false out of memory - CQuickArray &qa, // Where to put results. - LPCUTF8 szNameSpace, // Namespace for name. - LPCUTF8 szName) // Final part of name. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - int iLen = 2; - if (szNameSpace) - iLen += (int)strlen(szNameSpace); - if (szName) - iLen += (int)strlen(szName); - WCHAR *szOut = (WCHAR *) qa.AllocNoThrow(iLen); - if (!szOut) - return false; - return ns::MakePath(szOut, iLen, szNameSpace, szName); -} // int ns::MakePath() - -int ns::MakePath( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - const WCHAR *szNameSpace, // Namespace for name. - const WCHAR *szName) // Final part of name. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - int iLen = 2; - if (szNameSpace) - iLen += (int)u16_strlen(szNameSpace); - if (szName) - iLen += (int)u16_strlen(szName); - WCHAR *szOut = (WCHAR *) qb.AllocNoThrow(iLen * sizeof(WCHAR)); - if (!szOut) - return false; - return ns::MakePath(szOut, iLen, szNameSpace, szName); -} // int ns::MakePath() - void ns::MakePath( // throws on out of memory SString &ssBuf, // Where to put results. const SString &ssNameSpace, // Namespace for name. @@ -511,168 +362,3 @@ void ns::MakePath( // throws on out of memory ssBuf.Append(ssName); } } - -bool ns::MakeAssemblyQualifiedName( // true ok, false truncation - _Out_writes_(dwBuffer) WCHAR* pBuffer, // Buffer to receive the results - int dwBuffer, // Number of characters total in buffer - const WCHAR *szTypeName, // Namespace for name. - int dwTypeName, // Number of characters (not including null) - const WCHAR *szAssemblyName, // Final part of name. - int dwAssemblyName) // Number of characters (not including null) -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - - if (dwBuffer < 2) - return false; - - int iCopyMax = 0; - _ASSERTE(pBuffer); - *pBuffer = W('\0'); - - if (szTypeName && *szTypeName != W('\0')) - { - _ASSERTE(dwTypeName > 0); - iCopyMax = min(dwBuffer-1, dwTypeName); - wcsncpy_s(pBuffer, dwBuffer, szTypeName, iCopyMax); - dwBuffer -= iCopyMax; - } - - if (szAssemblyName && *szAssemblyName != W('\0')) - { - - if(dwBuffer < ASSEMBLY_SEPARATOR_LEN) - return false; - - for(DWORD i = 0; i < ASSEMBLY_SEPARATOR_LEN; i++) - pBuffer[iCopyMax+i] = ASSEMBLY_SEPARATOR_WSTR[i]; - - dwBuffer -= ASSEMBLY_SEPARATOR_LEN; - if(dwBuffer == 0) - return false; - - int iCur = iCopyMax + ASSEMBLY_SEPARATOR_LEN; - _ASSERTE(dwAssemblyName > 0); - iCopyMax = min(dwBuffer-1, dwAssemblyName); - wcsncpy_s(pBuffer + iCur, dwBuffer, szAssemblyName, iCopyMax); - pBuffer[iCur + iCopyMax] = W('\0'); - - if (iCopyMax < dwAssemblyName) - return false; - } - else { - if(dwBuffer == 0) { - PREFIX_ASSUME(iCopyMax > 0); - pBuffer[iCopyMax-1] = W('\0'); - return false; - } - else - pBuffer[iCopyMax] = W('\0'); - } - - return true; -} // int ns::MakePath() - -bool ns::MakeAssemblyQualifiedName( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - const WCHAR *szTypeName, // Namespace for name. - const WCHAR *szAssemblyName) // Final part of name. -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - int iTypeName = 0; - int iAssemblyName = 0; - if (szTypeName) - iTypeName = (int)u16_strlen(szTypeName); - if (szAssemblyName) - iAssemblyName = (int)u16_strlen(szAssemblyName); - - int iLen = ASSEMBLY_SEPARATOR_LEN + iTypeName + iAssemblyName + 1; // Space for null terminator - WCHAR *szOut = (WCHAR *) qb.AllocNoThrow(iLen * sizeof(WCHAR)); - if (!szOut) - return false; - - bool ret; - ret = ns::MakeAssemblyQualifiedName(szOut, iLen, szTypeName, iTypeName, szAssemblyName, iAssemblyName); - _ASSERTE(ret); - return true; -} - -int ns::MakeNestedTypeName( // true ok, false out of memory - CQuickBytes &qb, // Where to put results. - LPCUTF8 szEnclosingName, // Full name for enclosing type - LPCUTF8 szNestedName) // Full name for nested type -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - _ASSERTE(szEnclosingName && szNestedName); - int iLen = 2; - iLen += (int)strlen(szEnclosingName); - iLen += (int)strlen(szNestedName); - LPUTF8 szOut = (LPUTF8) qb.AllocNoThrow(iLen); - if (!szOut) - return false; - return ns::MakeNestedTypeName(szOut, iLen, szEnclosingName, szNestedName); -} // int ns::MakeNestedTypeName() - -int ns::MakeNestedTypeName( // true ok, false truncation. - _Out_writes_ (cchChars) LPUTF8 szOut, // output path for name. - int cchChars, // max chars for output path. - LPCUTF8 szEnclosingName, // Full name for enclosing type - LPCUTF8 szNestedName) // Full name for nested type -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - - if (cchChars < 1) - return false; - - int iCopyMax = 0, iLen; - int brtn = true; - *szOut = 0; - - iLen = (int)strlen(szEnclosingName); - iCopyMax = min(cchChars-1, iLen); - strncpy_s(szOut, cchChars, szEnclosingName, iCopyMax); - - if (iLen >= cchChars) - brtn = false; - - szOut[iCopyMax] = NESTED_SEPARATOR_CHAR; - int iCur = iCopyMax+1; // iCopyMax characters + nested_separator_char - cchChars -= iCur; - if(cchChars == 0) - return false; - - iLen = (int)strlen(szNestedName); - iCopyMax = min(cchChars-1, iLen); - strncpy_s(&szOut[iCur], cchChars, szNestedName, iCopyMax); - szOut[iCur + iCopyMax] = 0; - - if (iLen >= cchChars) - brtn = false; - - return brtn; -} // int ns::MakeNestedTypeName() - -void ns::MakeNestedTypeName( // throws on out of memory - SString &ssBuf, // output path for name. - const SString &ssEnclosingName, // Full name for enclosing type - const SString &ssNestedName) // Full name for nested type -{ - STATIC_CONTRACT_THROWS; - STATIC_CONTRACT_GC_NOTRIGGER; - - ssBuf.Clear(); - - ssBuf.Append(ssEnclosingName); - ssBuf.Append(NESTED_SEPARATOR_WCHAR); - ssBuf.Append(ssNestedName); -} - diff --git a/src/coreclr/vm/class.cpp b/src/coreclr/vm/class.cpp index f15c87cf3b96f..8e6de1746c037 100644 --- a/src/coreclr/vm/class.cpp +++ b/src/coreclr/vm/class.cpp @@ -2290,7 +2290,11 @@ SString &MethodTable::_GetFullyQualifiedNameForClassNestedAwareInternal(SString ns::MakePath(ssPath, StackSString(SString::Utf8, redirectFunctor(szEnclNameSpace)), StackSString(SString::Utf8, szEnclName)); - ns::MakeNestedTypeName(ssFullyQualifiedName, ssPath, ssName); + + ssFullyQualifiedName.Clear(); + ssFullyQualifiedName.Append(ssPath); + ssFullyQualifiedName.Append('+'); + ssFullyQualifiedName.Append(ssName); ssName = ssFullyQualifiedName; } @@ -3291,4 +3295,3 @@ EEClass::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, MethodTable * pMT) } #endif // DACCESS_COMPILE -