It's time to start merging fixes backwards... especially to deal with stack-allocated classes. See nscore-class-annotation-types for my magic mojo.
authorbenjamin@smedbergs.us
Thu, 20 Dec 2007 13:20:36 -0500
changeset 69 d09f8c6883b5fea4797d39d21345ead6b7f96ed3
parent 68 49c5ee4b50b4e29f7da5e637a83b47436455034d
child 70 94e945ee06a99c5ffbcfd08ce99176f1694328d3
push id1
push userbsmedberg@mozilla.com
push dateTue, 15 Apr 2008 21:51:22 +0000
It's time to start merging fixes backwards... especially to deal with stack-allocated classes. See nscore-class-annotation-types for my magic mojo.
CallGetService-nullcheck
gfx-refcounting
nsAutoPopupStatePusherExternal
nsAutoPopupStatePusherExternal-manual-fixup
nsSingletonFactory
nsWebShell-operator-new
nscore-class-annotation-types
series
new file mode 100644
--- /dev/null
+++ b/CallGetService-nullcheck
@@ -0,0 +1,35 @@
+diff --git a/xpcom/glue/nsComponentManagerUtils.cpp b/xpcom/glue/nsComponentManagerUtils.cpp
+--- a/xpcom/glue/nsComponentManagerUtils.cpp
++++ b/xpcom/glue/nsComponentManagerUtils.cpp
+@@ -77,9 +77,12 @@ nsresult
+ nsresult
+ CallGetService(const nsCID &aCID, const nsIID &aIID, void **aResult)
+ {
+-    nsComponentManagerImpl *compMgr =
+-        nsComponentManagerImpl::gComponentManager->instance;
+-    NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
++    NS_ENSURE_TRUE(nsComponentManagerImpl::gComponentManager &&
++                   nsComponentManagerImpl::gComponentManager->instance,
++                   NS_ERROR_NOT_INITIALIZED);
++
++    nsComponentManagerImpl *compMgr =
++        nsComponentManagerImpl::gComponentManager->instance;
+ 
+     return compMgr->nsComponentManagerImpl::GetService(aCID, aIID, aResult);
+ }
+@@ -87,9 +90,12 @@ nsresult
+ nsresult
+ CallGetService(const char *aContractID, const nsIID &aIID, void **aResult)
+ {
+-    nsComponentManagerImpl *compMgr =
+-        nsComponentManagerImpl::gComponentManager->instance;
+-    NS_ENSURE_TRUE(compMgr, NS_ERROR_NOT_INITIALIZED);
++    NS_ENSURE_TRUE(nsComponentManagerImpl::gComponentManager &&
++                   nsComponentManagerImpl::gComponentManager->instance,
++                   NS_ERROR_NOT_INITIALIZED);
++
++    nsComponentManagerImpl *compMgr =
++        nsComponentManagerImpl::gComponentManager->instance;
+ 
+     return compMgr->
+         nsComponentManagerImpl::GetServiceByContractID(aContractID,
new file mode 100644
--- /dev/null
+++ b/gfx-refcounting
@@ -0,0 +1,77 @@
+diff --git a/gfx/thebes/public/gfxTypes.h b/gfx/thebes/public/gfxTypes.h
+--- a/gfx/thebes/public/gfxTypes.h
++++ b/gfx/thebes/public/gfxTypes.h
+@@ -96,4 +96,49 @@ protected:                              
+     gfxAutoRefCnt mRefCnt;                                                    \
+ public:
+ 
++template<class T>
++class gfxRefPtr
++{
++private:
++    T *mPtr;
++
++public:
++    gfxRefPtr() : mPtr(nsnull) { }
++    gfxRefPtr(T* ptr) : mPtr(nsnull) { set(mPtr); }
++
++    ~gfxRefPtr() { set(nsnull); }
++
++    operator T*() const
++    {
++        return mPtr;
++    }
++
++    T* operator->() const
++    {
++        return mPtr;
++    }
++
++    T* operator=(T* ptr)
++    {
++        set(ptr);
++        return mPtr;
++    }
++
++    T* get() const
++    {
++        return mPtr;
++    }
++
++    void set(T* ptr)
++    {
++        if (mPtr)
++            mPtr->Release();
++
++        mPtr = ptr;
++
++        if (mPtr)
++            mPtr->AddRef();
++    }
++};
++
+ #endif /* GFX_TYPES_H */
+diff --git a/gfx/thebes/src/gfxFontconfigUtils.cpp b/gfx/thebes/src/gfxFontconfigUtils.cpp
+--- a/gfx/thebes/src/gfxFontconfigUtils.cpp
++++ b/gfx/thebes/src/gfxFontconfigUtils.cpp
+@@ -384,7 +384,7 @@ gfxFontconfigUtils::ResolveFontName(cons
+     if (mAliasForMultiFonts.IndexOfIgnoreCase(fontname) >= 0) {
+         nsCAutoString key;
+         ToLowerCase(fontname, key);
+-        nsRefPtr<gfxFontNameList> fonts = nsnull;
++        gfxRefPtr<gfxFontNameList> fonts = nsnull;
+         if (!mAliasTable.Get(key, &fonts))
+             NS_ERROR("The mAliasTable was broken!");
+         for (PRUint32 i = 0; i < fonts->Length(); i++) {
+diff --git a/gfx/thebes/src/gfxFontconfigUtils.h b/gfx/thebes/src/gfxFontconfigUtils.h
+--- a/gfx/thebes/src/gfxFontconfigUtils.h
++++ b/gfx/thebes/src/gfxFontconfigUtils.h
+@@ -91,7 +91,7 @@ protected:
+     nsCStringArray mAliasForSingleFont;
+     nsCStringArray mAliasForMultiFonts;
+ 
+-    nsDataHashtable<nsCStringHashKey, nsRefPtr<gfxFontNameList> > mAliasTable;
++    nsDataHashtable<nsCStringHashKey, gfxRefPtr<gfxFontNameList> > mAliasTable;
+ };
+ 
+ #endif /* GFX_FONTCONFIG_UTILS_H */
new file mode 100644
--- /dev/null
+++ b/nsAutoPopupStatePusherExternal
@@ -0,0 +1,23 @@
+diff --git a/dom/public/base/nsPIDOMWindow.h b/dom/public/base/nsPIDOMWindow.h
+--- a/dom/public/base/nsPIDOMWindow.h
++++ b/dom/public/base/nsPIDOMWindow.h
+@@ -442,7 +442,7 @@ PopPopupControlState(PopupControlState a
+ // library.  We give the two object layouts different names so the symbols
+ // don't conflict, but code should always use the name
+ // |nsAutoPopupStatePusher|.
+-class NS_AUTO_POPUP_STATE_PUSHER
++class NS_STACK_CLASS NS_AUTO_POPUP_STATE_PUSHER
+ {
+ public:
+ #ifdef _IMPL_NS_LAYOUT
+@@ -480,8 +480,8 @@ protected:
+ 
+ private:
+   // Hide so that this class can only be stack-allocated
+-  static void* operator new(size_t /*size*/) CPP_THROW_NEW { return nsnull; }
+-  static void operator delete(void* /*memory*/) {}
++  static void* operator new(size_t /*size*/) CPP_THROW_NEW;
++  static void operator delete(void* /*memory*/);
+ };
+ 
+ #define nsAutoPopupStatePusher NS_AUTO_POPUP_STATE_PUSHER
new file mode 100644
--- /dev/null
+++ b/nsAutoPopupStatePusherExternal-manual-fixup
@@ -0,0 +1,12 @@
+diff --git a/dom/public/base/nsPIDOMWindow.h b/dom/public/base/nsPIDOMWindow.h
+--- a/dom/public/base/nsPIDOMWindow.h
++++ b/dom/public/base/nsPIDOMWindow.h
+@@ -474,7 +474,7 @@ public:
+ 
+ protected:
+ #ifndef _IMPL_NS_LAYOUT
+-  nsCOMPtr<nsPIDOMWindow> mWindow;
++  nsPIDOMWindow* mWindow;
+ #endif
+   PopupControlState mOldState;
+ 
new file mode 100644
--- /dev/null
+++ b/nsSingletonFactory
@@ -0,0 +1,12 @@
+diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
+--- a/toolkit/xre/nsAppRunner.cpp
++++ b/toolkit/xre/nsAppRunner.cpp
+@@ -953,7 +953,7 @@ ScopedXPCOMStartup::DoAutoreg()
+  * This is a little factory class that serves as a singleton-service-factory
+  * for the nativeappsupport object.
+  */
+-class nsSingletonFactory : public nsIFactory
++class nsSingletonFactory : public XPCOMGCFinalizedObject, public nsIFactory
+ {
+ public:
+   NS_DECL_ISUPPORTS
new file mode 100644
--- /dev/null
+++ b/nsWebShell-operator-new
@@ -0,0 +1,12 @@
+diff --git a/docshell/base/nsWebShell.h b/docshell/base/nsWebShell.h
+--- a/docshell/base/nsWebShell.h
++++ b/docshell/base/nsWebShell.h
+@@ -72,8 +72,6 @@ public:
+     nsWebShell();
+     virtual ~nsWebShell();
+ 
+-    NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
+-
+     NS_DECL_ISUPPORTS_INHERITED
+     NS_DECL_NSIINTERFACEREQUESTOR
+     NS_DECL_NSICLIPBOARDCOMMANDS
new file mode 100644
--- /dev/null
+++ b/nscore-class-annotation-types
@@ -0,0 +1,45 @@
+diff --git a/configure.in b/configure.in
+--- a/configure.in
++++ b/configure.in
+@@ -1230,7 +1230,7 @@ if test "$GNU_CC"; then
+     # -Wbad-function-cast - warns when casting a function to a new return type
+     # -Wconversion - complained when char's or short's were used a function args
+     # -Wshadow - removed because it generates more noise than help --pete
+-    _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wall -W -Wno-unused -Wpointer-arith -Wcast-align"
++    _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-attributes"
+ 
+     dnl Turn pedantic on but disable the warnings for long long
+     _PEDANTIC=1
+diff --git a/xpcom/base/nscore.h b/xpcom/base/nscore.h
+--- a/xpcom/base/nscore.h
++++ b/xpcom/base/nscore.h
+@@ -471,4 +471,29 @@ typedef PRUint32 nsrefcnt;
+ #define XPCOM_GLUE_AVOID_NSPR
+ #endif
+ 
++/**
++ * Class type annotations. These indicate in what circumstances a class
++ * may be instantiated:
++ *
++ * NS_STACK_CLASS:    the class may only be a stack-allocated object
++ * NS_OUTER_CLASS:    the class must be the outermost object: either not
++ *                    subclassed or the leftmost base of a subclass
++ * NS_FINAL_CLASS:    the class may not be subclassed
++ * NS_GC_CLASS:       the class must be GC-allocated
++ * NS_NOGC_CLASS:     the class must not be GC-allocated
++ */
++#ifdef __GNUC__
++#define NS_STACK_CLASS   __attribute__((stack))
++#define NS_OUTER_CLASS   __attribute__((outer))
++#define NS_FINAL_CLASS   __attribute__((final))
++#define NS_GC_CLASS      __attribute__((GC))
++#define NS_NOGC_CLASS    __attribute__((NOGC))
++#else
++#define NS_STACK_CLASS
++#define NS_OUTER_CLASS
++#define NS_FINAL_CLASS
++#define NS_GC_CLASS
++#define NS_NOGC_CLASS
++#endif
++
+ #endif /* nscore_h___ */
--- a/series
+++ b/series
@@ -121,8 +121,15 @@ nsSlots
 xpcomgcbase.patch2
 nsAttrAndChildArray
 root-running-threads
 xpcshell-shutdown-necko
 xpconnect-gc-mainthread-only
 debug-unittests2
 temp-debug-necko-unittests
 necko-deadlocks5
+CallGetService-nullcheck
+nsSingletonFactory
+gfx-refcounting
+nsWebShell-operator-new
+nscore-class-annotation-types
+nsAutoPopupStatePusherExternal
+nsAutoPopupStatePusherExternal-manual-fixup