Bug 944905 - Fixed char16_t/wchar_t mismatch in xpcom/ r=bsmedberg

This commit is contained in:
Jacek Caban 2013-12-04 13:19:09 +01:00
parent a4dbd57c7e
commit 50a5638f29
18 changed files with 52 additions and 51 deletions

View File

@ -478,8 +478,8 @@ Break(const char *aMsg)
*/
PROCESS_INFORMATION pi;
STARTUPINFOW si;
PRUnichar executable[MAX_PATH];
PRUnichar* pName;
wchar_t executable[MAX_PATH];
wchar_t* pName;
memset(&pi, 0, sizeof(pi));
@ -488,13 +488,13 @@ Break(const char *aMsg)
si.wShowWindow = SW_SHOW;
// 2nd arg of CreateProcess is in/out
PRUnichar *msgCopy = (PRUnichar*) _alloca((strlen(aMsg) + 1)*sizeof(PRUnichar));
wcscpy(msgCopy , (PRUnichar*)NS_ConvertUTF8toUTF16(aMsg).get());
wchar_t *msgCopy = (wchar_t*) _alloca((strlen(aMsg) + 1)*sizeof(wchar_t));
wcscpy(msgCopy, NS_ConvertUTF8toUTF16(aMsg).get());
if(GetModuleFileNameW(GetModuleHandleW(L"xpcom.dll"), (LPWCH)executable, MAX_PATH) &&
if(GetModuleFileNameW(GetModuleHandleW(L"xpcom.dll"), executable, MAX_PATH) &&
nullptr != (pName = wcsrchr(executable, '\\')) &&
nullptr != wcscpy((WCHAR*)pName + 1, L"windbgdlg.exe") &&
CreateProcessW((LPCWSTR)executable, (LPWSTR)msgCopy, nullptr, nullptr,
nullptr != wcscpy(pName + 1, L"windbgdlg.exe") &&
CreateProcessW(executable, msgCopy, nullptr, nullptr,
false, DETACHED_PROCESS | NORMAL_PRIORITY_CLASS,
nullptr, nullptr, &si, &pi)) {
WaitForSingleObject(pi.hProcess, INFINITE);

View File

@ -22,7 +22,7 @@ public:
#ifdef XP_WIN
static nsresult Get(const char *argv0, char aResult[MAXPATHLEN])
{
PRUnichar wide_path[MAXPATHLEN];
wchar_t wide_path[MAXPATHLEN];
nsresult rv = GetW(argv0, wide_path);
if (NS_FAILED(rv))
return rv;
@ -32,7 +32,7 @@ public:
}
private:
static nsresult GetW(const char *argv0, PRUnichar aResult[MAXPATHLEN])
static nsresult GetW(const char *argv0, wchar_t aResult[MAXPATHLEN])
{
if (::GetModuleFileNameW(0, aResult, MAXPATHLEN))
return NS_OK;
@ -138,7 +138,7 @@ public:
{
nsCOMPtr<nsIFile> lf;
#ifdef XP_WIN
PRUnichar exePath[MAXPATHLEN];
wchar_t exePath[MAXPATHLEN];
nsresult rv = GetW(argv0, exePath);
#else
char exePath[MAXPATHLEN];

View File

@ -586,7 +586,7 @@ nsStringKey::nsStringKey(const nsStringKey& aKey)
}
nsStringKey::nsStringKey(const nsAFlatString& str)
: mStr(const_cast<PRUnichar*>(str.get())),
: mStr((PRUnichar*)str.get()),
mStrLen(str.Length()),
mOwnership(OWN_CLONE)
{

View File

@ -44,7 +44,7 @@ interface nsIAtom : nsISupports
return aString.Equals(nsDependentString(mString, mLength));
}
inline const PRUnichar* GetUTF16String() const {
inline char16ptr_t GetUTF16String() const {
return mString;
}

View File

@ -158,7 +158,7 @@ nsWindowsRegKey::GetChildName(uint32_t index, nsAString &result)
FILETIME lastWritten;
PRUnichar nameBuf[MAX_KEY_NAME_LEN + 1];
wchar_t nameBuf[MAX_KEY_NAME_LEN + 1];
DWORD nameLen = sizeof(nameBuf) / sizeof(nameBuf[0]);
LONG rv = RegEnumKeyExW(mKey, index, nameBuf, &nameLen, nullptr, nullptr,
@ -213,7 +213,7 @@ nsWindowsRegKey::GetValueName(uint32_t index, nsAString &result)
if (NS_WARN_IF(!mKey))
return NS_ERROR_NOT_INITIALIZED;
PRUnichar nameBuf[MAX_VALUE_NAME_LEN];
wchar_t nameBuf[MAX_VALUE_NAME_LEN];
DWORD nameLen = sizeof(nameBuf) / sizeof(nameBuf[0]);
LONG rv = RegEnumValueW(mKey, index, nameBuf, &nameLen, nullptr, nullptr,

View File

@ -27,12 +27,12 @@ struct VersionPart {
struct VersionPartW {
int32_t numA;
const PRUnichar *strB; // NOT null-terminated, can be a null pointer
wchar_t *strB; // NOT null-terminated, can be a null pointer
uint32_t strBlen;
int32_t numC;
PRUnichar *extraD; // null-terminated
wchar_t *extraD; // null-terminated
};
#endif
@ -112,11 +112,11 @@ ParseVP(char *part, VersionPart &result)
* @returns A pointer to the next versionpart, or null if none.
*/
#ifdef XP_WIN
static PRUnichar*
ParseVP(PRUnichar *part, VersionPartW &result)
static wchar_t*
ParseVP(wchar_t *part, VersionPartW &result)
{
PRUnichar *dot;
wchar_t *dot;
result.numA = 0;
result.strB = nullptr;
@ -136,7 +136,7 @@ ParseVP(PRUnichar *part, VersionPartW &result)
result.strB = L"";
}
else {
result.numA = wcstol(part, const_cast<PRUnichar**>(&result.strB), 10);
result.numA = wcstol(part, const_cast<wchar_t**>(&result.strB), 10);
}
if (!*result.strB) {
@ -145,14 +145,14 @@ ParseVP(PRUnichar *part, VersionPartW &result)
}
else {
if (result.strB[0] == '+') {
static const PRUnichar kPre[] = L"pre";
static wchar_t kPre[] = L"pre";
++result.numA;
result.strB = kPre;
result.strBlen = sizeof(kPre) - 1;
}
else {
const PRUnichar *numstart = wcspbrk(result.strB, L"0123456789+-");
const wchar_t *numstart = wcspbrk(result.strB, L"0123456789+-");
if (!numstart) {
result.strBlen = wcslen(result.strB);
}
@ -282,18 +282,18 @@ namespace mozilla {
int32_t
CompareVersions(const PRUnichar *A, const PRUnichar *B)
{
PRUnichar *A2 = wcsdup(A);
wchar_t *A2 = wcsdup(char16ptr_t(A));
if (!A2)
return 1;
PRUnichar *B2 = wcsdup(B);
wchar_t *B2 = wcsdup(char16ptr_t(B));
if (!B2) {
free(A2);
return 1;
}
int32_t result;
PRUnichar *a = A2, *b = B2;
wchar_t *a = A2, *b = B2;
do {
VersionPartW va, vb;

View File

@ -170,7 +170,7 @@ GetLibrarySaveToPath(int aFallbackFolderId, REFKNOWNFOLDERID aFolderId,
if (shellLib &&
SUCCEEDED(shellLib->GetDefaultSaveFolder(DSFT_DETECT, IID_IShellItem,
getter_AddRefs(savePath)))) {
PRUnichar* str = nullptr;
wchar_t* str = nullptr;
if (SUCCEEDED(savePath->GetDisplayName(SIGDN_FILESYSPATH, &str))) {
nsAutoString path;
path.Assign(str);

View File

@ -97,12 +97,12 @@ nsDirectoryService::GetCurrentProcessDirectory(nsIFile** aFile)
#ifdef XP_WIN
PRUnichar buf[MAX_PATH + 1];
wchar_t buf[MAX_PATH + 1];
SetLastError(ERROR_SUCCESS);
if (GetModuleFileNameW(0, buf, mozilla::ArrayLength(buf)) &&
GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
// chop off the executable name by finding the rightmost backslash
PRUnichar* lastSlash = wcsrchr(buf, L'\\');
wchar_t* lastSlash = wcsrchr(buf, L'\\');
if (lastSlash)
*(lastSlash + 1) = L'\0';

View File

@ -223,7 +223,7 @@ nsLocalFile::GetRelativeDescriptor(nsIFile *fromFile, nsACString& _retval)
for (nodeIndex = 0; nodeIndex < thisNodeCnt && nodeIndex < fromNodeCnt; ++nodeIndex) {
#ifdef XP_WIN
if (_wcsicmp(thisNodes[nodeIndex], fromNodes[nodeIndex]))
if (_wcsicmp(char16ptr_t(thisNodes[nodeIndex]), char16ptr_t(fromNodes[nodeIndex])))
break;
#else
if (nsCRT::strcmp(thisNodes[nodeIndex], fromNodes[nodeIndex]))

View File

@ -689,7 +689,7 @@ GetFileInfo(const nsAFlatString &name, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA fileData;
if (name.IsEmpty() || name.FindCharInSet(L"?*") != kNotFound)
if (name.IsEmpty() || name.FindCharInSet(MOZ_UTF16("?*")) != kNotFound)
return NS_ERROR_INVALID_ARG;
if (!::GetFileAttributesExW(name.get(), GetFileExInfoStandard, &fileData))
@ -782,7 +782,7 @@ ReadDir(nsDir *dir, PRDirFlags flags, nsString& name)
if (rv == 0)
break;
const PRUnichar *fileName;
const wchar_t *fileName;
nsString tmp;
fileName = (dir)->data.cFileName;
@ -1268,7 +1268,7 @@ nsLocalFile::Create(uint32_t type, uint32_t attributes)
}
// search for first slash after the drive (or volume) name
PRUnichar* slash = wcschr(path, L'\\');
wchar_t* slash = wcschr(path, L'\\');
nsresult directoryCreateError = NS_OK;
if (slash)
@ -1637,8 +1637,7 @@ nsLocalFile::GetVersionInfoField(const char* aField, nsAString& _retval)
// Cast away const-ness here because WinAPI functions don't understand it,
// the path is used for [in] parameters only however so it's safe.
WCHAR *path = const_cast<WCHAR*>(mFollowSymlinks ? mResolvedPath.get()
: mWorkingPath.get());
const WCHAR *path = mFollowSymlinks ? mResolvedPath.get() : mWorkingPath.get();
DWORD dummy;
DWORD size = ::GetFileVersionInfoSizeW(path, &dummy);
@ -1659,7 +1658,7 @@ nsLocalFile::GetVersionInfoField(const char* aField, nsAString& _retval)
{
for (int32_t i = 0; i < 2; ++i)
{
PRUnichar subBlock[MAX_PATH];
wchar_t subBlock[MAX_PATH];
_snwprintf(subBlock, MAX_PATH,
L"\\StringFileInfo\\%04x%04x\\%s",
(i == 0 ? translate[0].wLanguage
@ -1737,8 +1736,8 @@ nsLocalFile::SetShortcut(nsIFile* targetFile,
mWorkingPath.get(),
targetFilePath,
workingDirPath,
args,
description,
char16ptr_t(args),
char16ptr_t(description),
iconFilePath,
iconFilePath? iconIndex : 0);
if (targetFilePath && NS_SUCCEEDED(rv)) {
@ -2348,7 +2347,7 @@ nsLocalFile::SetModDate(PRTime aLastModifiedTime, const PRUnichar *filePath)
{
// The FILE_FLAG_BACKUP_SEMANTICS is required in order to change the
// modification time for directories.
HANDLE file = ::CreateFileW(filePath, // pointer to name of the file
HANDLE file = ::CreateFileW(char16ptr_t(filePath), // pointer to name of the file
GENERIC_WRITE, // access (write) mode
0, // share mode
nullptr, // pointer to security attributes

View File

@ -914,7 +914,7 @@ NS_CopyUnicodeToNative(const nsAString &input, nsACString &output)
nsAString::const_iterator iter;
input.BeginReading(iter);
const PRUnichar *buf = iter.get();
char16ptr_t buf = iter.get();
// determine length of result
uint32_t resultLen = 0;
@ -957,7 +957,7 @@ NS_ConvertWtoA(const PRUnichar *aStrInW, int aBufferSizeOut,
if ((!aStrInW) || (!aStrOutA) || (aBufferSizeOut <= 0))
return 0;
int numCharsConverted = WideCharToMultiByte(CP_ACP, 0, aStrInW, -1,
int numCharsConverted = WideCharToMultiByte(CP_ACP, 0, char16ptr_t(aStrInW), -1,
aStrOutA, aBufferSizeOut,
aDefault, nullptr);

View File

@ -871,7 +871,7 @@ nsString::Find( const nsAFlatString& aString, int32_t aOffset, int32_t aCount )
// this method changes the meaning of aOffset and aCount:
Find_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount);
int32_t result = FindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), false);
int32_t result = FindSubstring(mData + aOffset, aCount, static_cast<const char16_t*>(aString.get()), aString.Length(), false);
if (result != kNotFound)
result += aOffset;
return result;
@ -889,7 +889,7 @@ nsString::RFind( const nsAFlatString& aString, int32_t aOffset, int32_t aCount )
// this method changes the meaning of aOffset and aCount:
RFind_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount);
int32_t result = RFindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), false);
int32_t result = RFindSubstring(mData + aOffset, aCount, static_cast<const char16_t*>(aString.get()), aString.Length(), false);
if (result != kNotFound)
result += aOffset;
return result;

View File

@ -15,7 +15,7 @@ nsTDependentString_CharT::Rebind( const string_type& str, uint32_t startPos )
if (startPos > strLength)
startPos = strLength;
mData = const_cast<char_type*>(str.Data()) + startPos;
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
mLength = strLength - startPos;
SetDataFlags(F_TERMINATED);

View File

@ -15,7 +15,7 @@ nsTDependentSubstring_CharT::Rebind( const substring_type& str, uint32_t startPo
if (startPos > strLength)
startPos = strLength;
mData = const_cast<char_type*>(str.Data()) + startPos;
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
mLength = XPCOM_MIN(length, strLength - startPos);
SetDataFlags(F_NONE);
@ -29,7 +29,7 @@ nsTDependentSubstring_CharT::Rebind( const char_type* data, size_type length )
// If we currently own a buffer, release it.
Finalize();
mData = const_cast<char_type*>(data);
mData = const_cast<char_type*>(static_cast<const char_type*>(data));
mLength = length;
SetDataFlags(F_NONE);
}

View File

@ -9,7 +9,7 @@ nsTPromiseFlatString_CharT::Init(const substring_type& str)
{
if (str.IsTerminated())
{
mData = const_cast<char_type*>(str.Data());
mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data()));
mLength = str.Length();
mFlags = F_TERMINATED; // does not promote F_VOIDED
}

View File

@ -467,7 +467,7 @@ nsTString_CharT::ReplaceSubstring( const self_type& aTarget, const self_type& aN
uint32_t i = 0;
while (i < mLength)
{
int32_t r = FindSubstring(mData + i, mLength - i, aTarget.Data(), aTarget.Length(), false);
int32_t r = FindSubstring(mData + i, mLength - i, static_cast<const char_type*>(aTarget.Data()), aTarget.Length(), false);
if (r == kNotFound)
break;

View File

@ -258,7 +258,9 @@ FakeInputStream::CheckTest(nsACString& aResult)
}
#ifdef XP_WIN
#define NS_tstrcmp wcscmp
static inline int NS_tstrcmp(char16ptr_t x, char16ptr_t y) {
return wcscmp(x, y);
}
#else
#define NS_tstrcmp strcmp
#endif

View File

@ -113,7 +113,7 @@ nsProcess::Init(nsIFile* executable)
#if defined(XP_WIN)
// Out param `wideCmdLine` must be PR_Freed by the caller.
static int assembleCmdLine(char *const *argv, PRUnichar **wideCmdLine,
static int assembleCmdLine(char *const *argv, wchar_t **wideCmdLine,
UINT codePage)
{
char *const *arg;
@ -214,7 +214,7 @@ static int assembleCmdLine(char *const *argv, PRUnichar **wideCmdLine,
*p = '\0';
int32_t numChars = MultiByteToWideChar(codePage, 0, cmdLine, -1, nullptr, 0);
*wideCmdLine = (PRUnichar *) PR_MALLOC(numChars*sizeof(PRUnichar));
*wideCmdLine = (wchar_t *) PR_MALLOC(numChars*sizeof(wchar_t));
MultiByteToWideChar(codePage, 0, cmdLine, -1, *wideCmdLine, numChars);
PR_Free(cmdLine);
return 0;
@ -430,7 +430,7 @@ nsProcess::RunProcess(bool blocking, char **my_argv, nsIObserver* observer,
#if defined(PROCESSMODEL_WINAPI)
BOOL retVal;
PRUnichar *cmdLine = nullptr;
wchar_t *cmdLine = nullptr;
// The 'argv' array is null-terminated and always starts with the program path.
// If the second slot is non-null then arguments are being passed.