Bug 1450321, part 3 - Make xptiInterfaceInfo use normal refcounting. draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 30 Mar 2018 12:36:39 -0700
changeset 776987 d247f217c7cf7b5c55b9e7244c24ab49d742ea2e
parent 776986 764f688b823c307e70e8aa0792b9c9296a88aa70
child 776988 7f0cef94efae5a3682c7874e70b3b1a5e330d9bc
push id105047
push userbmo:continuation@gmail.com
push dateTue, 03 Apr 2018 23:36:00 +0000
bugs1450321
milestone61.0a1
Bug 1450321, part 3 - Make xptiInterfaceInfo use normal refcounting. This class can only be used on the main thread, so there's no need to worry about an object going away from under us while we're in Release(). The clearing of the weak pointer gets moved to the dtor. MozReview-Commit-ID: 9XhLWsRmO87
xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
xpcom/reflect/xptinfo/xptiprivate.h
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfo.cpp
@@ -580,70 +580,31 @@ xptiInterfaceInfo::BuildParent()
                  mEntry->Parent(),
                "bad BuildParent call");
   mParent = mEntry->Parent()->InterfaceInfo();
   return true;
 }
 
 /***************************************************************************/
 
-NS_IMPL_QUERY_INTERFACE(xptiInterfaceInfo, nsIInterfaceInfo)
+NS_IMPL_ISUPPORTS(xptiInterfaceInfo, nsIInterfaceInfo)
 
-xptiInterfaceInfo::xptiInterfaceInfo(xptiInterfaceEntry* entry)
-  : mEntry(entry)
+xptiInterfaceInfo::xptiInterfaceInfo(xptiInterfaceEntry* aEntry)
+  : mEntry(aEntry)
 {
+  MOZ_ASSERT(aEntry);
 }
 
 xptiInterfaceInfo::~xptiInterfaceInfo()
 {
-  NS_ASSERTION(!mEntry, "bad state in dtor");
+  if (mEntry) {
+    mEntry->InterfaceInfoDeathNotification();
+  }
 }
 
 void
 xptiInterfaceInfo::Invalidate()
 {
   mParent = nullptr;
   mEntry = nullptr;
 }
 
-MozExternalRefCountType
-xptiInterfaceInfo::AddRef(void)
-{
-  nsrefcnt cnt = ++mRefCnt;
-  NS_LOG_ADDREF(this, cnt, "xptiInterfaceInfo", sizeof(*this));
-  return cnt;
-}
-
-MozExternalRefCountType
-xptiInterfaceInfo::Release(void)
-{
-  xptiInterfaceEntry* entry = mEntry;
-  nsrefcnt cnt = --mRefCnt;
-  NS_LOG_RELEASE(this, cnt, "xptiInterfaceInfo");
-  if (!cnt) {
-    // If InterfaceInfo added and *released* a reference before we
-    // acquired the monitor then 'this' might already be dead. In that
-    // case we would not want to try to access any instance data. We
-    // would want to bail immediately. If 'this' is already dead then the
-    // entry will no longer have a pointer to 'this'. So, we can protect
-    // ourselves from danger without more aggressive locking.
-    if (entry && !entry->InterfaceInfoEquals(this)) {
-      return 0;
-    }
-
-    // If InterfaceInfo added a reference before we acquired the monitor
-    // then we want to bail out of here without destorying the object.
-    if (mRefCnt) {
-      return 1;
-    }
-
-    if (mEntry) {
-      mEntry->InterfaceInfoDeathNotification();
-      mEntry = nullptr;
-    }
-
-    delete this;
-    return 0;
-  }
-  return cnt;
-}
-
 /***************************************************************************/
--- a/xpcom/reflect/xptinfo/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/xptiprivate.h
@@ -214,20 +214,16 @@ public:
   bool GetHasNotXPCOMFlag() const { return mFlags.GetFlagBit(HASNOTXPCOM); }
 
   const nsID* GetTheIID() const { return &mIID; }
   const char* GetTheName() const { return mName; }
 
   bool EnsureResolved() { return IsFullyResolved() ? true : Resolve(); }
 
   already_AddRefed<xptiInterfaceInfo> InterfaceInfo();
-  bool InterfaceInfoEquals(const xptiInterfaceInfo* info) const
-  {
-    return info == mInfo;
-  }
 
   void InvalidateInterfaceInfo();
   void InterfaceInfoDeathNotification() { mInfo = nullptr; }
 
   xptiInterfaceEntry* Parent() const
   {
     NS_ASSERTION(IsFullyResolved(), "Parent() called while not resolved?");
     return mParent;