Backed out changeset 11c7b498a836 (bug 1353593)
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sat, 10 Jun 2017 10:04:13 +0200
changeset 413855 e273a44edbae36c831756124c70e35e6e98d6554
parent 413854 f40ea9d14a1114c305108475053a5353fceb9304
child 413856 3955d49d5cd776dfb0849ce44fd7975e49fc34f8
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1353593
milestone55.0a1
backs out11c7b498a83650e1d9f658700ff06d07a9106329
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 11c7b498a836 (bug 1353593)
ipc/mscom/Utils.cpp
widget/windows/IMMHandler.cpp
xpcom/base/nsSystemInfo.cpp
xpcom/ds/nsWindowsRegKey.cpp
xpcom/io/FileUtilsWin.cpp
xpcom/io/nsLocalFileWin.cpp
xpcom/io/nsNativeCharsetUtils.cpp
xpcom/string/nsString.h
--- a/ipc/mscom/Utils.cpp
+++ b/ipc/mscom/Utils.cpp
@@ -80,17 +80,17 @@ IsValidGUID(REFGUID aCheckGuid)
 
 void
 GUIDToString(REFGUID aGuid, nsAString& aOutString)
 {
   // This buffer length is long enough to hold a GUID string that is formatted
   // to include curly braces and dashes.
   const int kBufLenWithNul = 39;
   aOutString.SetLength(kBufLenWithNul);
-  int result = StringFromGUID2(aGuid, char16ptr_t(aOutString.BeginWriting()), kBufLenWithNul);
+  int result = StringFromGUID2(aGuid, wwc(aOutString.BeginWriting()), kBufLenWithNul);
   MOZ_ASSERT(result);
   if (result) {
     // Truncate the terminator
     aOutString.SetLength(result - 1);
   }
 }
 
 #endif // defined(MOZILLA_INTERNAL_API)
--- a/widget/windows/IMMHandler.cpp
+++ b/widget/windows/IMMHandler.cpp
@@ -339,17 +339,17 @@ void
 IMMHandler::InitKeyboardLayout(nsWindow* aWindow,
                                HKL aKeyboardLayout)
 {
   UINT IMENameLength = ::ImmGetDescriptionW(aKeyboardLayout, nullptr, 0);
   if (IMENameLength) {
     // Add room for the terminating null character
     sIMEName.SetLength(++IMENameLength);
     IMENameLength =
-      ::ImmGetDescriptionW(aKeyboardLayout, sIMEName.get(),
+      ::ImmGetDescriptionW(aKeyboardLayout, wwc(sIMEName.BeginWriting()),
                            IMENameLength);
     // Adjust the length to ignore the terminating null character
     sIMEName.SetLength(IMENameLength);
   } else {
     sIMEName.Truncate();
   }
 
   WORD langID = LOWORD(aKeyboardLayout);
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -224,17 +224,17 @@ nsresult GetCountryCode(nsAString& aCoun
   }
   // Get required length
   int numChars = GetGeoInfoW(geoid, GEO_ISO2, nullptr, 0, 0);
   if (!numChars) {
     return NS_ERROR_FAILURE;
   }
   // Now get the string for real
   aCountryCode.SetLength(numChars);
-  numChars = GetGeoInfoW(geoid, GEO_ISO2, char16ptr_t(aCountryCode.BeginWriting()),
+  numChars = GetGeoInfoW(geoid, GEO_ISO2, wwc(aCountryCode.BeginWriting()),
                          aCountryCode.Length(), 0);
   if (!numChars) {
     return NS_ERROR_FAILURE;
   }
 
   // numChars includes null terminator
   aCountryCode.Truncate(numChars - 1);
   return NS_OK;
--- a/xpcom/ds/nsWindowsRegKey.cpp
+++ b/xpcom/ds/nsWindowsRegKey.cpp
@@ -349,18 +349,21 @@ nsWindowsRegKey::ReadStringValue(const n
     if (resultLen > 1) {
       nsAutoString expandedResult;
       // |resultLen| includes the terminating null character
       --resultLen;
       if (!expandedResult.SetLength(resultLen, mozilla::fallible)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
+      nsAString::iterator begin;
+      expandedResult.BeginWriting(begin);
+
       resultLen = ExpandEnvironmentStringsW(flatSource.get(),
-                                            expandedResult.get(),
+                                            wwc(begin.get()),
                                             resultLen + 1);
       if (resultLen <= 0) {
         rv = ERROR_UNKNOWN_FEATURE;
         aResult.Truncate();
       } else {
         rv = ERROR_SUCCESS;
         aResult = expandedResult;
       }
--- a/xpcom/io/FileUtilsWin.cpp
+++ b/xpcom/io/FileUtilsWin.cpp
@@ -56,17 +56,17 @@ HandleToFilename(HANDLE aHandle, const L
     return false;
   }
   nsAutoString mappedFilename;
   DWORD len = 0;
   SetLastError(ERROR_SUCCESS);
   do {
     mappedFilename.SetLength(mappedFilename.Length() + MAX_PATH);
     len = GetMappedFileNameW(GetCurrentProcess(), view,
-                             mappedFilename.get(),
+                             wwc(mappedFilename.BeginWriting()),
                              mappedFilename.Length());
   } while (!len && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
   if (!len) {
     return false;
   }
   mappedFilename.Truncate(len);
   return NtPathToDosPath(mappedFilename, aFilename);
 }
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -990,17 +990,17 @@ nsLocalFile::ResolveShortcut()
     return NS_ERROR_FAILURE;
   }
 
   mResolvedPath.SetLength(MAX_PATH);
   if (mResolvedPath.Length() != MAX_PATH) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  wchar_t* resolvedPath = mResolvedPath.get();
+  wchar_t* resolvedPath = wwc(mResolvedPath.BeginWriting());
 
   // resolve this shortcut
   nsresult rv = gResolver->Resolve(mWorkingPath.get(), resolvedPath);
 
   size_t len = NS_FAILED(rv) ? 0 : wcslen(resolvedPath);
   mResolvedPath.SetLength(len);
 
   return rv;
@@ -1360,17 +1360,17 @@ nsLocalFile::Create(uint32_t aType, uint
   //                       ^--- start here
   //
   //   - UNC path:  \\machine\volume\some\path\on\this\drive
   //                                     ^--- start here
   //
   // Skip the first 'X:\' for the first form, and skip the first full
   // '\\machine\volume\' segment for the second form.
 
-  wchar_t* path = char16ptr_t(mResolvedPath.BeginWriting());
+  wchar_t* path = wwc(mResolvedPath.BeginWriting());
 
   if (path[0] == L'\\' && path[1] == L'\\') {
     // dealing with a UNC path here; skip past '\\machine\'
     path = wcschr(path + 2, L'\\');
     if (!path) {
       return NS_ERROR_FILE_INVALID_PATH;
     }
     ++path;
@@ -3738,17 +3738,17 @@ nsDriveEnumerator::Init()
   /* If the length passed to GetLogicalDriveStrings is smaller
    * than the length of the string it would return, it returns
    * the length required for the string. */
   DWORD length = GetLogicalDriveStringsW(0, 0);
   /* The string is null terminated */
   if (!mDrives.SetLength(length + 1, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
-  if (!GetLogicalDriveStringsW(length, mDrives.get())) {
+  if (!GetLogicalDriveStringsW(length, wwc(mDrives.BeginWriting()))) {
     return NS_ERROR_FAILURE;
   }
   mDrives.BeginReading(mStartOfCurrentDrive);
   mDrives.EndReading(mEndOfDrivesString);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -924,18 +924,22 @@ NS_CopyNativeToUnicode(const nsACString&
     resultLen += n;
   }
 
   // allocate sufficient space
   if (!aOutput.SetLength(resultLen, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   if (resultLen > 0) {
-    char16ptr_t result = aOutput.BeginWriting();
-    ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, result, resultLen);
+    nsAString::iterator out_iter;
+    aOutput.BeginWriting(out_iter);
+
+    char16_t* result = out_iter.get();
+
+    ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, wwc(result), resultLen);
   }
   return NS_OK;
 }
 
 nsresult
 NS_CopyUnicodeToNative(const nsAString&  aInput, nsACString& aOutput)
 {
   uint32_t inputLen = aInput.Length();
@@ -969,16 +973,51 @@ NS_CopyUnicodeToNative(const nsAString& 
     char* result = out_iter.get();
 
     ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, result, resultLen,
                           &defaultChar, nullptr);
   }
   return NS_OK;
 }
 
+// moved from widget/windows/nsToolkit.cpp
+int32_t
+NS_ConvertAtoW(const char* aStrInA, int aBufferSize, char16_t* aStrOutW)
+{
+  return MultiByteToWideChar(CP_ACP, 0, aStrInA, -1, wwc(aStrOutW), aBufferSize);
+}
+
+int32_t
+NS_ConvertWtoA(const char16_t* aStrInW, int aBufferSizeOut,
+               char* aStrOutA, const char* aDefault)
+{
+  if ((!aStrInW) || (!aStrOutA) || (aBufferSizeOut <= 0)) {
+    return 0;
+  }
+
+  int numCharsConverted = WideCharToMultiByte(CP_ACP, 0, char16ptr_t(aStrInW), -1,
+                                              aStrOutA, aBufferSizeOut,
+                                              aDefault, nullptr);
+
+  if (!numCharsConverted) {
+    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+      // Overflow, add missing null termination but return 0
+      aStrOutA[aBufferSizeOut - 1] = '\0';
+    } else {
+      // Other error, clear string and return 0
+      aStrOutA[0] = '\0';
+    }
+  } else if (numCharsConverted < aBufferSizeOut) {
+    // Add 2nd null (really necessary?)
+    aStrOutA[numCharsConverted] = '\0';
+  }
+
+  return numCharsConverted;
+}
+
 #else
 
 #include "nsReadableUtils.h"
 
 nsresult
 NS_CopyNativeToUnicode(const nsACString& aInput, nsAString& aOutput)
 {
   CopyASCIItoUTF16(aInput, aOutput);
--- a/xpcom/string/nsString.h
+++ b/xpcom/string/nsString.h
@@ -143,16 +143,59 @@ public:
     AppendUTF8toUTF16(aCString, *this);
   }
 
 private:
   // NOT TO BE IMPLEMENTED
   NS_ConvertUTF8toUTF16(char16_t) = delete;
 };
 
+
+#ifdef MOZ_USE_CHAR16_WRAPPER
+
+inline char16_t*
+wwc(wchar_t* aStr)
+{
+  return reinterpret_cast<char16_t*>(aStr);
+}
+
+inline wchar_t*
+wwc(char16_t* aStr)
+{
+  return reinterpret_cast<wchar_t*>(aStr);
+}
+
+inline const char16_t*
+wwc(const wchar_t* aStr)
+{
+  return reinterpret_cast<const char16_t*>(aStr);
+}
+
+inline const wchar_t*
+wwc(const char16_t* aStr)
+{
+  return reinterpret_cast<const wchar_t*>(aStr);
+}
+
+#else
+
+inline char16_t*
+wwc(char16_t* aStr)
+{
+  return aStr;
+}
+
+inline const char16_t*
+wwc(const char16_t* aStr)
+{
+  return aStr;
+}
+
+#endif
+
 // the following are included/declared for backwards compatibility
 typedef nsAutoString nsVoidableString;
 
 #include "nsDependentString.h"
 #include "nsLiteralString.h"
 #include "nsPromiseFlatString.h"
 
 // need to include these for backwards compatibility