Bug 551298, patch A: Move THEBES_INLINE_DECL_REFCOUNTING to xpcom (with s/THEBES/NS/). r=bsmedberg
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 01 Apr 2010 11:05:40 -0700
changeset 40107 9e32f526a3d09b36ddc2d3473c1108339eef3bd4
parent 40106 e3e903d1519a3ff394287dffa9a7d061e3380a07
child 40108 2cc4f1006536491cde02419e1dee65338d7dac07
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs551298
milestone1.9.3a4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 551298, patch A: Move THEBES_INLINE_DECL_REFCOUNTING to xpcom (with s/THEBES/NS/). r=bsmedberg
gfx/thebes/public/gfxTypes.h
xpcom/glue/nsISupportsImpl.h
xpcom/glue/nsISupportsUtils.h
--- a/gfx/thebes/public/gfxTypes.h
+++ b/gfx/thebes/public/gfxTypes.h
@@ -93,37 +93,17 @@ enum gfxBreakPriority {
 /**
  * Define refcounting for Thebes.  For now use the stuff from nsISupportsImpl
  * even though it forces the functions to be virtual...
  */
 #include "nsISupportsImpl.h"
 #include "nsAutoPtr.h"
 
 #define THEBES_INLINE_DECL_REFCOUNTING(_class)                                \
-public:                                                                       \
-    nsrefcnt AddRef(void) {                                                   \
-        NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");             \
-        ++mRefCnt;                                                            \
-        NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this));                 \
-        return mRefCnt;                                                       \
-    }                                                                         \
-    nsrefcnt Release(void) {                                                  \
-        NS_PRECONDITION(0 != mRefCnt, "dup release");                         \
-        --mRefCnt;                                                            \
-        NS_LOG_RELEASE(this, mRefCnt, #_class);                               \
-        if (mRefCnt == 0) {                                                   \
-            mRefCnt = 1; /* stabilize */                                      \
-            NS_DELETEXPCOM(this);                                             \
-            return 0;                                                         \
-        }                                                                     \
-        return mRefCnt;                                                       \
-    }                                                                         \
-protected:                                                                    \
-    nsAutoRefCnt mRefCnt;                                                     \
-public:
+    NS_INLINE_DECL_REFCOUNTING(_class)
 
 #define THEBES_INLINE_DECL_THREADSAFE_REFCOUNTING(_class)                     \
 public:                                                                       \
     nsrefcnt AddRef(void) {                                                   \
         NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");             \
         nsrefcnt count = PR_AtomicIncrement((PRInt32*)&mRefCnt);              \
         NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                   \
         return count;                                                         \
--- a/xpcom/glue/nsISupportsImpl.h
+++ b/xpcom/glue/nsISupportsImpl.h
@@ -299,16 +299,45 @@ public:
 /**
  * Previously used to initialize the reference count, but no longer needed.
  *
  * DEPRECATED.
  */
 #define NS_INIT_ISUPPORTS() ((void)0)
 
 /**
+ * Use this macro to declare and implement the AddRef & Release methods for a
+ * given non-XPCOM <i>_class</i>.
+ *
+ * The implementations here should match NS_IMPL_ADDREF/NS_IMPL_RELEASE, minus
+ * the nsrefcnt return-value and the NS_ASSERT_OWNINGTHREAD() call.
+ *
+ * @param _class The name of the class implementing the method
+ */
+#define NS_INLINE_DECL_REFCOUNTING(_class)                                    \
+public:                                                                       \
+  void AddRef(void) {                                                         \
+    NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");                 \
+    ++mRefCnt;                                                                \
+    NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this));                     \
+  }                                                                           \
+  void Release(void) {                                                        \
+    NS_PRECONDITION(0 != mRefCnt, "dup release");                             \
+    --mRefCnt;                                                                \
+    NS_LOG_RELEASE(this, mRefCnt, #_class);                                   \
+    if (mRefCnt == 0) {                                                       \
+      mRefCnt = 1; /* stabilize */                                            \
+      NS_DELETEXPCOM(this);                                                   \
+    }                                                                         \
+  }                                                                           \
+protected:                                                                    \
+  nsAutoRefCnt mRefCnt;                                                       \
+public:
+
+/**
  * Use this macro to implement the AddRef method for a given <i>_class</i>
  * @param _class The name of the class implementing the method
  */
 #define NS_IMPL_ADDREF(_class)                                                \
 NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void)                                 \
 {                                                                             \
   NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");                   \
   NS_ASSERT_OWNINGTHREAD(_class);                                             \
--- a/xpcom/glue/nsISupportsUtils.h
+++ b/xpcom/glue/nsISupportsUtils.h
@@ -103,20 +103,22 @@ extern "C++" {
 // ...because some one is accidentally including this file inside
 // an |extern "C"|
 
 
 // Making this a |inline| |template| allows |expr| to be evaluated only once,
 // yet still denies you the ability to |AddRef()| an |nsCOMPtr|.
 template <class T>
 inline
-nsrefcnt
+void
 ns_if_addref( T expr )
 {
-    return expr ? expr->AddRef() : 0;
+    if (expr) {
+        expr->AddRef();
+    }
 }
 
 } /* extern "C++" */
 
 /**
  * Macro for adding a reference to an interface that checks for NULL.
  * @param _expr The interface pointer.
  */