зеркало из https://github.com/mozilla/pjs.git
Bug 234858: Make do_GetWeakReference typesafe.
r=dbaron sr=bryner
This commit is contained in:
Родитель
5edddb11be
Коммит
0b0ba29712
|
@ -411,7 +411,8 @@ NS_IMETHODIMP nsSystemPrefService::AddObserver(const char *aDomain, nsIObserver
|
||||||
nsMemory::Free(pCallbackData);
|
nsMemory::Free(pCallbackData);
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
observerRef = do_GetWeakReference(weakRefFactory);
|
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(weakRefFactory);
|
||||||
|
observerRef = tmp;
|
||||||
} else {
|
} else {
|
||||||
observerRef = aObserver;
|
observerRef = aObserver;
|
||||||
}
|
}
|
||||||
|
@ -460,8 +461,11 @@ NS_IMETHODIMP nsSystemPrefService::RemoveObserver(const char *aDomain, nsIObserv
|
||||||
if (pCallbackData->bIsWeakRef) {
|
if (pCallbackData->bIsWeakRef) {
|
||||||
nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
|
nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
|
||||||
do_QueryInterface(aObserver);
|
do_QueryInterface(aObserver);
|
||||||
if (weakRefFactory)
|
if (weakRefFactory) {
|
||||||
observerRef = do_GetWeakReference(aObserver);
|
nsCOMPtr<nsIWeakReference> tmp =
|
||||||
|
do_GetWeakReference(aObserver);
|
||||||
|
observerRef = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!observerRef)
|
if (!observerRef)
|
||||||
observerRef = aObserver;
|
observerRef = aObserver;
|
||||||
|
|
|
@ -635,7 +635,8 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObser
|
||||||
nsMemory::Free(pCallback);
|
nsMemory::Free(pCallback);
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
observerRef = do_GetWeakReference(weakRefFactory);
|
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(weakRefFactory);
|
||||||
|
observerRef = tmp;
|
||||||
} else {
|
} else {
|
||||||
observerRef = aObserver;
|
observerRef = aObserver;
|
||||||
}
|
}
|
||||||
|
@ -677,8 +678,10 @@ NS_IMETHODIMP nsPrefBranch::RemoveObserver(const char *aDomain, nsIObserver *aOb
|
||||||
nsCOMPtr<nsISupports> observerRef;
|
nsCOMPtr<nsISupports> observerRef;
|
||||||
if (pCallback->bIsWeakRef) {
|
if (pCallback->bIsWeakRef) {
|
||||||
nsCOMPtr<nsISupportsWeakReference> weakRefFactory = do_QueryInterface(aObserver);
|
nsCOMPtr<nsISupportsWeakReference> weakRefFactory = do_QueryInterface(aObserver);
|
||||||
if (weakRefFactory)
|
if (weakRefFactory) {
|
||||||
observerRef = do_GetWeakReference(aObserver);
|
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(aObserver);
|
||||||
|
observerRef = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!observerRef)
|
if (!observerRef)
|
||||||
observerRef = aObserver;
|
observerRef = aObserver;
|
||||||
|
|
|
@ -89,23 +89,12 @@ do_QueryReferent( nsIWeakReference* aRawPtr, nsresult* error = 0 )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
class NS_COM_GLUE nsGetWeakReference : public nsCOMPtr_helper
|
* Deprecated, use |do_GetWeakReference| instead.
|
||||||
{
|
*/
|
||||||
public:
|
extern NS_COM_GLUE
|
||||||
nsGetWeakReference( nsISupports* aRawPtr, nsresult* error )
|
nsIWeakReference*
|
||||||
: mRawPtr(aRawPtr),
|
NS_GetWeakReference( nsISupports* , nsresult* aResult=0 );
|
||||||
mErrorPtr(error)
|
|
||||||
{
|
|
||||||
// nothing else to do here
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual nsresult NS_FASTCALL operator()( const nsIID&, void** ) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
nsISupports* mRawPtr;
|
|
||||||
nsresult* mErrorPtr;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* |do_GetWeakReference| is a convenience function that bundles up all the work needed
|
* |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);|.
|
* |nsWeakPtr myWeakPtr = do_GetWeakReference(aPtr);|.
|
||||||
*/
|
*/
|
||||||
inline
|
inline
|
||||||
const nsGetWeakReference
|
already_AddRefed<nsIWeakReference>
|
||||||
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
|
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
|
||||||
{
|
{
|
||||||
return nsGetWeakReference(aRawPtr, error);
|
return NS_GetWeakReference(aRawPtr, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
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>.
|
// 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
|
#endif
|
||||||
|
|
|
@ -60,40 +60,29 @@ nsQueryReferent::operator()( const nsIID& aIID, void** answer ) const
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
NS_COM_GLUE nsIWeakReference* // or else |already_AddRefed<nsIWeakReference>|
|
||||||
nsGetWeakReference::operator()( const nsIID&, void** aResult ) const
|
NS_GetWeakReference( nsISupports* aInstancePtr, nsresult* aErrorPtr )
|
||||||
{
|
{
|
||||||
nsresult status;
|
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.");
|
NS_ASSERTION(factoryPtr, "Oops! You're asking for a weak reference to an object that doesn't support that.");
|
||||||
if ( factoryPtr )
|
if ( factoryPtr )
|
||||||
{
|
{
|
||||||
nsIWeakReference* temp;
|
status = factoryPtr->GetWeakReference(&result);
|
||||||
status = factoryPtr->GetWeakReference(&temp);
|
|
||||||
*aResult = temp;
|
|
||||||
}
|
}
|
||||||
// else, |status| has already been set by |do_QueryInterface|
|
// else, |status| has already been set by |do_QueryInterface|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = NS_ERROR_NULL_POINTER;
|
status = NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
if ( mErrorPtr )
|
if ( aErrorPtr )
|
||||||
*mErrorPtr = status;
|
*aErrorPtr = status;
|
||||||
return status;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_COM_GLUE nsresult
|
NS_COM_GLUE nsresult
|
||||||
|
@ -118,49 +107,7 @@ nsSupportsWeakReference::GetWeakReference( nsIWeakReference** aInstancePtr )
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP_(nsrefcnt)
|
NS_IMPL_ISUPPORTS1(nsWeakReference, nsIWeakReference)
|
||||||
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_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsWeakReference::QueryReferent( const nsIID& aIID, void** aInstancePtr )
|
nsWeakReference::QueryReferent( const nsIID& aIID, void** aInstancePtr )
|
||||||
|
|
|
@ -89,9 +89,7 @@ class NS_COM_GLUE nsWeakReference : public nsIWeakReference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// nsISupports...
|
// nsISupports...
|
||||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
NS_DECL_ISUPPORTS
|
||||||
NS_IMETHOD_(nsrefcnt) Release();
|
|
||||||
NS_IMETHOD QueryInterface( const nsIID&, void** );
|
|
||||||
|
|
||||||
// nsIWeakReference...
|
// nsIWeakReference...
|
||||||
NS_DECL_NSIWEAKREFERENCE
|
NS_DECL_NSIWEAKREFERENCE
|
||||||
|
@ -100,8 +98,7 @@ class NS_COM_GLUE nsWeakReference : public nsIWeakReference
|
||||||
friend class nsSupportsWeakReference;
|
friend class nsSupportsWeakReference;
|
||||||
|
|
||||||
nsWeakReference( nsSupportsWeakReference* referent )
|
nsWeakReference( nsSupportsWeakReference* referent )
|
||||||
: mRefCount(0),
|
: mReferent(referent)
|
||||||
mReferent(referent)
|
|
||||||
// ...I can only be constructed by an |nsSupportsWeakReference|
|
// ...I can only be constructed by an |nsSupportsWeakReference|
|
||||||
{
|
{
|
||||||
// nothing else to do here
|
// nothing else to do here
|
||||||
|
@ -121,7 +118,6 @@ class NS_COM_GLUE nsWeakReference : public nsIWeakReference
|
||||||
mReferent = 0;
|
mReferent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsrefcnt mRefCount;
|
|
||||||
nsSupportsWeakReference* mReferent;
|
nsSupportsWeakReference* mReferent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче