Skip to content

Commit

Permalink
Delete wchar_t redefinition in the PAL (dotnet#26705)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Sep 13, 2019
1 parent 747d235 commit bce868f
Show file tree
Hide file tree
Showing 106 changed files with 469 additions and 605 deletions.
2 changes: 1 addition & 1 deletion src/ToolBox/superpmi/superpmi-shared/asmdumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ASMDumper::DumpToFile(HANDLE hFile, MethodContext* mc, CompileResult* cr)
}
disasm->FDecode(&instr, ops, 3);

wchar_t instrMnemonic[64]; // I never know how much to allocate...
WCHAR instrMnemonic[64]; // I never know how much to allocate...
disasm->CchFormatInstr(instrMnemonic, 64);
buff_offset += sprintf_s(&buff[buff_offset], bufflen - buff_offset, "\r\n%p %S",
(void*)((size_t)orig_hotCodeBlock + offset), instrMnemonic);
Expand Down
6 changes: 3 additions & 3 deletions src/ToolBox/superpmi/superpmi-shared/icorjithostimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ void* allocateMemory(size_t size);
void freeMemory(void* block);

// Return an integer config value for the given key, if any exists.
int getIntConfigValue(const wchar_t* name, int defaultValue);
int getIntConfigValue(const WCHAR* name, int defaultValue);

// Return a string config value for the given key, if any exists.
const wchar_t* getStringConfigValue(const wchar_t* name);
const WCHAR* getStringConfigValue(const WCHAR* name);

// Free a string ConfigValue returned by the runtime.
// JITs using the getStringConfigValue query are required
// to return the string values to the runtime for deletion.
// This avoids leaking the memory in the JIT.
void freeStringConfigValue(const wchar_t* value);
void freeStringConfigValue(const WCHAR* value);

#endif
26 changes: 13 additions & 13 deletions src/ToolBox/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6240,7 +6240,7 @@ bool MethodContext::repIsFieldStatic(CORINFO_FIELD_HANDLE fhld)
return result;
}

void MethodContext::recGetIntConfigValue(const wchar_t* name, int defaultValue, int result)
void MethodContext::recGetIntConfigValue(const WCHAR* name, int defaultValue, int result)
{
if (GetIntConfigValue == nullptr)
GetIntConfigValue = new LightWeightMap<Agnostic_ConfigIntInfo, DWORD>();
Expand All @@ -6251,7 +6251,7 @@ void MethodContext::recGetIntConfigValue(const wchar_t* name, int defaultValue,
ZeroMemory(&key, sizeof(Agnostic_ConfigIntInfo));

DWORD index =
(DWORD)GetIntConfigValue->AddBuffer((unsigned char*)name, sizeof(wchar_t) * ((unsigned int)wcslen(name) + 1));
(DWORD)GetIntConfigValue->AddBuffer((unsigned char*)name, sizeof(WCHAR) * ((unsigned int)wcslen(name) + 1));

key.nameIndex = index;
key.defaultValue = defaultValue;
Expand All @@ -6262,12 +6262,12 @@ void MethodContext::recGetIntConfigValue(const wchar_t* name, int defaultValue,

void MethodContext::dmpGetIntConfigValue(const Agnostic_ConfigIntInfo& key, int value)
{
const wchar_t* name = (const wchar_t*)GetIntConfigValue->GetBuffer(key.nameIndex);
const WCHAR* name = (const WCHAR*)GetIntConfigValue->GetBuffer(key.nameIndex);
printf("GetIntConfigValue name %S, default value %d, value %d", name, key.defaultValue, value);
GetIntConfigValue->Unlock();
}

int MethodContext::repGetIntConfigValue(const wchar_t* name, int defaultValue)
int MethodContext::repGetIntConfigValue(const WCHAR* name, int defaultValue)
{
if (GetIntConfigValue == nullptr)
return defaultValue;
Expand All @@ -6277,7 +6277,7 @@ int MethodContext::repGetIntConfigValue(const wchar_t* name, int defaultValue)
Agnostic_ConfigIntInfo key;
ZeroMemory(&key, sizeof(Agnostic_ConfigIntInfo));

size_t nameLenInBytes = sizeof(wchar_t) * (wcslen(name) + 1);
size_t nameLenInBytes = sizeof(WCHAR) * (wcslen(name) + 1);
int nameIndex = GetIntConfigValue->Contains((unsigned char*)name, (unsigned int)nameLenInBytes);
if (nameIndex == -1) // config name not in map
return defaultValue;
Expand All @@ -6290,47 +6290,47 @@ int MethodContext::repGetIntConfigValue(const wchar_t* name, int defaultValue)
return (int)result;
}

void MethodContext::recGetStringConfigValue(const wchar_t* name, const wchar_t* result)
void MethodContext::recGetStringConfigValue(const WCHAR* name, const WCHAR* result)
{
if (GetStringConfigValue == nullptr)
GetStringConfigValue = new LightWeightMap<DWORD, DWORD>();

AssertCodeMsg(name != nullptr, EXCEPTIONCODE_MC, "Name can not be nullptr");

DWORD nameIndex = (DWORD)GetStringConfigValue->AddBuffer((unsigned char*)name,
sizeof(wchar_t) * ((unsigned int)wcslen(name) + 1));
sizeof(WCHAR) * ((unsigned int)wcslen(name) + 1));

DWORD resultIndex = (DWORD)-1;
if (result != nullptr)
resultIndex = (DWORD)GetStringConfigValue->AddBuffer((unsigned char*)result,
sizeof(wchar_t) * ((unsigned int)wcslen(result) + 1));
sizeof(WCHAR) * ((unsigned int)wcslen(result) + 1));

GetStringConfigValue->Add(nameIndex, resultIndex);
DEBUG_REC(dmpGetStringConfigValue(nameIndex, resultIndex));
}

void MethodContext::dmpGetStringConfigValue(DWORD nameIndex, DWORD resultIndex)
{
const wchar_t* name = (const wchar_t*)GetStringConfigValue->GetBuffer(nameIndex);
const wchar_t* result = (const wchar_t*)GetStringConfigValue->GetBuffer(resultIndex);
const WCHAR* name = (const WCHAR*)GetStringConfigValue->GetBuffer(nameIndex);
const WCHAR* result = (const WCHAR*)GetStringConfigValue->GetBuffer(resultIndex);
printf("GetStringConfigValue name %S, result %S", name, result);
GetStringConfigValue->Unlock();
}

const wchar_t* MethodContext::repGetStringConfigValue(const wchar_t* name)
const WCHAR* MethodContext::repGetStringConfigValue(const WCHAR* name)
{
if (GetStringConfigValue == nullptr)
return nullptr;

AssertCodeMsg(name != nullptr, EXCEPTIONCODE_MC, "Name can not be nullptr");

size_t nameLenInBytes = sizeof(wchar_t) * (wcslen(name) + 1);
size_t nameLenInBytes = sizeof(WCHAR) * (wcslen(name) + 1);
int nameIndex = GetStringConfigValue->Contains((unsigned char*)name, (unsigned int)nameLenInBytes);
if (nameIndex == -1) // config name not in map
return nullptr;

int resultIndex = GetStringConfigValue->Get(nameIndex);
const wchar_t* value = (const wchar_t*)GetStringConfigValue->GetBuffer(resultIndex);
const WCHAR* value = (const WCHAR*)GetStringConfigValue->GetBuffer(resultIndex);

DEBUG_REP(dmpGetStringConfigValue(nameIndex, resultIndex));

Expand Down
8 changes: 4 additions & 4 deletions src/ToolBox/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1310,13 +1310,13 @@ class MethodContext
void dmpIsFieldStatic(DWORDLONG key, DWORD value);
bool repIsFieldStatic(CORINFO_FIELD_HANDLE fhld);

void recGetIntConfigValue(const wchar_t* name, int defaultValue, int result);
void recGetIntConfigValue(const WCHAR* name, int defaultValue, int result);
void dmpGetIntConfigValue(const Agnostic_ConfigIntInfo& key, int value);
int repGetIntConfigValue(const wchar_t* name, int defaultValue);
int repGetIntConfigValue(const WCHAR* name, int defaultValue);

void recGetStringConfigValue(const wchar_t* name, const wchar_t* result);
void recGetStringConfigValue(const WCHAR* name, const WCHAR* result);
void dmpGetStringConfigValue(DWORD nameIndex, DWORD result);
const wchar_t* repGetStringConfigValue(const wchar_t* name);
const WCHAR* repGetStringConfigValue(const WCHAR* name);

struct Environment
{
Expand Down
8 changes: 4 additions & 4 deletions src/ToolBox/superpmi/superpmi-shim-collector/jithost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void JitHost::freeMemory(void* block)
return wrappedHost->freeMemory(block);
}

int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)
int JitHost::getIntConfigValue(const WCHAR* key, int defaultValue)
{
mc->cr->AddCall("getIntConfigValue");
int result = wrappedHost->getIntConfigValue(key, defaultValue);
Expand All @@ -44,10 +44,10 @@ int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)
return result;
}

const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
const WCHAR* JitHost::getStringConfigValue(const WCHAR* key)
{
mc->cr->AddCall("getStringConfigValue");
const wchar_t* result = wrappedHost->getStringConfigValue(key);
const WCHAR* result = wrappedHost->getStringConfigValue(key);

// Don't store null returns, which is the default
if (result != nullptr)
Expand All @@ -57,7 +57,7 @@ const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
return result;
}

void JitHost::freeStringConfigValue(const wchar_t* value)
void JitHost::freeStringConfigValue(const WCHAR* value)
{
mc->cr->AddCall("freeStringConfigValue");
wrappedHost->freeStringConfigValue(value);
Expand Down
6 changes: 3 additions & 3 deletions src/ToolBox/superpmi/superpmi-shim-counter/jithost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ void JitHost::freeMemory(void* block)
return wrappedHost->freeMemory(block);
}

int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)
int JitHost::getIntConfigValue(const WCHAR* key, int defaultValue)
{
mcs->AddCall("getIntConfigValue");
return wrappedHost->getIntConfigValue(key, defaultValue);
}

const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
const WCHAR* JitHost::getStringConfigValue(const WCHAR* key)
{
mcs->AddCall("getStringConfigValue");
return wrappedHost->getStringConfigValue(key);
}

void JitHost::freeStringConfigValue(const wchar_t* value)
void JitHost::freeStringConfigValue(const WCHAR* value)
{
mcs->AddCall("freeStringConfigValue");
wrappedHost->freeStringConfigValue(value);
Expand Down
6 changes: 3 additions & 3 deletions src/ToolBox/superpmi/superpmi-shim-simple/jithost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ void JitHost::freeMemory(void* block)
return wrappedHost->freeMemory(block);
}

int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)
int JitHost::getIntConfigValue(const WCHAR* key, int defaultValue)
{
return wrappedHost->getIntConfigValue(key, defaultValue);
}

const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
const WCHAR* JitHost::getStringConfigValue(const WCHAR* key)
{
return wrappedHost->getStringConfigValue(key);
}

void JitHost::freeStringConfigValue(const wchar_t* value)
void JitHost::freeStringConfigValue(const WCHAR* value)
{
wrappedHost->freeStringConfigValue(value);
}
14 changes: 7 additions & 7 deletions src/ToolBox/superpmi/superpmi/commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void CommandLine::DumpHelp(const char* program)
printf(" ; if there are any failures, record their MC numbers in the file fail.mcl\n");
}

static bool ParseJitOption(const char* optionString, wchar_t** key, wchar_t** value)
static bool ParseJitOption(const char* optionString, WCHAR** key, WCHAR** value)
{
char tempKey[1024];

Expand All @@ -169,11 +169,11 @@ static bool ParseJitOption(const char* optionString, wchar_t** key, wchar_t** va
const char* tempVal = &optionString[i + 1];

const unsigned keyLen = i;
wchar_t* keyBuf = new wchar_t[keyLen + 1];
WCHAR* keyBuf = new WCHAR[keyLen + 1];
MultiByteToWideChar(CP_UTF8, 0, tempKey, keyLen + 1, keyBuf, keyLen + 1);

const unsigned valLen = (unsigned)strlen(tempVal);
wchar_t* valBuf = new wchar_t[valLen + 1];
WCHAR* valBuf = new WCHAR[valLen + 1];
MultiByteToWideChar(CP_UTF8, 0, tempVal, valLen + 1, valBuf, valLen + 1);

*key = keyBuf;
Expand Down Expand Up @@ -670,18 +670,18 @@ bool CommandLine::AddJitOption(int& currArgument,
targetjitOptions = *pJitOptions;
}

wchar_t* key;
wchar_t* value;
WCHAR* key;
WCHAR* value;
if ((currArgument >= argc) || !ParseJitOption(argv[currArgument], &key, &value))
{
DumpHelp(argv[0]);
return false;
}

DWORD keyIndex =
(DWORD)targetjitOptions->AddBuffer((unsigned char*)key, sizeof(wchar_t) * ((unsigned int)wcslen(key) + 1));
(DWORD)targetjitOptions->AddBuffer((unsigned char*)key, sizeof(WCHAR) * ((unsigned int)wcslen(key) + 1));
DWORD valueIndex =
(DWORD)targetjitOptions->AddBuffer((unsigned char*)value, sizeof(wchar_t) * ((unsigned int)wcslen(value) + 1));
(DWORD)targetjitOptions->AddBuffer((unsigned char*)value, sizeof(WCHAR) * ((unsigned int)wcslen(value) + 1));
targetjitOptions->Add(keyIndex, valueIndex);

delete[] key;
Expand Down
26 changes: 13 additions & 13 deletions src/ToolBox/superpmi/superpmi/jithost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// Look for 'key' as an environment variable named COMPlus_<key>. The returned value
// is nullptr if it is not found, or a string if found. If not nullptr, the returned
// value must be freed with jitInstance.freeLongLivedArray(value).
wchar_t* GetCOMPlusVariable(const wchar_t* key, JitInstance& jitInstance)
WCHAR* GetCOMPlusVariable(const WCHAR* key, JitInstance& jitInstance)
{
static const wchar_t Prefix[] = W("COMPlus_");
static const WCHAR Prefix[] = W("COMPlus_");
static const size_t PrefixLen = (sizeof(Prefix) / sizeof(Prefix[0])) - 1;

// Prepend "COMPlus_" to the provided key
size_t keyLen = wcslen(key);
size_t keyBufferLen = keyLen + PrefixLen + 1;
wchar_t* keyBuffer =
reinterpret_cast<wchar_t*>(jitInstance.allocateArray(static_cast<ULONG>(sizeof(wchar_t) * keyBufferLen)));
WCHAR* keyBuffer =
reinterpret_cast<WCHAR*>(jitInstance.allocateArray(static_cast<ULONG>(sizeof(WCHAR) * keyBufferLen)));
wcscpy_s(keyBuffer, keyBufferLen, Prefix);
wcscpy_s(&keyBuffer[PrefixLen], keyLen + 1, key);

Expand All @@ -34,7 +34,7 @@ wchar_t* GetCOMPlusVariable(const wchar_t* key, JitInstance& jitInstance)
}

// Note this value must live as long as the jit instance does.
wchar_t* value = reinterpret_cast<wchar_t*>(jitInstance.allocateLongLivedArray(sizeof(wchar_t) * valueLen));
WCHAR* value = reinterpret_cast<WCHAR*>(jitInstance.allocateLongLivedArray(sizeof(WCHAR) * valueLen));
DWORD newValueLen = GetEnvironmentVariableW(keyBuffer, value, valueLen);

jitInstance.freeArray(keyBuffer);
Expand All @@ -61,14 +61,14 @@ void JitHost::freeMemory(void* block)
InitIEEMemoryManager(&jitInstance)->ClrVirtualFree(block, 0, 0);
}

bool JitHost::convertStringValueToInt(const wchar_t* key, const wchar_t* stringValue, int& result)
bool JitHost::convertStringValueToInt(const WCHAR* key, const WCHAR* stringValue, int& result)
{
if (stringValue == nullptr)
{
return false;
}

wchar_t* endPtr;
WCHAR* endPtr;
unsigned long longResult = wcstoul(stringValue, &endPtr, 16);
bool succeeded = (errno != ERANGE) && (endPtr != stringValue) && (longResult <= INT_MAX);
if (!succeeded)
Expand All @@ -81,7 +81,7 @@ bool JitHost::convertStringValueToInt(const wchar_t* key, const wchar_t* stringV
return true;
}

int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)
int JitHost::getIntConfigValue(const WCHAR* key, int defaultValue)
{
jitInstance.mc->cr->AddCall("getIntConfigValue");

Expand Down Expand Up @@ -123,7 +123,7 @@ int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)

if (!valueFound)
{
wchar_t* complusVar = GetCOMPlusVariable(key, jitInstance);
WCHAR* complusVar = GetCOMPlusVariable(key, jitInstance);
valueFound = convertStringValueToInt(key, complusVar, result);
if (complusVar != nullptr)
{
Expand All @@ -139,12 +139,12 @@ int JitHost::getIntConfigValue(const wchar_t* key, int defaultValue)
return valueFound ? result : defaultValue;
}

const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
const WCHAR* JitHost::getStringConfigValue(const WCHAR* key)
{
jitInstance.mc->cr->AddCall("getStringConfigValue");

bool needToDup = true;
const wchar_t* result = nullptr;
const WCHAR* result = nullptr;

// First check the force options, then mc value. If value is not presented there, probe the JIT options and then the
// environment.
Expand All @@ -171,7 +171,7 @@ const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
{
// Now we need to dup it, so you can call freeStringConfigValue() on what we return.
size_t resultLenInChars = wcslen(result) + 1;
wchar_t* dupResult = (wchar_t*)jitInstance.allocateLongLivedArray((ULONG)(sizeof(wchar_t) * resultLenInChars));
WCHAR* dupResult = (WCHAR*)jitInstance.allocateLongLivedArray((ULONG)(sizeof(WCHAR) * resultLenInChars));
wcscpy_s(dupResult, resultLenInChars, result);
result = dupResult;
}
Expand All @@ -183,7 +183,7 @@ const wchar_t* JitHost::getStringConfigValue(const wchar_t* key)
return result;
}

void JitHost::freeStringConfigValue(const wchar_t* value)
void JitHost::freeStringConfigValue(const WCHAR* value)
{
jitInstance.mc->cr->AddCall("freeStringConfigValue");
jitInstance.freeLongLivedArray((void*)value);
Expand Down
2 changes: 1 addition & 1 deletion src/ToolBox/superpmi/superpmi/jithost.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JitHost final : public ICorJitHost
#include "icorjithostimpl.h"

private:
bool convertStringValueToInt(const wchar_t* key, const wchar_t* stringValue, int& result);
bool convertStringValueToInt(const WCHAR* key, const WCHAR* stringValue, int& result);

JitInstance& jitInstance;
};
Expand Down
Loading

0 comments on commit bce868f

Please sign in to comment.