Renamed the ctor/dtor counting macros to make more sense

git-svn-id: svn://10.0.0.236/trunk@49840 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kipp%netscape.com
1999-10-05 14:54:05 +00:00
parent a87258a834
commit ebce0e90ac
3 changed files with 47 additions and 15 deletions

View File

@@ -113,10 +113,10 @@ protected:
#ifdef DEBUG
#define MOZ_DECL_CTOR(_type) \
#define MOZ_DECL_CTOR_COUNTER(_type) \
static mozCtorDtorCounter gCounter_##_type
#define MOZ_CTOR(_type) \
#define MOZ_COUNT_CTOR(_type) \
PR_BEGIN_MACRO \
if (0 == gCounter_##_type . ctors) { \
nsTraceRefcnt::RegisterCtor(#_type, &gCounter_##_type); \
@@ -124,16 +124,16 @@ PR_BEGIN_MACRO \
gCounter_##_type . ctors++; \
PR_END_MACRO
#define MOZ_DTOR(_type) \
#define MOZ_COUNT_DTOR(_type) \
PR_BEGIN_MACRO \
gCounter_##_type . dtors ++; \
PR_END_MACRO
#else
#define MOZ_DECL_CTOR(_type)
#define MOZ_CTOR(_type)
#define MOZ_DTOR(_type)
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type)
#define MOZ_COUNT_DTOR(_type)
#endif /* DEBUG */

View File

@@ -113,10 +113,10 @@ protected:
#ifdef DEBUG
#define MOZ_DECL_CTOR(_type) \
#define MOZ_DECL_CTOR_COUNTER(_type) \
static mozCtorDtorCounter gCounter_##_type
#define MOZ_CTOR(_type) \
#define MOZ_COUNT_CTOR(_type) \
PR_BEGIN_MACRO \
if (0 == gCounter_##_type . ctors) { \
nsTraceRefcnt::RegisterCtor(#_type, &gCounter_##_type); \
@@ -124,16 +124,16 @@ PR_BEGIN_MACRO \
gCounter_##_type . ctors++; \
PR_END_MACRO
#define MOZ_DTOR(_type) \
#define MOZ_COUNT_DTOR(_type) \
PR_BEGIN_MACRO \
gCounter_##_type . dtors ++; \
PR_END_MACRO
#else
#define MOZ_DECL_CTOR(_type)
#define MOZ_CTOR(_type)
#define MOZ_DTOR(_type)
#define MOZ_DECL_CTOR_COUNTER(_type)
#define MOZ_COUNT_CTOR(_type)
#define MOZ_COUNT_DTOR(_type)
#endif /* DEBUG */

View File

@@ -47,10 +47,9 @@ NS_COM void NS_PurgeAtomTable(void)
{
if (gAtomHashTable) {
#if defined(DEBUG_kipp) && (defined(XP_UNIX) || defined(XP_PC))
if (0 != gAtoms) {
printf("*** leaking %d atoms\n", gAtoms);
if (gAtoms) {
if (getenv("MOZ_DUMP_ATOM_LEAKS")) {
printf("*** leaked atoms:\n");
printf("*** leaking %d atoms\n", gAtoms);
PL_HashTableEnumerateEntries(gAtomHashTable, DumpAtomLeaks, 0);
}
}
@@ -60,8 +59,12 @@ NS_COM void NS_PurgeAtomTable(void)
}
}
MOZ_DECL_CTOR_COUNTER(AtomImpl);
AtomImpl::AtomImpl()
{
MOZ_COUNT_CTOR(AtomImpl);
NS_INIT_REFCNT();
// Every live atom holds a reference on the atom hashtable
gAtoms++;
@@ -69,6 +72,8 @@ AtomImpl::AtomImpl()
AtomImpl::~AtomImpl()
{
MOZ_COUNT_DTOR(AtomImpl);
NS_PRECONDITION(nsnull != gAtomHashTable, "null atom hashtable");
if (nsnull != gAtomHashTable) {
PL_HashTableRemove(gAtomHashTable, mString);
@@ -82,7 +87,34 @@ AtomImpl::~AtomImpl()
}
}
#ifdef LOG_ATOM_REFCNTS
extern "C" {
void __log_addref(void* p, int oldrc, int newrc);
void __log_release(void* p, int oldrc, int newrc);
}
nsrefcnt AtomImpl::AddRef(void)
{
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
__log_addref((void*) this, mRefCnt, mRefCnt + 1);
return ++mRefCnt;
}
nsrefcnt AtomImpl::Release(void)
{
__log_release((void*) this, mRefCnt, mRefCnt - 1);
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (--mRefCnt == 0) {
NS_DELETEXPCOM(this);
return 0;
}
return mRefCnt;
}
NS_IMPL_QUERY_INTERFACE1(AtomImpl, nsIAtom)
#else
NS_IMPL_ISUPPORTS1(AtomImpl, nsIAtom)
#endif /* LOG_ATOM_REFCNTS */
void* AtomImpl::operator new(size_t size, const PRUnichar* us, PRInt32 uslen)
{