reland the part of bug 801466 backed out in 02a65951d77d since it wasn't at fault
authorTrevor Saunders <trev.saunders@gmail.com>
Mon, 10 Dec 2012 03:19:02 -0500
changeset 124574 5c2f1dfa1f67a38631ff62bbe4ae658a36235649
parent 124573 25d2aefdca3794b4374156a0742f3d2a16b7fc91
child 124575 49d2d16b9d5b6f35c606cc854896961fcdab94f6
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs801466
milestone20.0a1
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
reland the part of bug 801466 backed out in 02a65951d77d since it wasn't at fault
intl/strres/src/nsStringBundle.cpp
netwerk/base/src/nsSerializationHelper.cpp
netwerk/base/src/nsSocketTransport2.cpp
netwerk/cache/nsCacheMetaData.cpp
netwerk/cache/nsCacheMetaData.h
netwerk/protocol/data/nsDataChannel.cpp
--- a/intl/strres/src/nsStringBundle.cpp
+++ b/intl/strres/src/nsStringBundle.cpp
@@ -19,18 +19,16 @@
 #include "nsHashtable.h"
 #include "nsMemory.h"
 #include "plstr.h"
 #include "nsNetUtil.h"
 #include "nsIURL.h"
 #include "nsIComponentManager.h"
 #include "nsIMemory.h"
 #include "nsIObserverService.h"
-#include "pratom.h"
-#include "prmem.h"
 #include "nsCOMArray.h"
 #include "nsTextFormatter.h"
 #include "nsIErrorService.h"
 #include "nsICategoryManager.h"
 
 #include "nsPrintfCString.h"
 // for async loading
 #ifdef ASYNC_LOADING
--- a/netwerk/base/src/nsSerializationHelper.cpp
+++ b/netwerk/base/src/nsSerializationHelper.cpp
@@ -1,26 +1,27 @@
 /* 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 "nsSerializationHelper.h"
 
-#include "plbase64.h"
-#include "prmem.h"
 
+#include "mozilla/Base64.h"
 #include "nsISerializable.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIObjectInputStream.h"
 #include "nsString.h"
 #include "nsBase64Encoder.h"
 #include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsStringStream.h"
 
+using namespace mozilla;
+
 nsresult
 NS_SerializeToString(nsISerializable* obj, nsCSubstring& str)
 {
   nsRefPtr<nsBase64Encoder> stream(new nsBase64Encoder());
   if (!stream)
     return NS_ERROR_OUT_OF_MEMORY;
 
   nsCOMPtr<nsIObjectOutputStream> objstream =
@@ -33,40 +34,22 @@ NS_SerializeToString(nsISerializable* ob
       objstream->WriteCompoundObject(obj, NS_GET_IID(nsISupports), true);
   NS_ENSURE_SUCCESS(rv, rv);
   return stream->Finish(str);
 }
 
 nsresult
 NS_DeserializeObject(const nsCSubstring& str, nsISupports** obj)
 {
-  // Base64 maps 3 binary bytes -> 4 ASCII bytes.  If the original byte array
-  // does not have length 0 mod 3, the input is padded with zeros and the
-  // output is padded with a corresponding number of trailing '=' (which are
-  // then sometimes dropped).  To compute the correct length of the original
-  // byte array, we have to subtract the number of trailing '=' and then
-  // multiply by 3 and then divide by 4 (making sure this is an integer
-  // division).
+  nsCString decodedData;
+  nsresult rv = Base64Decode(str, decodedData);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  uint32_t size = str.Length();
-  if (size > 0 && str[size-1] == '=') {
-    if (size > 1 && str[size-2] == '=') {
-      size -= 2;
-    } else {
-      size -= 1;
-    }
-  }
-  size = (size * 3) / 4;
-  char* buf = PL_Base64Decode(str.BeginReading(), str.Length(), nullptr);
-  if (!buf)
-    return NS_ERROR_OUT_OF_MEMORY;
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream),
-                                         Substring(buf, size));
-  PR_Free(buf);
+  rv = NS_NewCStringInputStream(getter_AddRefs(stream), decodedData);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIObjectInputStream> objstream =
       do_CreateInstance("@mozilla.org/binaryinputstream;1");
   if (!objstream)
     return NS_ERROR_OUT_OF_MEMORY;
 
   objstream->SetInputStream(stream);
--- a/netwerk/base/src/nsSocketTransport2.cpp
+++ b/netwerk/base/src/nsSocketTransport2.cpp
@@ -14,17 +14,16 @@
 #include "nsNetSegmentUtils.h"
 #include "nsNetAddr.h"
 #include "nsTransportUtils.h"
 #include "nsProxyInfo.h"
 #include "nsNetCID.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "netCore.h"
-#include "prmem.h"
 #include "plstr.h"
 #include "prnetdb.h"
 #include "prerror.h"
 #include "prerr.h"
 #include "NetworkActivityMonitor.h"
 
 #include "nsIServiceManager.h"
 #include "nsISocketProviderService.h"
--- a/netwerk/cache/nsCacheMetaData.cpp
+++ b/netwerk/cache/nsCacheMetaData.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; 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 "nsCacheMetaData.h"
 #include "nsICacheEntryDescriptor.h"
-#include "prmem.h"
 
 const char *
 nsCacheMetaData::GetElement(const char * key)
 {
     const char * data = mBuffer;
     const char * limit = mBuffer + mMetaSize;
 
     while (data < limit) {
@@ -147,17 +146,17 @@ nsCacheMetaData::VisitElements(nsICacheM
     NS_ABORT_IF_FALSE(data == limit, "Metadata corrupted");
     return NS_OK;
 }
 
 nsresult
 nsCacheMetaData::EnsureBuffer(uint32_t bufSize)
 {
     if (mBufferSize < bufSize) {
-        char * buf = (char *)PR_REALLOC(mBuffer, bufSize);
+        char * buf = (char *)moz_realloc(mBuffer, bufSize);
         if (!buf) {
             return NS_ERROR_OUT_OF_MEMORY;
         }
         mBuffer = buf;
         mBufferSize = bufSize;
     }
     return NS_OK;
 }        
--- a/netwerk/cache/nsCacheMetaData.h
+++ b/netwerk/cache/nsCacheMetaData.h
@@ -13,17 +13,18 @@
 class nsICacheMetaDataVisitor;
 
 class nsCacheMetaData {
 public:
     nsCacheMetaData() : mBuffer(nullptr), mBufferSize(0), mMetaSize(0) { }
 
     ~nsCacheMetaData() {
         mBufferSize = mMetaSize = 0;  
-        PR_FREEIF(mBuffer);
+        moz_free(mBuffer);
+        mBuffer = nullptr;
     }
 
     const char *  GetElement(const char * key);
 
     nsresult      SetElement(const char * key, const char * value);
 
     uint32_t      Size(void) { return mMetaSize; }
 
--- a/netwerk/protocol/data/nsDataChannel.cpp
+++ b/netwerk/protocol/data/nsDataChannel.cpp
@@ -1,27 +1,28 @@
 /* -*- Mode: C++; tab-width: 2; 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/. */
 
 // data implementation
 
+#include "nsDataChannel.h"
+
+#include "mozilla/Base64.h"
 #include "nsIOService.h"
-#include "nsDataChannel.h"
 #include "nsDataHandler.h"
 #include "nsNetUtil.h"
 #include "nsIPipe.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsReadableUtils.h"
 #include "nsEscape.h"
-#include "plbase64.h"
-#include "plstr.h"
-#include "prmem.h"
+
+using namespace mozilla;
 
 nsresult
 nsDataChannel::OpenContentStream(bool async, nsIInputStream **result,
                                  nsIChannel** channel)
 {
     NS_ENSURE_TRUE(URI(), NS_ERROR_NOT_INITIALIZED);
 
     nsresult rv;
@@ -65,27 +66,20 @@ nsDataChannel::OpenContentStream(bool as
                 resultLen = dataLen-2;
             else
                 resultLen = dataLen-1;
         } else {
             resultLen = dataLen;
         }
         resultLen = ((resultLen * 3) / 4);
 
-        // XXX PL_Base64Decode will return a null pointer for decoding
-        // errors.  Since those are more likely than out-of-memory,
-        // should we return NS_ERROR_MALFORMED_URI instead?
-        char * decodedData = PL_Base64Decode(dataBuffer.get(), dataLen, nullptr);
-        if (!decodedData) {
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
-
-        rv = bufOutStream->Write(decodedData, resultLen, &contentLen);
-
-        PR_Free(decodedData);
+        nsAutoCString decodedData;
+        rv = Base64Decode(dataBuffer, decodedData);
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = bufOutStream->Write(decodedData.get(), resultLen, &contentLen);
     } else {
         rv = bufOutStream->Write(dataBuffer.get(), dataBuffer.Length(), &contentLen);
     }
     if (NS_FAILED(rv))
         return rv;
 
     SetContentType(contentType);
     SetContentCharset(contentCharset);