Bug 234858: Make do_GetWeakReference typesafe.

r=dbaron sr=bryner
This commit is contained in:
cvshook%sicking.cc 2005-01-24 22:59:27 +00:00
Родитель 5edddb11be
Коммит 0b0ba29712
5 изменённых файлов: 34 добавлений и 104 удалений

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

@ -411,7 +411,8 @@ NS_IMETHODIMP nsSystemPrefService::AddObserver(const char *aDomain, nsIObserver
nsMemory::Free(pCallbackData);
return NS_ERROR_INVALID_ARG;
}
observerRef = do_GetWeakReference(weakRefFactory);
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(weakRefFactory);
observerRef = tmp;
} else {
observerRef = aObserver;
}
@ -460,8 +461,11 @@ NS_IMETHODIMP nsSystemPrefService::RemoveObserver(const char *aDomain, nsIObserv
if (pCallbackData->bIsWeakRef) {
nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
do_QueryInterface(aObserver);
if (weakRefFactory)
observerRef = do_GetWeakReference(aObserver);
if (weakRefFactory) {
nsCOMPtr<nsIWeakReference> tmp =
do_GetWeakReference(aObserver);
observerRef = tmp;
}
}
if (!observerRef)
observerRef = aObserver;

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

@ -635,7 +635,8 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObser
nsMemory::Free(pCallback);
return NS_ERROR_INVALID_ARG;
}
observerRef = do_GetWeakReference(weakRefFactory);
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(weakRefFactory);
observerRef = tmp;
} else {
observerRef = aObserver;
}
@ -677,8 +678,10 @@ NS_IMETHODIMP nsPrefBranch::RemoveObserver(const char *aDomain, nsIObserver *aOb
nsCOMPtr<nsISupports> observerRef;
if (pCallback->bIsWeakRef) {
nsCOMPtr<nsISupportsWeakReference> weakRefFactory = do_QueryInterface(aObserver);
if (weakRefFactory)
observerRef = do_GetWeakReference(aObserver);
if (weakRefFactory) {
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(aObserver);
observerRef = tmp;
}
}
if (!observerRef)
observerRef = aObserver;

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

@ -89,23 +89,12 @@ do_QueryReferent( nsIWeakReference* aRawPtr, nsresult* error = 0 )
}
class NS_COM_GLUE nsGetWeakReference : public nsCOMPtr_helper
{
public:
nsGetWeakReference( nsISupports* aRawPtr, nsresult* error )
: mRawPtr(aRawPtr),
mErrorPtr(error)
{
// nothing else to do here
}
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
private:
nsISupports* mRawPtr;
nsresult* mErrorPtr;
};
/**
* Deprecated, use |do_GetWeakReference| instead.
*/
extern NS_COM_GLUE
nsIWeakReference*
NS_GetWeakReference( nsISupports* , nsresult* aResult=0 );
/**
* |do_GetWeakReference| is a convenience function that bundles up all the work needed
@ -115,10 +104,10 @@ class NS_COM_GLUE nsGetWeakReference : public nsCOMPtr_helper
* |nsWeakPtr myWeakPtr = do_GetWeakReference(aPtr);|.
*/
inline
const nsGetWeakReference
already_AddRefed<nsIWeakReference>
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
{
return nsGetWeakReference(aRawPtr, error);
return NS_GetWeakReference(aRawPtr, error);
}
inline
@ -150,13 +139,4 @@ do_GetWeakReference( already_AddRefed<T>&, nsresult* )
// someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>.
}
/**
* Deprecated, use |do_GetWeakReference| instead.
*/
extern NS_COM_GLUE
nsIWeakReference*
NS_GetWeakReference( nsISupports* , nsresult* aResult=0 );
#endif

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

@ -60,40 +60,29 @@ nsQueryReferent::operator()( const nsIID& aIID, void** answer ) const
return status;
}
nsresult
nsGetWeakReference::operator()( const nsIID&, void** aResult ) const
NS_COM_GLUE nsIWeakReference* // or else |already_AddRefed<nsIWeakReference>|
NS_GetWeakReference( nsISupports* aInstancePtr, nsresult* aErrorPtr )
{
nsresult status;
// nsIWeakReference** result = &NS_STATIC_CAST(nsIWeakReference*, *aResult);
*aResult = 0;
if ( mRawPtr )
nsIWeakReference* result = nsnull;
if ( aInstancePtr )
{
nsCOMPtr<nsISupportsWeakReference> factoryPtr = do_QueryInterface(mRawPtr, &status);
nsCOMPtr<nsISupportsWeakReference> factoryPtr = do_QueryInterface(aInstancePtr, &status);
NS_ASSERTION(factoryPtr, "Oops! You're asking for a weak reference to an object that doesn't support that.");
if ( factoryPtr )
{
nsIWeakReference* temp;
status = factoryPtr->GetWeakReference(&temp);
*aResult = temp;
status = factoryPtr->GetWeakReference(&result);
}
// else, |status| has already been set by |do_QueryInterface|
}
else
status = NS_ERROR_NULL_POINTER;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
NS_COM_GLUE nsIWeakReference* // or else |already_AddRefed<nsIWeakReference>|
NS_GetWeakReference( nsISupports* aInstancePtr, nsresult* aErrorPtr )
{
void* result = 0;
nsGetWeakReference(aInstancePtr, aErrorPtr)(NS_GET_IID(nsIWeakReference), &result);
return NS_STATIC_CAST(nsIWeakReference*, result);
if ( aErrorPtr )
*aErrorPtr = status;
return result;
}
NS_COM_GLUE nsresult
@ -118,49 +107,7 @@ nsSupportsWeakReference::GetWeakReference( nsIWeakReference** aInstancePtr )
return status;
}
NS_IMETHODIMP_(nsrefcnt)
nsWeakReference::AddRef()
{
return ++mRefCount;
}
NS_IMETHODIMP_(nsrefcnt)
nsWeakReference::Release()
{
nsrefcnt temp = --mRefCount;
if ( !mRefCount )
delete this;
return temp;
}
NS_IMETHODIMP
nsWeakReference::QueryInterface( const nsIID& aIID, void** aInstancePtr )
{
NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!");
if ( !aInstancePtr )
return NS_ERROR_NULL_POINTER;
nsISupports* foundInterface;
if ( aIID.Equals(NS_GET_IID(nsIWeakReference)) )
foundInterface = NS_STATIC_CAST(nsIWeakReference*, this);
else if ( aIID.Equals(NS_GET_IID(nsISupports)) )
foundInterface = NS_STATIC_CAST(nsISupports*, this);
else
foundInterface = 0;
nsresult status;
if ( !foundInterface )
status = NS_NOINTERFACE;
else
{
NS_ADDREF(foundInterface);
status = NS_OK;
}
*aInstancePtr = foundInterface;
return status;
}
NS_IMPL_ISUPPORTS1(nsWeakReference, nsIWeakReference)
NS_IMETHODIMP
nsWeakReference::QueryReferent( const nsIID& aIID, void** aInstancePtr )

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

@ -89,9 +89,7 @@ class NS_COM_GLUE nsWeakReference : public nsIWeakReference
{
public:
// nsISupports...
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface( const nsIID&, void** );
NS_DECL_ISUPPORTS
// nsIWeakReference...
NS_DECL_NSIWEAKREFERENCE
@ -100,8 +98,7 @@ class NS_COM_GLUE nsWeakReference : public nsIWeakReference
friend class nsSupportsWeakReference;
nsWeakReference( nsSupportsWeakReference* referent )
: mRefCount(0),
mReferent(referent)
: mReferent(referent)
// ...I can only be constructed by an |nsSupportsWeakReference|
{
// nothing else to do here
@ -121,7 +118,6 @@ class NS_COM_GLUE nsWeakReference : public nsIWeakReference
mReferent = 0;
}
nsrefcnt mRefCount;
nsSupportsWeakReference* mReferent;
};