1 /*
2  * Copyright 2006. Rene Rivera
3  * Distributed under the Boost Software License, Version 1.0.
4  * (See accompanying file LICENSE_1_0.txt or copy at
5  * http://www.boost.org/LICENSE_1_0.txt)
6  */
7 
8 #ifndef BJAM_MEM_H
9 #define BJAM_MEM_H
10 
11 #include "config.h"
12 
13 /* Standard C memory allocation. */
14 #include <stdlib.h>
15 
16 #define bjam_malloc_x(s) malloc(s)
17 #define bjam_calloc_x(n,s) calloc(n,s)
18 #define bjam_realloc_x(p,s) realloc(p,s)
19 #define bjam_free_x(p) free(p)
20 
21 #ifndef bjam_malloc_atomic_x
22     #define bjam_malloc_atomic_x(s) bjam_malloc_x(s)
23 #endif
24 #ifndef bjam_calloc_atomic_x
25     #define bjam_calloc_atomic_x(n,s) bjam_calloc_x(n,s)
26 #endif
27 #ifndef bjam_mem_init_x
28     #define bjam_mem_init_x()
29 #endif
30 #ifndef bjam_mem_close_x
31     #define bjam_mem_close_x()
32 #endif
33 #ifndef bjam_malloc_raw_x
34     #define bjam_malloc_raw_x(s) bjam_malloc_x(s)
35 #endif
36 #ifndef bjam_calloc_raw_x
37     #define bjam_calloc_raw_x(n,s) bjam_calloc_x(n,s)
38 #endif
39 #ifndef bjam_realloc_raw_x
40     #define bjam_realloc_raw_x(p,s) bjam_realloc_x(p,s)
41 #endif
42 #ifndef bjam_free_raw_x
43     #define bjam_free_raw_x(p) bjam_free_x(p)
44 #endif
45 
46 #ifdef OPT_DEBUG_PROFILE
47     /* Profile tracing of memory allocations. */
48     #include "debug.h"
49 
50     #define BJAM_MALLOC(s) (profile_memory(s), bjam_malloc_x(s))
51     #define BJAM_MALLOC_ATOMIC(s) (profile_memory(s), bjam_malloc_atomic_x(s))
52     #define BJAM_CALLOC(n,s) (profile_memory(n*s), bjam_calloc_x(n,s))
53     #define BJAM_CALLOC_ATOMIC(n,s) (profile_memory(n*s), bjam_calloc_atomic_x(n,s))
54     #define BJAM_REALLOC(p,s) (profile_memory(s), bjam_realloc_x(p,s))
55 
56     #define BJAM_MALLOC_RAW(s) (profile_memory(s), bjam_malloc_raw_x(s))
57     #define BJAM_CALLOC_RAW(n,s) (profile_memory(n*s), bjam_calloc_raw_x(n,s))
58     #define BJAM_REALLOC_RAW(p,s) (profile_memory(s), bjam_realloc_raw_x(p,s))
59 #else
60     /* No mem tracing. */
61     #define BJAM_MALLOC(s) bjam_malloc_x(s)
62     #define BJAM_MALLOC_ATOMIC(s) bjam_malloc_atomic_x(s)
63     #define BJAM_CALLOC(n,s) bjam_calloc_x(n,s)
64     #define BJAM_CALLOC_ATOMIC(n,s) bjam_calloc_atomic_x(n,s)
65     #define BJAM_REALLOC(p,s) bjam_realloc_x(p,s)
66 
67     #define BJAM_MALLOC_RAW(s) bjam_malloc_raw_x(s)
68     #define BJAM_CALLOC_RAW(n,s) bjam_calloc_raw_x(n,s)
69     #define BJAM_REALLOC_RAW(p,s) bjam_realloc_raw_x(p,s)
70 #endif
71 
72 #define BJAM_MEM_INIT() bjam_mem_init_x()
73 #define BJAM_MEM_CLOSE() bjam_mem_close_x()
74 
75 #define BJAM_FREE(p) bjam_free_x(p)
76 #define BJAM_FREE_RAW(p) bjam_free_raw_x(p)
77 
78 #endif
79