@@ -46,7 +46,7 @@ typedef struct {
46
46
uint32_t signature;
47
47
} alloc_info_t ;
48
48
49
- #ifdef MBED_HEAP_STATS_ENABLED
49
+ #if MBED_HEAP_STATS_ENABLED
50
50
#define MBED_HEAP_STATS_SIGNATURE (0xdeadbeef )
51
51
52
52
static SingletonPtr<PlatformMutex> malloc_stats_mutex;
@@ -63,7 +63,7 @@ typedef struct {
63
63
64
64
void mbed_stats_heap_get (mbed_stats_heap_t *stats)
65
65
{
66
- #ifdef MBED_HEAP_STATS_ENABLED
66
+ #if MBED_HEAP_STATS_ENABLED
67
67
extern uint32_t mbed_heap_size;
68
68
heap_stats.reserved_size = mbed_heap_size;
69
69
@@ -100,10 +100,10 @@ extern "C" void *__wrap__malloc_r(struct _reent *r, size_t size)
100
100
extern " C" void *malloc_wrapper (struct _reent *r, size_t size, void *caller)
101
101
{
102
102
void *ptr = NULL ;
103
- #ifdef MBED_MEM_TRACING_ENABLED
103
+ #if MBED_MEM_TRACING_ENABLED
104
104
mbed_mem_trace_lock ();
105
105
#endif
106
- #ifdef MBED_HEAP_STATS_ENABLED
106
+ #if MBED_HEAP_STATS_ENABLED
107
107
malloc_stats_mutex->lock ();
108
108
alloc_info_t *alloc_info = (alloc_info_t *)__real__malloc_r (r, size + sizeof (alloc_info_t ));
109
109
if (alloc_info != NULL ) {
@@ -121,23 +121,23 @@ extern "C" void *malloc_wrapper(struct _reent *r, size_t size, void *caller)
121
121
heap_stats.alloc_fail_cnt += 1 ;
122
122
}
123
123
malloc_stats_mutex->unlock ();
124
- #else // #ifdef MBED_HEAP_STATS_ENABLED
124
+ #else // #if MBED_HEAP_STATS_ENABLED
125
125
ptr = __real__malloc_r (r, size);
126
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
127
- #ifdef MBED_MEM_TRACING_ENABLED
126
+ #endif // #if MBED_HEAP_STATS_ENABLED
127
+ #if MBED_MEM_TRACING_ENABLED
128
128
mbed_mem_trace_malloc (ptr, size, caller);
129
129
mbed_mem_trace_unlock ();
130
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
130
+ #endif // #if MBED_MEM_TRACING_ENABLED
131
131
return ptr;
132
132
}
133
133
134
134
extern " C" void *__wrap__realloc_r (struct _reent *r, void *ptr, size_t size)
135
135
{
136
136
void *new_ptr = NULL ;
137
- #ifdef MBED_MEM_TRACING_ENABLED
137
+ #if MBED_MEM_TRACING_ENABLED
138
138
mbed_mem_trace_lock ();
139
139
#endif
140
- #ifdef MBED_HEAP_STATS_ENABLED
140
+ #if MBED_HEAP_STATS_ENABLED
141
141
// Implement realloc_r with malloc and free.
142
142
// The function realloc_r can't be used here directly since
143
143
// it can call into __wrap__malloc_r (returns ptr + 4) or
@@ -164,13 +164,13 @@ extern "C" void *__wrap__realloc_r(struct _reent *r, void *ptr, size_t size)
164
164
memcpy (new_ptr, (void *)ptr, copy_size);
165
165
free (ptr);
166
166
}
167
- #else // #ifdef MBED_HEAP_STATS_ENABLED
167
+ #else // #if MBED_HEAP_STATS_ENABLED
168
168
new_ptr = __real__realloc_r (r, ptr, size);
169
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
170
- #ifdef MBED_MEM_TRACING_ENABLED
169
+ #endif // #if MBED_HEAP_STATS_ENABLED
170
+ #if MBED_MEM_TRACING_ENABLED
171
171
mbed_mem_trace_realloc (new_ptr, ptr, size, MBED_CALLER_ADDR ());
172
172
mbed_mem_trace_unlock ();
173
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
173
+ #endif // #if MBED_MEM_TRACING_ENABLED
174
174
return new_ptr;
175
175
}
176
176
@@ -181,10 +181,10 @@ extern "C" void __wrap__free_r(struct _reent *r, void *ptr)
181
181
182
182
extern " C" void free_wrapper (struct _reent *r, void *ptr, void *caller)
183
183
{
184
- #ifdef MBED_MEM_TRACING_ENABLED
184
+ #if MBED_MEM_TRACING_ENABLED
185
185
mbed_mem_trace_lock ();
186
186
#endif
187
- #ifdef MBED_HEAP_STATS_ENABLED
187
+ #if MBED_HEAP_STATS_ENABLED
188
188
malloc_stats_mutex->lock ();
189
189
alloc_info_t *alloc_info = NULL ;
190
190
if (ptr != NULL ) {
@@ -203,35 +203,35 @@ extern "C" void free_wrapper(struct _reent *r, void *ptr, void *caller)
203
203
}
204
204
205
205
malloc_stats_mutex->unlock ();
206
- #else // #ifdef MBED_HEAP_STATS_ENABLED
206
+ #else // #if MBED_HEAP_STATS_ENABLED
207
207
__real__free_r (r, ptr);
208
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
209
- #ifdef MBED_MEM_TRACING_ENABLED
208
+ #endif // #if MBED_HEAP_STATS_ENABLED
209
+ #if MBED_MEM_TRACING_ENABLED
210
210
mbed_mem_trace_free (ptr, caller);
211
211
mbed_mem_trace_unlock ();
212
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
212
+ #endif // #if MBED_MEM_TRACING_ENABLED
213
213
}
214
214
215
215
extern " C" void *__wrap__calloc_r (struct _reent *r, size_t nmemb, size_t size)
216
216
{
217
217
void *ptr = NULL ;
218
- #ifdef MBED_MEM_TRACING_ENABLED
218
+ #if MBED_MEM_TRACING_ENABLED
219
219
mbed_mem_trace_lock ();
220
220
#endif
221
- #ifdef MBED_HEAP_STATS_ENABLED
221
+ #if MBED_HEAP_STATS_ENABLED
222
222
// Note - no lock needed since malloc is thread safe
223
223
224
224
ptr = malloc (nmemb * size);
225
225
if (ptr != NULL ) {
226
226
memset (ptr, 0 , nmemb * size);
227
227
}
228
- #else // #ifdef MBED_HEAP_STATS_ENABLED
228
+ #else // #if MBED_HEAP_STATS_ENABLED
229
229
ptr = __real__calloc_r (r, nmemb, size);
230
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
231
- #ifdef MBED_MEM_TRACING_ENABLED
230
+ #endif // #if MBED_HEAP_STATS_ENABLED
231
+ #if MBED_MEM_TRACING_ENABLED
232
232
mbed_mem_trace_calloc (ptr, nmemb, size, MBED_CALLER_ADDR ());
233
233
mbed_mem_trace_unlock ();
234
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
234
+ #endif // #if MBED_MEM_TRACING_ENABLED
235
235
return ptr;
236
236
}
237
237
@@ -287,10 +287,10 @@ extern "C" void *SUB_MALLOC(size_t size)
287
287
extern " C" void *malloc_wrapper (size_t size, void *caller)
288
288
{
289
289
void *ptr = NULL ;
290
- #ifdef MBED_MEM_TRACING_ENABLED
290
+ #if MBED_MEM_TRACING_ENABLED
291
291
mbed_mem_trace_lock ();
292
292
#endif
293
- #ifdef MBED_HEAP_STATS_ENABLED
293
+ #if MBED_HEAP_STATS_ENABLED
294
294
malloc_stats_mutex->lock ();
295
295
alloc_info_t *alloc_info = (alloc_info_t *)SUPER_MALLOC (size + sizeof (alloc_info_t ));
296
296
if (alloc_info != NULL ) {
@@ -308,24 +308,24 @@ extern "C" void *malloc_wrapper(size_t size, void *caller)
308
308
heap_stats.alloc_fail_cnt += 1 ;
309
309
}
310
310
malloc_stats_mutex->unlock ();
311
- #else // #ifdef MBED_HEAP_STATS_ENABLED
311
+ #else // #if MBED_HEAP_STATS_ENABLED
312
312
ptr = SUPER_MALLOC (size);
313
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
314
- #ifdef MBED_MEM_TRACING_ENABLED
313
+ #endif // #if MBED_HEAP_STATS_ENABLED
314
+ #if MBED_MEM_TRACING_ENABLED
315
315
mbed_mem_trace_malloc (ptr, size, caller);
316
316
mbed_mem_trace_unlock ();
317
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
317
+ #endif // #if MBED_MEM_TRACING_ENABLED
318
318
return ptr;
319
319
}
320
320
321
321
322
322
extern " C" void *SUB_REALLOC (void *ptr, size_t size)
323
323
{
324
324
void *new_ptr = NULL ;
325
- #ifdef MBED_MEM_TRACING_ENABLED
325
+ #if MBED_MEM_TRACING_ENABLED
326
326
mbed_mem_trace_lock ();
327
327
#endif
328
- #ifdef MBED_HEAP_STATS_ENABLED
328
+ #if MBED_HEAP_STATS_ENABLED
329
329
// Note - no lock needed since malloc and free are thread safe
330
330
331
331
// Get old size
@@ -347,35 +347,35 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size)
347
347
memcpy (new_ptr, (void *)ptr, copy_size);
348
348
free (ptr);
349
349
}
350
- #else // #ifdef MBED_HEAP_STATS_ENABLED
350
+ #else // #if MBED_HEAP_STATS_ENABLED
351
351
new_ptr = SUPER_REALLOC (ptr, size);
352
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
353
- #ifdef MBED_MEM_TRACING_ENABLED
352
+ #endif // #if MBED_HEAP_STATS_ENABLED
353
+ #if MBED_MEM_TRACING_ENABLED
354
354
mbed_mem_trace_realloc (new_ptr, ptr, size, MBED_CALLER_ADDR ());
355
355
mbed_mem_trace_unlock ();
356
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
356
+ #endif // #if MBED_MEM_TRACING_ENABLED
357
357
return new_ptr;
358
358
}
359
359
360
360
extern " C" void *SUB_CALLOC (size_t nmemb, size_t size)
361
361
{
362
362
void *ptr = NULL ;
363
- #ifdef MBED_MEM_TRACING_ENABLED
363
+ #if MBED_MEM_TRACING_ENABLED
364
364
mbed_mem_trace_lock ();
365
365
#endif
366
- #ifdef MBED_HEAP_STATS_ENABLED
366
+ #if MBED_HEAP_STATS_ENABLED
367
367
// Note - no lock needed since malloc is thread safe
368
368
ptr = malloc (nmemb * size);
369
369
if (ptr != NULL ) {
370
370
memset (ptr, 0 , nmemb * size);
371
371
}
372
- #else // #ifdef MBED_HEAP_STATS_ENABLED
372
+ #else // #if MBED_HEAP_STATS_ENABLED
373
373
ptr = SUPER_CALLOC (nmemb, size);
374
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
375
- #ifdef MBED_MEM_TRACING_ENABLED
374
+ #endif // #if MBED_HEAP_STATS_ENABLED
375
+ #if MBED_MEM_TRACING_ENABLED
376
376
mbed_mem_trace_calloc (ptr, nmemb, size, MBED_CALLER_ADDR ());
377
377
mbed_mem_trace_unlock ();
378
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
378
+ #endif // #if MBED_MEM_TRACING_ENABLED
379
379
return ptr;
380
380
}
381
381
@@ -386,10 +386,10 @@ extern "C" void SUB_FREE(void *ptr)
386
386
387
387
extern " C" void free_wrapper (void *ptr, void *caller)
388
388
{
389
- #ifdef MBED_MEM_TRACING_ENABLED
389
+ #if MBED_MEM_TRACING_ENABLED
390
390
mbed_mem_trace_lock ();
391
391
#endif
392
- #ifdef MBED_HEAP_STATS_ENABLED
392
+ #if MBED_HEAP_STATS_ENABLED
393
393
malloc_stats_mutex->lock ();
394
394
alloc_info_t *alloc_info = NULL ;
395
395
if (ptr != NULL ) {
@@ -408,13 +408,13 @@ extern "C" void free_wrapper(void *ptr, void *caller)
408
408
}
409
409
410
410
malloc_stats_mutex->unlock ();
411
- #else // #ifdef MBED_HEAP_STATS_ENABLED
411
+ #else // #if MBED_HEAP_STATS_ENABLED
412
412
SUPER_FREE (ptr);
413
- #endif // #ifdef MBED_HEAP_STATS_ENABLED
414
- #ifdef MBED_MEM_TRACING_ENABLED
413
+ #endif // #if MBED_HEAP_STATS_ENABLED
414
+ #if MBED_MEM_TRACING_ENABLED
415
415
mbed_mem_trace_free (ptr, caller);
416
416
mbed_mem_trace_unlock ();
417
- #endif // #ifdef MBED_MEM_TRACING_ENABLED
417
+ #endif // #if MBED_MEM_TRACING_ENABLED
418
418
}
419
419
420
420
#endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED)
@@ -425,11 +425,11 @@ extern "C" void free_wrapper(void *ptr, void *caller)
425
425
426
426
#else
427
427
428
- #ifdef MBED_MEM_TRACING_ENABLED
428
+ #if MBED_MEM_TRACING_ENABLED
429
429
#error Memory tracing is not supported with the current toolchain.
430
430
#endif
431
431
432
- #ifdef MBED_HEAP_STATS_ENABLED
432
+ #if MBED_HEAP_STATS_ENABLED
433
433
#error Heap statistics are not supported with the current toolchain.
434
434
#endif
435
435
0 commit comments