source: trunk/src/odincrt/malloc_vac.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 4.1 KB
RevLine 
[9715]1/* $Id: malloc.cpp,v 1.9 2003-01-23 12:33:04 sandervl Exp $ */
[1906]2/*
3 * Project Odin Software License can be found in LICENSE.TXT
4 * Memory RTL function wrappers
5 *
6 * Copyright 1999 Sander van Leeuwen
7 *
8 */
9
[9709]10#define ORIGINAL_VAC_FUNCTIONS
[1904]11#include <malloc.h>
12#include <umalloc.h>
13#include <os2sel.h>
14
15void * _IMPORT _LNK_CONV _debug_calloc( size_t, size_t, const char *, size_t );
16void _IMPORT _LNK_CONV _debug_free( void *, const char *, size_t );
17void * _IMPORT _LNK_CONV _debug_malloc( size_t, const char *, size_t );
18void * _IMPORT _LNK_CONV _debug_realloc( void *, size_t, const char *, size_t );
19void * _IMPORT _LNK_CONV _debug_umalloc(Heap_t , size_t , const char *,size_t);
20void * _IMPORT _LNK_CONV _debug_ucalloc(Heap_t , size_t, size_t ,const char *,size_t);
21
[7627]22#ifdef DEBUG
23unsigned long nrcalls_malloc = 0;
24unsigned long nrcalls_free = 0;
25unsigned long totalmemalloc = 0;
26
[21826]27void SYSTEM getcrtstat(unsigned long *pnrcalls_malloc,
28 unsigned long *pnrcalls_free,
29 unsigned long *ptotalmemalloc)
[7627]30{
31 *pnrcalls_malloc = nrcalls_malloc;
32 *pnrcalls_free = nrcalls_free;
33 *ptotalmemalloc = totalmemalloc;
34}
[9266]35
[7627]36#endif
37
[9709]38void * _LNK_CONV CRTWRAP(calloc)( size_t a, size_t b )
[1904]39{
[1991]40 unsigned short sel = RestoreOS2FS();
[1904]41 void *rc;
42
[7627]43#ifdef DEBUG
44 totalmemalloc += a*b;
45 nrcalls_malloc++;
46#endif
[1904]47 rc = calloc(a,b);
48 SetFS(sel);
49 return rc;
50}
51
[9709]52void _LNK_CONV CRTWRAP(free)( void *a )
[1904]53{
[1991]54 unsigned short sel = RestoreOS2FS();
[1904]55
[7627]56#ifdef DEBUG
57 nrcalls_free++;
58 totalmemalloc -= _msize(a);
59#endif
[1991]60 free(a);
[1904]61 SetFS(sel);
62}
63
[9709]64void * _LNK_CONV CRTWRAP(malloc)( size_t a)
[1904]65{
[1991]66 unsigned short sel = RestoreOS2FS();
[1904]67 void *rc;
68
[7627]69
70#ifdef DEBUG
71 totalmemalloc += a;
72 nrcalls_malloc++;
73#endif
[1904]74 rc = malloc(a);
75 SetFS(sel);
76 return rc;
77}
78
[9709]79void * _LNK_CONV CRTWRAP(realloc)( void *a, size_t b)
[1904]80{
[1991]81 unsigned short sel = RestoreOS2FS();
[1904]82 void *rc;
83
[7627]84#ifdef DEBUG
85 totalmemalloc += (b - _msize(a));
86#endif
87
[1904]88 rc = realloc(a, b);
89 SetFS(sel);
90 return rc;
91}
92
[9709]93void * _LNK_CONV CRTWRAP(_debug_calloc)( size_t a, size_t b, const char *c, size_t d)
[1904]94{
[1991]95 unsigned short sel = RestoreOS2FS();
[1904]96 void *rc;
97
[7627]98#ifdef DEBUG
99 totalmemalloc += a*b;
100 nrcalls_malloc++;
101#endif
102
[1904]103 rc = _debug_calloc(a,b,c,d);
104 SetFS(sel);
105 return rc;
106}
107
[9709]108void _LNK_CONV CRTWRAP(_debug_free)( void *a, const char *b, size_t c)
[1904]109{
[1991]110 unsigned short sel = RestoreOS2FS();
[1904]111
[7627]112
113#ifdef DEBUG
114 nrcalls_free++;
115 totalmemalloc -= _msize(a);
116#endif
[1904]117 _debug_free(a,b,c);
118 SetFS(sel);
119}
120
[9709]121void * _LNK_CONV CRTWRAP(_debug_malloc)( size_t a, const char *b, size_t c)
[1904]122{
[1991]123 unsigned short sel = RestoreOS2FS();
[1904]124 void *rc;
125
[7627]126#ifdef DEBUG
127 totalmemalloc += a;
128 nrcalls_malloc++;
129#endif
[1991]130 rc = _debug_calloc(1,a,b,c);
[1904]131 SetFS(sel);
132 return rc;
133}
134
[9709]135void * _LNK_CONV CRTWRAP(_debug_realloc)( void *a, size_t b, const char *c, size_t d)
[1904]136{
[1991]137 unsigned short sel = RestoreOS2FS();
[1904]138 void *rc;
139
[7627]140#ifdef DEBUG
141 totalmemalloc += (b - _msize(a));
142#endif
[1904]143 rc = _debug_realloc(a,b,c,d);
144 SetFS(sel);
145 return rc;
146}
147
[9709]148void * _LNK_CONV CRTWRAP(_umalloc)(Heap_t a, size_t b)
[1904]149{
[1991]150 unsigned short sel = RestoreOS2FS();
[1904]151 void *rc;
152
[7627]153#ifdef DEBUG
154 totalmemalloc += b;
155 nrcalls_malloc++;
156#endif
[1904]157 rc = _umalloc(a,b);
158 SetFS(sel);
159 return rc;
160}
161
[9709]162void * _LNK_CONV CRTWRAP(_ucalloc)(Heap_t a, size_t b, size_t c)
[1904]163{
[1991]164 unsigned short sel = RestoreOS2FS();
[1904]165 void *rc;
166
[7627]167#ifdef DEBUG
168 totalmemalloc += b*c;
169 nrcalls_malloc++;
170#endif
[1904]171 rc = _ucalloc(a,b,c);
172 SetFS(sel);
173 return rc;
174}
175
[9709]176void * _LNK_CONV CRTWRAP(_debug_umalloc)(Heap_t a, size_t b, const char *c, size_t d)
[1904]177{
[1991]178 unsigned short sel = RestoreOS2FS();
[1904]179 void *rc;
180
[7627]181#ifdef DEBUG
182 totalmemalloc += b;
183 nrcalls_malloc++;
184#endif
[1991]185 rc = _debug_ucalloc(a, 1, b,c,d);
[1904]186 SetFS(sel);
187 return rc;
188}
189
[9709]190void * _LNK_CONV CRTWRAP(_debug_ucalloc)(Heap_t a, size_t b, size_t c, const char *d, size_t e)
[1904]191{
[1991]192 unsigned short sel = RestoreOS2FS();
[1904]193 void *rc;
194
[7627]195#ifdef DEBUG
196 totalmemalloc += b*c;
197 nrcalls_malloc++;
198#endif
[1904]199 rc = _debug_ucalloc(a,b,c,d,e);
200 SetFS(sel);
201 return rc;
202}
203
Note: See TracBrowser for help on using the repository browser.