source: trunk/include/helpers/memdebug.h@ 97

Last change on this file since 97 was 91, checked in by umoeller, 24 years ago

Misc changes

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1
2/*
3 *@@sourcefile memdebug.h:
4 * header file for memdebug.c.
5 * See remarks there.
6 *
7 * The following macros are used:
8 *
9 * -- __XWPMEMDEBUG__: if defined, memory debugging is generally
10 * enabled. This must be set in setup.h.
11 *
12 * -- __DEBUG_MALLOC_ENABLED__: malloc etc. have been replaced
13 * with memdMalloc etc. This is automatically
14 * defined by this header if __XWPMEMDEBUG__
15 * is defined, unless DONT_REPLACE_MALLOC
16 * is also defined.
17 *
18 * Note: Version numbering in this file relates to XWorkplace version
19 * numbering.
20 *
21 *@@include #include <os2.h>
22 *@@include #include "memdebug.h"
23 */
24
25/* Copyright (C) 2000 Ulrich M”ller.
26 * This file is part of the "XWorkplace helpers" source package.
27 * This is free software; you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published
29 * by the Free Software Foundation, in version 2 as it comes in the
30 * "COPYING" file of the XWorkplace main distribution.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 */
36
37#if __cplusplus
38extern "C" {
39#endif
40
41#ifndef MEMDEBUG_HEADER_INCLUDED
42 #define MEMDEBUG_HEADER_INCLUDED
43
44 #ifndef __stdlib_h // <stdlib.h>
45 #error stdlib.h must be included before memdebug.h.
46 #endif
47
48 typedef void (FNCBMEMDLOG)(const char*); // message
49 typedef FNCBMEMDLOG *PFNCBMEMDLOG;
50
51 // global variable for memory error logger func
52 extern PFNCBMEMDLOG G_pMemdLogFunc;
53
54 /* ******************************************************************
55 *
56 * Private declarations
57 *
58 ********************************************************************/
59
60 #ifdef MEMDEBUG_PRIVATE
61
62 BOOL memdLock(VOID);
63
64 VOID memdUnlock(VOID);
65
66 /*
67 *@@ HEAPITEM:
68 * informational structure created for each
69 * malloc() call by memdMalloc. These are stored
70 * in a global linked list (G_pHeapItemsRoot).
71 *
72 * We cannot use the linklist.c functions for
73 * managing the linked list because these use
74 * malloc in turn, which would lead to infinite
75 * loops.
76 *
77 *@@added V0.9.3 (2000-04-11) [umoeller]
78 */
79
80 typedef struct _HEAPITEM
81 {
82 struct _HEAPITEM *pNext; // next item in linked list or NULL if last
83
84 void *pAfterMagic; // memory pointer returned by memdMalloc;
85 // this points to after the magic string
86 unsigned long ulSize; // requested size (without magic head and tail)
87
88 const char *pcszSourceFile; // as passed to memdMalloc
89 unsigned long ulLine; // as passed to memdMalloc
90 const char *pcszFunction; // as passed to memdMalloc
91
92 DATETIME dtAllocated; // system date/time at time of memdMalloc call
93
94 ULONG ulTID; // thread ID that memdMalloc was running on
95
96 BOOL fFreed; // TRUE only after item has been freed by memdFree
97 } HEAPITEM, *PHEAPITEM;
98
99 extern PHEAPITEM G_pHeapItemsRoot;
100 extern ULONG G_ulItemsReleased;
101 extern ULONG G_ulBytesReleased;
102
103 #endif // MEMDEBUG_PRIVATE
104
105 /* ******************************************************************
106 *
107 * Publics
108 *
109 ********************************************************************/
110
111 void* memdMalloc(size_t stSize,
112 const char *pcszSourceFile,
113 unsigned long ulLine,
114 const char *pcszFunction);
115
116 void* memdCalloc(size_t num,
117 size_t stSize,
118 const char *pcszSourceFile,
119 unsigned long ulLine,
120 const char *pcszFunction);
121
122 void memdFree(void *p,
123 const char *pcszSourceFile,
124 unsigned long ulLine,
125 const char *pcszFunction);
126
127 void* memdRealloc(void *p,
128 size_t stSize,
129 const char *pcszSourceFile,
130 unsigned long ulLine,
131 const char *pcszFunction);
132
133 unsigned long memdReleaseFreed(void);
134
135 #ifdef __XWPMEMDEBUG__
136
137 #ifndef DONT_REPLACE_MALLOC
138 #define malloc(ul) memdMalloc(ul, __FILE__, __LINE__, __FUNCTION__)
139 #define calloc(n, size) memdCalloc(n, size, __FILE__, __LINE__, __FUNCTION__)
140 #define realloc(p, ul) memdRealloc(p, ul, __FILE__, __LINE__, __FUNCTION__)
141 #define free(p) memdFree(p, __FILE__, __LINE__, __FUNCTION__)
142
143 #ifdef __string_h
144 // string.h included and debugging is on:
145 // redefine strdup to use memory debugging
146 #define strdup(psz) \
147 strcpy( (char*)memdMalloc(strlen(psz) + 1, __FILE__, __LINE__, __FUNCTION__), psz)
148 // the original crashes also if psz is NULL
149 #endif
150
151 #define __DEBUG_MALLOC_ENABLED__
152
153 #endif
154 #endif
155
156 #ifdef PM_INCLUDED
157 /********************************************************************
158 *
159 * XFolder debugging helpers
160 *
161 ********************************************************************/
162
163 #ifdef _PMPRINTF_
164 void memdDumpMemoryBlock(PBYTE pb,
165 ULONG ulSize,
166 ULONG ulIndent);
167 #else
168 // _PMPRINTF not #define'd: do nothing
169 #define memdDumpMemoryBlock(pb, ulSize, ulIndent)
170 #endif
171
172 /* ******************************************************************
173 *
174 * Heap debugging window
175 *
176 ********************************************************************/
177
178 MRESULT EXPENTRY memd_fnwpMemDebug(HWND hwndClient, ULONG msg, MPARAM mp1, MPARAM mp2);
179
180 VOID memdCreateMemDebugWindow(VOID);
181 #endif
182
183#endif
184
185#if __cplusplus
186}
187#endif
188
Note: See TracBrowser for help on using the repository browser.