diff --git a/dom/xul/nsXULPrototypeCache.cpp b/dom/xul/nsXULPrototypeCache.cpp index 306ad05faf87..fc58cd28f515 100644 --- a/dom/xul/nsXULPrototypeCache.cpp +++ b/dom/xul/nsXULPrototypeCache.cpp @@ -30,6 +30,7 @@ #include "mozilla/scache/StartupCacheUtils.h" #include "mozilla/Telemetry.h" #include "mozilla/RefPtr.h" +#include "mozilla/UniquePtrExtensions.h" #include "mozilla/intl/LocaleService.h" using namespace mozilla; @@ -285,7 +286,7 @@ nsresult nsXULPrototypeCache::FinishOutputStream(CacheType cacheType, nsCOMPtr outputStream = do_QueryInterface(storageStream); outputStream->Close(); - UniquePtr buf; + UniqueFreePtr buf; uint32_t len; rv = NewBufferFromStorageStream(storageStream, &buf, &len); NS_ENSURE_SUCCESS(rv, rv); @@ -425,7 +426,8 @@ nsresult nsXULPrototypeCache::BeginCaching(nsIURI* aURI) { } if (NS_SUCCEEDED(rv)) { - auto putBuf = MakeUnique(len); + auto putBuf = UniqueFreePtr( + reinterpret_cast(malloc(sizeof(char) * len))); rv = inputStream->Read(putBuf.get(), len, &amtRead); if (NS_SUCCEEDED(rv) && len == amtRead) rv = startupCache->PutBuffer(kXULCacheInfoKey, std::move(putBuf), len); diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index 78bfad19dd3a..49bbb49ba834 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -746,7 +746,7 @@ class FontNameCache { LOG(("putting FontNameCache to " CACHE_KEY ", length %zu", buf.Length() + 1)); - mCache->PutBuffer(CACHE_KEY, UniquePtr(ToNewCString(buf)), + mCache->PutBuffer(CACHE_KEY, UniqueFreePtr(ToNewCString(buf)), buf.Length() + 1); mWriteNeeded = false; } @@ -1563,7 +1563,8 @@ void gfxFT2FontList::WriteCache() { mozilla::scache::StartupCache::GetSingleton(); if (cache && mJarModifiedTime > 0) { const size_t bufSize = sizeof(mJarModifiedTime); - auto buf = MakeUnique(bufSize); + auto buf = UniqueFreePtr( + reinterpret_cast(malloc(sizeof(char) * bufSize))); LittleEndian::writeInt64(buf.get(), mJarModifiedTime); LOG(("WriteCache: putting Jar, length %zu", bufSize)); diff --git a/js/xpconnect/loader/mozJSLoaderUtils.cpp b/js/xpconnect/loader/mozJSLoaderUtils.cpp index a92ec495485c..d955aec79392 100644 --- a/js/xpconnect/loader/mozJSLoaderUtils.cpp +++ b/js/xpconnect/loader/mozJSLoaderUtils.cpp @@ -66,7 +66,7 @@ nsresult WriteCachedStencil(StartupCache* cache, nsACString& cachePath, } // Move the vector buffer into a unique pointer buffer. - UniquePtr buf( + UniqueFreePtr buf( reinterpret_cast(buffer.extractOrCopyRawBuffer())); nsresult rv = cache->PutBuffer(PromiseFlatCString(cachePath).get(), std::move(buf), size); diff --git a/startupcache/StartupCache.cpp b/startupcache/StartupCache.cpp index 2085be5f7ab3..67d19155eb2d 100644 --- a/startupcache/StartupCache.cpp +++ b/startupcache/StartupCache.cpp @@ -412,7 +412,8 @@ nsresult StartupCache::GetBuffer(const char* id, const char** outbuf, Span compressed = Span( mCacheData.get().get() + mCacheEntriesBaseOffset + value.mOffset, value.mCompressedSize); - value.mData = MakeUnique(value.mUncompressedSize); + value.mData = UniqueFreePtr(reinterpret_cast( + malloc(sizeof(char) * value.mUncompressedSize))); Span uncompressed = Span(value.mData.get(), value.mUncompressedSize); MMAP_FAULT_HANDLER_BEGIN_BUFFER(uncompressed.Elements(), uncompressed.Length()) @@ -453,7 +454,7 @@ nsresult StartupCache::GetBuffer(const char* id, const char** outbuf, } // Makes a copy of the buffer, client retains ownership of inbuf. -nsresult StartupCache::PutBuffer(const char* id, UniquePtr&& inbuf, +nsresult StartupCache::PutBuffer(const char* id, UniqueFreePtr&& inbuf, uint32_t len) MOZ_NO_THREAD_SAFETY_ANALYSIS { NS_ASSERTION(NS_IsMainThread(), "Startup cache only available on main thread"); diff --git a/startupcache/StartupCache.h b/startupcache/StartupCache.h index 55c2b17b0249..86f266039f52 100644 --- a/startupcache/StartupCache.h +++ b/startupcache/StartupCache.h @@ -27,6 +27,7 @@ #include "mozilla/Mutex.h" #include "mozilla/Result.h" #include "mozilla/UniquePtr.h" +#include "mozilla/UniquePtrExtensions.h" /** * The StartupCache is a persistent cache of simple key-value pairs, @@ -83,7 +84,7 @@ namespace mozilla { namespace scache { struct StartupCacheEntry { - UniquePtr mData; + UniqueFreePtr mData; uint32_t mOffset; uint32_t mCompressedSize; uint32_t mUncompressedSize; @@ -101,7 +102,7 @@ struct StartupCacheEntry { mRequestedOrder(0), mRequested(false) {} - StartupCacheEntry(UniquePtr aData, size_t aLength, + StartupCacheEntry(UniqueFreePtr aData, size_t aLength, int32_t aRequestedOrder) : mData(std::move(aData)), mOffset(0), @@ -148,7 +149,7 @@ class StartupCache : public nsIMemoryReporter { nsresult GetBuffer(const char* id, const char** outbuf, uint32_t* length); // Stores a buffer. Caller yields ownership. - nsresult PutBuffer(const char* id, UniquePtr&& inbuf, + nsresult PutBuffer(const char* id, UniqueFreePtr&& inbuf, uint32_t length); // Removes the cache file. diff --git a/startupcache/StartupCacheUtils.cpp b/startupcache/StartupCacheUtils.cpp index 8f3622328ded..c8dcdd7f1173 100644 --- a/startupcache/StartupCacheUtils.cpp +++ b/startupcache/StartupCacheUtils.cpp @@ -66,7 +66,8 @@ nsresult NewObjectOutputWrappedStorageStream( } nsresult NewBufferFromStorageStream(nsIStorageStream* storageStream, - UniquePtr* buffer, uint32_t* len) { + UniqueFreePtr* buffer, + uint32_t* len) { nsresult rv; nsCOMPtr inputStream; rv = storageStream->NewInputStream(0, getter_AddRefs(inputStream)); @@ -78,7 +79,8 @@ nsresult NewBufferFromStorageStream(nsIStorageStream* storageStream, NS_ENSURE_TRUE(avail64 <= UINT32_MAX, NS_ERROR_FILE_TOO_BIG); uint32_t avail = (uint32_t)avail64; - auto temp = MakeUnique(avail); + auto temp = UniqueFreePtr( + reinterpret_cast(malloc(sizeof(char) * avail))); uint32_t read; rv = inputStream->Read(temp.get(), avail, &read); if (NS_SUCCEEDED(rv) && avail != read) rv = NS_ERROR_UNEXPECTED; diff --git a/startupcache/StartupCacheUtils.h b/startupcache/StartupCacheUtils.h index 0a8499d18253..a59f0e4fac40 100644 --- a/startupcache/StartupCacheUtils.h +++ b/startupcache/StartupCacheUtils.h @@ -10,6 +10,7 @@ #include "nsIObjectInputStream.h" #include "nsIObjectOutputStream.h" #include "mozilla/UniquePtr.h" +#include "mozilla/UniquePtrExtensions.h" class nsIURI; @@ -33,7 +34,8 @@ nsresult NewObjectOutputWrappedStorageStream( // allocated with 'new []'. After calling this function, the caller would // typically call StartupCache::PutBuffer with the returned buffer. nsresult NewBufferFromStorageStream(nsIStorageStream* storageStream, - UniquePtr* buffer, uint32_t* len); + UniqueFreePtr* buffer, + uint32_t* len); nsresult ResolveURI(nsIURI* in, nsIURI** out); diff --git a/startupcache/test/TestStartupCache.cpp b/startupcache/test/TestStartupCache.cpp index d60bbcb8c70e..9a66b52e0203 100644 --- a/startupcache/test/TestStartupCache.cpp +++ b/startupcache/test/TestStartupCache.cpp @@ -23,6 +23,7 @@ #include "mozilla/Maybe.h" #include "mozilla/Printf.h" #include "mozilla/UniquePtr.h" +#include "mozilla/UniquePtrExtensions.h" #include "nsNetCID.h" #include "nsIURIMutator.h" @@ -83,7 +84,8 @@ TEST_F(TestStartupCache, StartupWriteRead) { const char* outbuf; uint32_t len; - rv = sc->PutBuffer(id, UniquePtr(strdup(buf)), strlen(buf) + 1); + rv = sc->PutBuffer(id, mozilla::UniqueFreePtr(strdup(buf)), + strlen(buf) + 1); EXPECT_NS_SUCCEEDED(rv); rv = sc->GetBuffer(id, &outbuf, &len); @@ -108,7 +110,8 @@ TEST_F(TestStartupCache, WriteInvalidateRead) { StartupCache* sc = StartupCache::GetSingleton(); ASSERT_TRUE(sc); - rv = sc->PutBuffer(id, UniquePtr(strdup(buf)), strlen(buf) + 1); + rv = sc->PutBuffer(id, mozilla::UniqueFreePtr(strdup(buf)), + strlen(buf) + 1); EXPECT_NS_SUCCEEDED(rv); sc->InvalidateCache(); @@ -153,7 +156,7 @@ TEST_F(TestStartupCache, WriteObject) { rv = objectOutput->WriteObject(objQI, true); EXPECT_NS_SUCCEEDED(rv); - UniquePtr buf; + mozilla::UniqueFreePtr buf; uint32_t len; NewBufferFromStorageStream(storageStream, &buf, &len);