Bug 758992 - Make the classes which use the XPCOM nsISupports implementation macros final, to avoid the warning about deleting using a pointer to a base class with virtual functions and no virtual dtor (more xpcom and gonk parts); r=jrmuizel
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 19 Jun 2012 23:41:56 -0400
changeset 101155 debdfc7a3de8b580b66c6e5ecffa5f701e3cf628
parent 101154 c5ca1456419a44b862906d947cbf9a761b57b291
child 101156 bf8a77e238f0a6ddc6bfaee9d3b67b6bb38e3be2
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel
bugs758992
milestone16.0a1
Bug 758992 - Make the classes which use the XPCOM nsISupports implementation macros final, to avoid the warning about deleting using a pointer to a base class with virtual functions and no virtual dtor (more xpcom and gonk parts); r=jrmuizel
dom/system/gonk/AutoMounterSetting.cpp
xpcom/sample/nsSample.h
xpcom/tests/TestAutoPtr.cpp
xpcom/tests/TestCOMArray.cpp
xpcom/tests/TestCallTemplates.cpp
xpcom/tests/TestHashtables.cpp
xpcom/tests/TestObserverService.cpp
xpcom/tests/TestPipe.cpp
xpcom/tests/TestRacingServiceManager.cpp
xpcom/tests/TestThreadPoolListener.cpp
xpcom/tests/TestTimers.cpp
--- a/dom/system/gonk/AutoMounterSetting.cpp
+++ b/dom/system/gonk/AutoMounterSetting.cpp
@@ -11,28 +11,29 @@
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsIObserverService.h"
 #include "nsIJSContextStack.h"
 #include "nsISettingsService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "xpcpublic.h"
+#include "mozilla/Attributes.h"
 
 #undef LOG
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "AutoMounterSetting" , ## args)
 #define ERR(args...)  __android_log_print(ANDROID_LOG_ERROR, "AutoMounterSetting" , ## args)
 
 #define UMS_MODE                "ums.mode"
 #define MOZSETTINGS_CHANGED     "mozsettings-changed"
 
 namespace mozilla {
 namespace system {
 
-class SettingsServiceCallback : public nsISettingsServiceCallback
+class SettingsServiceCallback MOZ_FINAL : public nsISettingsServiceCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
   SettingsServiceCallback() {}
 
   NS_IMETHOD Handle(const nsAString &aName, const JS::Value &aResult, JSContext *aContext) {
     if (JSVAL_IS_INT(aResult)) {
--- a/xpcom/sample/nsSample.h
+++ b/xpcom/sample/nsSample.h
@@ -5,16 +5,17 @@
 
 /**
  * A sample of XPConnect. This file is the header of an implementation
  * nsSample of the nsISample interface.
  *
  */
 
 #include "nsISample.h"
+#include "mozilla/Attributes.h"
 
 /**
  * SampleImpl is an implementation of the nsISample interface.  In XPCOM,
  * there can be more than one implementation of an given interface.  Class
  * IDs (CIDs) uniquely identify a particular implementation of an interface.
  * Interface IDs (IIDs) uniquely identify an interface.
  *
  * The CID is also a unique number that looks just like an IID
@@ -23,17 +24,17 @@
  */
 
 #define NS_SAMPLE_CID \
 { 0x7cb5b7a0, 0x7d7, 0x11d3, { 0xbd, 0xe2, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
 
 #define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
 
 
-class nsSampleImpl : public nsISample
+class nsSampleImpl MOZ_FINAL : public nsISample
 {
 public:
     nsSampleImpl();
 
     /**
      * This macro expands into a declaration of the nsISupports interface.
      * Every XPCOM component needs to implement nsISupports, as it acts
      * as the gateway to other interfaces this component implements.  You
--- a/xpcom/tests/TestAutoPtr.cpp
+++ b/xpcom/tests/TestAutoPtr.cpp
@@ -2,16 +2,17 @@
 // vim:cindent:ts=4:et:sw=4:
 /* 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/. */
 
 #include "nsAutoPtr.h"
 #include <stdio.h>
 #include "nscore.h"
+#include "mozilla/Attributes.h"
 
 class TestObjectBaseA {
     public:
         // Virtual dtor for deleting through base class pointer
         virtual ~TestObjectBaseA() { };
         int fooA;
 };
 
@@ -48,17 +49,17 @@ class TestRefObjectBaseA {
 
 class TestRefObjectBaseB {
     public:
         int fooB;
         virtual nsrefcnt AddRef() = 0;
         virtual nsrefcnt Release() = 0;
 };
 
-class TestRefObject : public TestRefObjectBaseA, public TestRefObjectBaseB {
+class TestRefObject MOZ_FINAL : public TestRefObjectBaseA, public TestRefObjectBaseB {
     public:
         TestRefObject()
             : mRefCount(0)
         {
             printf("  Creating TestRefObject %p.\n",
                    static_cast<void*>(this));
         }
 
--- a/xpcom/tests/TestCOMArray.cpp
+++ b/xpcom/tests/TestCOMArray.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 // vim:cindent:ts=4:et:sw=4:
 /* 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/. */
 
 #include "TestHarness.h"
 #include "nsCOMArray.h"
+#include "mozilla/Attributes.h"
 
 // {9e70a320-be02-11d1-8031-006008159b5a}
 #define NS_IFOO_IID \
   {0x9e70a320, 0xbe02, 0x11d1,    \
     {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
 
 class IFoo : public nsISupports {
 public:
@@ -18,17 +19,17 @@ public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
 
   NS_IMETHOD_(nsrefcnt) RefCnt() = 0;
   NS_IMETHOD_(PRInt32) ID() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(IFoo, NS_IFOO_IID)
 
-class Foo : public IFoo {
+class Foo MOZ_FINAL : public IFoo {
 public:
 
   Foo(PRInt32 aID);
   ~Foo();
 
   // nsISupports implementation
   NS_DECL_ISUPPORTS
 
@@ -68,17 +69,17 @@ typedef nsCOMArray<IFoo> Array;
 class IBar : public nsISupports {
 public:
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBAR_IID)
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(IBar, NS_IBAR_IID)
 
-class Bar : public IBar {
+class Bar MOZ_FINAL : public IBar {
 public:
 
   explicit Bar(nsCOMArray<IBar>& aArray);
   ~Bar();
 
   // nsISupports implementation
   NS_DECL_ISUPPORTS
 
--- a/xpcom/tests/TestCallTemplates.cpp
+++ b/xpcom/tests/TestCallTemplates.cpp
@@ -15,29 +15,31 @@
 #include "nsIComponentManager.h"
 #include "nsIServiceManager.h"
 #include "nsWeakReference.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsAutoPtr.h"
+#include "mozilla/Attributes.h"
 
 #define NS_ITESTSERVICE_IID \
   {0x127b5253, 0x37b1, 0x43c7, \
     { 0x96, 0x2b, 0xab, 0xf1, 0x2d, 0x22, 0x56, 0xae }}
 
 class NS_NO_VTABLE nsITestService : public nsISupports {
   public: 
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITESTSERVICE_IID)
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsITestService, NS_ITESTSERVICE_IID)
 
-class nsTestService : public nsITestService, public nsSupportsWeakReference
+class nsTestService MOZ_FINAL : public nsITestService,
+                                public nsSupportsWeakReference
 {
   public:
     NS_DECL_ISUPPORTS
 };
 
 NS_IMPL_ISUPPORTS2(nsTestService, nsITestService, nsISupportsWeakReference)
 
 #define NS_TEST_SERVICE_CONTRACTID "@mozilla.org/test/testservice;1"
--- a/xpcom/tests/TestHashtables.cpp
+++ b/xpcom/tests/TestHashtables.cpp
@@ -7,16 +7,17 @@
 #include "nsBaseHashtable.h"
 #include "nsDataHashtable.h"
 #include "nsInterfaceHashtable.h"
 #include "nsClassHashtable.h"
 
 #include "nsCOMPtr.h"
 #include "nsISupports.h"
 #include "nsCOMArray.h"
+#include "mozilla/Attributes.h"
 
 #include <stdio.h>
 
 namespace TestHashtables {
 
 class TestUniChar // for nsClassHashtable
 {
 public:
@@ -186,17 +187,17 @@ nsCEnum(const nsACString& aKey, nsAutoPt
 //
 // all this nsIFoo stuff was copied wholesale from TestCOMPtr.cpp
 //
 
 #define NS_IFOO_IID \
 { 0x6f7652e0,  0xee43, 0x11d1, \
  { 0x9c, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
 
-class IFoo : public nsISupports
+class IFoo MOZ_FINAL : public nsISupports
   {
     public:
       NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
 
       IFoo();
 
       NS_IMETHOD_(nsrefcnt) AddRef();
       NS_IMETHOD_(nsrefcnt) Release();
--- a/xpcom/tests/TestObserverService.cpp
+++ b/xpcom/tests/TestObserverService.cpp
@@ -6,16 +6,17 @@
 #include "nsISupports.h"
 #include "nsIComponentManager.h"
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "nsIEnumerator.h"
 #include "nsStringGlue.h"
 #include "nsWeakReference.h"
 #include "nsComponentManagerUtils.h"
+#include "mozilla/Attributes.h"
 
 #include <stdio.h>
 
 static nsIObserverService *anObserverService = NULL;
 
 static void testResult( nsresult rv ) {
     if ( NS_SUCCEEDED( rv ) ) {
         printf("...ok\n");
@@ -24,17 +25,19 @@ static void testResult( nsresult rv ) {
     }
     return;
 }
 
 void printString(nsString &str) {
     printf("%s", NS_ConvertUTF16toUTF8(str).get());
 }
 
-class TestObserver : public nsIObserver, public nsSupportsWeakReference {
+class TestObserver MOZ_FINAL : public nsIObserver,
+                               public nsSupportsWeakReference
+{
 public:
     TestObserver( const nsAString &name )
         : mName( name ) {
     }
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 
     nsString mName;
--- a/xpcom/tests/TestPipe.cpp
+++ b/xpcom/tests/TestPipe.cpp
@@ -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/. */
 
 #include "TestHarness.h"
 
 #include "nsIPipe.h"
 #include "nsIMemory.h"
+#include "mozilla/Attributes.h"
 
 /** NS_NewPipe2 reimplemented, because it's not exported by XPCOM */
 nsresult TP_NewPipe2(nsIAsyncInputStream** input,
                      nsIAsyncOutputStream** output,
                      bool nonBlockingInput,
                      bool nonBlockingOutput,
                      PRUint32 segmentSize,
                      PRUint32 segmentCount,
@@ -36,17 +37,17 @@ nsresult TP_NewPipe2(nsIAsyncInputStream
 }
 
 /**
  * Allocator can allocate exactly count * size bytes, stored at mMemory;
  * immediately after the end of this is a byte-map of 0/1 values indicating
  * which <size>-byte locations in mMemory are empty and which are filled.
  * Pretty stupid, but enough to test bug 394692.
  */
-class BackwardsAllocator : public nsIMemory
+class BackwardsAllocator MOZ_FINAL : public nsIMemory
 {
   public:
     BackwardsAllocator()
       : mMemory(0),
         mIndex(0xFFFFFFFF),
         mCount(0xFFFFFFFF),
         mSize(0)
     { }
--- a/xpcom/tests/TestRacingServiceManager.cpp
+++ b/xpcom/tests/TestRacingServiceManager.cpp
@@ -10,16 +10,17 @@
 #include "nsXULAppAPI.h"
 #include "nsIThread.h"
 #include "nsIComponentRegistrar.h"
 
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "prmon.h"
+#include "mozilla/Attributes.h"
 
 #include "mozilla/ReentrantMonitor.h"
 using namespace mozilla;
 
 #ifdef DEBUG
 #define TEST_ASSERTION(_test, _msg) \
     NS_ASSERTION(_test, _msg);
 #else
@@ -78,17 +79,17 @@ public:
       *mReentrantMonitorPtr = nsnull;
     }
   }
 
 private:
   ReentrantMonitor** mReentrantMonitorPtr;
 };
 
-class Factory : public nsIFactory
+class Factory MOZ_FINAL : public nsIFactory
 {
 public:
   NS_DECL_ISUPPORTS
 
   Factory() : mFirstComponentCreated(false) { }
 
   NS_IMETHOD CreateInstance(nsISupports* aDelegate,
                             const nsIID& aIID,
@@ -98,17 +99,17 @@ public:
     return NS_OK;
   }
 
   bool mFirstComponentCreated;
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(Factory, nsIFactory)
 
-class Component1 : public nsISupports
+class Component1 MOZ_FINAL : public nsISupports
 {
 public:
   NS_DECL_ISUPPORTS
 
   Component1() {
     // This is the real test - make sure that only one instance is ever created.
     PRInt32 count = PR_AtomicIncrement(&gComponent1Count);
     TEST_ASSERTION(count == 1, "Too many components created!");
@@ -118,17 +119,17 @@ public:
 NS_IMPL_THREADSAFE_ADDREF(Component1)
 NS_IMPL_THREADSAFE_RELEASE(Component1)
 
 NS_INTERFACE_MAP_BEGIN(Component1)
   NS_INTERFACE_MAP_ENTRY(Component1)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
-class Component2 : public nsISupports
+class Component2 MOZ_FINAL : public nsISupports
 {
 public:
   NS_DECL_ISUPPORTS
 
   Component2() {
     // This is the real test - make sure that only one instance is ever created.
     PRInt32 count = PR_AtomicIncrement(&gComponent2Count);
     TEST_ASSERTION(count == 1, "Too many components created!");
--- a/xpcom/tests/TestThreadPoolListener.cpp
+++ b/xpcom/tests/TestThreadPoolListener.cpp
@@ -9,16 +9,17 @@
 #include "nsIThreadPool.h"
 
 #include "nsThreadUtils.h"
 #include "nsXPCOMCIDInternal.h"
 #include "pratom.h"
 #include "prinrval.h"
 #include "prmon.h"
 #include "prthread.h"
+#include "mozilla/Attributes.h"
 
 #include "mozilla/ReentrantMonitor.h"
 using namespace mozilla;
 
 #define NUMBER_OF_THREADS 4
 
 // One hour... because test boxes can be slow!
 #define IDLE_THREAD_TIMEOUT 3600000
@@ -39,17 +40,17 @@ static bool gAllThreadsShutDown = false;
 #define TEST_ASSERTION(_test, _msg) \
   PR_BEGIN_MACRO \
     if (!(_test)) { \
       NS_DebugBreak(NS_DEBUG_ABORT, _msg, #_test, __FILE__, __LINE__); \
     } \
   PR_END_MACRO
 #endif
 
-class Listener : public nsIThreadPoolListener
+class Listener MOZ_FINAL : public nsIThreadPoolListener
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSITHREADPOOLLISTENER
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(Listener, nsIThreadPoolListener)
 
--- a/xpcom/tests/TestTimers.cpp
+++ b/xpcom/tests/TestTimers.cpp
@@ -9,16 +9,17 @@
 #include "nsITimer.h"
 
 #include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "prinrval.h"
 #include "prmon.h"
+#include "mozilla/Attributes.h"
 
 #include "mozilla/ReentrantMonitor.h"
 using namespace mozilla;
 
 typedef nsresult(*TestFuncPtr)();
 
 class AutoTestThread
 {
@@ -63,17 +64,17 @@ public:
   operator ReentrantMonitor* () {
     return mReentrantMonitor;
   }
 
 private:
   ReentrantMonitor* mReentrantMonitor;
 };
 
-class TimerCallback : public nsITimerCallback
+class TimerCallback MOZ_FINAL : public nsITimerCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
   TimerCallback(nsIThread** aThreadPtr, ReentrantMonitor* aReentrantMonitor)
   : mThreadPtr(aThreadPtr), mReentrantMonitor(aReentrantMonitor) { }
 
   NS_IMETHOD Notify(nsITimer* aTimer) {