Bug 1219246 - use UniquePtr instead of nsAutoArrayPtr in xpcom/; r=erahm

This commit is contained in:
Nathan Froyd 2015-10-28 09:50:29 -04:00
parent c6e4cfbbbd
commit a5bf910f3f
4 changed files with 41 additions and 37 deletions

View File

@ -71,6 +71,7 @@
#include "nsArrayEnumerator.h"
#include "nsStringEnumerator.h"
#include "mozilla/FileUtils.h"
#include "mozilla/UniquePtr.h"
#include "nsDataHashtable.h"
#include <new> // for placement new
@ -620,18 +621,18 @@ DoRegisterManifest(NSLocationType aType,
MOZ_ASSERT(!aXPTOnly || !nsComponentManagerImpl::gComponentManager);
uint32_t len;
FileLocation::Data data;
nsAutoArrayPtr<char> buf;
UniquePtr<char[]> buf;
nsresult rv = aFile.GetData(data);
if (NS_SUCCEEDED(rv)) {
rv = data.GetSize(&len);
}
if (NS_SUCCEEDED(rv)) {
buf = new char[len + 1];
rv = data.Copy(buf, len);
buf = MakeUnique<char[]>(len + 1);
rv = data.Copy(buf.get(), len);
}
if (NS_SUCCEEDED(rv)) {
buf[len] = '\0';
ParseManifest(aType, aFile, buf, aChromeOnly, aXPTOnly);
ParseManifest(aType, aFile, buf.get(), aChromeOnly, aXPTOnly);
} else if (NS_BOOTSTRAPPED_LOCATION != aType) {
nsCString uri;
aFile.GetURIString(uri);
@ -699,17 +700,17 @@ DoRegisterXPT(FileLocation& aFile)
uint32_t len;
FileLocation::Data data;
nsAutoArrayPtr<char> buf;
UniquePtr<char[]> buf;
nsresult rv = aFile.GetData(data);
if (NS_SUCCEEDED(rv)) {
rv = data.GetSize(&len);
}
if (NS_SUCCEEDED(rv)) {
buf = new char[len];
rv = data.Copy(buf, len);
buf = MakeUnique<char[]>(len);
rv = data.Copy(buf.get(), len);
}
if (NS_SUCCEEDED(rv)) {
XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf, len);
XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf.get(), len);
#ifdef MOZ_B2G_LOADER
MarkRegisteredXPTIInfo(aFile);
#endif

View File

@ -24,6 +24,8 @@
#define READ_BINARYMODE "r"
#endif
using namespace mozilla;
#ifdef XP_WIN
inline FILE*
TS_tfopen(const char* aPath, const wchar_t* aMode)
@ -123,7 +125,7 @@ nsINIParser::InitFromFILE(FILE* aFd)
}
/* malloc an internal buf the size of the file */
mFileContents = new char[flen + 2];
mFileContents = MakeUnique<char[]>(flen + 2);
if (!mFileContents) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -133,7 +135,7 @@ nsINIParser::InitFromFILE(FILE* aFd)
return NS_BASE_STREAM_OSERROR;
}
int rd = fread(mFileContents, sizeof(char), flen, aFd);
int rd = fread(mFileContents.get(), sizeof(char), flen, aFd);
if (rd != flen) {
return NS_BASE_STREAM_OSERROR;
}
@ -172,13 +174,13 @@ nsINIParser::InitFromFILE(FILE* aFd)
return NS_ERROR_FAILURE;
}
nsAutoArrayPtr<char> utf8Buffer(new char[flen]);
UniquePtr<char[]> utf8Buffer(new char[flen]);
if (WideCharToMultiByte(CP_UTF8, 0, reinterpret_cast<LPWSTR>(buffer), -1,
utf8Buffer, flen, nullptr, nullptr) == 0) {
utf8Buffer.get(), flen, nullptr, nullptr) == 0) {
return NS_ERROR_FAILURE;
}
mFileContents = utf8Buffer.forget();
buffer = mFileContents;
mFileContents = Move(utf8Buffer);
buffer = mFileContents.get();
}
#endif
@ -242,13 +244,13 @@ nsINIParser::InitFromFILE(FILE* aFd)
break;
}
if (!v->next) {
v->next = new INIValue(key, token);
v->next = MakeUnique<INIValue>(key, token);
if (!v->next) {
return NS_ERROR_OUT_OF_MEMORY;
}
break;
}
v = v->next;
v = v->next.get();
}
NS_ASSERTION(v, "v should never be null coming out of this loop");
}
@ -269,7 +271,7 @@ nsINIParser::GetString(const char* aSection, const char* aKey,
return NS_OK;
}
val = val->next;
val = val->next.get();
}
return NS_ERROR_FAILURE;
@ -293,7 +295,7 @@ nsINIParser::GetString(const char* aSection, const char* aKey,
return NS_OK;
}
val = val->next;
val = val->next.get();
}
return NS_ERROR_FAILURE;
@ -318,7 +320,7 @@ nsINIParser::GetStrings(const char* aSection,
for (mSections.Get(aSection, &val);
val;
val = val->next) {
val = val->next.get()) {
if (!aCB(val->key, val->value, aClosure)) {
return NS_OK;

View File

@ -15,7 +15,7 @@
#include "nscore.h"
#include "nsClassHashtable.h"
#include "nsAutoPtr.h"
#include "mozilla/UniquePtr.h"
#include <stdio.h>
@ -106,11 +106,11 @@ private:
const char* key;
const char* value;
nsAutoPtr<INIValue> next;
mozilla::UniquePtr<INIValue> next;
};
nsClassHashtable<nsDepCharHashKey, INIValue> mSections;
nsAutoArrayPtr<char> mFileContents;
mozilla::UniquePtr<char[]> mFileContents;
nsresult InitFromFILE(FILE* aFd);
};

View File

@ -18,6 +18,7 @@
#include "nsIFile.h"
#include "prinrval.h"
#include "nsThreadUtils.h"
#include "mozilla/UniquePtr.h"
#include "gtest/gtest.h"
namespace TestExpirationTracker {
@ -49,7 +50,7 @@ public:
LogAction(obj, "Created");
}
nsTArray<nsAutoArrayPtr<Object> > mUniverse;
nsTArray<mozilla::UniquePtr<Object>> mUniverse;
void LogAction(Object* aObj, const char* aAction) {
if (logging) {
@ -79,28 +80,28 @@ public:
break;
}
case 1: {
obj = mUniverse[uint32_t(rand())%mUniverse.Length()];
if (obj->mExpiration.IsTracked()) {
nsExpirationTracker<Object,K>::RemoveObject(obj);
LogAction(obj, "Removed");
UniquePtr<Object>& objref = mUniverse[uint32_t(rand())%mUniverse.Length()];
if (objref->mExpiration.IsTracked()) {
nsExpirationTracker<Object,K>::RemoveObject(objref.get());
LogAction(objref.get(), "Removed");
}
break;
}
case 2: {
obj = mUniverse[uint32_t(rand())%mUniverse.Length()];
if (!obj->mExpiration.IsTracked()) {
obj->Touch();
nsExpirationTracker<Object,K>::AddObject(obj);
LogAction(obj, "Added");
UniquePtr<Object>& objref = mUniverse[uint32_t(rand())%mUniverse.Length()];
if (!objref->mExpiration.IsTracked()) {
objref->Touch();
nsExpirationTracker<Object,K>::AddObject(objref.get());
LogAction(objref.get(), "Added");
}
break;
}
case 3: {
obj = mUniverse[uint32_t(rand())%mUniverse.Length()];
if (obj->mExpiration.IsTracked()) {
obj->Touch();
nsExpirationTracker<Object,K>::MarkUsed(obj);
LogAction(obj, "Marked used");
UniquePtr<Object>& objref = mUniverse[uint32_t(rand())%mUniverse.Length()];
if (objref->mExpiration.IsTracked()) {
objref->Touch();
nsExpirationTracker<Object,K>::MarkUsed(objref.get());
LogAction(objref.get(), "Marked used");
}
break;
}