Back to index

lightning-sunbird  0.9+nobinonly
nsTraceRefcnt.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   L. David Baron <dbaron@dbaron.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef nsTraceRefcnt_h___
00039 #define nsTraceRefcnt_h___
00040 
00041 #include "nscore.h"
00042 
00043 class nsISupports;
00044 
00045 // By default refcnt logging is not part of the build.
00046 #undef NS_BUILD_REFCNT_LOGGING
00047 
00048 #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
00049 // Make refcnt logging part of the build. This doesn't mean that
00050 // actual logging will occur (that requires a separate enable; see
00051 // nsTraceRefcnt.h for more information).
00052 #define NS_BUILD_REFCNT_LOGGING 1
00053 #endif
00054 
00055 // If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
00056 // in the build. This overrides FORCE_BUILD_REFCNT_LOGGING.
00057 #if defined(NO_BUILD_REFCNT_LOGGING)
00058 #undef NS_BUILD_REFCNT_LOGGING
00059 #endif
00060 
00061 #ifdef NS_BUILD_REFCNT_LOGGING
00062 
00063 #define NS_LOG_ADDREF(_p, _rc, _type, _size) \
00064   nsTraceRefcnt::LogAddRef((_p), (_rc), (_type), (PRUint32) (_size))
00065 
00066 #define NS_LOG_RELEASE(_p, _rc, _type) \
00067   nsTraceRefcnt::LogRelease((_p), (_rc), (_type))
00068 
00069 #define MOZ_DECL_CTOR_COUNTER(_type)
00070 
00071 #define MOZ_COUNT_CTOR(_type)                                 \
00072 PR_BEGIN_MACRO                                                \
00073   nsTraceRefcnt::LogCtor((void*)this, #_type, sizeof(*this)); \
00074 PR_END_MACRO
00075 
00076 #define MOZ_COUNT_DTOR(_type)                                 \
00077 PR_BEGIN_MACRO                                                \
00078   nsTraceRefcnt::LogDtor((void*)this, #_type, sizeof(*this)); \
00079 PR_END_MACRO
00080 
00081 #ifdef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR  // from autoconf (XXX needs to be
00082                                           // set for non-autoconf platforms)
00083 
00084 // nsCOMPtr.h allows these macros to be defined by clients
00085 // These logging functions require dynamic_cast<void *>, so we don't
00086 // define these macros if we don't have dynamic_cast.
00087 #define NSCAP_LOG_ASSIGNMENT(_c, _p)                                \
00088   if (_p)                                                           \
00089     nsTraceRefcnt::LogAddCOMPtr((_c),NS_STATIC_CAST(nsISupports*,_p))
00090 
00091 #define NSCAP_LOG_RELEASE(_c, _p)                                   \
00092   if (_p)                                                           \
00093     nsTraceRefcnt::LogReleaseCOMPtr((_c), NS_STATIC_CAST(nsISupports*,_p))
00094 
00095 #endif /* HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR */
00096 
00097 #else /* !NS_BUILD_REFCNT_LOGGING */
00098 
00099 #define NS_LOG_ADDREF(_p, _rc, _type, _size)
00100 #define NS_LOG_RELEASE(_p, _rc, _type)
00101 #define MOZ_DECL_CTOR_COUNTER(_type)
00102 #define MOZ_COUNT_CTOR(_type)
00103 #define MOZ_COUNT_DTOR(_type)
00104 
00105 #endif /* NS_BUILD_REFCNT_LOGGING */
00106 
00107 //----------------------------------------------------------------------
00108 
00113 class nsTraceRefcnt {
00114 public:
00115   static NS_COM_GLUE void LogAddRef(void* aPtr,
00116                                     nsrefcnt aNewRefCnt,
00117                                     const char* aTypeName,
00118                                     PRUint32 aInstanceSize);
00119 
00120   static NS_COM_GLUE void LogRelease(void* aPtr,
00121                                      nsrefcnt aNewRefCnt,
00122                                      const char* aTypeName);
00123 
00124   static NS_COM_GLUE void LogCtor(void* aPtr, const char* aTypeName,
00125                                   PRUint32 aInstanceSize);
00126 
00127   static NS_COM_GLUE void LogDtor(void* aPtr, const char* aTypeName,
00128                                   PRUint32 aInstanceSize);
00129 
00130   static NS_COM_GLUE void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject);
00131 
00132   static NS_COM_GLUE void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject);
00133 
00134 };
00135 #endif /* nsTraceRefcnt_h___ */