2013-10-30 21:55:19 +08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-10-19 11:48:42 +08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/* Helpers for defining and using refcounted objects. */
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
#ifndef mozilla_RefPtr_h
|
|
|
|
#define mozilla_RefPtr_h
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
#include "mozilla/Assertions.h"
|
2013-10-30 21:55:19 +08:00
|
|
|
#include "mozilla/Atomics.h"
|
2012-08-28 02:41:49 +08:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-07 09:43:25 +08:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
template<typename T> class RefCounted;
|
|
|
|
template<typename T> class RefPtr;
|
|
|
|
template<typename T> class TemporaryRef;
|
|
|
|
template<typename T> class OutParamRef;
|
|
|
|
template<typename T> OutParamRef<T> byRef(RefPtr<T>&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RefCounted<T> is a sort of a "mixin" for a class T. RefCounted
|
|
|
|
* manages, well, refcounting for T, and because RefCounted is
|
|
|
|
* parameterized on T, RefCounted<T> can call T's destructor directly.
|
|
|
|
* This means T doesn't need to have a virtual dtor and so doesn't
|
|
|
|
* need a vtable.
|
|
|
|
*
|
|
|
|
* RefCounted<T> is created with refcount == 0. Newly-allocated
|
|
|
|
* RefCounted<T> must immediately be assigned to a RefPtr to make the
|
|
|
|
* refcount > 0. It's an error to allocate and free a bare
|
|
|
|
* RefCounted<T>, i.e. outside of the RefPtr machinery. Attempts to
|
|
|
|
* do so will abort DEBUG builds.
|
|
|
|
*
|
|
|
|
* Live RefCounted<T> have refcount > 0. The lifetime (refcounts) of
|
|
|
|
* live RefCounted<T> are controlled by RefPtr<T> and
|
|
|
|
* RefPtr<super/subclass of T>. Upon a transition from refcounted==1
|
|
|
|
* to 0, the RefCounted<T> "dies" and is destroyed. The "destroyed"
|
2013-05-22 17:31:07 +08:00
|
|
|
* state is represented in DEBUG builds by refcount==0xffffdead. This
|
2012-08-28 02:41:49 +08:00
|
|
|
* state distinguishes use-before-ref (refcount==0) from
|
2013-05-22 17:31:07 +08:00
|
|
|
* use-after-destroy (refcount==0xffffdead).
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
2013-05-22 17:31:07 +08:00
|
|
|
namespace detail {
|
2013-10-30 21:55:19 +08:00
|
|
|
#ifdef DEBUG
|
2013-05-22 17:31:07 +08:00
|
|
|
static const int DEAD = 0xffffdead;
|
|
|
|
#endif
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
// This is used WeakPtr.h as well as this file.
|
|
|
|
enum RefCountAtomicity
|
|
|
|
{
|
|
|
|
AtomicRefCount,
|
|
|
|
NonAtomicRefCount
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, RefCountAtomicity Atomicity>
|
2012-08-28 02:41:49 +08:00
|
|
|
class RefCounted
|
|
|
|
{
|
|
|
|
friend class RefPtr<T>;
|
|
|
|
|
2013-05-22 17:31:07 +08:00
|
|
|
protected:
|
2012-08-28 02:41:49 +08:00
|
|
|
RefCounted() : refCnt(0) { }
|
2013-08-07 09:43:25 +08:00
|
|
|
~RefCounted() {
|
|
|
|
MOZ_ASSERT(refCnt == detail::DEAD);
|
|
|
|
}
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-05-22 17:31:07 +08:00
|
|
|
public:
|
2012-08-28 02:41:49 +08:00
|
|
|
// Compatibility with nsRefPtr.
|
|
|
|
void AddRef() {
|
2012-10-19 11:48:42 +08:00
|
|
|
MOZ_ASSERT(refCnt >= 0);
|
|
|
|
++refCnt;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Release() {
|
2012-10-19 11:48:42 +08:00
|
|
|
MOZ_ASSERT(refCnt > 0);
|
|
|
|
if (0 == --refCnt) {
|
2012-08-28 02:41:49 +08:00
|
|
|
#ifdef DEBUG
|
2013-05-22 17:31:07 +08:00
|
|
|
refCnt = detail::DEAD;
|
2012-08-28 02:41:49 +08:00
|
|
|
#endif
|
2012-10-19 11:48:42 +08:00
|
|
|
delete static_cast<T*>(this);
|
|
|
|
}
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compatibility with wtf::RefPtr.
|
|
|
|
void ref() { AddRef(); }
|
|
|
|
void deref() { Release(); }
|
|
|
|
int refCount() const { return refCnt; }
|
|
|
|
bool hasOneRef() const {
|
2012-10-19 11:48:42 +08:00
|
|
|
MOZ_ASSERT(refCnt > 0);
|
|
|
|
return refCnt == 1;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
private:
|
2013-10-30 21:55:19 +08:00
|
|
|
typename Conditional<Atomicity == AtomicRefCount, Atomic<int>, int>::Type refCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class RefCounted : public detail::RefCounted<T, detail::NonAtomicRefCount>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~RefCounted() {
|
|
|
|
static_assert(IsBaseOf<RefCounted, T>::value,
|
|
|
|
"T must derive from RefCounted<T>");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AtomicRefCounted<T> is like RefCounted<T>, with an atomically updated
|
|
|
|
* reference counter.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class AtomicRefCounted : public detail::RefCounted<T, detail::AtomicRefCount>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~AtomicRefCounted() {
|
|
|
|
static_assert(IsBaseOf<AtomicRefCounted, T>::value,
|
|
|
|
"T must derive from AtomicRefCounted<T>");
|
|
|
|
}
|
2012-08-28 02:41:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RefPtr points to a refcounted thing that has AddRef and Release
|
|
|
|
* methods to increase/decrease the refcount, respectively. After a
|
|
|
|
* RefPtr<T> is assigned a T*, the T* can be used through the RefPtr
|
|
|
|
* as if it were a T*.
|
|
|
|
*
|
|
|
|
* A RefPtr can forget its underlying T*, which results in the T*
|
|
|
|
* being wrapped in a temporary object until the T* is either
|
|
|
|
* re-adopted from or released by the temporary.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class RefPtr
|
|
|
|
{
|
|
|
|
// To allow them to use unref()
|
|
|
|
friend class TemporaryRef<T>;
|
|
|
|
friend class OutParamRef<T>;
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
struct DontRef {};
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
public:
|
2012-08-28 02:41:49 +08:00
|
|
|
RefPtr() : ptr(0) { }
|
|
|
|
RefPtr(const RefPtr& o) : ptr(ref(o.ptr)) {}
|
|
|
|
RefPtr(const TemporaryRef<T>& o) : ptr(o.drop()) {}
|
|
|
|
RefPtr(T* t) : ptr(ref(t)) {}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
RefPtr(const RefPtr<U>& o) : ptr(ref(o.get())) {}
|
|
|
|
|
|
|
|
~RefPtr() { unref(ptr); }
|
|
|
|
|
|
|
|
RefPtr& operator=(const RefPtr& o) {
|
2012-10-19 11:48:42 +08:00
|
|
|
assign(ref(o.ptr));
|
|
|
|
return *this;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
RefPtr& operator=(const TemporaryRef<T>& o) {
|
2012-10-19 11:48:42 +08:00
|
|
|
assign(o.drop());
|
|
|
|
return *this;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
RefPtr& operator=(T* t) {
|
2012-10-19 11:48:42 +08:00
|
|
|
assign(ref(t));
|
|
|
|
return *this;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
RefPtr& operator=(const RefPtr<U>& o) {
|
2012-10-19 11:48:42 +08:00
|
|
|
assign(ref(o.get()));
|
|
|
|
return *this;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<T> forget() {
|
2012-10-19 11:48:42 +08:00
|
|
|
T* tmp = ptr;
|
|
|
|
ptr = 0;
|
|
|
|
return TemporaryRef<T>(tmp, DontRef());
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
T* get() const { return ptr; }
|
|
|
|
operator T*() const { return ptr; }
|
|
|
|
T* operator->() const { return ptr; }
|
|
|
|
T& operator*() const { return *ptr; }
|
|
|
|
template<typename U>
|
|
|
|
operator TemporaryRef<U>() { return TemporaryRef<U>(ptr); }
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
private:
|
2012-08-28 02:41:49 +08:00
|
|
|
void assign(T* t) {
|
2012-10-19 11:48:42 +08:00
|
|
|
unref(ptr);
|
|
|
|
ptr = t;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
T* ptr;
|
|
|
|
|
|
|
|
static MOZ_ALWAYS_INLINE T* ref(T* t) {
|
2012-10-19 11:48:42 +08:00
|
|
|
if (t)
|
|
|
|
t->AddRef();
|
|
|
|
return t;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MOZ_ALWAYS_INLINE void unref(T* t) {
|
2012-10-19 11:48:42 +08:00
|
|
|
if (t)
|
|
|
|
t->Release();
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TemporaryRef<T> represents an object that holds a temporary
|
|
|
|
* reference to a T. TemporaryRef objects can't be manually ref'd or
|
|
|
|
* unref'd (being temporaries, not lvalues), so can only relinquish
|
|
|
|
* references to other objects, or unref on destruction.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class TemporaryRef
|
|
|
|
{
|
|
|
|
// To allow it to construct TemporaryRef from a bare T*
|
|
|
|
friend class RefPtr<T>;
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
typedef typename RefPtr<T>::DontRef DontRef;
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
public:
|
2012-08-28 02:41:49 +08:00
|
|
|
TemporaryRef(T* t) : ptr(RefPtr<T>::ref(t)) {}
|
|
|
|
TemporaryRef(const TemporaryRef& o) : ptr(o.drop()) {}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
TemporaryRef(const TemporaryRef<U>& o) : ptr(o.drop()) {}
|
|
|
|
|
|
|
|
~TemporaryRef() { RefPtr<T>::unref(ptr); }
|
|
|
|
|
|
|
|
T* drop() const {
|
2012-10-19 11:48:42 +08:00
|
|
|
T* tmp = ptr;
|
|
|
|
ptr = 0;
|
|
|
|
return tmp;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
private:
|
|
|
|
TemporaryRef(T* t, const DontRef&) : ptr(t) {}
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
mutable T* ptr;
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
TemporaryRef() MOZ_DELETE;
|
|
|
|
void operator=(const TemporaryRef&) MOZ_DELETE;
|
2012-08-28 02:41:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OutParamRef is a wrapper that tracks a refcounted pointer passed as
|
|
|
|
* an outparam argument to a function. OutParamRef implements COM T**
|
|
|
|
* outparam semantics: this requires the callee to AddRef() the T*
|
|
|
|
* returned through the T** outparam on behalf of the caller. This
|
|
|
|
* means the caller (through OutParamRef) must Release() the old
|
|
|
|
* object contained in the tracked RefPtr. It's OK if the callee
|
|
|
|
* returns the same T* passed to it through the T** outparam, as long
|
|
|
|
* as the callee obeys the COM discipline.
|
|
|
|
*
|
|
|
|
* Prefer returning TemporaryRef<T> from functions over creating T**
|
|
|
|
* outparams and passing OutParamRef<T> to T**. Prefer RefPtr<T>*
|
|
|
|
* outparams over T** outparams.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class OutParamRef
|
|
|
|
{
|
|
|
|
friend OutParamRef byRef<T>(RefPtr<T>&);
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
public:
|
2012-08-28 02:41:49 +08:00
|
|
|
~OutParamRef() {
|
2012-10-19 11:48:42 +08:00
|
|
|
RefPtr<T>::unref(refPtr.ptr);
|
|
|
|
refPtr.ptr = tmp;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
operator T**() { return &tmp; }
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
private:
|
2012-08-28 02:41:49 +08:00
|
|
|
OutParamRef(RefPtr<T>& p) : refPtr(p), tmp(p.get()) {}
|
|
|
|
|
|
|
|
RefPtr<T>& refPtr;
|
|
|
|
T* tmp;
|
|
|
|
|
|
|
|
OutParamRef() MOZ_DELETE;
|
|
|
|
OutParamRef& operator=(const OutParamRef&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* byRef cooperates with OutParamRef to implement COM outparam semantics.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
OutParamRef<T>
|
|
|
|
byRef(RefPtr<T>& ptr)
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
return OutParamRef<T>(ptr);
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
// Command line that builds these tests
|
|
|
|
//
|
|
|
|
// cp RefPtr.h test.cc && g++ -g -Wall -pedantic -DDEBUG -o test test.cc && ./test
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
struct Foo : public RefCounted<Foo>
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
Foo() : dead(false) { }
|
|
|
|
~Foo() {
|
|
|
|
MOZ_ASSERT(!dead);
|
|
|
|
dead = true;
|
|
|
|
numDestroyed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dead;
|
|
|
|
static int numDestroyed;
|
2012-08-28 02:41:49 +08:00
|
|
|
};
|
|
|
|
int Foo::numDestroyed;
|
|
|
|
|
|
|
|
struct Bar : public Foo { };
|
|
|
|
|
|
|
|
TemporaryRef<Foo>
|
|
|
|
NewFoo()
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
return RefPtr<Foo>(new Foo());
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<Foo>
|
|
|
|
NewBar()
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
return new Bar();
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetNewFoo(Foo** f)
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
*f = new Bar();
|
|
|
|
// Kids, don't try this at home
|
|
|
|
(*f)->AddRef();
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetPassedFoo(Foo** f)
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
// Kids, don't try this at home
|
|
|
|
(*f)->AddRef();
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetNewFoo(RefPtr<Foo>* f)
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
*f = new Bar();
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetPassedFoo(RefPtr<Foo>* f)
|
|
|
|
{}
|
|
|
|
|
|
|
|
TemporaryRef<Foo>
|
|
|
|
GetNullFoo()
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
return 0;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
// This should blow up
|
2012-08-28 02:41:49 +08:00
|
|
|
// Foo* f = new Foo(); delete f;
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
MOZ_ASSERT(0 == Foo::numDestroyed);
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f = new Foo();
|
|
|
|
MOZ_ASSERT(f->refCount() == 1);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(1 == Foo::numDestroyed);
|
|
|
|
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f1 = NewFoo();
|
|
|
|
RefPtr<Foo> f2(NewFoo());
|
2012-08-28 02:41:49 +08:00
|
|
|
MOZ_ASSERT(1 == Foo::numDestroyed);
|
2012-10-19 11:48:42 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(3 == Foo::numDestroyed);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
{
|
|
|
|
RefPtr<Foo> b = NewBar();
|
2012-08-28 02:41:49 +08:00
|
|
|
MOZ_ASSERT(3 == Foo::numDestroyed);
|
2012-10-19 11:48:42 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(4 == Foo::numDestroyed);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
{
|
|
|
|
RefPtr<Foo> f1;
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
2012-10-19 11:48:42 +08:00
|
|
|
f1 = new Foo();
|
|
|
|
RefPtr<Foo> f2(f1);
|
|
|
|
RefPtr<Foo> f3 = f2;
|
|
|
|
MOZ_ASSERT(4 == Foo::numDestroyed);
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(4 == Foo::numDestroyed);
|
2012-10-19 11:48:42 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(5 == Foo::numDestroyed);
|
|
|
|
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f = new Foo();
|
|
|
|
f.forget();
|
|
|
|
MOZ_ASSERT(6 == Foo::numDestroyed);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f = new Foo();
|
|
|
|
GetNewFoo(byRef(f));
|
|
|
|
MOZ_ASSERT(7 == Foo::numDestroyed);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(8 == Foo::numDestroyed);
|
|
|
|
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f = new Foo();
|
|
|
|
GetPassedFoo(byRef(f));
|
2012-08-28 02:41:49 +08:00
|
|
|
MOZ_ASSERT(8 == Foo::numDestroyed);
|
2012-10-19 11:48:42 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(9 == Foo::numDestroyed);
|
|
|
|
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f = new Foo();
|
|
|
|
GetNewFoo(&f);
|
|
|
|
MOZ_ASSERT(10 == Foo::numDestroyed);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(11 == Foo::numDestroyed);
|
|
|
|
|
|
|
|
{
|
|
|
|
RefPtr<Foo> f = new Foo();
|
|
|
|
GetPassedFoo(&f);
|
2012-08-28 02:41:49 +08:00
|
|
|
MOZ_ASSERT(11 == Foo::numDestroyed);
|
2012-10-19 11:48:42 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(12 == Foo::numDestroyed);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
{
|
|
|
|
RefPtr<Foo> f1 = new Bar();
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(13 == Foo::numDestroyed);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
{
|
|
|
|
RefPtr<Foo> f = GetNullFoo();
|
2012-08-28 02:41:49 +08:00
|
|
|
MOZ_ASSERT(13 == Foo::numDestroyed);
|
2012-10-19 11:48:42 +08:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(13 == Foo::numDestroyed);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
return 0;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2013-10-30 21:55:19 +08:00
|
|
|
|
|
|
|
#endif /* mozilla_RefPtr_h */
|