diff --git a/mozilla/xpcom/base/nsCOMPtr.h b/mozilla/xpcom/base/nsCOMPtr.h index d463cf022d9..68b811b9dfb 100644 --- a/mozilla/xpcom/base/nsCOMPtr.h +++ b/mozilla/xpcom/base/nsCOMPtr.h @@ -17,10 +17,9 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Original Author: - * Scott Collins - * * Contributor(s): + * Scott Collins (original author) + * L. David Baron */ #ifndef nsCOMPtr_h___ @@ -650,6 +649,44 @@ class nsCOMPtr return get(); } + nsCOMPtr* + get_address() + { + return this; + } + + const nsCOMPtr* + get_address() const + { + return this; + } + + // This is going to become private soon, once all users of + // nsCOMPtr stop using it. It may even become: + // void operator&() const {} +// private: + const nsCOMPtr* + operator&() const + // This is private to prevent accidental use of |operator&| + // instead of |getter_AddRefs|, which can happen if the result + // is cast. + + // To pass an nsCOMPtr as an out parameter to a function, either + // (preferably) pass by reference or use |address_of|. + { + return this; + } + + nsCOMPtr* + operator&() + // This version is also needed so things will compile before + // all the uses are removed and we make it private. After it's + // private, we won't need two anymore. + { + return this; + } + +// public: nsDerivedSafe& operator*() const { @@ -814,6 +851,45 @@ class nsCOMPtr return get(); } + nsCOMPtr* + get_address() + { + return this; + } + + const nsCOMPtr* + get_address() const + { + return this; + } + + // This is going to become private soon, once all users of + // nsCOMPtr stop using it. It may even become: + // void operator&() const {} +// private: + const nsCOMPtr* + operator&() const + // This is private to prevent accidental use of |operator&| + // instead of |getter_AddRefs|, which can happen if the result + // is cast. + + // To pass an nsCOMPtr as an out parameter to a function, either + // (preferably) pass by reference or use |address_of|. + { + return this; + } + + nsCOMPtr* + operator&() + // This version is also needed so things will compile before + // all the uses are removed and we make it private. After it's + // private, we won't need two anymore. + { + return this; + } + +// public: + nsDerivedSafe& operator*() const { @@ -867,6 +943,21 @@ nsCOMPtr::begin_assignment() } #endif +template +inline +nsCOMPtr* +address_of( nsCOMPtr& aPtr ) + { + return aPtr.get_address(); + } + +template +inline +const nsCOMPtr* +address_of( const nsCOMPtr& aPtr ) + { + return aPtr.get_address(); + } template class nsGetterAddRefs @@ -900,7 +991,7 @@ class nsGetterAddRefs ~nsGetterAddRefs() { #ifdef NSCAP_LOG_EXTERNAL_ASSIGNMENT - NSCAP_LOG_ASSIGNMENT(&mTargetSmartPtr, mTargetSmartPtr.get()); + NSCAP_LOG_ASSIGNMENT(NS_REINTERPRET_CAST(void *, address_of(mTargetSmartPtr)), mTargetSmartPtr.get()); #endif #ifdef NSCAP_FEATURE_TEST_DONTQUERY_CASES @@ -949,7 +1040,7 @@ class nsGetterAddRefs #ifdef NSCAP_LOG_EXTERNAL_ASSIGNMENT ~nsGetterAddRefs() { - NSCAP_LOG_ASSIGNMENT(&mTargetSmartPtr, mTargetSmartPtr.get()); + NSCAP_LOG_ASSIGNMENT(NS_REINTERPRET_CAST(void *, address_of(mTargetSmartPtr)), mTargetSmartPtr.get()); } #endif diff --git a/mozilla/xpcom/glue/nsCOMPtr.h b/mozilla/xpcom/glue/nsCOMPtr.h index d463cf022d9..68b811b9dfb 100644 --- a/mozilla/xpcom/glue/nsCOMPtr.h +++ b/mozilla/xpcom/glue/nsCOMPtr.h @@ -17,10 +17,9 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Original Author: - * Scott Collins - * * Contributor(s): + * Scott Collins (original author) + * L. David Baron */ #ifndef nsCOMPtr_h___ @@ -650,6 +649,44 @@ class nsCOMPtr return get(); } + nsCOMPtr* + get_address() + { + return this; + } + + const nsCOMPtr* + get_address() const + { + return this; + } + + // This is going to become private soon, once all users of + // nsCOMPtr stop using it. It may even become: + // void operator&() const {} +// private: + const nsCOMPtr* + operator&() const + // This is private to prevent accidental use of |operator&| + // instead of |getter_AddRefs|, which can happen if the result + // is cast. + + // To pass an nsCOMPtr as an out parameter to a function, either + // (preferably) pass by reference or use |address_of|. + { + return this; + } + + nsCOMPtr* + operator&() + // This version is also needed so things will compile before + // all the uses are removed and we make it private. After it's + // private, we won't need two anymore. + { + return this; + } + +// public: nsDerivedSafe& operator*() const { @@ -814,6 +851,45 @@ class nsCOMPtr return get(); } + nsCOMPtr* + get_address() + { + return this; + } + + const nsCOMPtr* + get_address() const + { + return this; + } + + // This is going to become private soon, once all users of + // nsCOMPtr stop using it. It may even become: + // void operator&() const {} +// private: + const nsCOMPtr* + operator&() const + // This is private to prevent accidental use of |operator&| + // instead of |getter_AddRefs|, which can happen if the result + // is cast. + + // To pass an nsCOMPtr as an out parameter to a function, either + // (preferably) pass by reference or use |address_of|. + { + return this; + } + + nsCOMPtr* + operator&() + // This version is also needed so things will compile before + // all the uses are removed and we make it private. After it's + // private, we won't need two anymore. + { + return this; + } + +// public: + nsDerivedSafe& operator*() const { @@ -867,6 +943,21 @@ nsCOMPtr::begin_assignment() } #endif +template +inline +nsCOMPtr* +address_of( nsCOMPtr& aPtr ) + { + return aPtr.get_address(); + } + +template +inline +const nsCOMPtr* +address_of( const nsCOMPtr& aPtr ) + { + return aPtr.get_address(); + } template class nsGetterAddRefs @@ -900,7 +991,7 @@ class nsGetterAddRefs ~nsGetterAddRefs() { #ifdef NSCAP_LOG_EXTERNAL_ASSIGNMENT - NSCAP_LOG_ASSIGNMENT(&mTargetSmartPtr, mTargetSmartPtr.get()); + NSCAP_LOG_ASSIGNMENT(NS_REINTERPRET_CAST(void *, address_of(mTargetSmartPtr)), mTargetSmartPtr.get()); #endif #ifdef NSCAP_FEATURE_TEST_DONTQUERY_CASES @@ -949,7 +1040,7 @@ class nsGetterAddRefs #ifdef NSCAP_LOG_EXTERNAL_ASSIGNMENT ~nsGetterAddRefs() { - NSCAP_LOG_ASSIGNMENT(&mTargetSmartPtr, mTargetSmartPtr.get()); + NSCAP_LOG_ASSIGNMENT(NS_REINTERPRET_CAST(void *, address_of(mTargetSmartPtr)), mTargetSmartPtr.get()); } #endif