VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/glue/nsDebug.cpp

Last change on this file was 5522, checked in by vboxsync, 17 years ago

XPCOM: Fixed memory errors and leaks found by valgrind.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is XPCOM
15 *
16 * The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>
17 *
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37#include "nsXPCOM.h"
38#include "nsXPCOMPrivate.h"
39#include "nsCOMPtr.h"
40#include "nsIServiceManager.h"
41#include "nsDebug.h"
42#include "nsDebugImpl.h"
43
44static nsIDebug* gDebugObject = nsnull;
45
46// Note: Although the machinery here is similar to nsMemory.cpp, we cannot use
47// NS_ASSERTION macros below because they end up in nsDebug::Assertion and
48// therefore may produce endless recursion.
49
50static NS_METHOD FreeDebugObject(void)
51{
52 NS_IF_RELEASE(gDebugObject);
53 return NS_OK;
54}
55
56#define ENSURE_DEBUGOBJECT \
57 (gDebugObject ? PR_TRUE : (PRBool)(SetupDebugObject() != nsnull))
58
59static nsIDebug* SetupDebugObject()
60{
61 if (!gDebugObject)
62 {
63 NS_GetDebug(&gDebugObject);
64 if (gDebugObject)
65 NS_RegisterXPCOMExitRoutine(FreeDebugObject, 0);
66 }
67 return gDebugObject;
68}
69
70#ifdef XPCOM_GLUE
71nsresult GlueStartupDebug()
72{
73 if (!gDebugObject)
74 {
75 NS_GetDebug(&gDebugObject);
76 if (!gDebugObject)
77 return NS_ERROR_FAILURE;
78 }
79 return NS_OK;
80}
81
82void GlueShutdownDebug()
83{
84 NS_IF_RELEASE(gDebugObject);
85}
86#endif
87
88NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
89{
90 if (!ENSURE_DEBUGOBJECT)
91 return;
92
93 gDebugObject->Abort(aFile, aLine);
94}
95
96NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
97{
98 if (!ENSURE_DEBUGOBJECT)
99 return;
100
101 gDebugObject->Break(aFile, aLine);
102}
103
104NS_COM void nsDebug::Warning(const char* aStr,
105 const char* aFile,
106 PRIntn aLine)
107{
108 if (!ENSURE_DEBUGOBJECT)
109 return;
110 gDebugObject->Warning(aStr, aFile, aLine);
111}
112
113NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
114 const char* aFile, PRIntn aLine)
115{
116 if (!ENSURE_DEBUGOBJECT)
117 return;
118 gDebugObject->Assertion(aStr, aExpr, aFile, aLine);
119}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette