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

This commit is contained in:
Benjamin Smedberg 2008-08-11 11:05:58 -04:00
Родитель 0d19165bc2
Коммит 088d1de487
8 изменённых файлов: 50 добавлений и 162 удалений

Просмотреть файл

@ -120,9 +120,6 @@ protected:
PRBool mFixed;
friend class TransactionFactory;
friend class nsDerivedSafe<IMETextTxn>; // work around for a compiler bug
};
#endif

Просмотреть файл

@ -104,9 +104,6 @@ protected:
nsIEditor *mEditor;
friend class TransactionFactory;
friend class nsDerivedSafe<InsertTextTxn>; // work around for a compiler bug
};
#endif

Просмотреть файл

@ -1507,14 +1507,9 @@ nsStandardURL::Equals(nsIURI *unknownOther, PRBool *result)
NS_ENSURE_ARG_POINTER(unknownOther);
NS_PRECONDITION(result, "null pointer");
nsRefPtr<nsStandardURL> otherPtr;
nsRefPtr<nsStandardURL> 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!");

Просмотреть файл

@ -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<T>*() const|.
Use |get()| to resolve ambiguity or to get a castable pointer.
Returns a |nsDerivedSafe<T>*| 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<T*>(mRawPtr);
}
operator nsDerivedSafe<T>*() 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>*
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>&
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<T**>(&mRawPtr);
#endif
}
private:
nsDerivedSafe<T>*
get_DerivedSafe() const
{
return const_cast<nsDerivedSafe<T>*>
(reinterpret_cast<const nsDerivedSafe<T>*>(mRawPtr));
}
};
#ifdef CANT_RESOLVE_CPP_CONST_AMBIGUITY

Просмотреть файл

@ -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 T>
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<T>|.
*/
{
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<T>& 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 <class T>
nsrefcnt
nsDerivedSafe<T>::AddRef()
{
return 0;
}
template <class T>
nsrefcnt
nsDerivedSafe<T>::Release()
{
return 0;
}
#endif
template <class T>
struct already_AddRefed
/*
@ -853,30 +785,31 @@ nsCOMPtr
T*
get() const
/*
Prefer the implicit conversion provided automatically by |operator nsDerivedSafe<T>*() 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<T*>(mRawPtr);
}
operator nsDerivedSafe<T>*() 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>*
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>&
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<T>;
#endif
T**
StartAssignment()
{
@ -933,14 +861,6 @@ nsCOMPtr
return reinterpret_cast<T**>(&mRawPtr);
#endif
}
private:
nsDerivedSafe<T>*
get_DerivedSafe() const
{
return reinterpret_cast<nsDerivedSafe<T>*>(mRawPtr);
}
};
@ -1176,30 +1096,32 @@ class nsCOMPtr<nsISupports>
nsISupports*
get() const
/*
Prefer the implicit conversion provided automatically by |operator nsDerivedSafe<nsISupports>*() 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<nsISupports*>(mRawPtr);
}
operator nsDerivedSafe<nsISupports>*() 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>*
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<nsISupports>
public:
nsDerivedSafe<nsISupports>&
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<nsISupports>;
#endif
nsISupports**
StartAssignment()
{
@ -1257,14 +1174,6 @@ class nsCOMPtr<nsISupports>
return reinterpret_cast<nsISupports**>(&mRawPtr);
#endif
}
private:
nsDerivedSafe<nsISupports>*
get_DerivedSafe() const
{
return reinterpret_cast<nsDerivedSafe<nsISupports>*>(mRawPtr);
}
};
#ifndef NSCAP_FEATURE_USE_BASE

Просмотреть файл

@ -87,7 +87,7 @@ main()
const nsICOMPtrEqTestFoo* rc = 0;
nsICOMPtrEqTestFoo* const rk = 0;
const nsICOMPtrEqTestFoo* const rkc = 0;
nsDerivedSafe<nsICOMPtrEqTestFoo>* d = s;
nsICOMPtrEqTestFoo* d = s;
#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
nsCOMPtr<nsICOMPtrEqTestFoo2> s2;
@ -96,7 +96,7 @@ main()
const nsICOMPtrEqTestFoo2* rc2 = 0;
nsICOMPtrEqTestFoo2* const rk2 = 0;
const nsICOMPtrEqTestFoo2* const rkc2 = 0;
nsDerivedSafe<nsICOMPtrEqTestFoo2>* d2 = s2;
nsICOMPtrEqTestFoo2* d2 = s2;
#endif
return (!(PR_TRUE &&

Просмотреть файл

@ -115,12 +115,12 @@ public:
LOG(("Test thread successfully shut down [0x%p]", nativeThread));
}
operator nsDerivedSafe<nsIThread>*() const
operator nsIThread*() const
{
return mThread;
}
nsDerivedSafe<nsIThread>* operator->() const
nsIThread* operator->() const
{
return mThread;
}

Просмотреть файл

@ -65,11 +65,11 @@ public:
mThread->Shutdown();
}
operator nsDerivedSafe<nsIThread>*() const {
operator nsIThread*() const {
return mThread;
}
nsDerivedSafe<nsIThread>* operator->() const {
nsIThread* operator->() const {
return mThread;
}