summaryrefslogtreecommitdiff
path: root/src/coreclr
diff options
context:
space:
mode:
authorAaron Robinson <arobins@microsoft.com>2018-09-13 16:23:12 -0700
committerGitHub <noreply@github.com>2018-09-13 16:23:12 -0700
commit30e66e40b712fb11fcbbc60ecc041e2f02484796 (patch)
tree48ace30c4d9e35608a483e014369ff12212422ac /src/coreclr
parent091f8cfcdad7dd1df5c8e1d930ba1f4c6541a2fa (diff)
downloadcoreclr-30e66e40b712fb11fcbbc60ecc041e2f02484796.tar.gz
coreclr-30e66e40b712fb11fcbbc60ecc041e2f02484796.tar.bz2
coreclr-30e66e40b712fb11fcbbc60ecc041e2f02484796.zip
Dev16 removed the static_cast<> in a std::basic_string constructor so need to explicit convert string to wstring to avoid warning. (#19947)
Diffstat (limited to 'src/coreclr')
-rw-r--r--src/coreclr/hosts/coreshim/CoreShim.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/coreclr/hosts/coreshim/CoreShim.cpp b/src/coreclr/hosts/coreshim/CoreShim.cpp
index 497c10e5d2..f055b04fef 100644
--- a/src/coreclr/hosts/coreshim/CoreShim.cpp
+++ b/src/coreclr/hosts/coreshim/CoreShim.cpp
@@ -11,6 +11,7 @@
namespace
{
+ template<typename CT>
struct PathBuffer
{
PathBuffer()
@@ -38,21 +39,21 @@ namespace
return Len;
}
- operator WCHAR *()
+ operator CT *()
{
return Buf;
}
- WCHAR DefBuffer[MAX_PATH];
- std::vector<WCHAR> BigBuffer;
+ CT DefBuffer[MAX_PATH];
+ std::vector<CT> BigBuffer;
- WCHAR *Buf;
+ CT *Buf;
DWORD Len;
};
- std::string GetExePath()
+ std::wstring GetExePath()
{
- PathBuffer buffer;
+ PathBuffer<WCHAR> buffer;
DWORD len = ::GetModuleFileNameW(nullptr, buffer, buffer);
while (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
@@ -60,7 +61,7 @@ namespace
len = ::GetModuleFileNameW(nullptr, buffer, buffer);
}
- return std::string{ buffer.Buf, buffer.Buf + len };
+ return std::wstring{ buffer.Buf, buffer.Buf + len };
}
std::wstring GetEnvVar(_In_z_ const WCHAR *env)
@@ -69,13 +70,23 @@ namespace
if (len == 0)
throw __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND);
- PathBuffer buffer;
+ PathBuffer<WCHAR> buffer;
buffer.SetLength(len);
(void)::GetEnvironmentVariableW(env, buffer, buffer);
return static_cast<WCHAR *>(buffer.Buf);
}
+ std::string ConvertWideToUtf8(_In_ const std::wstring &wide)
+ {
+ // [TODO] Properly convert to UTF-8
+ std::string narrow;
+ for (WCHAR p : wide)
+ narrow.push_back(static_cast<CHAR>(p));
+
+ return narrow;
+ }
+
coreclr *s_CoreClrInstance;
}
@@ -86,7 +97,7 @@ namespace Utility
try
{
std::wstring envVarLocal = GetEnvVar(env);
- envVar = { std::begin(envVarLocal), std::end(envVarLocal) };
+ envVar = ConvertWideToUtf8(envVarLocal);
}
catch (HRESULT hr)
{
@@ -163,7 +174,7 @@ HRESULT coreclr::CreateTpaList(_Inout_ std::string &tpaList, _In_opt_z_ const WC
w_dirLocal = { dir };
}
- std::string dirLocal{ std::begin(w_dirLocal), std::end(w_dirLocal) };
+ std::string dirLocal = ConvertWideToUtf8(w_dirLocal);
w_dirLocal.append(W("\\*"));
std::set<std::wstring> addedAssemblies;
@@ -204,8 +215,7 @@ HRESULT coreclr::CreateTpaList(_Inout_ std::string &tpaList, _In_opt_z_ const WC
{
addedAssemblies.insert(std::move(filenameWithoutExt));
- // [TODO] Properly convert to UTF-8
- std::string filename_utf8{ std::begin(filename), std::end(filename) };
+ std::string filename_utf8 = ConvertWideToUtf8(filename);
tpaStream << dirLocal << "\\" << filename_utf8 << ";";
}
}
@@ -266,7 +276,8 @@ HRESULT coreclr::Initialize(
HRESULT hr;
try
{
- const std::string exePath = GetExePath();
+ const std::wstring exePathW = GetExePath();
+ const std::string exePath = ConvertWideToUtf8(exePathW);
RETURN_IF_FAILED(_initialize(exePath.c_str(), appDomainName, propertyCount, keys, values, &_clrInst, &_appDomainId));
}
catch (const std::bad_alloc&)