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

--HG--
extra : rebase_source : 2f81dd18df59e0498a577c437954c5b1f52f8e28
This commit is contained in:
Jacek Caban 2014-02-06 17:42:58 +01:00
parent 9481222b1c
commit 5d29b8239e
7 changed files with 36 additions and 15 deletions

View File

@ -333,7 +333,7 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
return NS_ERROR_OUT_OF_MEMORY;
resultLen = ExpandEnvironmentStringsW(flatSource.get(),
begin.get(),
wwc(begin.get()),
resultLen + 1);
if (resultLen <= 0) {
rv = ERROR_UNKNOWN_FEATURE;

View File

@ -513,9 +513,7 @@ static int cvt_S(SprintfState *ss, const char16_t *s, int width,
}
/* and away we go */
NS_NAMED_LITERAL_STRING(nullstr, "(null)");
return fill2(ss, s ? s : nullstr.get(), slen, width, flags);
return fill2(ss, s ? s : MOZ_UTF16("(null)"), slen, width, flags);
}
/*

View File

@ -100,7 +100,7 @@ struct NS_COM_GLUE VersionW
{
VersionW(const char16_t *versionStringW)
{
versionContentW = wcsdup(versionStringW);
versionContentW = reinterpret_cast<char16_t*>(wcsdup(char16ptr_t(versionStringW)));
}
const char16_t* ReadContentW() const

View File

@ -1021,7 +1021,7 @@ nsLocalFile::ResolveShortcut()
if (mResolvedPath.Length() != MAX_PATH)
return NS_ERROR_OUT_OF_MEMORY;
char16_t *resolvedPath = mResolvedPath.BeginWriting();
wchar_t *resolvedPath = wwc(mResolvedPath.BeginWriting());
// resolve this shortcut
nsresult rv = gResolver->Resolve(mWorkingPath.get(), resolvedPath);
@ -1256,7 +1256,7 @@ nsLocalFile::Create(uint32_t type, uint32_t attributes)
// Skip the first 'X:\' for the first form, and skip the first full
// '\\machine\volume\' segment for the second form.
char16_t* path = mResolvedPath.BeginWriting();
wchar_t* path = wwc(mResolvedPath.BeginWriting());
if (path[0] == L'\\' && path[1] == L'\\')
{
@ -1635,8 +1635,6 @@ nsLocalFile::GetVersionInfoField(const char* aField, nsAString& _retval)
rv = NS_ERROR_FAILURE;
// 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.
const WCHAR *path = mFollowSymlinks ? mResolvedPath.get() : mWorkingPath.get();
DWORD dummy;
@ -2343,11 +2341,11 @@ nsLocalFile::SetLastModifiedTimeOfLink(PRTime aLastModifiedTime)
}
nsresult
nsLocalFile::SetModDate(PRTime aLastModifiedTime, const char16_t *filePath)
nsLocalFile::SetModDate(PRTime aLastModifiedTime, const wchar_t *filePath)
{
// The FILE_FLAG_BACKUP_SEMANTICS is required in order to change the
// modification time for directories.
HANDLE file = ::CreateFileW(char16ptr_t(filePath), // pointer to name of the file
HANDLE file = ::CreateFileW(filePath, // pointer to name of the file
GENERIC_WRITE, // access (write) mode
0, // share mode
nullptr, // pointer to security attributes
@ -3446,7 +3444,7 @@ nsresult nsDriveEnumerator::Init()
/* The string is null terminated */
if (!mDrives.SetLength(length+1, fallible_t()))
return NS_ERROR_OUT_OF_MEMORY;
if (!GetLogicalDriveStringsW(length, mDrives.BeginWriting()))
if (!GetLogicalDriveStringsW(length, wwc(mDrives.BeginWriting())))
return NS_ERROR_FAILURE;
mDrives.BeginReading(mStartOfCurrentDrive);
mDrives.EndReading(mEndOfDrivesString);

View File

@ -94,7 +94,7 @@ private:
bool followSymlinks, bool move,
bool skipNtfsAclReset = false);
nsresult SetModDate(int64_t aLastModifiedTime, const char16_t *filePath);
nsresult SetModDate(int64_t aLastModifiedTime, const wchar_t *filePath);
nsresult HasFileAttribute(DWORD fileAttrib, bool *_retval);
nsresult AppendInternal(const nsAFlatString &node,
bool multipleComponents);

View File

@ -871,6 +871,7 @@ NS_ShutdownNativeCharsetUtils()
#elif defined(XP_WIN)
#include <windows.h>
#include "nsString.h"
#include "nsAString.h"
#include "nsReadableUtils.h"
@ -901,7 +902,7 @@ NS_CopyNativeToUnicode(const nsACString &input, nsAString &output)
char16_t *result = out_iter.get();
::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, result, resultLen);
::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, wwc(result), resultLen);
}
return NS_OK;
}
@ -947,7 +948,7 @@ NS_CopyUnicodeToNative(const nsAString &input, nsACString &output)
int32_t
NS_ConvertAtoW(const char *aStrInA, int aBufferSize, char16_t *aStrOutW)
{
return MultiByteToWideChar(CP_ACP, 0, aStrInA, -1, aStrOutW, aBufferSize);
return MultiByteToWideChar(CP_ACP, 0, aStrInA, -1, wwc(aStrOutW), aBufferSize);
}
int32_t

View File

@ -183,6 +183,30 @@ class NS_ConvertUTF8toUTF16 : public nsAutoString
};
#ifdef MOZ_USE_CHAR16_WRAPPER
inline char16_t*
wwc(wchar_t *str)
{
return reinterpret_cast<char16_t*>(str);
}
inline wchar_t*
wwc(char16_t *str)
{
return reinterpret_cast<wchar_t*>(str);
}
#else
inline char16_t*
wwc(char16_t *str)
{
return str;
}
#endif
// the following are included/declared for backwards compatibility
typedef nsAutoString nsVoidableString;