1 Index: sal/rtl/source/alloc.c
2 ===================================================================
3 RCS file: /cvs/porting/sal/rtl/source/alloc.c,v
4 retrieving revision 1.14
5 diff -u -3 -p -r1.14 alloc.c
6 --- sal/rtl/source/alloc.c 17 Dec 2003 17:10:01 -0000 1.14
7 +++ sal/rtl/source/alloc.c 29 Feb 2004 17:50:41 -0000
8 @@ -227,6 +227,39 @@ static sal_uInt32 __rtl_memory_vmpagesiz
10 /*===========================================================================
12 + * Determine allocation mode (debug/release) by examining environment
13 + * variable "OOO_FORCE_SYSALLOC".
15 + *=========================================================================*/
17 +#include <stdlib.h> /* getenv */
18 +#include <stdio.h> /* stderr */
21 + enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET }
24 +static AllocMode alloc_mode = AMode_UNSET;
26 +static void determine_alloc_mode ( void )
28 + /* This shouldn't happen, but still ... */
29 + if (alloc_mode != AMode_UNSET)
32 + if (getenv("OOO_FORCE_SYSALLOC") != NULL) {
33 + alloc_mode = AMode_SYSTEM;
34 + fprintf(stderr, "OOo: Using system memory allocator.\n");
35 + fprintf(stderr, "OOo: This is for debugging only. To disable,\n");
36 + fprintf(stderr, "OOo: unset the environment variable"
37 + " OOO_FORCE_SYSALLOC.\n");
39 + alloc_mode = AMode_CUSTOM;
43 +/*===========================================================================
45 * rtl_memory (global) internals.
47 *=========================================================================*/
48 @@ -1165,8 +1165,8 @@ static void __rtl_memory_enqueue (memory
50 * rtl_reallocateMemory.
52 -#ifndef FORCE_SYSALLOC
53 -void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
55 +void* SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
59 @@ -1322,18 +1322,33 @@ void* SAL_CALL rtl_reallocateMemory (voi
63 -#else /* FORCE_SYSALLOC */
64 -void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
67 +void* SAL_CALL rtl_reallocateMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
69 return realloc(p, (sal_Size)(n));
71 -#endif /* FORCE_SYSALLOC */
73 +void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
76 + if (alloc_mode == AMode_CUSTOM) {
77 + return rtl_reallocateMemory_CUSTOM(p,n);
79 + if (alloc_mode == AMode_SYSTEM) {
80 + return rtl_reallocateMemory_SYSTEM(p,n);
82 + determine_alloc_mode();
91 -#ifndef FORCE_SYSALLOC
92 -void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
94 +void* SAL_CALL rtl_allocateMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C()
98 @@ -1355,18 +1355,33 @@ void* SAL_CALL rtl_allocateMemory (sal_u
102 -#else /* FORCE_SYSALLOC */
103 -void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
106 +void* SAL_CALL rtl_allocateMemory_SYSTEM (sal_Size n) SAL_THROW_EXTERN_C()
108 return malloc((sal_Size)(n));
110 -#endif /* FORCE_SYSALLOC */
112 +void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
115 + if (alloc_mode == AMode_CUSTOM) {
116 + return rtl_allocateMemory_CUSTOM(n);
118 + if (alloc_mode == AMode_SYSTEM) {
119 + return rtl_allocateMemory_SYSTEM(n);
121 + determine_alloc_mode();
130 -#ifndef FORCE_SYSALLOC
131 -void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
133 +void SAL_CALL rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C()
137 @@ -1387,18 +1387,34 @@ void SAL_CALL rtl_freeMemory (void * p)
141 -#else /* FORCE_SYSALLOC */
142 -void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
145 +void SAL_CALL rtl_freeMemory_SYSTEM (void * p) SAL_THROW_EXTERN_C()
149 -#endif /* FORCE_SYSALLOC */
151 +void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
154 + if (alloc_mode == AMode_CUSTOM) {
155 + rtl_freeMemory_CUSTOM(p);
158 + if (alloc_mode == AMode_SYSTEM) {
159 + rtl_freeMemory_SYSTEM(p);
162 + determine_alloc_mode();
168 * rtl_allocateZeroMemory.
170 -#ifndef FORCE_SYSALLOC
171 -void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
173 +void* SAL_CALL rtl_allocateZeroMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C()
177 @@ -1421,18 +1421,32 @@ void* SAL_CALL rtl_allocateZeroMemory (s
181 -#else /* FORCE_SYSALLOC */
182 -void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
185 +void* SAL_CALL rtl_allocateZeroMemory_SYSTEM (sal_Size n) SAL_THROW_EXTERN_C()
187 return calloc((sal_Size)(n), 1);
189 -#endif /* FORCE_SYSALLOC */
191 +void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
194 + if (alloc_mode == AMode_CUSTOM) {
195 + return rtl_allocateZeroMemory_CUSTOM(n);
197 + if (alloc_mode == AMode_SYSTEM) {
198 + return rtl_allocateZeroMemory_SYSTEM(n);
200 + determine_alloc_mode();
206 * rtl_freeZeroMemory.
208 -#ifndef FORCE_SYSALLOC
209 -void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
211 +void SAL_CALL rtl_freeZeroMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
213 (void) n; /* unused */
215 @@ -1454,8 +1454,9 @@ void SAL_CALL rtl_freeZeroMemory (void *
219 -#else /* FORCE_SYSALLOC */
220 -void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
223 +void SAL_CALL rtl_freeZeroMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
227 @@ -1463,7 +1463,21 @@ void SAL_CALL rtl_freeZeroMemory (void *
231 -#endif /* FORCE_SYSALLOC */
233 +void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
236 + if (alloc_mode == AMode_CUSTOM) {
237 + rtl_freeZeroMemory_CUSTOM(p,n);
240 + if (alloc_mode == AMode_SYSTEM) {
241 + rtl_freeZeroMemory_SYSTEM(p,n);
244 + determine_alloc_mode();
248 /*===========================================================================