From d17741d0c44b13cb4df864e0184cf1e499edcd57 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 22 Jun 2022 18:01:38 -0700 Subject: [PATCH] Change SString::GetUTF8NoConvert to GetUTF8 that converts the SString (#71101) * Change SString::GetUTF8NoConvert to GetUTF8 that converts the SString This enables SString to get out of the UTF16 state and helps move us away from "SString's natural encoding is UTF16" * Remove some stack scratch buffers that are unneeded now (as we can now convert the SString itself and in some cases it was already in UTF8) and implement PR feedback. * Add SetAndConvertToUTF8 method and remove the GetUTF8 method variants with a scratch buffer. * Remove unneeded variables. Co-authored-by: Jan Kotas Co-authored-by: Aaron Robinson Co-authored-by: Jan Kotas --- src/coreclr/debug/daccess/daccess.cpp | 2 +- src/coreclr/inc/sstring.h | 14 +-- src/coreclr/inc/sstring.inl | 19 +++ src/coreclr/utilcode/clrconfig.cpp | 8 +- src/coreclr/utilcode/debug.cpp | 8 +- src/coreclr/utilcode/sstring.cpp | 116 +++++++++--------- src/coreclr/vm/array.cpp | 9 +- src/coreclr/vm/assembly.cpp | 3 +- src/coreclr/vm/assemblynative.cpp | 21 ++-- src/coreclr/vm/assemblyspec.cpp | 18 ++- src/coreclr/vm/bundle.cpp | 5 +- src/coreclr/vm/class.cpp | 12 +- src/coreclr/vm/class.h | 8 +- src/coreclr/vm/classhash.cpp | 6 +- src/coreclr/vm/clsload.cpp | 6 +- src/coreclr/vm/codepitchingmanager.cpp | 10 +- src/coreclr/vm/comcallablewrapper.cpp | 2 +- src/coreclr/vm/comdelegate.cpp | 6 +- src/coreclr/vm/coreassemblyspec.cpp | 8 +- src/coreclr/vm/corhost.cpp | 6 +- src/coreclr/vm/customattribute.cpp | 26 ++-- src/coreclr/vm/customattribute.h | 1 - src/coreclr/vm/dllimport.cpp | 7 +- .../vm/eventing/eventpipe/ep-rt-coreclr.h | 3 +- src/coreclr/vm/gdbjit.cpp | 15 +-- src/coreclr/vm/generics.cpp | 8 +- src/coreclr/vm/genmeth.cpp | 3 +- src/coreclr/vm/jitinterface.cpp | 26 ++-- src/coreclr/vm/jitinterface.h | 2 +- src/coreclr/vm/method.cpp | 8 +- src/coreclr/vm/methodtablebuilder.cpp | 9 +- src/coreclr/vm/mlinfo.cpp | 5 +- src/coreclr/vm/multicorejit.cpp | 3 +- src/coreclr/vm/multicorejitplayer.cpp | 2 +- src/coreclr/vm/nativelibrary.cpp | 3 +- src/coreclr/vm/pgo.cpp | 15 +-- src/coreclr/vm/profilinghelper.cpp | 6 +- src/coreclr/vm/stubgen.cpp | 13 +- src/coreclr/vm/typeparse.cpp | 3 +- 39 files changed, 210 insertions(+), 235 deletions(-) diff --git a/src/coreclr/debug/daccess/daccess.cpp b/src/coreclr/debug/daccess/daccess.cpp index 564aa84cd687..55c7a4d0829f 100644 --- a/src/coreclr/debug/daccess/daccess.cpp +++ b/src/coreclr/debug/daccess/daccess.cpp @@ -2501,7 +2501,7 @@ namespace serialization { namespace bin { return ErrOverflow; } - memcpy_s(dest, destSize, s.GetUTF8NoConvert(), cnt); + memcpy_s(dest, destSize, s.GetUTF8(), cnt); return cnt; } diff --git a/src/coreclr/inc/sstring.h b/src/coreclr/inc/sstring.h index 691a739b7a34..3145d1b1e30d 100644 --- a/src/coreclr/inc/sstring.h +++ b/src/coreclr/inc/sstring.h @@ -168,6 +168,7 @@ class EMPTY_BASES_DECL SString : private SBuffer void SetASCII(const ASCII *string); void SetUTF8(const UTF8 *string); void SetANSI(const ANSI *string); + void SetAndConvertToUTF8(const WCHAR* string); // Set this string to a copy of the first count chars of the given string void Set(const WCHAR *string, COUNT_T count); @@ -492,17 +493,15 @@ class EMPTY_BASES_DECL SString : private SBuffer // SString *s = ...; // { // StackScratchBuffer buffer; - // const UTF8 *utf8 = s->GetUTF8(buffer); - // CallFoo(utf8); + // const ANSI *ansi = s->GetANSI(buffer); + // CallFoo(ansi); // } // // No more pointers to returned buffer allowed. - - const UTF8 *GetUTF8(AbstractScratchBuffer &scratch) const; - const UTF8 *GetUTF8(AbstractScratchBuffer &scratch, COUNT_T *pcbUtf8) const; const ANSI *GetANSI(AbstractScratchBuffer &scratch) const; - // Used when the representation is known, throws if the representation doesn't match - const UTF8 *GetUTF8NoConvert() const; + // You can always get a UTF8 string. This will force a conversion + // if necessary. + const UTF8 *GetUTF8() const; // Converts/copies into the given output string void ConvertToUnicode(SString &dest) const; @@ -727,6 +726,7 @@ class EMPTY_BASES_DECL SString : private SBuffer void ConvertASCIIToUnicode(SString &dest) const; void ConvertToUnicode() const; void ConvertToUnicode(const CIterator &i) const; + void ConvertToUTF8() const; const SString &GetCompatibleString(const SString &s, SString &scratch) const; const SString &GetCompatibleString(const SString &s, SString &scratch, const CIterator &i) const; diff --git a/src/coreclr/inc/sstring.inl b/src/coreclr/inc/sstring.inl index eeb35d9c8041..0d48c5a181db 100644 --- a/src/coreclr/inc/sstring.inl +++ b/src/coreclr/inc/sstring.inl @@ -651,6 +651,25 @@ inline const WCHAR *SString::GetUnicode() const SS_RETURN GetRawUnicode(); } +// Get a const pointer to the internal buffer as a UTF8 string. +inline const UTF8 *SString::GetUTF8() const +{ + SS_CONTRACT(const UTF8 *) + { + GC_NOTRIGGER; + PRECONDITION(CheckPointer(this)); + SS_POSTCONDITION(CheckPointer(RETVAL)); + if (IsRepresentation(REPRESENTATION_UTF8)) NOTHROW; else THROWS; + GC_NOTRIGGER; + SUPPORTS_DAC; + } + SS_CONTRACT_END; + + ConvertToUTF8(); + + SS_RETURN GetRawUTF8(); +} + // Normalize the string to unicode. This will make many operations nonfailing. inline void SString::Normalize() const { diff --git a/src/coreclr/utilcode/clrconfig.cpp b/src/coreclr/utilcode/clrconfig.cpp index aaa33a6e4b03..5df6748739cc 100644 --- a/src/coreclr/utilcode/clrconfig.cpp +++ b/src/coreclr/utilcode/clrconfig.cpp @@ -200,15 +200,11 @@ namespace #if defined(DEBUG) && !defined(SELF_NO_HOST) // Validate the cache and no-cache logic result in the same answer SString nameToConvert(name); - SString nameAsUTF8; - nameToConvert.ConvertToUTF8(nameAsUTF8); - SString valueAsUTF8; - temp.ConvertToUTF8(valueAsUTF8); - CLRConfigNoCache nonCache = CLRConfigNoCache::Get(nameAsUTF8.GetUTF8NoConvert(), noPrefix); + CLRConfigNoCache nonCache = CLRConfigNoCache::Get(nameToConvert.GetUTF8(), noPrefix); LPCSTR valueNoCache = nonCache.AsString(); - _ASSERTE(SString::_stricmp(valueNoCache, valueAsUTF8.GetUTF8NoConvert()) == 0); + _ASSERTE(SString::_stricmp(valueNoCache, temp.GetUTF8()) == 0); #endif // defined(DEBUG) && !defined(SELF_NO_HOST) } } diff --git a/src/coreclr/utilcode/debug.cpp b/src/coreclr/utilcode/debug.cpp index 3f4c74d420f9..e78de404115e 100644 --- a/src/coreclr/utilcode/debug.cpp +++ b/src/coreclr/utilcode/debug.cpp @@ -364,7 +364,7 @@ bool _DbgBreakCheck( " Image: %s\n\n", GetCurrentProcessId(), GetCurrentProcessId(), GetCurrentThreadId(), GetCurrentThreadId(), - szExpr, szFile, iLine, modulePath.GetUTF8NoConvert()); + szExpr, szFile, iLine, modulePath.GetUTF8()); formattedMessages = TRUE; } @@ -680,11 +680,11 @@ void DECLSPEC_NORETURN __FreeBuildAssertFail(const char *szFile, int iLine, cons " File: %s, Line: %d Image:\n%s\n", GetCurrentProcessId(), GetCurrentProcessId(), GetCurrentThreadId(), GetCurrentThreadId(), - szExpr, szFile, iLine, modulePath.GetUTF8NoConvert()); - OutputDebugStringUtf8(buffer.GetUTF8NoConvert()); + szExpr, szFile, iLine, modulePath.GetUTF8()); + OutputDebugStringUtf8(buffer.GetUTF8()); // Write out the error to the console - printf(buffer.GetUTF8NoConvert()); + printf(buffer.GetUTF8()); // Log to the stress log. Note that we can't include the szExpr b/c that // may not be a string literal (particularly for formatt-able asserts). diff --git a/src/coreclr/utilcode/sstring.cpp b/src/coreclr/utilcode/sstring.cpp index ec3c340ff23d..75e90977775a 100644 --- a/src/coreclr/utilcode/sstring.cpp +++ b/src/coreclr/utilcode/sstring.cpp @@ -469,6 +469,29 @@ void SString::SetANSI(const ANSI *string, COUNT_T count) SS_RETURN; } +//----------------------------------------------------------------------------- +// Set this string to a copy of the given UTF16 string transcoded to UTF8 +//----------------------------------------------------------------------------- +void SString::SetAndConvertToUTF8(const WCHAR *string) +{ + SS_CONTRACT_VOID + { + // !!! Check for illegal UTF8 encoding? + INSTANCE_CHECK; + PRECONDITION(CheckPointer(string, NULL_OK)); + THROWS; + GC_NOTRIGGER; + SUPPORTS_DAC_HOST_ONLY; + } + SS_CONTRACT_END; + + SString utf16Str(Literal, string); + + utf16Str.ConvertToUTF8(*this); + + SS_RETURN; +} + //----------------------------------------------------------------------------- // Set this string to the given unicode character //----------------------------------------------------------------------------- @@ -777,6 +800,39 @@ void SString::ConvertToUnicode(const CIterator &i) const RETURN; } +//----------------------------------------------------------------------------- +// Convert the internal representation for this String to UTF8. +//----------------------------------------------------------------------------- +void SString::ConvertToUTF8() const +{ + CONTRACT_VOID + { + POSTCONDITION(IsRepresentation(REPRESENTATION_UTF8)); + if (IsRepresentation(REPRESENTATION_UTF8)) NOTHROW; else THROWS; + GC_NOTRIGGER; + SUPPORTS_DAC_HOST_ONLY; + } + CONTRACT_END; + + if (!IsRepresentation(REPRESENTATION_UTF8)) + { + if (IsRepresentation(REPRESENTATION_ASCII)) + { + // ASCII is a subset of UTF8, so we can just set the representation. + (const_cast(this))->SetRepresentation(REPRESENTATION_UTF8); + } + else + { + StackSString s; + ConvertToUTF8(s); + PREFIX_ASSUME(!s.IsImmutable()); + (const_cast(this))->Set(s); + } + } + + RETURN; +} + //----------------------------------------------------------------------------- // Set s to be a copy of this string's contents, but in the unicode format. //----------------------------------------------------------------------------- @@ -1787,66 +1843,6 @@ const CHAR *SString::GetANSI(AbstractScratchBuffer &scratch) const SS_RETURN ((SString&)scratch).GetRawANSI(); } -//----------------------------------------------------------------------------- -// Get a const pointer to the internal buffer as a UTF8 string. -//----------------------------------------------------------------------------- -const UTF8 *SString::GetUTF8(AbstractScratchBuffer &scratch) const -{ - CONTRACT(const UTF8 *) - { - INSTANCE_CHECK_NULL; - THROWS; - GC_NOTRIGGER; - } - CONTRACT_END; - - if (IsRepresentation(REPRESENTATION_UTF8)) - RETURN GetRawUTF8(); - - ConvertToUTF8((SString&)scratch); - RETURN ((SString&)scratch).GetRawUTF8(); -} - -const UTF8 *SString::GetUTF8(AbstractScratchBuffer &scratch, COUNT_T *pcbUtf8) const -{ - CONTRACT(const UTF8 *) - { - INSTANCE_CHECK_NULL; - THROWS; - GC_NOTRIGGER; - } - CONTRACT_END; - - if (IsRepresentation(REPRESENTATION_UTF8)) - { - *pcbUtf8 = GetRawCount() + 1; - RETURN GetRawUTF8(); - } - - *pcbUtf8 = ConvertToUTF8((SString&)scratch); - RETURN ((SString&)scratch).GetRawUTF8(); -} - -//----------------------------------------------------------------------------- -// Get a const pointer to the internal buffer which must already be a UTF8 string. -// This avoids the need to create a scratch buffer we know will never be used. -//----------------------------------------------------------------------------- -const UTF8 *SString::GetUTF8NoConvert() const -{ - CONTRACT(const UTF8 *) - { - INSTANCE_CHECK_NULL; - THROWS; - GC_NOTRIGGER; - } - CONTRACT_END; - - if (IsRepresentation(REPRESENTATION_UTF8)) - RETURN GetRawUTF8(); - - ThrowHR(E_INVALIDARG); -} - //----------------------------------------------------------------------------- // Safe version of sprintf. // Prints formatted ansi text w/ var args to this buffer. diff --git a/src/coreclr/vm/array.cpp b/src/coreclr/vm/array.cpp index 69617911e035..aae2b2fb6c32 100644 --- a/src/coreclr/vm/array.cpp +++ b/src/coreclr/vm/array.cpp @@ -402,8 +402,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy StackSString ssElemName; elemTypeHnd.GetName(ssElemName); - StackScratchBuffer scratch; - elemTypeHnd.GetAssembly()->ThrowTypeLoadException(ssElemName.GetUTF8(scratch), IDS_CLASSLOAD_VALUECLASSTOOLARGE); + elemTypeHnd.GetAssembly()->ThrowTypeLoadException(ssElemName.GetUTF8(), IDS_CLASSLOAD_VALUECLASSTOOLARGE); } } @@ -510,8 +509,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy #ifdef _DEBUG StackSString debugName; TypeString::AppendType(debugName, TypeHandle(pMT)); - StackScratchBuffer buff; - const char* pDebugNameUTF8 = debugName.GetUTF8(buff); + const char* pDebugNameUTF8 = debugName.GetUTF8(); S_SIZE_T safeLen = S_SIZE_T(strlen(pDebugNameUTF8))+S_SIZE_T(1); if(safeLen.IsOverflow()) COMPlusThrowHR(COR_E_OVERFLOW); size_t len = safeLen.Value(); @@ -657,8 +655,7 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy StackSString ssElemName; elemTypeHnd.GetName(ssElemName); - StackScratchBuffer scratch; - elemTypeHnd.GetAssembly()->ThrowTypeLoadException(ssElemName.GetUTF8(scratch), + elemTypeHnd.GetAssembly()->ThrowTypeLoadException(ssElemName.GetUTF8(), IDS_CLASSLOAD_VALUECLASSTOOLARGE); } diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index e0bf705f1e97..329e43b5b0ef 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -993,8 +993,7 @@ Module *Assembly::FindModuleByName(LPCSTR pszModuleName) SString moduleName(SString::Utf8, pszModuleName); moduleName.LowerCase(); - StackScratchBuffer buffer; - pszModuleName = moduleName.GetUTF8(buffer); + pszModuleName = moduleName.GetUTF8(); mdFile kFile = GetManifestFileToken(pszModuleName); if (kFile == mdTokenNil) diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index cd0222b96b95..393b31c77b70 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -76,7 +76,7 @@ extern "C" void QCALLTYPE AssemblyNative_InternalLoad(NativeAssemblyNameParts* p COMPlusThrow(kArgumentException, W("Format_StringZeroLength")); StackSString ssName; - SString(SString::Literal, pAssemblyNameParts->_pName).ConvertToUTF8(ssName); + ssName.SetAndConvertToUTF8(pAssemblyNameParts->_pName); AssemblyMetaDataInternal asmInfo; @@ -87,11 +87,11 @@ extern "C" void QCALLTYPE AssemblyNative_InternalLoad(NativeAssemblyNameParts* p SmallStackSString ssLocale; if (pAssemblyNameParts->_pCultureName != NULL) - SString(SString::Literal, pAssemblyNameParts->_pCultureName).ConvertToUTF8(ssLocale); - asmInfo.szLocale = (pAssemblyNameParts->_pCultureName != NULL) ? ssLocale.GetUTF8NoConvert() : NULL; + ssLocale.SetAndConvertToUTF8(pAssemblyNameParts->_pCultureName); + asmInfo.szLocale = (pAssemblyNameParts->_pCultureName != NULL) ? ssLocale.GetUTF8() : NULL; // Initialize spec - spec.Init(ssName.GetUTF8NoConvert(), &asmInfo, + spec.Init(ssName.GetUTF8(), &asmInfo, pAssemblyNameParts->_pPublicKeyOrToken, pAssemblyNameParts->_cbPublicKeyOrToken, pAssemblyNameParts->_flags); if (pParentAssembly != NULL) @@ -541,10 +541,10 @@ extern "C" BYTE * QCALLTYPE AssemblyNative_GetResource(QCall::AssemblyHandle pAs COMPlusThrow(kArgumentNullException, W("ArgumentNull_String")); // Get the name in UTF8 - SString name(SString::Literal, wszName); + StackSString name; + name.SetAndConvertToUTF8(wszName); - StackScratchBuffer scratch; - LPCUTF8 pNameUTF8 = name.GetUTF8(scratch); + LPCUTF8 pNameUTF8 = name.GetUTF8(); if (*pNameUTF8 == '\0') COMPlusThrow(kArgumentException, W("Format_StringZeroLength")); @@ -571,10 +571,9 @@ extern "C" INT32 QCALLTYPE AssemblyNative_GetManifestResourceInfo(QCall::Assembl COMPlusThrow(kArgumentNullException, W("ArgumentNull_String")); // Get the name in UTF8 - SString name(SString::Literal, wszName); - - StackScratchBuffer scratch; - LPCUTF8 pNameUTF8 = name.GetUTF8(scratch); + StackSString name; + name.SetAndConvertToUTF8(wszName); + LPCUTF8 pNameUTF8 = name.GetUTF8(); if (*pNameUTF8 == '\0') COMPlusThrow(kArgumentException, W("Format_StringZeroLength")); diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 2270d62c8039..55e3fd80c41a 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -275,13 +275,23 @@ void AssemblySpec::InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* as AssemblySpec spec; spec.InitializeWithAssemblyIdentity(assemblyName); - StackScratchBuffer nameBuffer; - spec.SetName(assemblyName->GetSimpleName().GetUTF8(nameBuffer)); + StackSString nameBuffer; + nameBuffer.SetAndConvertToUTF8(assemblyName->GetSimpleName().GetUnicode()); + spec.SetName(nameBuffer.GetUTF8()); - StackScratchBuffer cultureBuffer; + StackSString cultureBuffer; if (assemblyName->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE)) { - LPCSTR culture = assemblyName->IsNeutralCulture() ? "" : assemblyName->GetCulture().GetUTF8(cultureBuffer); + LPCSTR culture; + if (assemblyName->IsNeutralCulture()) + { + culture = ""; + } + else + { + cultureBuffer.SetAndConvertToUTF8(assemblyName->GetCulture().GetUnicode()); + culture = cultureBuffer.GetUTF8(); + } spec.SetCulture(culture); } diff --git a/src/coreclr/vm/bundle.cpp b/src/coreclr/vm/bundle.cpp index a51ed906b710..5b66a331dd48 100644 --- a/src/coreclr/vm/bundle.cpp +++ b/src/coreclr/vm/bundle.cpp @@ -60,8 +60,9 @@ BundleFileLocation Bundle::Probe(const SString& path, bool pathIsBundleRelative) // Bundle.Probe("path/to/exe/lib.dll") => m_probe("lib.dll") // Bundle.Probe("path/to/exe/and/some/more/lib.dll") => m_probe("and/some/more/lib.dll") - StackScratchBuffer scratchBuffer; - LPCSTR utf8Path(path.GetUTF8(scratchBuffer)); + StackSString pathBuffer; + pathBuffer.SetAndConvertToUTF8(path.GetUnicode()); + LPCSTR utf8Path(pathBuffer.GetUTF8()); if (!pathIsBundleRelative) { diff --git a/src/coreclr/vm/class.cpp b/src/coreclr/vm/class.cpp index 118dc8c6e846..a82a80f37290 100644 --- a/src/coreclr/vm/class.cpp +++ b/src/coreclr/vm/class.cpp @@ -2236,7 +2236,7 @@ void MethodTable::DebugRecursivelyDumpInstanceFields(LPCUTF8 pszClassName, BOOL // Display them if(debug) { ssBuff.Printf("%s:\n", pszClassName); - OutputDebugStringUtf8(ssBuff.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssBuff.GetUTF8()); } else { LOG((LF_CLASSLOADER, LL_ALWAYS, "%s:\n", pszClassName)); @@ -2250,7 +2250,7 @@ void MethodTable::DebugRecursivelyDumpInstanceFields(LPCUTF8 pszClassName, BOOL #endif if(debug) { ssBuff.Printf("offset %3d %s\n", pFD->GetOffset_NoLogging(), pFD->GetName()); - OutputDebugStringUtf8(ssBuff.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssBuff.GetUTF8()); } else { LOG((LF_CLASSLOADER, LL_ALWAYS, "offset %3d %s\n", pFD->GetOffset_NoLogging(), pFD->GetName())); @@ -2299,7 +2299,7 @@ void MethodTable::DebugDumpFieldLayout(LPCUTF8 pszClassName, BOOL debug) if (debug) { ssBuff.Printf("Field layout for '%s':\n\n", pszClassName); - OutputDebugStringUtf8(ssBuff.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssBuff.GetUTF8()); } else { @@ -2326,7 +2326,7 @@ void MethodTable::DebugDumpFieldLayout(LPCUTF8 pszClassName, BOOL debug) FieldDesc *pFD = GetClass()->GetFieldDescList() + ((GetNumInstanceFields()-cParentInstanceFields) + i); if(debug) { ssBuff.Printf("offset %3d %s\n", pFD->GetOffset_NoLogging(), pFD->GetName()); - OutputDebugStringUtf8(ssBuff.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssBuff.GetUTF8()); } else { @@ -2404,7 +2404,7 @@ MethodTable::DebugDumpGCDesc( if (fDebug) { ssBuff.Printf("GC description for '%s':\n\n", pszClassName); - OutputDebugStringUtf8(ssBuff.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssBuff.GetUTF8()); } else { @@ -2438,7 +2438,7 @@ MethodTable::DebugDumpGCDesc( pSeries->GetSeriesOffset() - OBJECT_SIZE, pSeries->GetSeriesSize(), pSeries->GetSeriesSize() + GetBaseSize() ); - OutputDebugStringUtf8(ssBuff.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssBuff.GetUTF8()); } else { diff --git a/src/coreclr/vm/class.h b/src/coreclr/vm/class.h index 7b9f77bca449..0bbd15542ef2 100644 --- a/src/coreclr/vm/class.h +++ b/src/coreclr/vm/class.h @@ -507,11 +507,11 @@ typedef struct #define DEFAULT_NONSTACK_CLASSNAME_SIZE (MAX_CLASSNAME_LENGTH/4) #define DefineFullyQualifiedNameForClass() \ - ScratchBuffer _scratchbuffer_; \ + InlineSString _ssclsname8_; \ InlineSString _ssclsname_; #define DefineFullyQualifiedNameForClassOnStack() \ - ScratchBuffer _scratchbuffer_; \ + InlineSString _ssclsname8_; \ InlineSString _ssclsname_; #define DefineFullyQualifiedNameForClassW() \ @@ -521,13 +521,13 @@ typedef struct InlineSString _ssclsname_w_; #define GetFullyQualifiedNameForClassNestedAware(pClass) \ - pClass->_GetFullyQualifiedNameForClassNestedAware(_ssclsname_).GetUTF8(_scratchbuffer_) + (pClass->_GetFullyQualifiedNameForClassNestedAware(_ssclsname_), _ssclsname8_.SetAndConvertToUTF8(_ssclsname_), _ssclsname8_.GetUTF8()) #define GetFullyQualifiedNameForClassNestedAwareW(pClass) \ pClass->_GetFullyQualifiedNameForClassNestedAware(_ssclsname_w_).GetUnicode() #define GetFullyQualifiedNameForClass(pClass) \ - pClass->_GetFullyQualifiedNameForClass(_ssclsname_).GetUTF8(_scratchbuffer_) + (pClass->_GetFullyQualifiedNameForClass(_ssclsname_), _ssclsname8_.SetAndConvertToUTF8(_ssclsname_), _ssclsname8_.GetUTF8()) #define GetFullyQualifiedNameForClassW(pClass) \ pClass->_GetFullyQualifiedNameForClass(_ssclsname_w_).GetUnicode() diff --git a/src/coreclr/vm/classhash.cpp b/src/coreclr/vm/classhash.cpp index 005a39256573..0731843d1d42 100644 --- a/src/coreclr/vm/classhash.cpp +++ b/src/coreclr/vm/classhash.cpp @@ -205,14 +205,12 @@ static void ConstructKeyFromDataCaseInsensitive(EEClassHashTable::ConstructKeyCa StackSString nameSpace(SString::Utf8, pszNameSpace); nameSpace.LowerCase(); - StackScratchBuffer nameSpaceBuffer; - Key[0] = (LPUTF8)nameSpace.GetUTF8(nameSpaceBuffer); + Key[0] = (LPUTF8)nameSpace.GetUTF8(); StackSString name(SString::Utf8, pszName); name.LowerCase(); - StackScratchBuffer nameBuffer; - Key[1] = (LPUTF8)name.GetUTF8(nameBuffer); + Key[1] = (LPUTF8)name.GetUTF8(); pCallback->UseKeys(Key); } diff --git a/src/coreclr/vm/clsload.cpp b/src/coreclr/vm/clsload.cpp index 1e91485aeada..89ca31846fdf 100644 --- a/src/coreclr/vm/clsload.cpp +++ b/src/coreclr/vm/clsload.cpp @@ -1748,15 +1748,13 @@ VOID ClassLoader::CreateCanonicallyCasedKey(LPCUTF8 pszNameSpace, LPCUTF8 pszNam StackSString nameSpace(SString::Utf8, pszNameSpace); nameSpace.LowerCase(); - StackScratchBuffer nameSpaceBuffer; - pszNameSpace = nameSpace.GetUTF8(nameSpaceBuffer); + pszNameSpace = nameSpace.GetUTF8(); StackSString name(SString::Utf8, pszName); name.LowerCase(); - StackScratchBuffer nameBuffer; - pszName = name.GetUTF8(nameBuffer); + pszName = name.GetUTF8(); size_t iNSLength = strlen(pszNameSpace); diff --git a/src/coreclr/vm/codepitchingmanager.cpp b/src/coreclr/vm/codepitchingmanager.cpp index 45bac532a317..0e7429a29590 100644 --- a/src/coreclr/vm/codepitchingmanager.cpp +++ b/src/coreclr/vm/codepitchingmanager.cpp @@ -232,9 +232,8 @@ static void LookupOrCreateInPitchingCandidate(MethodDesc* pMD, ULONG sizeOfCode) SString className, methodName, methodSig; pMD->GetMethodInfo(className, methodName, methodSig); - StackScratchBuffer scratch; - const char* szClassName = className.GetUTF8(scratch); - const char* szMethodSig = methodSig.GetUTF8(scratch); + const char* szClassName = className.GetUTF8(); + const char* szMethodSig = methodSig.GetUTF8(); printf("Candidate %lu %s :: %s %s\n", sizeOfCode, szClassName, pMD->GetName(), szMethodSig); @@ -418,9 +417,8 @@ void MethodDesc::PitchNativeCode() SString className, methodName, methodSig; GetMethodInfo(className, methodName, methodSig); - StackScratchBuffer scratch; - const char* szClassName = className.GetUTF8(scratch); - const char* szMethodSig = methodSig.GetUTF8(scratch); + const char* szClassName = className.GetUTF8(); + const char* szMethodSig = methodSig.GetUTF8(); printf("Pitched %lu %lu %s :: %s %s\n", s_PitchedMethodCounter, pitchedBytes, szClassName, GetName(), szMethodSig); diff --git a/src/coreclr/vm/comcallablewrapper.cpp b/src/coreclr/vm/comcallablewrapper.cpp index bd3c48ed443f..330858a4fbad 100644 --- a/src/coreclr/vm/comcallablewrapper.cpp +++ b/src/coreclr/vm/comcallablewrapper.cpp @@ -734,7 +734,7 @@ void SimpleComCallWrapper::LogRefCount(ComCallWrapper *pWrap, StackSString &ssMe EX_TRY { ssMessage.AppendPrintf(", RefCount=%u\n", dwRefCountToLog); - OutputDebugStringUtf8(ssMessage.GetUTF8NoConvert()); + OutputDebugStringUtf8(ssMessage.GetUTF8()); } EX_CATCH { } diff --git a/src/coreclr/vm/comdelegate.cpp b/src/coreclr/vm/comdelegate.cpp index 235e79ad58ef..4dde8873b2f0 100644 --- a/src/coreclr/vm/comdelegate.cpp +++ b/src/coreclr/vm/comdelegate.cpp @@ -924,9 +924,9 @@ FCIMPL5(FC_BOOL_RET, COMDelegate::BindToMethodName, // // get the name in UTF8 format - SString wszName(SString::Literal, gc.methodName->GetBuffer()); - StackScratchBuffer utf8Name; - LPCUTF8 szNameStr = wszName.GetUTF8(utf8Name); + StackSString szName; + szName.SetAndConvertToUTF8(gc.methodName->GetBuffer()); + LPCUTF8 szNameStr = szName.GetUTF8(); // pick a proper compare function typedef int (__cdecl *UTF8StringCompareFuncPtr)(const char *, const char *); diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 3b8d0c0e8e53..5688d9a4cebf 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -186,7 +186,7 @@ extern "C" void QCALLTYPE AssemblyName_InitializeAssemblySpec(NativeAssemblyName BEGIN_QCALL; StackSString ssName; - SString(SString::Literal, pAssemblyNameParts->_pName).ConvertToUTF8(ssName); + ssName.SetAndConvertToUTF8(pAssemblyNameParts->_pName); AssemblyMetaDataInternal asmInfo; @@ -197,11 +197,11 @@ extern "C" void QCALLTYPE AssemblyName_InitializeAssemblySpec(NativeAssemblyName SmallStackSString ssLocale; if (pAssemblyNameParts->_pCultureName != NULL) - SString(SString::Literal, pAssemblyNameParts->_pCultureName).ConvertToUTF8(ssLocale); - asmInfo.szLocale = (pAssemblyNameParts->_pCultureName != NULL) ? ssLocale.GetUTF8NoConvert() : NULL; + ssLocale.SetAndConvertToUTF8(pAssemblyNameParts->_pCultureName); + asmInfo.szLocale = (pAssemblyNameParts->_pCultureName != NULL) ? ssLocale.GetUTF8() : NULL; // Initialize spec - pAssemblySpec->Init(ssName.GetUTF8NoConvert(), &asmInfo, + pAssemblySpec->Init(ssName.GetUTF8(), &asmInfo, pAssemblyNameParts->_pPublicKeyOrToken, pAssemblyNameParts->_cbPublicKeyOrToken, pAssemblyNameParts->_flags); // Copy and own any fields we do not own diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index cc9fc82db720..e1babc7f6228 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -426,15 +426,13 @@ HRESULT CorHost2::ExecuteInDefaultAppDomain(LPCWSTR pwzAssemblyPath, Assembly *pAssembly = AssemblySpec::LoadAssembly(pwzAssemblyPath); SString szTypeName(pwzTypeName); - StackScratchBuffer buff1; - const char* szTypeNameUTF8 = szTypeName.GetUTF8(buff1); + const char* szTypeNameUTF8 = szTypeName.GetUTF8(); MethodTable *pMT = ClassLoader::LoadTypeByNameThrowing(pAssembly, NULL, szTypeNameUTF8).AsMethodTable(); SString szMethodName(pwzMethodName); - StackScratchBuffer buff; - const char* szMethodNameUTF8 = szMethodName.GetUTF8(buff); + const char* szMethodNameUTF8 = szMethodName.GetUTF8(); MethodDesc *pMethodMD = MemberLoader::FindMethod(pMT, szMethodNameUTF8, &gsig_SM_Str_RetInt); if (!pMethodMD) diff --git a/src/coreclr/vm/customattribute.cpp b/src/coreclr/vm/customattribute.cpp index 00c9150cddd7..ea18d499577a 100644 --- a/src/coreclr/vm/customattribute.cpp +++ b/src/coreclr/vm/customattribute.cpp @@ -33,9 +33,8 @@ TypeHandle Attribute::GetTypeForEnum(LPCUTF8 szEnumName, COUNT_T cbEnumName, Dom } CONTRACTL_END; - StackScratchBuffer buff; StackSString sszEnumName(SString::Utf8, szEnumName, cbEnumName); - return TypeName::GetTypeUsingCASearchRules(sszEnumName.GetUTF8(buff), pDomainAssembly->GetAssembly()); + return TypeName::GetTypeUsingCASearchRules(sszEnumName.GetUTF8(), pDomainAssembly->GetAssembly()); } /*static*/ @@ -389,12 +388,11 @@ HRESULT Attribute::ParseCaNamedArgs( IfFailGo(Attribute::ParseCaType(ca, pNamedArgType, pDomainAssembly, &ss)); LPCSTR szLoadedEnumName = NULL; - StackScratchBuffer buff; if (pNamedArgType->tag == SERIALIZATION_TYPE_ENUM || (pNamedArgType->tag == SERIALIZATION_TYPE_SZARRAY && pNamedArgType->arrayType == SERIALIZATION_TYPE_ENUM )) { - szLoadedEnumName = ss.GetUTF8(buff); + szLoadedEnumName = ss.GetUTF8(); } // Get name of Arg. @@ -471,23 +469,20 @@ HRESULT Attribute::ParseCaNamedArgs( } /*static*/ -HRESULT Attribute::InitCaType(CustomAttributeType* pType, Factory* pSstringFactory, Factory* pStackScratchBufferFactory, CaType* pCaType) +HRESULT Attribute::InitCaType(CustomAttributeType* pType, Factory* pSstringFactory, CaType* pCaType) { CONTRACTL { THROWS; PRECONDITION(CheckPointer(pType)); PRECONDITION(CheckPointer(pSstringFactory)); - PRECONDITION(CheckPointer(pStackScratchBufferFactory)); PRECONDITION(CheckPointer(pCaType)); } CONTRACTL_END; HRESULT hr = S_OK; SString* psszName = NULL; - StackScratchBuffer* scratchBuffer = NULL; IfNullGo(psszName = pSstringFactory->Create()); - IfNullGo(scratchBuffer = pStackScratchBufferFactory->Create()); psszName->Set(pType->m_enumName == NULL ? NULL : pType->m_enumName->GetBuffer()); @@ -495,7 +490,7 @@ HRESULT Attribute::InitCaType(CustomAttributeType* pType, Factory* pSst pType->m_tag, pType->m_arrayType, pType->m_enumType, - psszName->GetUTF8(*scratchBuffer), + psszName->GetUTF8(), (ULONG)psszName->GetCount()); ErrExit: @@ -539,7 +534,6 @@ FCIMPL5(VOID, Attribute::ParseAttributeArguments, void* pCa, INT32 cCa, // on what we can allocate inline here. Leave the Windows versions alone to retain the perf benefits // since we don't have the same constraints. NewHolder pCaValueArrayFactory = new InlineFactory, 4>(); - InlineFactory stackScratchBufferFactory; InlineFactory sstringFactory; #else // __GNUC__ @@ -552,9 +546,6 @@ FCIMPL5(VOID, Attribute::ParseAttributeArguments, void* pCa, INT32 cCa, InlineFactory, 4> caValueArrayFactory; InlineFactory, 4> *pCaValueArrayFactory = &caValueArrayFactory; - // Need one StackScratchBuffer per ctor arg and two per named arg - InlineFactory stackScratchBufferFactory; - // Need one SString per ctor arg and two per named arg InlineFactory sstringFactory; #endif // __GNUC__ @@ -573,7 +564,7 @@ FCIMPL5(VOID, Attribute::ParseAttributeArguments, void* pCa, INT32 cCa, for (COUNT_T i = 0; i < cArgs; i ++) { CaType caType; - IfFailGo(Attribute::InitCaType(&gc.pArgs[i].m_type, &sstringFactory, &stackScratchBufferFactory, &caType)); + IfFailGo(Attribute::InitCaType(&gc.pArgs[i].m_type, &sstringFactory, &caType)); pCaArgs[i].Init(caType); } @@ -595,18 +586,15 @@ FCIMPL5(VOID, Attribute::ParseAttributeArguments, void* pCa, INT32 cCa, CustomAttributeNamedArgument* pNamedArg = &gc.pNamedArgs[i]; CaType caType; - IfFailGo(Attribute::InitCaType(&pNamedArg->m_type, &sstringFactory, &stackScratchBufferFactory, &caType)); + IfFailGo(Attribute::InitCaType(&pNamedArg->m_type, &sstringFactory, &caType)); SString* psszName = NULL; IfNullGo(psszName = sstringFactory.Create()); psszName->Set(pNamedArg->m_argumentName->GetBuffer()); - StackScratchBuffer* scratchBuffer = NULL; - IfNullGo(scratchBuffer = stackScratchBufferFactory.Create()); - pCaNamedArgs[i].Init( - psszName->GetUTF8(*scratchBuffer), + psszName->GetUTF8(), pNamedArg->m_propertyOrField, caType); } diff --git a/src/coreclr/vm/customattribute.h b/src/coreclr/vm/customattribute.h index ac95fa80af99..6d4282d8f52a 100644 --- a/src/coreclr/vm/customattribute.h +++ b/src/coreclr/vm/customattribute.h @@ -139,7 +139,6 @@ class Attribute static HRESULT InitCaType( CustomAttributeType* pType, Factory* pSstringFactory, - Factory* pStackScratchBufferFactory, CaType* pCaType); static HRESULT ParseCaType( diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index dceb6f6b89f7..5fc6d3c15b9f 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -1010,7 +1010,7 @@ class ILStubState : public StubState strILStubCode.AppendPrintf("// Code size\t%d (0x%04x)\n", cbCode, cbCode); strILStubCode.AppendPrintf(".maxstack %d \n", maxStack); - strILStubCode.AppendPrintf(".locals %s\n", strLocalSig.GetUTF8NoConvert()); + strILStubCode.AppendPrintf(".locals %s\n", strLocalSig.GetUTF8()); m_slIL.LogILStub(jitFlags, &strILStubCode); @@ -4628,8 +4628,9 @@ HRESULT FindPredefinedILStubMethod(MethodDesc *pTargetMD, DWORD dwStubFlags, Met // // Find method using name + signature // - StackScratchBuffer buffer; - LPCUTF8 szMethodNameUTF8 = methodName.GetUTF8(buffer); + StackSString buffer; + buffer.SetAndConvertToUTF8(methodName); + LPCUTF8 szMethodNameUTF8 = buffer.GetUTF8(); pStubMD = MemberLoader::FindMethod(stubClassType.GetMethodTable(), szMethodNameUTF8, pStubSig, diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 6c35c8fa5019..c4246df418a6 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1369,10 +1369,9 @@ ep_rt_method_get_full_name ( EX_TRY { SString method_name; - StackScratchBuffer conversion; TypeString::AppendMethodInternal (method_name, method, TypeString::FormatNamespace | TypeString::FormatSignature); - const ep_char8_t *method_name_utf8 = method_name.GetUTF8 (conversion); + const ep_char8_t *method_name_utf8 = method_name.GetUTF8 (); if (method_name_utf8) { size_t method_name_utf8_len = strlen (method_name_utf8) + 1; size_t to_copy = method_name_utf8_len < name_len ? method_name_utf8_len : name_len; diff --git a/src/coreclr/vm/gdbjit.cpp b/src/coreclr/vm/gdbjit.cpp index 525ca50a28c2..eac4f9429e0b 100644 --- a/src/coreclr/vm/gdbjit.cpp +++ b/src/coreclr/vm/gdbjit.cpp @@ -512,8 +512,7 @@ GetDebugInfoFromPDB(MethodDesc* methodDescPtr, if (modName.IsEmpty()) return E_FAIL; - StackScratchBuffer scratch; - const char* szModName = modName.GetUTF8(scratch); + const char* szModName = modName.GetUTF8(); MethodDebugInfo methodDebugInfo(numMap, locals.countVars); @@ -956,8 +955,7 @@ void TypeInfoBase::CalculateName() TypeString::AppendType(sName, typeHandle, formatFlags); - StackScratchBuffer buffer; - const UTF8 *utf8 = sName.GetUTF8(buffer); + const UTF8 *utf8 = sName.GetUTF8(); if (typeHandle.IsValueType()) { m_type_name = new char[strlen(utf8) + 1]; @@ -1298,11 +1296,9 @@ void FunctionMember::DumpLinkageName(char* ptr, int& offset) md->GetMethodInfoNoSig(namespaceOrClassName, methodName); SString utf8namespaceOrClassName; SString utf8methodName; - namespaceOrClassName.ConvertToUTF8(utf8namespaceOrClassName); - methodName.ConvertToUTF8(utf8methodName); - const char *nspace = utf8namespaceOrClassName.GetUTF8NoConvert(); - const char *mname = utf8methodName.GetUTF8NoConvert(); + const char *nspace = utf8namespaceOrClassName.GetUTF8(); + const char *mname = utf8methodName.GetUTF8(); if (!nspace || !mname) { @@ -2538,8 +2534,7 @@ void NotifyGdb::OnMethodPrepared(MethodDesc* methodDescPtr) /* Get module name */ const Module* mod = methodDescPtr->GetMethodTable()->GetModule(); SString modName = mod->GetFile()->GetPath(); - StackScratchBuffer scratch; - const char* szModName = modName.GetUTF8(scratch); + const char* szModName = modName.GetUTF8(); const char* szModuleFile = SplitFilename(szModName); int length = MultiByteToWideChar(CP_UTF8, 0, szModuleFile, -1, NULL, 0); diff --git a/src/coreclr/vm/generics.cpp b/src/coreclr/vm/generics.cpp index fea2ce22645f..55f1d274990c 100644 --- a/src/coreclr/vm/generics.cpp +++ b/src/coreclr/vm/generics.cpp @@ -187,9 +187,8 @@ ClassLoader::CreateTypeHandleForNonCanonicalGenericInstantiation( TypeString::AppendTypeKeyDebug(debugTypeKeyName, pTypeKey); LOG((LF_CLASSLOADER, LL_INFO1000, "GENERICS: New instantiation requested: %S\n", debugTypeKeyName.GetUnicode())); - StackScratchBuffer buf; - if (g_pConfig->ShouldBreakOnInstantiation(debugTypeKeyName.GetUTF8(buf))) - CONSISTENCY_CHECK_MSGF(false, ("BreakOnInstantiation: typename '%s' ", debugTypeKeyName.GetUTF8(buf))); + if (g_pConfig->ShouldBreakOnInstantiation(debugTypeKeyName.GetUTF8())) + CONSISTENCY_CHECK_MSGF(false, ("BreakOnInstantiation: typename '%s' ", debugTypeKeyName.GetUTF8())); } #endif // _DEBUG @@ -474,8 +473,7 @@ ClassLoader::CreateTypeHandleForNonCanonicalGenericInstantiation( // Name for debugging StackSString debug_ClassNameString; TypeString::AppendTypeKey(debug_ClassNameString, pTypeKey, TypeString::FormatNamespace | TypeString::FormatAngleBrackets | TypeString::FormatFullInst); - StackScratchBuffer debug_ClassNameBuffer; - const char *debug_szClassNameBuffer = debug_ClassNameString.GetUTF8(debug_ClassNameBuffer); + const char *debug_szClassNameBuffer = debug_ClassNameString.GetUTF8(); S_SIZE_T safeLen = S_SIZE_T(strlen(debug_szClassNameBuffer)) + S_SIZE_T(1); if (safeLen.IsOverflow()) COMPlusThrowHR(COR_E_OVERFLOW); diff --git a/src/coreclr/vm/genmeth.cpp b/src/coreclr/vm/genmeth.cpp index 24b47038c296..a53119385ef2 100644 --- a/src/coreclr/vm/genmeth.cpp +++ b/src/coreclr/vm/genmeth.cpp @@ -475,8 +475,7 @@ InstantiatedMethodDesc::NewInstantiatedMethodDesc(MethodTable *pExactMT, #ifdef _DEBUG SString name; TypeString::AppendMethodDebug(name, pNewMD); - StackScratchBuffer buff; - const char* pDebugNameUTF8 = name.GetUTF8(buff); + const char* pDebugNameUTF8 = name.GetUTF8(); const char* verb = "Created"; if (pWrappedMD) LOG((LF_CLASSLOADER, LL_INFO1000, diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index bc06ec12eb4c..ccd6390b1bb2 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -6210,7 +6210,8 @@ const char* CEEInfo::getMethodName (CORINFO_METHOD_HANDLE ftnHnd, const char** s if (!inst.IsEmpty()) TypeString::AppendInst(ssClsNameBuff, inst); - *scopeName = ssClsNameBuff.GetUTF8(ssClsNameBuffScratch); + ssClsNameBuffUTF8.SetAndConvertToUTF8(ssClsNameBuff.GetUnicode()); + *scopeName = ssClsNameBuffUTF8.GetUTF8(); #else // !_DEBUG // since this is for diagnostic purposes only, // give up on the namespace, as we don't have a buffer to concat it @@ -9140,7 +9141,8 @@ const char* CEEInfo::getFieldName (CORINFO_FIELD_HANDLE fieldHnd, const char** s { #ifdef _DEBUG t.GetName(ssClsNameBuff); - *scopeName = ssClsNameBuff.GetUTF8(ssClsNameBuffScratch); + ssClsNameBuffUTF8.SetAndConvertToUTF8(ssClsNameBuff.GetUnicode()); + *scopeName = ssClsNameBuffUTF8.GetUTF8(); #else // !_DEBUG // since this is for diagnostic purposes only, // give up on the namespace, as we don't have a buffer to concat it @@ -12939,16 +12941,15 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config, SString moduleName; ftn->GetModule()->GetDomainAssembly()->GetPEAssembly()->GetPathOrCodeBase(moduleName); - MAKE_UTF8PTR_FROMWIDE(moduleNameUtf8, moduleName.GetUnicode()); SString codeBase; codeBase.AppendPrintf("%s,0x%x,%d,%d\n", - moduleNameUtf8, //module name + moduleName.GetUTF8(), //module name ftn->GetMemberDef(), //method token (unsigned)(methodJitTimeStop.QuadPart - methodJitTimeStart.QuadPart), //cycle count methodInfo.ILCodeSize //il size ); - OutputDebugStringUtf8(codeBase.GetUTF8NoConvert()); + OutputDebugStringUtf8(codeBase.GetUTF8()); } #endif // PERF_TRACK_METHOD_JITTIMES @@ -13738,8 +13739,9 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, #ifdef _DEBUG { - StackScratchBuffer buf; - _ASSERTE_MSG(false, fatalErrorString.GetUTF8(buf)); + StackSString buf; + buf.SetAndConvertToUTF8(fatalErrorString.GetUnicode()); + _ASSERTE_MSG(false, buf.GetUTF8()); // Run through the type layout logic again, after the assert, makes debugging easy TypeLayoutCheck(pMT, pBlob, /* printDiff */ TRUE); } @@ -13818,8 +13820,9 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, #ifdef _DEBUG { - StackScratchBuffer buf; - _ASSERTE_MSG(false, fatalErrorString.GetUTF8(buf)); + StackSString buf; + buf.SetAndConvertToUTF8(fatalErrorString.GetUnicode()); + _ASSERTE_MSG(false, buf.GetUTF8()); } #endif @@ -13939,8 +13942,9 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, #ifdef _DEBUG { - StackScratchBuffer buf; - _ASSERTE_MSG(false, fatalErrorString.GetUTF8(buf)); + StackSString buf; + buf.SetAndConvertToUTF8(fatalErrorString.GetUnicode()); + _ASSERTE_MSG(false, buf.GetUTF8()); } #endif _ASSERTE(!IsDebuggerPresent() && "Stop on assert here instead of fatal error for ease of live debugging"); diff --git a/src/coreclr/vm/jitinterface.h b/src/coreclr/vm/jitinterface.h index 492b2fbe5fe1..9355becf8305 100644 --- a/src/coreclr/vm/jitinterface.h +++ b/src/coreclr/vm/jitinterface.h @@ -520,7 +520,7 @@ class CEEInfo : public ICorJitInfo #ifdef _DEBUG InlineSString ssClsNameBuff; - ScratchBuffer ssClsNameBuffScratch; + InlineSString ssClsNameBuffUTF8; #endif public: diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index 221be23cd487..fef201a83cd9 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -353,17 +353,15 @@ VOID MethodDesc::GetFullMethodInfo(SString& fullMethodSigName) PCCOR_SIGNATURE pSig; SString methodFullName; - StackScratchBuffer namespaceNameBuffer, methodNameBuffer; methodFullName.AppendPrintf( (LPCUTF8)"[%s] %s::%s", GetModule()->GetAssembly()->GetSimpleName(), - namespaceOrClassName.GetUTF8(namespaceNameBuffer), - methodName.GetUTF8(methodNameBuffer)); + namespaceOrClassName.GetUTF8(), + methodName.GetUTF8()); GetSig(&pSig, &cSig); - StackScratchBuffer buffer; - PrettyPrintSig(pSig, (DWORD)cSig, methodFullName.GetUTF8(buffer), &qbOut, GetMDImport(), NULL); + PrettyPrintSig(pSig, (DWORD)cSig, methodFullName.GetUTF8(), &qbOut, GetMDImport(), NULL); fullMethodSigName.AppendUTF8((char *)qbOut.Ptr()); } diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index ffb90a935cac..57089d293765 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -1349,8 +1349,7 @@ MethodTableBuilder::BuildMethodTableThrowing( { StackSString debugName(SString::Utf8, GetDebugClassName()); TypeString::AppendInst(debugName, bmtGenerics->GetInstantiation(), TypeString::FormatBasic); - StackScratchBuffer buff; - const char* pDebugNameUTF8 = debugName.GetUTF8(buff); + const char* pDebugNameUTF8 = debugName.GetUTF8(); S_SIZE_T safeLen = S_SIZE_T(strlen(pDebugNameUTF8)) + S_SIZE_T(1); if(safeLen.IsOverflow()) COMPlusThrowHR(COR_E_OVERFLOW); @@ -1894,8 +1893,7 @@ MethodTableBuilder::BuildMethodTableThrowing( MethodDesc *pMD = methIt->GetUnboxedMethodDesc(); StackSString name; TypeString::AppendMethodDebug(name, pMD); - StackScratchBuffer buff; - const char* pDebugNameUTF8 = name.GetUTF8(buff); + const char* pDebugNameUTF8 = name.GetUTF8(); S_SIZE_T safeLen = S_SIZE_T(strlen(pDebugNameUTF8)) + S_SIZE_T(1); if(safeLen.IsOverflow()) COMPlusThrowHR(COR_E_OVERFLOW); size_t len = safeLen.Value(); @@ -1909,8 +1907,7 @@ MethodTableBuilder::BuildMethodTableThrowing( StackSString name; TypeString::AppendMethodDebug(name, pMD); - StackScratchBuffer buff; - const char* pDebugNameUTF8 = name.GetUTF8(buff); + const char* pDebugNameUTF8 = name.GetUTF8(); S_SIZE_T safeLen = S_SIZE_T(strlen(pDebugNameUTF8))+S_SIZE_T(1); if(safeLen.IsOverflow()) COMPlusThrowHR(COR_E_OVERFLOW); size_t len = safeLen.Value(); diff --git a/src/coreclr/vm/mlinfo.cpp b/src/coreclr/vm/mlinfo.cpp index 471cbb1165aa..8984b8e4e9ed 100644 --- a/src/coreclr/vm/mlinfo.cpp +++ b/src/coreclr/vm/mlinfo.cpp @@ -916,7 +916,7 @@ CustomMarshalerHelper *EEMarshalingData::GetCustomMarshalerHelper(Assembly *pAss // Load the custom marshaler class. BOOL fNameIsAsmQualified = FALSE; - hndCustomMarshalerType = TypeName::GetTypeUsingCASearchRules(strCMMarshalerTypeName.GetUTF8NoConvert(), pAssembly, &fNameIsAsmQualified); + hndCustomMarshalerType = TypeName::GetTypeUsingCASearchRules(strCMMarshalerTypeName.GetUTF8(), pAssembly, &fNameIsAsmQualified); if (hndCustomMarshalerType.IsGenericTypeDefinition()) { @@ -2067,9 +2067,8 @@ MarshalInfo::MarshalInfo(Module* pModule, { // Load the type. Use an SString for the string since we need to NULL terminate the string // that comes from the metadata. - StackScratchBuffer utf8Name; SString safeArrayUserDefTypeName(SString::Utf8, ParamInfo.m_strSafeArrayUserDefTypeName, ParamInfo.m_cSafeArrayUserDefTypeNameBytes); - thElement = TypeName::GetTypeUsingCASearchRules(safeArrayUserDefTypeName.GetUTF8(utf8Name), pAssembly); + thElement = TypeName::GetTypeUsingCASearchRules(safeArrayUserDefTypeName.GetUTF8(), pAssembly); } } else diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index 1a697a283bdd..bd940acb3b87 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -309,10 +309,9 @@ bool RecorderModuleInfo::SetModule(Module * pMod) simpleName.Set((const BYTE *) pModuleName, lenModuleName); // SBuffer::Set copies over name SString sAssemblyName; - StackScratchBuffer scratch; pMod->GetAssembly()->GetPEAssembly()->GetDisplayName(sAssemblyName); - LPCUTF8 pAssemblyName = sAssemblyName.GetUTF8(scratch); + LPCUTF8 pAssemblyName = sAssemblyName.GetUTF8(); unsigned lenAssemblyName = sAssemblyName.GetCount(); assemblyName.Set((const BYTE *) pAssemblyName, lenAssemblyName); diff --git a/src/coreclr/vm/multicorejitplayer.cpp b/src/coreclr/vm/multicorejitplayer.cpp index dd4801404644..46e2c6f72121 100644 --- a/src/coreclr/vm/multicorejitplayer.cpp +++ b/src/coreclr/vm/multicorejitplayer.cpp @@ -318,7 +318,7 @@ void PlayerModuleInfo::Dump(const CHAR * prefix, int index) i ++; } - MulticoreJitTrace(("%s", ssBuff.GetUTF8NoConvert())); + MulticoreJitTrace(("%s", ssBuff.GetUTF8())); } #endif diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index f5873ac0b9bf..3b1299986da3 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -719,8 +719,7 @@ namespace SString moduleName(SString::Utf8, szLibName); moduleName.LowerCase(); - StackScratchBuffer buffer; - szLibName = (LPSTR)moduleName.GetUTF8(buffer); + szLibName = (LPSTR)moduleName.GetUTF8(); Assembly *pAssembly = spec.LoadAssembly(FILE_LOADED); Module *pModule = pAssembly->FindModuleByName(szLibName); diff --git a/src/coreclr/vm/pgo.cpp b/src/coreclr/vm/pgo.cpp index a4bad1f5c6df..b6b1a155eb94 100644 --- a/src/coreclr/vm/pgo.cpp +++ b/src/coreclr/vm/pgo.cpp @@ -220,10 +220,8 @@ void PgoManager::WritePgoData() SString tClass, tMethodName, tMethodSignature; pgoData->header.method->GetMethodInfo(tClass, tMethodName, tMethodSignature); - StackScratchBuffer nameBuffer; - StackScratchBuffer nameBuffer2; - fprintf(pgoDataFile, "MethodName: %s.%s\n", tClass.GetUTF8(nameBuffer), tMethodName.GetUTF8(nameBuffer2)); - fprintf(pgoDataFile, "Signature: %s\n", tMethodSignature.GetUTF8(nameBuffer)); + fprintf(pgoDataFile, "MethodName: %s.%s\n", tClass.GetUTF8(), tMethodName.GetUTF8()); + fprintf(pgoDataFile, "Signature: %s\n", tMethodSignature.GetUTF8()); uint8_t* data = pgoData->header.GetData(); @@ -262,7 +260,6 @@ void PgoManager::WritePgoData() else { StackSString ss; - StackScratchBuffer nameBuffer; TypeString::AppendType(ss, th, TypeString::FormatNamespace | TypeString::FormatFullInst | TypeString::FormatAssembly); if (ss.GetCount() > 8192) { @@ -270,7 +267,7 @@ void PgoManager::WritePgoData() } else { - fprintf(pgoDataFile, s_TypeHandle, ss.GetUTF8(nameBuffer)); + fprintf(pgoDataFile, s_TypeHandle, ss.GetUTF8()); } } break; @@ -301,9 +298,7 @@ void PgoManager::WritePgoData() } else { - StackScratchBuffer methodNameBuffer; - StackScratchBuffer typeBuffer; - fprintf(pgoDataFile, "MethodHandle: %s|@|%s\n", tMethodName.GetUTF8(methodNameBuffer), tTypeName.GetUTF8(typeBuffer)); + fprintf(pgoDataFile, "MethodHandle: %s|@|%s\n", tMethodName.GetUTF8(), tTypeName.GetUTF8()); } } break; @@ -871,7 +866,7 @@ HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE** pAlloca TypeHandle th = TypeName::GetTypeManaged(typeString.GetUnicode(), NULL, FALSE, FALSE, FALSE, NULL, NULL); if (!th.IsNull()) { - MethodDesc* pMD = MemberLoader::FindMethodByName(th.GetMethodTable(), methodString.GetUTF8NoConvert()); + MethodDesc* pMD = MemberLoader::FindMethodByName(th.GetMethodTable(), methodString.GetUTF8()); newPtr = (INT_PTR)pMD; } } diff --git a/src/coreclr/vm/profilinghelper.cpp b/src/coreclr/vm/profilinghelper.cpp index 285bcaab9887..20d3cbf175f2 100644 --- a/src/coreclr/vm/profilinghelper.cpp +++ b/src/coreclr/vm/profilinghelper.cpp @@ -260,7 +260,7 @@ void ProfilingAPIUtility::AppendSupplementaryInformation(int iStringResource, SS pString->AppendUTF8(" "); pString->AppendPrintf( - supplementaryInformationUtf8.GetUTF8NoConvert(), + supplementaryInformationUtf8.GetUTF8(), GetCurrentProcessId(), iStringResource); } @@ -311,7 +311,7 @@ void ProfilingAPIUtility::LogProfEventVA( messageFromResource.ConvertToUTF8(messageFromResourceUtf8); StackSString messageToLog; - messageToLog.VPrintf(messageFromResourceUtf8.GetUTF8NoConvert(), insertionArgs); + messageToLog.VPrintf(messageFromResourceUtf8.GetUTF8(), insertionArgs); AppendSupplementaryInformation(iStringResourceID, &messageToLog); @@ -325,7 +325,7 @@ void ProfilingAPIUtility::LogProfEventVA( } // Ouput debug strings for diagnostic messages. - OutputDebugStringUtf8(messageToLog.GetUTF8NoConvert()); + OutputDebugStringUtf8(messageToLog.GetUTF8()); } // See code:ProfilingAPIUtility.LogProfEventVA for description of arguments. diff --git a/src/coreclr/vm/stubgen.cpp b/src/coreclr/vm/stubgen.cpp index a1dae94859cc..74f7428928df 100644 --- a/src/coreclr/vm/stubgen.cpp +++ b/src/coreclr/vm/stubgen.cpp @@ -106,10 +106,7 @@ void ILStubLinker::DumpIL_FormatToken(mdToken token, SString &strTokenFormatting SString typeName; TypeString::AppendType(typeName, TypeHandle(pFD->GetApproxEnclosingMethodTable())); - SString typeNameUtf8; - typeName.ConvertToUTF8(typeNameUtf8); - SString strFieldName(SString::Utf8, pFD->GetName()); - strTokenFormatting.Printf("%s::%s", typeNameUtf8.GetUTF8NoConvert(), strFieldName.GetUTF8NoConvert()); + strTokenFormatting.Printf("%s::%s", typeName.GetUTF8(), pFD->GetName()); } else if (TypeFromToken(token) == mdtModule) { @@ -550,13 +547,13 @@ ILStubLinker::LogILInstruction( // if (pDumpILStubCode) { - pDumpILStubCode->AppendPrintf("%s /*(%2d)*/ %s %s %s\n", strLabel.GetUTF8NoConvert(), iCurStack, strOpcode.GetUTF8NoConvert(), - strArgument.GetUTF8NoConvert(), strTokenName.GetUTF8NoConvert()); + pDumpILStubCode->AppendPrintf("%s /*(%2d)*/ %s %s %s\n", strLabel.GetUTF8(), iCurStack, strOpcode.GetUTF8(), + strArgument.GetUTF8(), strTokenName.GetUTF8()); } else { - LOG((LF_STUBS, LL_INFO1000, "%s (%2d) %s %s %s\n", strLabel.GetUTF8NoConvert(), iCurStack, \ - strOpcode.GetUTF8NoConvert(), strArgument.GetUTF8NoConvert(), strTokenName.GetUTF8NoConvert())); + LOG((LF_STUBS, LL_INFO1000, "%s (%2d) %s %s %s\n", strLabel.GetUTF8(), iCurStack, \ + strOpcode.GetUTF8(), strArgument.GetUTF8(), strTokenName.GetUTF8())); } } // ILStubLinker::LogILInstruction diff --git a/src/coreclr/vm/typeparse.cpp b/src/coreclr/vm/typeparse.cpp index 0defa23f4cf0..72939270d164 100644 --- a/src/coreclr/vm/typeparse.cpp +++ b/src/coreclr/vm/typeparse.cpp @@ -1303,8 +1303,7 @@ TypeName::GetTypeHaveAssemblyHelper( if (bIgnoreCase) name.LowerCase(); - StackScratchBuffer buffer; - typeName.SetName(name.GetUTF8(buffer)); + typeName.SetName(name.GetUTF8()); // typeName.m_pBucket gets set here if the type is found // it will be used in the next iteration to look up the nested type