Skip to content

Commit cfa1c25

Browse files
author
Mike McLaughlin
committed
Code review feedback - use utf16 mini pal functions
1 parent e2f1dca commit cfa1c25

File tree

5 files changed

+19
-38
lines changed

5 files changed

+19
-38
lines changed

src/coreclr/debug/createdump/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ else()
8686
crashinfounix.cpp
8787
threadinfounix.cpp
8888
dumpwriterelf.cpp
89+
${CLR_SRC_NATIVE_DIR}/minipal/utf8.c
8990
${CREATEDUMP_SOURCES}
9091
)
9192
endif(CLR_CMAKE_HOST_OSX)

src/coreclr/debug/createdump/crashinfo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,15 +977,16 @@ std::string
977977
ConvertString(const WCHAR* str)
978978
{
979979
if (str == nullptr)
980-
return{};
980+
return { };
981981

982-
int len = WideCharToMultiByte(CP_UTF8, 0, str, -1, nullptr, 0, nullptr, nullptr);
982+
size_t cch = u16_strlen(str) + 1;
983+
int len = minipal_get_length_utf16_to_utf8((CHAR16_T*)str, cch, 0);
983984
if (len == 0)
984-
return{};
985+
return { };
985986

986987
ArrayHolder<char> buffer = new char[len + 1];
987-
WideCharToMultiByte(CP_UTF8, 0, str, -1, buffer, len + 1, nullptr, nullptr);
988-
return std::string{ buffer };
988+
minipal_convert_utf16_to_utf8((CHAR16_T*)str, cch, buffer, len + 1, 0);
989+
return std::string { buffer };
989990
}
990991

991992
//

src/coreclr/debug/createdump/createdump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ typedef int T_CONTEXT;
5353
#include <arrayholder.h>
5454
#include <releaseholder.h>
5555
#ifdef HOST_UNIX
56+
#include <minipal/utf8.h>
57+
#include <dn-u16.h>
5658
#include <dumpcommon.h>
5759
#include <clrconfignocache.h>
5860
#include <unistd.h>

src/coreclr/debug/createdump/createdumppal.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,11 @@ typedef BOOL (*PFN_PAL_GetUnwindInfoSize)(
3333
PULONG64 ehFrameStart,
3434
PULONG64 ehFrameSize);
3535

36-
typedef int (*PFN_WideCharToMultiByte)(
37-
IN UINT codePage,
38-
IN DWORD dwFlags,
39-
IN LPCWSTR lpWideCharStr,
40-
IN int cchWideChar,
41-
OUT LPSTR lpMultiByteStr,
42-
IN int cbMultiByte,
43-
IN LPCSTR lpDefaultChar,
44-
OUT LPBOOL lpUsedDefaultChar);
45-
4636
bool g_initialized = false;
4737
PFN_PAL_InitializeDLL g_PAL_InitializeDLL = nullptr;
4838
PFN_PAL_TerminateEx g_PAL_TerminateEx = nullptr;
4939
PFN_PAL_VirtualUnwindOutOfProc g_PAL_VirtualUnwindOutOfProc = nullptr;
5040
PFN_PAL_GetUnwindInfoSize g_PAL_GetUnwindInfoSize = nullptr;
51-
PFN_WideCharToMultiByte g_WideCharToMultiByte = nullptr;
5241

5342
bool
5443
InitializePAL()
@@ -94,7 +83,6 @@ InitializePAL()
9483
g_PAL_TerminateEx = (PFN_PAL_TerminateEx)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_TerminateEx");
9584
g_PAL_VirtualUnwindOutOfProc = (PFN_PAL_VirtualUnwindOutOfProc)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_VirtualUnwindOutOfProc");
9685
g_PAL_GetUnwindInfoSize = (PFN_PAL_GetUnwindInfoSize)dlsym(dacModule, PAL_FUNCTION_PREFIX "PAL_GetUnwindInfoSize");
97-
g_WideCharToMultiByte = (PFN_WideCharToMultiByte)dlsym(dacModule, PAL_FUNCTION_PREFIX "WideCharToMultiByte");
9886
return true;
9987
}
10088

@@ -214,25 +202,6 @@ PAL_GetUnwindInfoSize(
214202
return g_PAL_GetUnwindInfoSize(baseAddress, ehFrameHdrAddr, readMemoryCallback, ehFrameStart, ehFrameSize);
215203
}
216204

217-
int
218-
PALAPI
219-
WideCharToMultiByte(
220-
IN UINT codePage,
221-
IN DWORD dwFlags,
222-
IN LPCWSTR lpWideCharStr,
223-
IN int cchWideChar,
224-
OUT LPSTR lpMultiByteStr,
225-
IN int cbMultiByte,
226-
IN LPCSTR lpDefaultChar,
227-
OUT LPBOOL lpUsedDefaultChar)
228-
{
229-
if (!InitializePAL() || g_WideCharToMultiByte == nullptr)
230-
{
231-
return 0;
232-
}
233-
return g_WideCharToMultiByte(codePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar);
234-
}
235-
236205
//
237206
// Used in pal\inc\rt\safecrt.h's _invalid_parameter handler
238207
//
@@ -248,6 +217,14 @@ RaiseException(
248217
throw;
249218
}
250219

220+
size_t u16_strlen(const WCHAR* str)
221+
{
222+
size_t nChar = 0;
223+
while (*str++)
224+
nChar++;
225+
return nChar;
226+
}
227+
251228
//
252229
// Used by _ASSERTE
253230
//

src/coreclr/debug/createdump/datatarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ DumpDataTarget::GetImageBase(
102102
*baseAddress = 0;
103103

104104
char tempModuleName[MAX_PATH];
105-
int length = WideCharToMultiByte(CP_ACP, 0, moduleName, -1, tempModuleName, sizeof(tempModuleName), NULL, NULL);
105+
size_t cch = u16_strlen(moduleName) + 1;
106+
int length = minipal_convert_utf16_to_utf8((CHAR16_T*)moduleName, cch, tempModuleName, sizeof(tempModuleName), 0);
106107
if (length > 0)
107108
{
108109
*baseAddress = m_crashInfo.GetBaseAddressFromName(tempModuleName);
109110
}
110-
111111
return *baseAddress != 0 ? S_OK : E_FAIL;
112112
}
113113

0 commit comments

Comments
 (0)