Update ooo320-m1
[ooovba.git] / applied_patches / 0250-valgrind-alloc.diff
blob5bc181e6434db8462bea77623849098a6bafc99b
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".
14 + *
15 + *=========================================================================*/
17 +#include <stdlib.h> /* getenv */
18 +#include <stdio.h> /* stderr */
20 +typedef
21 + enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET }
22 + AllocMode;
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)
30 + return;
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");
38 + } else {
39 + alloc_mode = AMode_CUSTOM;
40 + }
43 +/*===========================================================================
44 + *
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()
54 +static
55 +void* SAL_CALL rtl_reallocateMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
57 memory_type * memory;
58 if (!(!p || !n))
59 @@ -1322,18 +1322,33 @@ void* SAL_CALL rtl_reallocateMemory (voi
61 return (p);
63 -#else /* FORCE_SYSALLOC */
64 -void* SAL_CALL rtl_reallocateMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
66 +static
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()
75 + while (1) {
76 + if (alloc_mode == AMode_CUSTOM) {
77 + return rtl_reallocateMemory_CUSTOM(p,n);
78 + }
79 + if (alloc_mode == AMode_SYSTEM) {
80 + return rtl_reallocateMemory_SYSTEM(p,n);
81 + }
82 + determine_alloc_mode();
83 + }
89 * rtl_allocateMemory.
91 -#ifndef FORCE_SYSALLOC
92 -void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
93 +static
94 +void* SAL_CALL rtl_allocateMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C()
96 void * p = 0;
97 if (n > 0)
98 @@ -1355,18 +1355,33 @@ void* SAL_CALL rtl_allocateMemory (sal_u
100 return (p);
102 -#else /* FORCE_SYSALLOC */
103 -void* SAL_CALL rtl_allocateMemory (sal_Size n) SAL_THROW_EXTERN_C()
105 +static
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()
114 + while (1) {
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();
128 * rtl_freeMemory.
130 -#ifndef FORCE_SYSALLOC
131 -void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
132 +static
133 +void SAL_CALL rtl_freeMemory_CUSTOM (void * p) SAL_THROW_EXTERN_C()
135 if (p)
137 @@ -1387,18 +1387,34 @@ void SAL_CALL rtl_freeMemory (void * p)
138 RTL_MEMORY_LEAVE();
141 -#else /* FORCE_SYSALLOC */
142 -void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
144 +static
145 +void SAL_CALL rtl_freeMemory_SYSTEM (void * p) SAL_THROW_EXTERN_C()
147 free(p);
149 -#endif /* FORCE_SYSALLOC */
151 +void SAL_CALL rtl_freeMemory (void * p) SAL_THROW_EXTERN_C()
153 + while (1) {
154 + if (alloc_mode == AMode_CUSTOM) {
155 + rtl_freeMemory_CUSTOM(p);
156 + return;
158 + if (alloc_mode == AMode_SYSTEM) {
159 + rtl_freeMemory_SYSTEM(p);
160 + return;
162 + determine_alloc_mode();
168 * rtl_allocateZeroMemory.
170 -#ifndef FORCE_SYSALLOC
171 -void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
172 +static
173 +void* SAL_CALL rtl_allocateZeroMemory_CUSTOM (sal_Size n) SAL_THROW_EXTERN_C()
175 void * p = 0;
176 if (n > 0)
177 @@ -1421,18 +1421,32 @@ void* SAL_CALL rtl_allocateZeroMemory (s
179 return (p);
181 -#else /* FORCE_SYSALLOC */
182 -void* SAL_CALL rtl_allocateZeroMemory (sal_Size n) SAL_THROW_EXTERN_C()
184 +static
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()
193 + while (1) {
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()
210 +static
211 +void SAL_CALL rtl_freeZeroMemory_CUSTOM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
213 (void) n; /* unused */
214 if (p)
215 @@ -1454,8 +1454,9 @@ void SAL_CALL rtl_freeZeroMemory (void *
216 RTL_MEMORY_LEAVE();
219 -#else /* FORCE_SYSALLOC */
220 -void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
222 +static
223 +void SAL_CALL rtl_freeZeroMemory_SYSTEM (void * p, sal_Size n) SAL_THROW_EXTERN_C()
225 if (p)
227 @@ -1463,7 +1463,21 @@ void SAL_CALL rtl_freeZeroMemory (void *
228 free(p);
231 -#endif /* FORCE_SYSALLOC */
233 +void SAL_CALL rtl_freeZeroMemory (void * p, sal_Size n) SAL_THROW_EXTERN_C()
235 + while (1) {
236 + if (alloc_mode == AMode_CUSTOM) {
237 + rtl_freeZeroMemory_CUSTOM(p,n);
238 + return;
240 + if (alloc_mode == AMode_SYSTEM) {
241 + rtl_freeZeroMemory_SYSTEM(p,n);
242 + return;
244 + determine_alloc_mode();
248 /*===========================================================================