Bug 1114880 - Annotate some strong and weak references in XPCOM; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 23 Dec 2014 17:27:48 -0500
changeset 247080 b9094d876dc5e014dfd29de53694879920737714
parent 247079 45798e9a16c252f3792b49f119c8e5177cc43f7d
child 247081 ec3239373af79523d41f621d4d0c27283335eca0
push idunknown
push userunknown
push dateunknown
reviewersfroydnj
bugs1114880
milestone37.0a1
Bug 1114880 - Annotate some strong and weak references in XPCOM; r=froydnj
xpcom/base/AlreadyAddRefed.h
xpcom/base/StaticPtr.h
xpcom/base/nsAutoPtr.h
xpcom/base/nsRefPtr.h
xpcom/build/nsXREAppData.h
xpcom/glue/nsCOMPtr.h
xpcom/glue/nsComponentManagerUtils.h
xpcom/glue/nsHashKeys.h
xpcom/glue/nsIInterfaceRequestorUtils.h
xpcom/glue/nsProxyRelease.cpp
xpcom/glue/nsWeakReference.cpp
xpcom/glue/nsWeakReference.h
--- a/xpcom/base/AlreadyAddRefed.h
+++ b/xpcom/base/AlreadyAddRefed.h
@@ -132,12 +132,12 @@ struct already_AddRefed
   already_AddRefed<U> downcast()
   {
     U* tmp = static_cast<U*>(mRawPtr);
     mRawPtr = nullptr;
     return already_AddRefed<U>(tmp);
   }
 
 private:
-  T* mRawPtr;
+  T* MOZ_STRONG_REF mRawPtr;
 };
 
 #endif // AlreadyAddRefed_h
--- a/xpcom/base/StaticPtr.h
+++ b/xpcom/base/StaticPtr.h
@@ -136,17 +136,17 @@ private:
   {
     T* oldPtr = mRawPtr;
     mRawPtr = aNewPtr;
     if (oldPtr) {
       oldPtr->Release();
     }
   }
 
-  T* mRawPtr;
+  T* MOZ_STRONG_REF mRawPtr;
 };
 
 namespace StaticPtr_internal {
 class Zero;
 } // namespace StaticPtr_internal
 
 #define REFLEXIVE_EQUALITY_OPERATORS(type1, type2, eq_fn, ...) \
   template<__VA_ARGS__>                                        \
--- a/xpcom/base/nsAutoPtr.h
+++ b/xpcom/base/nsAutoPtr.h
@@ -55,21 +55,21 @@ private:
     }
 
     operator T*() const
     {
       return mPtr;
     }
 
   private:
-    T* mPtr;
+    T* MOZ_WEAK_REF mPtr;
   };
 
 private:
-  T* mRawPtr;
+  T* MOZ_STRONG_REF mRawPtr;
 
 public:
   typedef T element_type;
 
   ~nsAutoPtr()
   {
     delete mRawPtr;
   }
@@ -426,17 +426,17 @@ private:
   assign(T* aNewPtr)
   {
     T* oldPtr = mRawPtr;
     mRawPtr = aNewPtr;
     delete [] oldPtr;
   }
 
 private:
-  T* mRawPtr;
+  T* MOZ_STRONG_REF mRawPtr;
 
 public:
   typedef T element_type;
 
   ~nsAutoArrayPtr()
   {
     delete [] mRawPtr;
   }
@@ -773,17 +773,17 @@ public:
   virtual nsresult NS_FASTCALL operator()(const nsIID& aIID,
                                           void** aResult) const
   {
     nsresult status = mRawPtr ? mRawPtr->QueryInterface(aIID, aResult)
                               : NS_ERROR_NULL_POINTER;
     return status;
   }
 private:
-  T* mRawPtr;
+  T* MOZ_WEAK_REF mRawPtr;
 };
 
 template<class T>
 class nsQueryObjectWithError : public nsCOMPtr_helper
 {
 public:
   nsQueryObjectWithError(T* aRawPtr, nsresult* aErrorPtr)
     : mRawPtr(aRawPtr), mErrorPtr(aErrorPtr)
@@ -796,17 +796,17 @@ public:
     nsresult status = mRawPtr ? mRawPtr->QueryInterface(aIID, aResult)
                               : NS_ERROR_NULL_POINTER;
     if (mErrorPtr) {
       *mErrorPtr = status;
     }
     return status;
   }
 private:
-  T* mRawPtr;
+  T* MOZ_WEAK_REF mRawPtr;
   nsresult* mErrorPtr;
 };
 
 template<class T>
 inline nsQueryObject<T>
 do_QueryObject(T* aRawPtr)
 {
   return nsQueryObject<T>(aRawPtr);
--- a/xpcom/base/nsRefPtr.h
+++ b/xpcom/base/nsRefPtr.h
@@ -43,17 +43,17 @@ private:
     T* oldPtr = mRawPtr;
     mRawPtr = aNewPtr;
     if (oldPtr) {
       oldPtr->Release();
     }
   }
 
 private:
-  T* mRawPtr;
+  T* MOZ_STRONG_REF mRawPtr;
 
 public:
   typedef T element_type;
 
   ~nsRefPtr()
   {
     if (mRawPtr) {
       mRawPtr->Release();
--- a/xpcom/build/nsXREAppData.h
+++ b/xpcom/build/nsXREAppData.h
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #ifndef nsXREAppData_h
 #define nsXREAppData_h
 
 #include <stdint.h>
+#include "mozilla/Attributes.h"
 
 class nsIFile;
 
 /**
  * Application-specific data needed to start the apprunner.
  *
  * @note When this structure is allocated and manipulated by XRE_CreateAppData,
  *       string fields will be allocated with NS_Alloc, and interface pointers
@@ -25,17 +26,17 @@ struct nsXREAppData
    * is maintained.
    */
   uint32_t size;
 
   /**
    * The directory of the application to be run. May be null if the
    * xulrunner and the app are installed into the same directory.
    */
-  nsIFile* directory;
+  nsIFile* MOZ_WEAK_REF directory;
 
   /**
    * The name of the application vendor. This must be ASCII, and is normally
    * mixed-case, e.g. "Mozilla". Optional (may be null), but highly
    * recommended. Must not be the empty string.
    */
   const char* vendor;
 
@@ -87,17 +88,17 @@ struct nsXREAppData
    * Combination of NS_XRE_ prefixed flags (defined below).
    */
   uint32_t flags;
 
   /**
    * The location of the XRE. XRE_main may not be able to figure this out
    * programatically.
    */
-  nsIFile* xreDirectory;
+  nsIFile* MOZ_WEAK_REF xreDirectory;
 
   /**
    * The minimum/maximum compatible XRE version.
    */
   const char* minVersion;
   const char* maxVersion;
 
   /**
--- a/xpcom/glue/nsCOMPtr.h
+++ b/xpcom/glue/nsCOMPtr.h
@@ -162,32 +162,32 @@ class MOZ_STACK_CLASS nsQueryInterface M
 {
 public:
   explicit
   nsQueryInterface(nsISupports* aRawPtr) : mRawPtr(aRawPtr) {}
 
   nsresult NS_FASTCALL operator()(const nsIID& aIID, void**) const;
 
 private:
-  nsISupports* mRawPtr;
+  nsISupports* MOZ_STRONG_REF mRawPtr;
 };
 
 class nsQueryInterfaceWithError
 {
 public:
   nsQueryInterfaceWithError(nsISupports* aRawPtr, nsresult* aError)
     : mRawPtr(aRawPtr)
     , mErrorPtr(aError)
   {
   }
 
   nsresult NS_FASTCALL operator()(const nsIID& aIID, void**) const;
 
 private:
-  nsISupports* mRawPtr;
+  nsISupports* MOZ_STRONG_REF mRawPtr;
   nsresult* mErrorPtr;
 };
 
 inline nsQueryInterface
 do_QueryInterface(nsISupports* aRawPtr)
 {
   return nsQueryInterface(aRawPtr);
 }
@@ -314,17 +314,17 @@ public:
   assign_from_gs_contractid_with_error(const nsGetServiceByContractIDWithError&,
                                        const nsIID&);
   void NS_FASTCALL
   assign_from_helper(const nsCOMPtr_helper&, const nsIID&);
   void** NS_FASTCALL
   begin_assignment();
 
 protected:
-  NS_MAY_ALIAS_PTR(nsISupports) mRawPtr;
+  NS_MAY_ALIAS_PTR(nsISupports) MOZ_STRONG_REF mRawPtr;
 
   void assign_assuming_AddRef(nsISupports* aNewPtr)
   {
     // |AddRef()|ing the new value (before entering this function) before
     // |Release()|ing the old lets us safely ignore the self-assignment case.
     // We must, however, be careful only to |Release()| _after_ doing the
     // assignment, in case the |Release()| leads to our _own_ destruction,
     // which would, in turn, cause an incorrect second |Release()| of our old
@@ -373,17 +373,17 @@ private:
     NSCAP_LOG_ASSIGNMENT(this, aNewPtr);
     NSCAP_LOG_RELEASE(this, oldPtr);
     if (oldPtr) {
       NSCAP_RELEASE(this, oldPtr);
     }
   }
 
 private:
-  T* mRawPtr;
+  T* MOZ_STRONG_REF mRawPtr;
 #endif
 
 public:
   typedef T element_type;
 
 #ifndef NSCAP_FEATURE_USE_BASE
   ~nsCOMPtr()
   {
--- a/xpcom/glue/nsComponentManagerUtils.h
+++ b/xpcom/glue/nsComponentManagerUtils.h
@@ -36,17 +36,17 @@ public:
     , mErrorPtr(aErrorPtr)
   {
   }
 
   virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const;
 
 private:
   const nsCID&    mCID;
-  nsISupports*    mOuter;
+  nsISupports* MOZ_WEAK_REF mOuter;
   nsresult*       mErrorPtr;
 };
 
 class nsCreateInstanceByContractID : public nsCOMPtr_helper
 {
 public:
   nsCreateInstanceByContractID(const char* aContractID, nsISupports* aOuter,
                                nsresult* aErrorPtr)
@@ -55,17 +55,17 @@ public:
     , mErrorPtr(aErrorPtr)
   {
   }
 
   virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const;
 
 private:
   const char*   mContractID;
-  nsISupports*  mOuter;
+  nsISupports* MOZ_WEAK_REF mOuter;
   nsresult*     mErrorPtr;
 };
 
 class nsCreateInstanceFromFactory : public nsCOMPtr_helper
 {
 public:
   nsCreateInstanceFromFactory(nsIFactory* aFactory, nsISupports* aOuter,
                               nsresult* aErrorPtr)
@@ -73,18 +73,18 @@ public:
     , mOuter(aOuter)
     , mErrorPtr(aErrorPtr)
   {
   }
 
   virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const;
 
 private:
-  nsIFactory*   mFactory;
-  nsISupports*  mOuter;
+  nsIFactory* MOZ_WEAK_REF mFactory;
+  nsISupports* MOZ_WEAK_REF mOuter;
   nsresult*     mErrorPtr;
 };
 
 
 inline const nsCreateInstanceByCID
 do_CreateInstance(const nsCID& aCID, nsresult* aError = 0)
 {
   return nsCreateInstanceByCID(aCID, 0, aError);
--- a/xpcom/glue/nsHashKeys.h
+++ b/xpcom/glue/nsHashKeys.h
@@ -380,17 +380,17 @@ public:
   static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
   static PLDHashNumber HashKey(KeyTypePointer aKey)
   {
     return NS_PTR_TO_UINT32(aKey) >> 2;
   }
   enum { ALLOW_MEMMOVE = true };
 
 protected:
-  T* mKey;
+  T* MOZ_WEAK_REF mKey;
 };
 
 /**
  * hashkey wrapper using T* KeyType that sets key to nullptr upon
  * destruction. Relevant only in cases where a memory pointer-scanner
  * like valgrind might get confused about stale references.
  *
  * @see nsTHashtable::EntryType for specification
--- a/xpcom/glue/nsIInterfaceRequestorUtils.h
+++ b/xpcom/glue/nsIInterfaceRequestorUtils.h
@@ -29,17 +29,17 @@ public:
     : mSource(aSource)
     , mErrorPtr(aError)
   {
   }
 
   virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const;
 
 private:
-  nsISupports* mSource;
+  nsISupports* MOZ_WEAK_REF mSource;
   nsresult* mErrorPtr;
 };
 
 inline const nsGetInterface
 do_GetInterface(nsISupports* aSource, nsresult* aError = 0)
 {
   return nsGetInterface(aSource, aError);
 }
--- a/xpcom/glue/nsProxyRelease.cpp
+++ b/xpcom/glue/nsProxyRelease.cpp
@@ -15,17 +15,17 @@ public:
 
   NS_IMETHOD Run()
   {
     mDoomed->Release();
     return NS_OK;
   }
 
 private:
-  nsISupports* mDoomed;
+  nsISupports* MOZ_STRONG_REF mDoomed;
 };
 
 nsresult
 NS_ProxyRelease(nsIEventTarget* aTarget, nsISupports* aDoomed,
                 bool aAlwaysProxy)
 {
   nsresult rv;
 
--- a/xpcom/glue/nsWeakReference.cpp
+++ b/xpcom/glue/nsWeakReference.cpp
@@ -40,17 +40,17 @@ private:
 
   void
   NoticeReferentDestruction()
   // ...called (only) by an |nsSupportsWeakReference| from _its_ dtor.
   {
     mReferent = 0;
   }
 
-  nsSupportsWeakReference*  mReferent;
+  nsSupportsWeakReference* MOZ_WEAK_REF mReferent;
 };
 
 nsresult
 nsQueryReferent::operator()(const nsIID& aIID, void** aAnswer) const
 {
   nsresult status;
   if (mWeakPtr) {
     if (NS_FAILED(status = mWeakPtr->QueryReferent(aIID, aAnswer))) {
--- a/xpcom/glue/nsWeakReference.h
+++ b/xpcom/glue/nsWeakReference.h
@@ -26,17 +26,17 @@ protected:
   inline ~nsSupportsWeakReference();
 
 private:
   friend class nsWeakReference;
 
   // Called (only) by an |nsWeakReference| from _its_ dtor.
   void NoticeProxyDestruction() { mProxy = 0; }
 
-  nsWeakReference* mProxy;
+  nsWeakReference* MOZ_WEAK_REF mProxy;
 
 protected:
 
   void ClearWeakReferences();
   bool HasWeakReferences() const { return mProxy != 0; }
 };
 
 inline