Bug 1232374 - remove nsAutoArrayPtr usages from toolkit/; r=froydnj
authorHaik Aftandilian <haftandilian@mozilla.com>
Thu, 17 Dec 2015 09:37:47 -0800
changeset 316180 a20e57b2fd303645f1f22fbc1d1c0daac86c3943
parent 316179 ce51411b731f62cce960d3ad6cb9e3720767f790
child 316181 581264224b8d9bddcc0a17b48c836cf83a28804c
push id8516
push userjlund@mozilla.com
push dateFri, 18 Dec 2015 00:52:34 +0000
reviewersfroydnj
bugs1232374
milestone46.0a1
Bug 1232374 - remove nsAutoArrayPtr usages from toolkit/; r=froydnj
toolkit/components/parentalcontrols/nsParentalControlsServiceWin.cpp
toolkit/profile/nsToolkitProfileService.cpp
toolkit/system/gnome/nsPackageKitService.cpp
toolkit/xre/MacLaunchHelper.mm
--- a/toolkit/components/parentalcontrols/nsParentalControlsServiceWin.cpp
+++ b/toolkit/components/parentalcontrols/nsParentalControlsServiceWin.cpp
@@ -8,16 +8,17 @@
 #include "nsIArray.h"
 #include "nsIWidget.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIFile.h"
 #include "nsILocalFileWin.h"
 #include "nsArrayUtils.h"
 #include "nsIXULAppInfo.h"
+#include "mozilla/UniquePtr.h"
 #include "mozilla/WindowsVersion.h"
 
 using namespace mozilla;
 
 static const CLSID CLSID_WinParentalControls = {0xE77CC89B,0x7401,0x4C04,{0x8C,0xED,0x14,0x9D,0xB3,0x5A,0xDD,0x04}};
 static const IID IID_IWinParentalControls  = {0x28B4D88B,0xE072,0x49E6,{0x80,0x4D,0x26,0xED,0xBE,0x21,0xA7,0xB9}};
 
 NS_IMPL_ISUPPORTS(nsParentalControlsService, nsIParentalControlsService)
@@ -243,19 +244,17 @@ nsParentalControlsService::RequestURIOve
     return NS_ERROR_INVALID_ARG;
   
   rootURI->GetSpec(rootSpec);
   if (rootSpec.IsEmpty())
     return NS_ERROR_INVALID_ARG;
 
   // Allocate an array of sub uri
   int32_t count = arrayLength - 1;
-  nsAutoArrayPtr<LPCWSTR> arrUrls(new LPCWSTR[count]);
-  if (!arrUrls)
-    return NS_ERROR_OUT_OF_MEMORY;
+  auto arrUrls = MakeUnique<LPCWSTR[]>(count);
 
   uint32_t uriIdx = 0, idx;
   for (idx = 1; idx < arrayLength; idx++)
   {
     nsCOMPtr<nsIURI> uri = do_QueryElementAt(aTargets, idx);
     if (!uri)
       continue;
 
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/UniquePtr.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <prprf.h>
 #include <prtime.h>
 #include "nsProfileLock.h"
 
 #ifdef XP_WIN
@@ -966,22 +967,20 @@ nsToolkitProfileService::Flush()
     uint32_t pCount = 0;
     nsToolkitProfile *cur;
 
     for (cur = mFirst; cur != nullptr; cur = cur->mNext)
         ++pCount;
 
     uint32_t length;
     const int bufsize = 100+MAXPATHLEN*pCount;
-    nsAutoArrayPtr<char> buffer (new char[bufsize]);
+    auto buffer = MakeUnique<char[]>(bufsize);
 
-    NS_ENSURE_TRUE(buffer, NS_ERROR_OUT_OF_MEMORY);
-
-    char *pos = buffer;
-    char *end = buffer + bufsize;
+    char *pos = buffer.get();
+    char *end = pos + bufsize;
 
     pos += snprintf(pos, end - pos,
                     "[General]\n"
                     "StartWithLastProfile=%s\n\n",
                     mStartWithLast ? "1" : "0");
 
     nsAutoCString path;
     cur = mFirst;
@@ -1019,23 +1018,21 @@ nsToolkitProfileService::Flush()
         cur = cur->mNext;
         ++pCount;
     }
 
     FILE* writeFile;
     rv = mListFile->OpenANSIFileDesc("w", &writeFile);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    if (buffer) {
-        length = pos - buffer;
+    length = pos - buffer.get();
 
-        if (fwrite(buffer, sizeof(char), length, writeFile) != length) {
-            fclose(writeFile);
-            return NS_ERROR_UNEXPECTED;
-        }
+    if (fwrite(buffer.get(), sizeof(char), length, writeFile) != length) {
+        fclose(writeFile);
+        return NS_ERROR_UNEXPECTED;
     }
 
     fclose(writeFile);
     return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS(nsToolkitProfileFactory, nsIFactory)
 
--- a/toolkit/system/gnome/nsPackageKitService.cpp
+++ b/toolkit/system/gnome/nsPackageKitService.cpp
@@ -1,22 +1,22 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsArrayUtils.h"
-#include "nsAutoPtr.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsISupportsPrimitives.h"
 #include "nsPackageKitService.h"
 #include "nsString.h"
 #include "prlink.h"
 #include "mozilla/unused.h"
+#include "mozilla/UniquePtr.h"
 
 #include <glib.h>
 #include <glib-object.h>
 #include <limits>
 
 using namespace mozilla;
 
 typedef struct _GAsyncResult GAsyncResult;
@@ -211,17 +211,17 @@ nsPackageKitService::InstallPackages(uin
   if (arrayLength == 0 ||
       arrayLength == std::numeric_limits<uint32_t>::max() ||
       aInstallMethod >= PK_INSTALL_METHOD_COUNT) {
     return NS_ERROR_INVALID_ARG;
   }
 
   // Create the GVariant* parameter from the list of packages.
   GVariant* parameters = nullptr;
-  nsAutoArrayPtr<gchar*> packages(new gchar*[arrayLength + 1]);
+  auto packages = MakeUnique<gchar*[]>(arrayLength + 1);
 
   nsresult rv = NS_OK;
   for (uint32_t i = 0; i < arrayLength; i++) {
     nsCOMPtr<nsISupportsString> package =
       do_QueryElementAt(aPackageArray, i);
     if (!package) {
       rv = NS_ERROR_FAILURE;
       break;
--- a/toolkit/xre/MacLaunchHelper.mm
+++ b/toolkit/xre/MacLaunchHelper.mm
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MacLaunchHelper.h"
 
 #include "nsMemory.h"
-#include "nsAutoPtr.h"
 #include "nsIAppStartup.h"
+#include "mozilla/UniquePtr.h"
 
 #include <stdio.h>
 #include <spawn.h>
 #include <crt_externs.h>
 
 using namespace mozilla;
 
 namespace {
@@ -35,17 +35,17 @@ cpu_type_t cpu_x64_86_types[2] = {
                                  CPU_TYPE_ANY };
 } // namespace
 
 void LaunchChildMac(int aArgc, char** aArgv,
                     uint32_t aRestartType, pid_t *pid)
 {
   // "posix_spawnp" uses null termination for arguments rather than a count.
   // Note that we are not duplicating the argument strings themselves.
-  nsAutoArrayPtr<char*> argv_copy(new char*[aArgc + 1]);
+  auto argv_copy = MakeUnique<char*[]>(aArgc + 1);
   for (int i = 0; i < aArgc; i++) {
     argv_copy[i] = aArgv[i];
   }
   argv_copy[aArgc] = NULL;
 
   // Initialize spawn attributes.
   posix_spawnattr_t spawnattr;
   if (posix_spawnattr_init(&spawnattr) != 0) {
@@ -75,16 +75,16 @@ void LaunchChildMac(int aArgc, char** aA
 
   // Pass along our environment.
   char** envp = NULL;
   char*** cocoaEnvironment = _NSGetEnviron();
   if (cocoaEnvironment) {
     envp = *cocoaEnvironment;
   }
 
-  int result = posix_spawnp(pid, argv_copy[0], NULL, &spawnattr, argv_copy, envp);
+  int result = posix_spawnp(pid, argv_copy[0], NULL, &spawnattr, argv_copy.get(), envp);
 
   posix_spawnattr_destroy(&spawnattr);
 
   if (result != 0) {
     printf("Process spawn failed with code %d!", result);
   }
 }