diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index a058ed262cba..148e87123ebc 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -165,6 +165,7 @@ #include "mozilla/Move.h" #include "mozilla/MruCache.h" #include "mozilla/SegmentedVector.h" +#include "mozilla/UniquePtr.h" #include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionNoteRootCallback.h" @@ -1109,7 +1110,7 @@ class nsCycleCollector : public nsIMemoryReporter { ccPhase mIncrementalPhase; CCGraph mGraph; - nsAutoPtr mBuilder; + UniquePtr mBuilder; RefPtr mLogger; #ifdef DEBUG @@ -1828,7 +1829,7 @@ class CCGraphBuilder final : public nsCycleCollectionTraversalCallback, nsCString mNextEdgeName; RefPtr mLogger; bool mMergeZones; - nsAutoPtr mCurrNode; + UniquePtr mCurrNode; uint32_t mNoteChildCount; struct PtrInfoCache : public MruCache { @@ -2034,7 +2035,7 @@ void CCGraphBuilder::DoneAddingRoots() { // We've finished adding roots, and everything in the graph is a root. mGraph.mRootCount = mGraph.MapCount(); - mCurrNode = new NodePool::Enumerator(mGraph.mNodes); + mCurrNode = MakeUnique(mGraph.mNodes); } MOZ_NEVER_INLINE bool CCGraphBuilder::BuildGraph(SliceBudget& aBudget) { @@ -3603,8 +3604,8 @@ void nsCycleCollector::BeginCollection( mResults.mMergedZones = mergeZones; MOZ_ASSERT(!mBuilder, "Forgot to clear mBuilder"); - mBuilder = - new CCGraphBuilder(mGraph, mResults, mCCJSRuntime, mLogger, mergeZones); + mBuilder = MakeUnique(mGraph, mResults, mCCJSRuntime, mLogger, + mergeZones); timeLog.Checkpoint("BeginCollection prepare graph builder"); if (mCCJSRuntime) { diff --git a/xpcom/build/MainThreadIOLogger.cpp b/xpcom/build/MainThreadIOLogger.cpp index 243a77496373..7af95093aba4 100644 --- a/xpcom/build/MainThreadIOLogger.cpp +++ b/xpcom/build/MainThreadIOLogger.cpp @@ -11,7 +11,7 @@ #include "mozilla/IOInterposer.h" #include "mozilla/StaticPtr.h" #include "mozilla/TimeStamp.h" -#include "nsAutoPtr.h" +#include "mozilla/UniquePtr.h" #include "nsNativeCharsetUtils.h" #include "nsThreadUtils.h" @@ -210,11 +210,11 @@ namespace mozilla { namespace MainThreadIOLogger { bool Init() { - nsAutoPtr impl(new MainThreadIOLoggerImpl()); + auto impl = MakeUnique(); if (!impl->Init()) { return false; } - sImpl = impl.forget(); + sImpl = impl.release(); IOInterposer::Register(IOInterposeObserver::OpAllWithStaging, sImpl); return true; } diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 9b2b4197b6c7..a28087b3f089 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -1592,7 +1592,7 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass, const char* aName, return NS_ERROR_FACTORY_NOT_REGISTERED; } - nsAutoPtr f(new nsFactoryEntry(aClass, aFactory)); + auto f = MakeUnique(aClass, aFactory); SafeMutexAutoLock lock(mLock); if (auto entry = mFactories.LookupForAdd(f->mCIDEntry->cid)) { @@ -1604,12 +1604,12 @@ nsComponentManagerImpl::RegisterFactory(const nsCID& aClass, const char* aName, } if (aContractID) { nsDependentCString contractID(aContractID); - mContractIDs.Put(contractID, f); + mContractIDs.Put(contractID, f.get()); // We allow dynamically-registered contract IDs to override static // entries, so invalidate any static entry for this contract ID. StaticComponents::InvalidateContractID(contractID); } - entry.OrInsert([&f]() { return f.forget(); }); + entry.OrInsert([&f]() { return f.release(); }); } return NS_OK; diff --git a/xpcom/components/nsComponentManager.h b/xpcom/components/nsComponentManager.h index 547475b58c2b..5e7424f3f401 100644 --- a/xpcom/components/nsComponentManager.h +++ b/xpcom/components/nsComponentManager.h @@ -20,6 +20,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/Module.h" #include "mozilla/Mutex.h" +#include "mozilla/UniquePtr.h" #include "nsXULAppAPI.h" #include "nsIFactory.h" #include "nsIInterfaceRequestor.h" @@ -27,7 +28,6 @@ #include "PLDHashTable.h" #include "prtime.h" #include "nsCOMPtr.h" -#include "nsAutoPtr.h" #include "nsWeakReference.h" #include "nsCOMArray.h" #include "nsDataHashtable.h" @@ -222,7 +222,7 @@ class nsComponentManagerImpl final : public nsIComponentManager, // The KnownModule is kept alive by these members, it is // referenced by pointer from the factory entries. - nsTArray> mKnownStaticModules; + nsTArray> mKnownStaticModules; // The key is the URI string of the module nsClassHashtable mKnownModules; diff --git a/xpcom/threads/BlockingResourceBase.cpp b/xpcom/threads/BlockingResourceBase.cpp index 1963f2ccd859..692796e56440 100644 --- a/xpcom/threads/BlockingResourceBase.cpp +++ b/xpcom/threads/BlockingResourceBase.cpp @@ -9,8 +9,6 @@ #ifdef DEBUG # include "prthread.h" -# include "nsAutoPtr.h" - # ifndef MOZ_CALLSTACK_DISABLED # include "CodeAddressService.h" # include "nsHashKeys.h" @@ -24,6 +22,7 @@ # include "mozilla/ReentrantMonitor.h" # include "mozilla/Mutex.h" # include "mozilla/RWLock.h" +# include "mozilla/UniquePtr.h" # if defined(MOZILLA_INTERNAL_API) # include "GeckoProfiler.h" @@ -89,9 +88,9 @@ void BlockingResourceBase::GetStackTrace(AcquisitionState& aState) { * some info is written into |aOut| */ static bool PrintCycle( - const BlockingResourceBase::DDT::ResourceAcquisitionArray* aCycle, + const BlockingResourceBase::DDT::ResourceAcquisitionArray& aCycle, 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; @@ -99,14 +98,14 @@ static bool PrintCycle( aOut += "Cyclical dependency starts at\n"; const BlockingResourceBase::DDT::ResourceAcquisitionArray::elem_type res = - aCycle->ElementAt(0); + aCycle.ElementAt(0); maybeImminent &= res->Print(aOut); BlockingResourceBase::DDT::ResourceAcquisitionArray::index_type i; BlockingResourceBase::DDT::ResourceAcquisitionArray::size_type len = - aCycle->Length(); + aCycle.Length(); const BlockingResourceBase::DDT::ResourceAcquisitionArray::elem_type* it = - 1 + aCycle->Elements(); + 1 + aCycle.Elements(); for (i = 1; i < len - 1; ++i, ++it) { fputs("\n--- Next dependency:\n", stderr); aOut += "\nNext dependency:\n"; @@ -221,7 +220,7 @@ void BlockingResourceBase::CheckAcquire() { } BlockingResourceBase* chainFront = ResourceChainFront(); - nsAutoPtr cycle( + mozilla::UniquePtr cycle( sDeadlockDetector->CheckAcquisition(chainFront ? chainFront : 0, this)); if (!cycle) { return; @@ -234,7 +233,7 @@ void BlockingResourceBase::CheckAcquire() { fputs("###!!! ERROR: Potential deadlock detected:\n", stderr); nsAutoCString out("Potential deadlock detected:\n"); - bool maybeImminent = PrintCycle(cycle, out); + bool maybeImminent = PrintCycle(*cycle, out); if (maybeImminent) { fputs("\n###!!! Deadlock may happen NOW!\n\n", stderr); diff --git a/xpcom/threads/MozPromise.h b/xpcom/threads/MozPromise.h index 8b9b2767937a..c71daab9998c 100644 --- a/xpcom/threads/MozPromise.h +++ b/xpcom/threads/MozPromise.h @@ -14,6 +14,7 @@ # include "mozilla/RefPtr.h" # include "mozilla/Tuple.h" # include "mozilla/TypeTraits.h" +# include "mozilla/UniquePtr.h" # include "mozilla/Variant.h" # include "nsISerialEventTarget.h" @@ -1350,7 +1351,7 @@ class ProxyRunnable : public CancelableRunnable { private: RefPtr mProxyPromise; - nsAutoPtr> + UniquePtr> mMethodCall; };