mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-12 11:04:32 +00:00
Bug 1241518 - Part 3: Switch various nsAutoPtr uses to UniquePtr in xpcom/ r=kmag
This converts straightforward `nsAutoPtr` usage over to `UniquePtr`. `nsClassHashtable` is left alone for now as that will have a larger impact. `nsThread` is left alone for now as it has non-trivial ownership concepts. Differential Revision: https://phabricator.services.mozilla.com/D58284 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
6012f510a8
commit
bf24e992e3
@ -165,6 +165,7 @@
|
|||||||
#include "mozilla/Move.h"
|
#include "mozilla/Move.h"
|
||||||
#include "mozilla/MruCache.h"
|
#include "mozilla/MruCache.h"
|
||||||
#include "mozilla/SegmentedVector.h"
|
#include "mozilla/SegmentedVector.h"
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsCycleCollectionNoteRootCallback.h"
|
#include "nsCycleCollectionNoteRootCallback.h"
|
||||||
@ -1109,7 +1110,7 @@ class nsCycleCollector : public nsIMemoryReporter {
|
|||||||
|
|
||||||
ccPhase mIncrementalPhase;
|
ccPhase mIncrementalPhase;
|
||||||
CCGraph mGraph;
|
CCGraph mGraph;
|
||||||
nsAutoPtr<CCGraphBuilder> mBuilder;
|
UniquePtr<CCGraphBuilder> mBuilder;
|
||||||
RefPtr<nsCycleCollectorLogger> mLogger;
|
RefPtr<nsCycleCollectorLogger> mLogger;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -1828,7 +1829,7 @@ class CCGraphBuilder final : public nsCycleCollectionTraversalCallback,
|
|||||||
nsCString mNextEdgeName;
|
nsCString mNextEdgeName;
|
||||||
RefPtr<nsCycleCollectorLogger> mLogger;
|
RefPtr<nsCycleCollectorLogger> mLogger;
|
||||||
bool mMergeZones;
|
bool mMergeZones;
|
||||||
nsAutoPtr<NodePool::Enumerator> mCurrNode;
|
UniquePtr<NodePool::Enumerator> mCurrNode;
|
||||||
uint32_t mNoteChildCount;
|
uint32_t mNoteChildCount;
|
||||||
|
|
||||||
struct PtrInfoCache : public MruCache<void*, PtrInfo*, PtrInfoCache, 491> {
|
struct PtrInfoCache : public MruCache<void*, PtrInfo*, PtrInfoCache, 491> {
|
||||||
@ -2034,7 +2035,7 @@ void CCGraphBuilder::DoneAddingRoots() {
|
|||||||
// We've finished adding roots, and everything in the graph is a root.
|
// We've finished adding roots, and everything in the graph is a root.
|
||||||
mGraph.mRootCount = mGraph.MapCount();
|
mGraph.mRootCount = mGraph.MapCount();
|
||||||
|
|
||||||
mCurrNode = new NodePool::Enumerator(mGraph.mNodes);
|
mCurrNode = MakeUnique<NodePool::Enumerator>(mGraph.mNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_NEVER_INLINE bool CCGraphBuilder::BuildGraph(SliceBudget& aBudget) {
|
MOZ_NEVER_INLINE bool CCGraphBuilder::BuildGraph(SliceBudget& aBudget) {
|
||||||
@ -3603,8 +3604,8 @@ void nsCycleCollector::BeginCollection(
|
|||||||
mResults.mMergedZones = mergeZones;
|
mResults.mMergedZones = mergeZones;
|
||||||
|
|
||||||
MOZ_ASSERT(!mBuilder, "Forgot to clear mBuilder");
|
MOZ_ASSERT(!mBuilder, "Forgot to clear mBuilder");
|
||||||
mBuilder =
|
mBuilder = MakeUnique<CCGraphBuilder>(mGraph, mResults, mCCJSRuntime, mLogger,
|
||||||
new CCGraphBuilder(mGraph, mResults, mCCJSRuntime, mLogger, mergeZones);
|
mergeZones);
|
||||||
timeLog.Checkpoint("BeginCollection prepare graph builder");
|
timeLog.Checkpoint("BeginCollection prepare graph builder");
|
||||||
|
|
||||||
if (mCCJSRuntime) {
|
if (mCCJSRuntime) {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "mozilla/IOInterposer.h"
|
#include "mozilla/IOInterposer.h"
|
||||||
#include "mozilla/StaticPtr.h"
|
#include "mozilla/StaticPtr.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "mozilla/TimeStamp.h"
|
||||||
#include "nsAutoPtr.h"
|
#include "mozilla/UniquePtr.h"
|
||||||
#include "nsNativeCharsetUtils.h"
|
#include "nsNativeCharsetUtils.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
|
||||||
@ -210,11 +210,11 @@ namespace mozilla {
|
|||||||
namespace MainThreadIOLogger {
|
namespace MainThreadIOLogger {
|
||||||
|
|
||||||
bool Init() {
|
bool Init() {
|
||||||
nsAutoPtr<MainThreadIOLoggerImpl> impl(new MainThreadIOLoggerImpl());
|
auto impl = MakeUnique<MainThreadIOLoggerImpl>();
|
||||||
if (!impl->Init()) {
|
if (!impl->Init()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sImpl = impl.forget();
|
sImpl = impl.release();
|
||||||
IOInterposer::Register(IOInterposeObserver::OpAllWithStaging, sImpl);
|
IOInterposer::Register(IOInterposeObserver::OpAllWithStaging, sImpl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1592,7 +1592,7 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass, const char* aName,
|
|||||||
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aClass, aFactory));
|
auto f = MakeUnique<nsFactoryEntry>(aClass, aFactory);
|
||||||
|
|
||||||
SafeMutexAutoLock lock(mLock);
|
SafeMutexAutoLock lock(mLock);
|
||||||
if (auto entry = mFactories.LookupForAdd(f->mCIDEntry->cid)) {
|
if (auto entry = mFactories.LookupForAdd(f->mCIDEntry->cid)) {
|
||||||
@ -1604,12 +1604,12 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass, const char* aName,
|
|||||||
}
|
}
|
||||||
if (aContractID) {
|
if (aContractID) {
|
||||||
nsDependentCString contractID(aContractID);
|
nsDependentCString contractID(aContractID);
|
||||||
mContractIDs.Put(contractID, f);
|
mContractIDs.Put(contractID, f.get());
|
||||||
// We allow dynamically-registered contract IDs to override static
|
// We allow dynamically-registered contract IDs to override static
|
||||||
// entries, so invalidate any static entry for this contract ID.
|
// entries, so invalidate any static entry for this contract ID.
|
||||||
StaticComponents::InvalidateContractID(contractID);
|
StaticComponents::InvalidateContractID(contractID);
|
||||||
}
|
}
|
||||||
entry.OrInsert([&f]() { return f.forget(); });
|
entry.OrInsert([&f]() { return f.release(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "mozilla/MemoryReporting.h"
|
#include "mozilla/MemoryReporting.h"
|
||||||
#include "mozilla/Module.h"
|
#include "mozilla/Module.h"
|
||||||
#include "mozilla/Mutex.h"
|
#include "mozilla/Mutex.h"
|
||||||
|
#include "mozilla/UniquePtr.h"
|
||||||
#include "nsXULAppAPI.h"
|
#include "nsXULAppAPI.h"
|
||||||
#include "nsIFactory.h"
|
#include "nsIFactory.h"
|
||||||
#include "nsIInterfaceRequestor.h"
|
#include "nsIInterfaceRequestor.h"
|
||||||
@ -27,7 +28,6 @@
|
|||||||
#include "PLDHashTable.h"
|
#include "PLDHashTable.h"
|
||||||
#include "prtime.h"
|
#include "prtime.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsAutoPtr.h"
|
|
||||||
#include "nsWeakReference.h"
|
#include "nsWeakReference.h"
|
||||||
#include "nsCOMArray.h"
|
#include "nsCOMArray.h"
|
||||||
#include "nsDataHashtable.h"
|
#include "nsDataHashtable.h"
|
||||||
@ -222,7 +222,7 @@ class nsComponentManagerImpl final : public nsIComponentManager,
|
|||||||
|
|
||||||
// The KnownModule is kept alive by these members, it is
|
// The KnownModule is kept alive by these members, it is
|
||||||
// referenced by pointer from the factory entries.
|
// referenced by pointer from the factory entries.
|
||||||
nsTArray<nsAutoPtr<KnownModule>> mKnownStaticModules;
|
nsTArray<mozilla::UniquePtr<KnownModule>> mKnownStaticModules;
|
||||||
// The key is the URI string of the module
|
// The key is the URI string of the module
|
||||||
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownModules;
|
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownModules;
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# include "prthread.h"
|
# include "prthread.h"
|
||||||
|
|
||||||
# include "nsAutoPtr.h"
|
|
||||||
|
|
||||||
# ifndef MOZ_CALLSTACK_DISABLED
|
# ifndef MOZ_CALLSTACK_DISABLED
|
||||||
# include "CodeAddressService.h"
|
# include "CodeAddressService.h"
|
||||||
# include "nsHashKeys.h"
|
# include "nsHashKeys.h"
|
||||||
@ -24,6 +22,7 @@
|
|||||||
# include "mozilla/ReentrantMonitor.h"
|
# include "mozilla/ReentrantMonitor.h"
|
||||||
# include "mozilla/Mutex.h"
|
# include "mozilla/Mutex.h"
|
||||||
# include "mozilla/RWLock.h"
|
# include "mozilla/RWLock.h"
|
||||||
|
# include "mozilla/UniquePtr.h"
|
||||||
|
|
||||||
# if defined(MOZILLA_INTERNAL_API)
|
# if defined(MOZILLA_INTERNAL_API)
|
||||||
# include "GeckoProfiler.h"
|
# include "GeckoProfiler.h"
|
||||||
@ -89,9 +88,9 @@ void BlockingResourceBase::GetStackTrace(AcquisitionState& aState) {
|
|||||||
* some info is written into |aOut|
|
* some info is written into |aOut|
|
||||||
*/
|
*/
|
||||||
static bool PrintCycle(
|
static bool PrintCycle(
|
||||||
const BlockingResourceBase::DDT::ResourceAcquisitionArray* aCycle,
|
const BlockingResourceBase::DDT::ResourceAcquisitionArray& aCycle,
|
||||||
nsACString& aOut) {
|
nsACString& aOut) {
|
||||||
NS_ASSERTION(aCycle->Length() > 1, "need > 1 element for cycle!");
|
NS_ASSERTION(aCycle.Length() > 1, "need > 1 element for cycle!");
|
||||||
|
|
||||||
bool maybeImminent = true;
|
bool maybeImminent = true;
|
||||||
|
|
||||||
@ -99,14 +98,14 @@ static bool PrintCycle(
|
|||||||
aOut += "Cyclical dependency starts at\n";
|
aOut += "Cyclical dependency starts at\n";
|
||||||
|
|
||||||
const BlockingResourceBase::DDT::ResourceAcquisitionArray::elem_type res =
|
const BlockingResourceBase::DDT::ResourceAcquisitionArray::elem_type res =
|
||||||
aCycle->ElementAt(0);
|
aCycle.ElementAt(0);
|
||||||
maybeImminent &= res->Print(aOut);
|
maybeImminent &= res->Print(aOut);
|
||||||
|
|
||||||
BlockingResourceBase::DDT::ResourceAcquisitionArray::index_type i;
|
BlockingResourceBase::DDT::ResourceAcquisitionArray::index_type i;
|
||||||
BlockingResourceBase::DDT::ResourceAcquisitionArray::size_type len =
|
BlockingResourceBase::DDT::ResourceAcquisitionArray::size_type len =
|
||||||
aCycle->Length();
|
aCycle.Length();
|
||||||
const BlockingResourceBase::DDT::ResourceAcquisitionArray::elem_type* it =
|
const BlockingResourceBase::DDT::ResourceAcquisitionArray::elem_type* it =
|
||||||
1 + aCycle->Elements();
|
1 + aCycle.Elements();
|
||||||
for (i = 1; i < len - 1; ++i, ++it) {
|
for (i = 1; i < len - 1; ++i, ++it) {
|
||||||
fputs("\n--- Next dependency:\n", stderr);
|
fputs("\n--- Next dependency:\n", stderr);
|
||||||
aOut += "\nNext dependency:\n";
|
aOut += "\nNext dependency:\n";
|
||||||
@ -221,7 +220,7 @@ void BlockingResourceBase::CheckAcquire() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BlockingResourceBase* chainFront = ResourceChainFront();
|
BlockingResourceBase* chainFront = ResourceChainFront();
|
||||||
nsAutoPtr<DDT::ResourceAcquisitionArray> cycle(
|
mozilla::UniquePtr<DDT::ResourceAcquisitionArray> cycle(
|
||||||
sDeadlockDetector->CheckAcquisition(chainFront ? chainFront : 0, this));
|
sDeadlockDetector->CheckAcquisition(chainFront ? chainFront : 0, this));
|
||||||
if (!cycle) {
|
if (!cycle) {
|
||||||
return;
|
return;
|
||||||
@ -234,7 +233,7 @@ void BlockingResourceBase::CheckAcquire() {
|
|||||||
|
|
||||||
fputs("###!!! ERROR: Potential deadlock detected:\n", stderr);
|
fputs("###!!! ERROR: Potential deadlock detected:\n", stderr);
|
||||||
nsAutoCString out("Potential deadlock detected:\n");
|
nsAutoCString out("Potential deadlock detected:\n");
|
||||||
bool maybeImminent = PrintCycle(cycle, out);
|
bool maybeImminent = PrintCycle(*cycle, out);
|
||||||
|
|
||||||
if (maybeImminent) {
|
if (maybeImminent) {
|
||||||
fputs("\n###!!! Deadlock may happen NOW!\n\n", stderr);
|
fputs("\n###!!! Deadlock may happen NOW!\n\n", stderr);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# include "mozilla/RefPtr.h"
|
# include "mozilla/RefPtr.h"
|
||||||
# include "mozilla/Tuple.h"
|
# include "mozilla/Tuple.h"
|
||||||
# include "mozilla/TypeTraits.h"
|
# include "mozilla/TypeTraits.h"
|
||||||
|
# include "mozilla/UniquePtr.h"
|
||||||
# include "mozilla/Variant.h"
|
# include "mozilla/Variant.h"
|
||||||
|
|
||||||
# include "nsISerialEventTarget.h"
|
# include "nsISerialEventTarget.h"
|
||||||
@ -1350,7 +1351,7 @@ class ProxyRunnable : public CancelableRunnable {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
RefPtr<typename PromiseType::Private> mProxyPromise;
|
RefPtr<typename PromiseType::Private> mProxyPromise;
|
||||||
nsAutoPtr<MethodCall<PromiseType, MethodType, ThisType, Storages...>>
|
UniquePtr<MethodCall<PromiseType, MethodType, ThisType, Storages...>>
|
||||||
mMethodCall;
|
mMethodCall;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user