Investigating leaks in bug 463263, backout bug 453403.
[wine-gecko.git] / xpcom / glue / nsTraceRefcnt.h
blob68ce6b2ae28e882d7d873f1b46ebb72fe0377f0f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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
13 * License.
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.
22 * Contributor(s):
23 * L. David Baron <dbaron@dbaron.org>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or 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 MPL, 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 MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsTraceRefcnt_h___
39 #define nsTraceRefcnt_h___
41 #include "nsXPCOM.h"
43 /* By default refcnt logging is not part of the build. */
44 #undef NS_BUILD_REFCNT_LOGGING
46 #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
47 /* Make refcnt logging part of the build. This doesn't mean that
48 * actual logging will occur (that requires a separate enable; see
49 * nsTraceRefcnt.h for more information). */
50 #define NS_BUILD_REFCNT_LOGGING 1
51 #endif
53 /* If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
54 * in the build. This overrides FORCE_BUILD_REFCNT_LOGGING. */
55 #if defined(NO_BUILD_REFCNT_LOGGING)
56 #undef NS_BUILD_REFCNT_LOGGING
57 #endif
59 #ifdef NS_BUILD_REFCNT_LOGGING
61 #define NS_LOG_ADDREF(_p, _rc, _type, _size) \
62 NS_LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
64 #define NS_LOG_RELEASE(_p, _rc, _type) \
65 NS_LogRelease((_p), (_rc), (_type))
67 #define MOZ_COUNT_CTOR(_type) \
68 PR_BEGIN_MACRO \
69 NS_LogCtor((void*)this, #_type, sizeof(*this)); \
70 PR_END_MACRO
72 #define MOZ_COUNT_DTOR(_type) \
73 PR_BEGIN_MACRO \
74 NS_LogDtor((void*)this, #_type, sizeof(*this)); \
75 PR_END_MACRO
77 /* nsCOMPtr.h allows these macros to be defined by clients
78 * These logging functions require dynamic_cast<void*>, so they don't
79 * do anything useful if we don't have dynamic_cast<void*>. */
80 #define NSCAP_LOG_ASSIGNMENT(_c, _p) \
81 if (_p) \
82 NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
84 #define NSCAP_LOG_RELEASE(_c, _p) \
85 if (_p) \
86 NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
88 #else /* !NS_BUILD_REFCNT_LOGGING */
90 #define NS_LOG_ADDREF(_p, _rc, _type, _size)
91 #define NS_LOG_RELEASE(_p, _rc, _type)
92 #define MOZ_COUNT_CTOR(_type)
93 #define MOZ_COUNT_DTOR(_type)
95 #endif /* NS_BUILD_REFCNT_LOGGING */
97 #ifdef __cplusplus
99 class nsTraceRefcnt {
100 public:
101 inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
102 const char* aTypeName, PRUint32 aInstanceSize) {
103 NS_LogAddRef(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
106 inline static void LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
107 const char* aTypeName) {
108 NS_LogRelease(aPtr, aNewRefCnt, aTypeName);
111 inline static void LogCtor(void* aPtr, const char* aTypeName,
112 PRUint32 aInstanceSize) {
113 NS_LogCtor(aPtr, aTypeName, aInstanceSize);
116 inline static void LogDtor(void* aPtr, const char* aTypeName,
117 PRUint32 aInstanceSize) {
118 NS_LogDtor(aPtr, aTypeName, aInstanceSize);
121 inline static void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject) {
122 NS_LogCOMPtrAddRef(aCOMPtr, aObject);
125 inline static void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject) {
126 NS_LogCOMPtrRelease(aCOMPtr, aObject);
130 #endif /* defined(__cplusplus) */
132 #endif /* nsTraceRefcnt_h___ */