Bug 1249389 - part 6 - provide UniquePtr overload for nsIStartupCache::GetBuffer; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Thu, 18 Feb 2016 14:35:21 -0500
changeset 323691 2a3bc10a643708d268364d928c2342bb5930f8d7
parent 323690 bcfb36dfee0fea8de1555b658b6b04d30ccad263
child 323692 4121f9b10c82af02598ccca3a688a67531440b64
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1249389
milestone47.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
Bug 1249389 - part 6 - provide UniquePtr overload for nsIStartupCache::GetBuffer; r=erahm The lone remaining startup cache-related uses of nsAutoArrayPtr are both in TestStartupCache.cpp, for use with nsIStartupCache::GetBuffer. The uses can't use StartupCache::GetBuffer because StartupCache::GetBuffer isn't visible outside of libxul, and TestStartupCache is a normal C++ unit test. The Right Thing is to convert TestStartupCache to a gtest so we can see libxul internal symbols and then delete nsIStartupCache entirely. That's a bit complicated, as TestStartupCache doesn't fit nicely into gtest's framework. The simpler solution is to add a UniquePtr overload in the interface that hides the XPCOM outparam management details.
startupcache/nsIStartupCache.idl
startupcache/test/TestStartupCache.cpp
--- a/startupcache/nsIStartupCache.idl
+++ b/startupcache/nsIStartupCache.idl
@@ -4,26 +4,42 @@
  * 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 "nsIInputStream.idl"
 #include "nsISupports.idl"
 #include "nsIObserver.idl"
 #include "nsIObjectOutputStream.idl"
 
+%{C++
+#include "mozilla/UniquePtr.h"
+%}
+
 [uuid(25957820-90a1-428c-8739-b0845d3cc534)]
 interface nsIStartupCache : nsISupports
 {
 
   /** This interface is provided for testing purposes only, basically
    *  just to solve link vagaries. See docs in StartupCache.h
    *  GetBuffer, PutBuffer, and InvalidateCache act as described 
    *  in that file. */
 
   uint32_t getBuffer(in string aID, out charPtr aBuffer);
+%{C++
+  /* A more convenient interface for using from C++.  */
+  nsresult GetBuffer(const char* id, mozilla::UniquePtr<char[]>* outbuf, uint32_t* length)
+  {
+    char* buf;
+    nsresult rv = GetBuffer(id, &buf, length);
+    NS_ENSURE_SUCCESS(rv, rv);
+    outbuf->reset(buf);
+    return rv;
+  }
+%}
+
   void putBuffer(in string aID, in string aBuffer, 
                             in uint32_t aLength);
  
   void invalidateCache();
   
   void ignoreDiskCache();
 
   /** In debug builds, wraps this object output stream with a stream that will 
--- a/startupcache/test/TestStartupCache.cpp
+++ b/startupcache/test/TestStartupCache.cpp
@@ -87,36 +87,33 @@ TestStartupWriteRead() {
     return NS_ERROR_FAILURE;
   } else {
     passed("got a pointer?");
   }
   sc->InvalidateCache();
   
   const char* buf = "Market opportunities for BeardBook";
   const char* id = "id";
-  char* outbufPtr = nullptr;
-  nsAutoArrayPtr<char> outbuf;  
+  UniquePtr<char[]> outbuf;  
   uint32_t len;
   
   rv = sc->PutBuffer(id, buf, strlen(buf) + 1);
   NS_ENSURE_SUCCESS(rv, rv);
   
-  rv = sc->GetBuffer(id, &outbufPtr, &len);
+  rv = sc->GetBuffer(id, &outbuf, &len);
   NS_ENSURE_SUCCESS(rv, rv);
-  outbuf = outbufPtr;
-  NS_ENSURE_STR_MATCH(buf, outbuf, "pre-write read");
+  NS_ENSURE_STR_MATCH(buf, outbuf.get(), "pre-write read");
 
   rv = sc->ResetStartupWriteTimer();
   rv = WaitForStartupTimer();
   NS_ENSURE_SUCCESS(rv, rv);
   
-  rv = sc->GetBuffer(id, &outbufPtr, &len);
+  rv = sc->GetBuffer(id, &outbuf, &len);
   NS_ENSURE_SUCCESS(rv, rv);
-  outbuf = outbufPtr;
-  NS_ENSURE_STR_MATCH(buf, outbuf, "simple write/read");
+  NS_ENSURE_STR_MATCH(buf, outbuf.get(), "simple write/read");
 
   return NS_OK;
 }
 
 nsresult
 TestWriteInvalidateRead() {
   nsresult rv;
   const char* buf = "BeardBook competitive analysis";