1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is Mozilla Communicator client code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* L. David Baron <dbaron@dbaron.org>
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
38
#ifndef nsTraceRefcnt_h___
39
#define nsTraceRefcnt_h___
45
// By default refcnt logging is not part of the build.
46
#undef NS_BUILD_REFCNT_LOGGING
48
#if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
49
// Make refcnt logging part of the build. This doesn't mean that
50
// actual logging will occur (that requires a separate enable; see
51
// nsTraceRefcnt.h for more information).
52
#define NS_BUILD_REFCNT_LOGGING 1
55
// If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
56
// in the build. This overrides FORCE_BUILD_REFCNT_LOGGING.
57
#if defined(NO_BUILD_REFCNT_LOGGING)
58
#undef NS_BUILD_REFCNT_LOGGING
61
#ifdef NS_BUILD_REFCNT_LOGGING
63
#define NS_LOG_ADDREF(_p, _rc, _type, _size) \
64
nsTraceRefcnt::LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
66
#define NS_LOG_RELEASE(_p, _rc, _type) \
67
nsTraceRefcnt::LogRelease((_p), (_rc), (_type))
69
#define MOZ_DECL_CTOR_COUNTER(_type)
71
#define MOZ_COUNT_CTOR(_type) \
73
nsTraceRefcnt::LogCtor((void*)this, #_type, sizeof(*this)); \
76
#define MOZ_COUNT_DTOR(_type) \
78
nsTraceRefcnt::LogDtor((void*)this, #_type, sizeof(*this)); \
81
#ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR // from autoconf (XXX needs to be
82
// set for non-autoconf platforms)
84
// nsCOMPtr.h allows these macros to be defined by clients
85
// These logging functions require dynamic_cast<void *>, so we don't
86
// define these macros if we don't have dynamic_cast.
87
#define NSCAP_LOG_ASSIGNMENT(_c, _p) \
89
nsTraceRefcnt::LogAddCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p))
91
#define NSCAP_LOG_RELEASE(_c, _p) \
93
nsTraceRefcnt::LogReleaseCOMPtr((_c), NS_STATIC_CAST(nsISupports*,_p))
95
#endif /* HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR */
97
#else /* !NS_BUILD_REFCNT_LOGGING */
99
#define NS_LOG_ADDREF(_p, _rc, _type, _size)
100
#define NS_LOG_RELEASE(_p, _rc, _type)
101
#define MOZ_DECL_CTOR_COUNTER(_type)
102
#define MOZ_COUNT_CTOR(_type)
103
#define MOZ_COUNT_DTOR(_type)
105
#endif /* NS_BUILD_REFCNT_LOGGING */
107
//----------------------------------------------------------------------
110
* Note: The implementations for these methods are no-ops in a build
111
* where NS_BUILD_REFCNT_LOGGING is disabled.
113
class nsTraceRefcnt {
115
static NS_COM void LogAddRef(void* aPtr,
117
const char* aTypeName,
118
PRUint32 aInstanceSize);
120
static NS_COM void LogRelease(void* aPtr,
122
const char* aTypeName);
124
static NS_COM void LogCtor(void* aPtr, const char* aTypeName,
125
PRUint32 aInstanceSize);
127
static NS_COM void LogDtor(void* aPtr, const char* aTypeName,
128
PRUint32 aInstanceSize);
130
static NS_COM void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject);
132
static NS_COM void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject);
135
#endif /* nsTraceRefcnt_h___ */