Bug 895720 - Actually use the fuzz value.
[gecko.git] / xpcom / glue / nsTraceRefcnt.h
blobb132540e77abb20317dd76d30dd00fb6d40d71da
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsTraceRefcnt_h___
6 #define nsTraceRefcnt_h___
8 #include "nsXPCOM.h"
10 #ifdef NS_BUILD_REFCNT_LOGGING
12 #define NS_LOG_ADDREF(_p, _rc, _type, _size) \
13 NS_LogAddRef((_p), (_rc), (_type), (uint32_t) (_size))
15 #define NS_LOG_RELEASE(_p, _rc, _type) \
16 NS_LogRelease((_p), (_rc), (_type))
18 #define MOZ_COUNT_CTOR(_type) \
19 do { \
20 NS_LogCtor((void*)this, #_type, sizeof(*this)); \
21 } while (0)
23 #define MOZ_COUNT_CTOR_INHERITED(_type, _base) \
24 do { \
25 NS_LogCtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
26 } while (0)
28 #define MOZ_COUNT_DTOR(_type) \
29 do { \
30 NS_LogDtor((void*)this, #_type, sizeof(*this)); \
31 } while (0)
33 #define MOZ_COUNT_DTOR_INHERITED(_type, _base) \
34 do { \
35 NS_LogDtor((void*)this, #_type, sizeof(*this) - sizeof(_base)); \
36 } while (0)
38 /* nsCOMPtr.h allows these macros to be defined by clients
39 * These logging functions require dynamic_cast<void*>, so they don't
40 * do anything useful if we don't have dynamic_cast<void*>. */
41 #define NSCAP_LOG_ASSIGNMENT(_c, _p) \
42 if (_p) \
43 NS_LogCOMPtrAddRef((_c),static_cast<nsISupports*>(_p))
45 #define NSCAP_LOG_RELEASE(_c, _p) \
46 if (_p) \
47 NS_LogCOMPtrRelease((_c), static_cast<nsISupports*>(_p))
49 #else /* !NS_BUILD_REFCNT_LOGGING */
51 #define NS_LOG_ADDREF(_p, _rc, _type, _size)
52 #define NS_LOG_RELEASE(_p, _rc, _type)
53 #define MOZ_COUNT_CTOR(_type)
54 #define MOZ_COUNT_CTOR_INHERITED(_type, _base)
55 #define MOZ_COUNT_DTOR(_type)
56 #define MOZ_COUNT_DTOR_INHERITED(_type, _base)
58 #endif /* NS_BUILD_REFCNT_LOGGING */
60 #ifdef __cplusplus
62 class nsTraceRefcnt {
63 public:
64 inline static void LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
65 const char* aTypeName, uint32_t aInstanceSize) {
66 NS_LogAddRef(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
69 inline static void LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
70 const char* aTypeName) {
71 NS_LogRelease(aPtr, aNewRefCnt, aTypeName);
74 inline static void LogCtor(void* aPtr, const char* aTypeName,
75 uint32_t aInstanceSize) {
76 NS_LogCtor(aPtr, aTypeName, aInstanceSize);
79 inline static void LogDtor(void* aPtr, const char* aTypeName,
80 uint32_t aInstanceSize) {
81 NS_LogDtor(aPtr, aTypeName, aInstanceSize);
84 inline static void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject) {
85 NS_LogCOMPtrAddRef(aCOMPtr, aObject);
88 inline static void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject) {
89 NS_LogCOMPtrRelease(aCOMPtr, aObject);
93 #endif /* defined(__cplusplus) */
95 #endif /* nsTraceRefcnt_h___ */