From 088d1de487566deb44e31f244b1016189dabab99 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Mon, 11 Aug 2008 11:05:58 -0400 Subject: [PATCH] From bug 449561, bug 445949, and others: let's just ditch nsDerivedSafe since the class of errors it's trying to protect against are uncommon in today's world. r=dbaron --- editor/libeditor/base/IMETextTxn.h | 3 - editor/libeditor/base/InsertTextTxn.h | 3 - netwerk/base/src/nsStandardURL.cpp | 11 +- xpcom/base/nsAutoPtr.h | 38 +++---- xpcom/glue/nsCOMPtr.h | 145 +++++--------------------- xpcom/tests/TestCOMPtrEq.cpp | 4 +- xpcom/tests/TestProxies.cpp | 4 +- xpcom/tests/TestTimers.cpp | 4 +- 8 files changed, 50 insertions(+), 162 deletions(-) diff --git a/editor/libeditor/base/IMETextTxn.h b/editor/libeditor/base/IMETextTxn.h index cfd3578bb0f3..fed17bfa76a9 100644 --- a/editor/libeditor/base/IMETextTxn.h +++ b/editor/libeditor/base/IMETextTxn.h @@ -120,9 +120,6 @@ protected: PRBool mFixed; friend class TransactionFactory; - - friend class nsDerivedSafe; // work around for a compiler bug - }; #endif diff --git a/editor/libeditor/base/InsertTextTxn.h b/editor/libeditor/base/InsertTextTxn.h index cab137b2d357..16eeb443b38d 100644 --- a/editor/libeditor/base/InsertTextTxn.h +++ b/editor/libeditor/base/InsertTextTxn.h @@ -104,9 +104,6 @@ protected: nsIEditor *mEditor; friend class TransactionFactory; - - friend class nsDerivedSafe; // work around for a compiler bug - }; #endif diff --git a/netwerk/base/src/nsStandardURL.cpp b/netwerk/base/src/nsStandardURL.cpp index cd9d7bb24f0d..77468405576f 100644 --- a/netwerk/base/src/nsStandardURL.cpp +++ b/netwerk/base/src/nsStandardURL.cpp @@ -1507,14 +1507,9 @@ nsStandardURL::Equals(nsIURI *unknownOther, PRBool *result) NS_ENSURE_ARG_POINTER(unknownOther); NS_PRECONDITION(result, "null pointer"); - nsRefPtr otherPtr; + nsRefPtr other; nsresult rv = unknownOther->QueryInterface(kThisImplCID, - getter_AddRefs(otherPtr)); - - // Hack around issue with MSVC++ not allowing the nsDerivedSafe to access - // the private members and not doing the implicit conversion to a raw - // pointer. - nsStandardURL* other = otherPtr; + getter_AddRefs(other)); if (NS_FAILED(rv)) { *result = PR_FALSE; return NS_OK; @@ -1572,7 +1567,7 @@ nsStandardURL::Equals(nsIURI *unknownOther, PRBool *result) rv = other->EnsureFile(); if (NS_FAILED(rv)) { LOG(("nsStandardURL::Equals [other=%p spec=%s] other failed to ensure file", - other, other->mSpec.get())); + other.get(), other->mSpec.get())); return rv; } NS_ASSERTION(other->mFile, "EnsureFile() lied!"); diff --git a/xpcom/base/nsAutoPtr.h b/xpcom/base/nsAutoPtr.h index d078254074ad..b622ef8701b5 100644 --- a/xpcom/base/nsAutoPtr.h +++ b/xpcom/base/nsAutoPtr.h @@ -42,7 +42,7 @@ // Wrapping includes can speed up compiles (see "Large Scale C++ Software Design") #ifndef nsCOMPtr_h___ - // For |already_AddRefed|, |nsDerivedSafe|, |NSCAP_Zero|, + // For |already_AddRefed|, |NSCAP_Zero|, // |NSCAP_DONT_PROVIDE_NONCONST_OPEQ|, // |NSCAP_FEATURE_INLINE_STARTASSIGNMENT| #include "nsCOMPtr.h" @@ -1056,32 +1056,31 @@ class nsRefPtr T* get() const /* - Prefer the implicit conversion provided automatically by |operator nsDerivedSafe*() const|. - Use |get()| to resolve ambiguity or to get a castable pointer. - - Returns a |nsDerivedSafe*| to deny clients the use of |AddRef| and |Release|. + Prefer the implicit conversion provided automatically by |operator T*() const|. + Use |get()| to resolve ambiguity or to get a castable pointer. */ { return const_cast(mRawPtr); } - operator nsDerivedSafe*() const + operator T*() const /* - ...makes an |nsRefPtr| act like its underlying raw pointer type (except against |AddRef()|, |Release()|, - and |delete|) whenever it is used in a context where a raw pointer is expected. It is this operator - that makes an |nsRefPtr| substitutable for a raw pointer. + ...makes an |nsRefPtr| act like its underlying raw pointer type whenever it + is used in a context where a raw pointer is expected. It is this operator + that makes an |nsRefPtr| substitutable for a raw pointer. - Prefer the implicit use of this operator to calling |get()|, except where necessary to resolve ambiguity. + Prefer the implicit use of this operator to calling |get()|, except where + necessary to resolve ambiguity. */ { - return get_DerivedSafe(); + return get(); } - nsDerivedSafe* + T* operator->() const { NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsRefPtr with operator->()."); - return get_DerivedSafe(); + return get(); } #ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY @@ -1116,11 +1115,11 @@ class nsRefPtr #endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY public: - nsDerivedSafe& + T& operator*() const { NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsRefPtr with operator*()."); - return *get_DerivedSafe(); + return *get(); } T** @@ -1133,15 +1132,6 @@ class nsRefPtr return reinterpret_cast(&mRawPtr); #endif } - - private: - nsDerivedSafe* - get_DerivedSafe() const - { - return const_cast*> - (reinterpret_cast*>(mRawPtr)); - } - }; #ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY diff --git a/xpcom/glue/nsCOMPtr.h b/xpcom/glue/nsCOMPtr.h index f50d28ae9e87..e25eee3f6234 100644 --- a/xpcom/glue/nsCOMPtr.h +++ b/xpcom/glue/nsCOMPtr.h @@ -174,7 +174,6 @@ VC++4.2 is very picky. To compile under VC++4.2, the classes must be defined in an order that satisfies: - nsDerivedSafe < nsCOMPtr already_AddRefed < nsCOMPtr nsCOMPtr < nsGetterAddRefs @@ -182,73 +181,6 @@ classes, on pain of breaking 4.2 compatibility. */ - -template -class - NS_FINAL_CLASS - NS_STACK_CLASS -nsDerivedSafe : public T - /* - No client should ever see or have to type the name of this class. It is the - artifact that makes it a compile-time error to call |AddRef| and |Release| - on a |nsCOMPtr|. DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. - - See |nsCOMPtr::operator->|, |nsCOMPtr::operator*|, et al. - - This type should be a nested class inside |nsCOMPtr|. - */ - { - private: -#ifdef HAVE_CPP_ACCESS_CHANGING_USING - using T::AddRef; - using T::Release; -#else - nsrefcnt AddRef(void); - nsrefcnt Release(void); -#endif - -#if !defined(AIX) && !defined(IRIX) - void operator delete( void*, size_t ); // NOT TO BE IMPLEMENTED - // declaring |operator delete| private makes calling delete on an interface pointer a compile error -#endif - - nsDerivedSafe& operator=( const T& ); // NOT TO BE IMPLEMENTED - // you may not call |operator=()| through a dereferenced |nsCOMPtr|, because you'd get the wrong one - - /* - Compiler warnings and errors: nsDerivedSafe operator=() hides inherited operator=(). - If you see that, that means somebody checked in a [XP]COM interface class that declares an - |operator=()|, and that's _bad_. So bad, in fact, that this declaration exists explicitly - to stop people from doing it. - */ - - protected: - nsDerivedSafe(); // NOT TO BE IMPLEMENTED - /* - This ctor exists to avoid compile errors and warnings about nsDeriviedSafe using the - default ctor but inheriting classes without an empty ctor. See bug 209667. - */ - }; - -#if !defined(HAVE_CPP_ACCESS_CHANGING_USING) && defined(NEED_CPP_UNUSED_IMPLEMENTATIONS) -template -nsrefcnt -nsDerivedSafe::AddRef() - { - return 0; - } - -template -nsrefcnt -nsDerivedSafe::Release() - { - return 0; - } - -#endif - - - template struct already_AddRefed /* @@ -853,30 +785,31 @@ nsCOMPtr T* get() const /* - Prefer the implicit conversion provided automatically by |operator nsDerivedSafe*() const|. - Use |get()| to resolve ambiguity or to get a castable pointer. + Prefer the implicit conversion provided automatically by |operator T*() const|. + Use |get()| to resolve ambiguity or to get a castable pointer. */ { return reinterpret_cast(mRawPtr); } - operator nsDerivedSafe*() const + operator T*() const /* - ...makes an |nsCOMPtr| act like its underlying raw pointer type (except against |AddRef()|, |Release()|, - and |delete|) whenever it is used in a context where a raw pointer is expected. It is this operator - that makes an |nsCOMPtr| substitutable for a raw pointer. + ...makes an |nsCOMPtr| act like its underlying raw pointer type whenever it + is used in a context where a raw pointer is expected. It is this operator + that makes an |nsCOMPtr| substitutable for a raw pointer. - Prefer the implicit use of this operator to calling |get()|, except where necessary to resolve ambiguity. + Prefer the implicit use of this operator to calling |get()|, except where + necessary to resolve ambiguity. */ { - return get_DerivedSafe(); + return get(); } - nsDerivedSafe* + T* operator->() const { NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator->()."); - return get_DerivedSafe(); + return get(); } #ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY @@ -911,18 +844,13 @@ nsCOMPtr #endif // CANT_RESOLVE_CPP_CONST_AMBIGUITY public: - nsDerivedSafe& + T& operator*() const { NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator*()."); - return *get_DerivedSafe(); + return *get(); } -#if 0 - private: - friend class nsGetterAddRefs; -#endif - T** StartAssignment() { @@ -933,14 +861,6 @@ nsCOMPtr return reinterpret_cast(&mRawPtr); #endif } - - private: - nsDerivedSafe* - get_DerivedSafe() const - { - return reinterpret_cast*>(mRawPtr); - } - }; @@ -1176,30 +1096,32 @@ class nsCOMPtr nsISupports* get() const /* - Prefer the implicit conversion provided automatically by |operator nsDerivedSafe*() const|. - Use |get()| to resolve ambiguity or to get a castable pointer. + Prefer the implicit conversion provided automatically by + |operator nsISupports*() const|. + Use |get()| to resolve ambiguity or to get a castable pointer. */ { return reinterpret_cast(mRawPtr); } - operator nsDerivedSafe*() const + operator nsISupports*() const /* - ...makes an |nsCOMPtr| act like its underlying raw pointer type (except against |AddRef()|, |Release()|, - and |delete|) whenever it is used in a context where a raw pointer is expected. It is this operator - that makes an |nsCOMPtr| substitutable for a raw pointer. + ...makes an |nsCOMPtr| act like its underlying raw pointer type whenever it + is used in a context where a raw pointer is expected. It is this operator + that makes an |nsCOMPtr| substitutable for a raw pointer. - Prefer the implicit use of this operator to calling |get()|, except where necessary to resolve ambiguity. + Prefer the implicit use of this operator to calling |get()|, except where + necessary to resolve ambiguity. */ { - return get_DerivedSafe(); + return get(); } - nsDerivedSafe* + nsISupports* operator->() const { NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator->()."); - return get_DerivedSafe(); + return get(); } #ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY @@ -1235,18 +1157,13 @@ class nsCOMPtr public: - nsDerivedSafe& + nsISupports& operator*() const { NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator*()."); - return *get_DerivedSafe(); + return *get(); } -#if 0 - private: - friend class nsGetterAddRefs; -#endif - nsISupports** StartAssignment() { @@ -1257,14 +1174,6 @@ class nsCOMPtr return reinterpret_cast(&mRawPtr); #endif } - - private: - nsDerivedSafe* - get_DerivedSafe() const - { - return reinterpret_cast*>(mRawPtr); - } - }; #ifndef NSCAP_FEATURE_USE_BASE diff --git a/xpcom/tests/TestCOMPtrEq.cpp b/xpcom/tests/TestCOMPtrEq.cpp index d78d49c720fa..97dc45f7bcf7 100644 --- a/xpcom/tests/TestCOMPtrEq.cpp +++ b/xpcom/tests/TestCOMPtrEq.cpp @@ -87,7 +87,7 @@ main() const nsICOMPtrEqTestFoo* rc = 0; nsICOMPtrEqTestFoo* const rk = 0; const nsICOMPtrEqTestFoo* const rkc = 0; - nsDerivedSafe* d = s; + nsICOMPtrEqTestFoo* d = s; #ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES nsCOMPtr s2; @@ -96,7 +96,7 @@ main() const nsICOMPtrEqTestFoo2* rc2 = 0; nsICOMPtrEqTestFoo2* const rk2 = 0; const nsICOMPtrEqTestFoo2* const rkc2 = 0; - nsDerivedSafe* d2 = s2; + nsICOMPtrEqTestFoo2* d2 = s2; #endif return (!(PR_TRUE && diff --git a/xpcom/tests/TestProxies.cpp b/xpcom/tests/TestProxies.cpp index 1500c9658991..779466ea855d 100644 --- a/xpcom/tests/TestProxies.cpp +++ b/xpcom/tests/TestProxies.cpp @@ -115,12 +115,12 @@ public: LOG(("Test thread successfully shut down [0x%p]", nativeThread)); } - operator nsDerivedSafe*() const + operator nsIThread*() const { return mThread; } - nsDerivedSafe* operator->() const + nsIThread* operator->() const { return mThread; } diff --git a/xpcom/tests/TestTimers.cpp b/xpcom/tests/TestTimers.cpp index e11f6568669e..55a050e44af4 100644 --- a/xpcom/tests/TestTimers.cpp +++ b/xpcom/tests/TestTimers.cpp @@ -65,11 +65,11 @@ public: mThread->Shutdown(); } - operator nsDerivedSafe*() const { + operator nsIThread*() const { return mThread; } - nsDerivedSafe* operator->() const { + nsIThread* operator->() const { return mThread; }