From f4efe8b540b15ddd2294d9dd6cbbeb8063304e10 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Thu, 7 Sep 2006 03:57:02 +0000 Subject: [PATCH] Cleanup memory allocation calls to use macros defined in new mem.h header. This new header will handle configuration of both memory allocator to use, and memory profiling. [SVN r35029] --- src/engine/build.jam | 1 + src/engine/builtins.c | 1 - src/engine/command.c | 17 +++------ src/engine/compile.c | 6 +--- src/engine/debug.c | 1 - src/engine/execnt.c | 33 ++++++----------- src/engine/execunix.c | 4 +-- src/engine/filent.c | 5 +-- src/engine/fileunix.c | 7 ++-- src/engine/hash.c | 24 ++++--------- src/engine/hcache.c | 2 +- src/engine/jam.c | 9 ++--- src/engine/jam.h | 6 ++++ src/engine/lists.c | 5 +-- src/engine/make.c | 6 ++++ src/engine/make1.c | 8 ++--- src/engine/mem.h | 74 ++++++++++++++++++++++++++++++++++++++ src/engine/modules.c | 1 - src/engine/modules/order.c | 23 +++++------- src/engine/modules/regex.c | 6 ++-- src/engine/newstr.c | 9 ++--- src/engine/parse.c | 7 ++-- src/engine/regexp.c | 6 ++-- src/engine/rules.c | 35 ++++++------------ src/engine/scan.c | 7 ++-- src/engine/strings.c | 10 +++--- src/engine/timestamp.c | 1 - 27 files changed, 160 insertions(+), 154 deletions(-) create mode 100644 src/engine/mem.h diff --git a/src/engine/build.jam b/src/engine/build.jam index 43c024173..f95b31c91 100644 --- a/src/engine/build.jam +++ b/src/engine/build.jam @@ -418,6 +418,7 @@ if ! $(debug) || --noassert in $(ARGV) --defs += OPT_GRAPH_DEBUG_EXT ; --defs += OPT_SEMAPHORE ; --defs += OPT_AT_FILES ; +--defs += OPT_DEBUG_PROFILE ; # Bug fixes --defs += OPT_FIX_TARGET_VARIABLES_EXT ; diff --git a/src/engine/builtins.c b/src/engine/builtins.c index 30aa649ad..6be62b9d2 100644 --- a/src/engine/builtins.c +++ b/src/engine/builtins.c @@ -5,7 +5,6 @@ */ # include "jam.h" -# include "debug.h" # include "lists.h" # include "parse.h" diff --git a/src/engine/command.c b/src/engine/command.c index 727a3278c..712bd211e 100644 --- a/src/engine/command.c +++ b/src/engine/command.c @@ -20,7 +20,6 @@ # include "parse.h" # include "variable.h" # include "rules.h" -# include "debug.h" # include "command.h" # include @@ -37,15 +36,12 @@ cmd_new( LIST *sources, LIST *shell ) { - CMD *cmd = (CMD *)malloc( sizeof( CMD ) ); + CMD *cmd = (CMD *)BJAM_MALLOC( sizeof( CMD ) ); /* lift line-length limitation entirely when JAMSHELL is just "%" */ int no_limit = ( shell && !strcmp(shell->string,"%") && !list_next(shell) ); int max_line = MAXLINE; int allocated = -1; - if ( DEBUG_PROFILE ) - profile_memory( sizeof( CMD ) ); - cmd->rule = rule; cmd->shell = shell; cmd->next = 0; @@ -57,12 +53,9 @@ cmd_new( do { - free(cmd->buf); /* free any buffer from previous iteration */ + BJAM_FREE(cmd->buf); /* free any buffer from previous iteration */ - cmd->buf = (char*)malloc(max_line + 1); - - if ( DEBUG_PROFILE ) - profile_memory( max_line + 1 ); + cmd->buf = (char*)BJAM_MALLOC(max_line + 1); if (cmd->buf == 0) break; @@ -106,6 +99,6 @@ cmd_free( CMD *cmd ) { lol_free( &cmd->args ); list_free( cmd->shell ); - free( cmd->buf ); - free( (char *)cmd ); + BJAM_FREE( cmd->buf ); + BJAM_FREE( (char *)cmd ); } diff --git a/src/engine/compile.c b/src/engine/compile.c index 75464cf75..f44eb1213 100644 --- a/src/engine/compile.c +++ b/src/engine/compile.c @@ -11,7 +11,6 @@ */ # include "jam.h" -# include "debug.h" # include "lists.h" # include "parse.h" @@ -1007,12 +1006,9 @@ evaluate_rule( /* The action is associated with this instance of this rule */ - action = (ACTION *)malloc( sizeof( ACTION ) ); + action = (ACTION *)BJAM_MALLOC( sizeof( ACTION ) ); memset( (char *)action, '\0', sizeof( *action ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( ACTION ) ); - action->rule = rule; action->targets = targetlist( (TARGETS *)0, lol_get( frame->args, 0 ) ); action->sources = targetlist( (TARGETS *)0, lol_get( frame->args, 1 ) ); diff --git a/src/engine/debug.c b/src/engine/debug.c index d3f5ef04f..c6635d0d1 100644 --- a/src/engine/debug.c +++ b/src/engine/debug.c @@ -5,7 +5,6 @@ */ # include "jam.h" -# include "debug.h" # include "hash.h" diff --git a/src/engine/execnt.c b/src/engine/execnt.c index 081bc56ef..930ac3c11 100644 --- a/src/engine/execnt.c +++ b/src/engine/execnt.c @@ -14,7 +14,6 @@ # include "lists.h" # include "execcmd.h" # include "pathsys.h" -# include "debug.h" # include # include # include @@ -116,8 +115,8 @@ int maxline() static void free_argv( char** args ) { - free( args[0] ); - free( args ); + BJAM_FREE( args[0] ); + BJAM_FREE( args ); } /* Convert a command string into arguments for spawnvp. The original @@ -150,27 +149,21 @@ string_to_args( const char* string ) /* Copy the input string into a buffer we can modify */ - line = (char*)malloc( src_len+1 ); + line = (char*)BJAM_MALLOC( src_len+1 ); if (!line) return 0; - if ( DEBUG_PROFILE ) - profile_memory( src_len+1 ); - /* allocate the argv array. * element 0: stores the path to the executable * element 1: stores the command-line arguments to the executable * element 2: NULL terminator */ - argv = (char**)malloc( 3 * sizeof(char*) ); + argv = (char**)BJAM_MALLOC( 3 * sizeof(char*) ); if (!argv) { - free( line ); + BJAM_FREE( line ); return 0; } - - if ( DEBUG_PROFILE ) - profile_memory( 3 * sizeof(char*) ); /* Strip quotes from the first command-line argument and find * where it ends. Quotes are illegal in Win32 pathnames, so we @@ -287,11 +280,9 @@ process_del( char* command ) if ( len <= 0 ) return 1; - line = (char*)malloc( len+4+1 ); + line = (char*)BJAM_MALLOC( len+4+1 ); if (!line) return 1; - if ( DEBUG_PROFILE ) - profile_memory( len+4+1 ); strncpy( line, "del ", 4 ); strncpy( line+4, q, len ); @@ -302,7 +293,7 @@ process_del( char* command ) else result = !DeleteFile( line+4 ); - free( line ); + BJAM_FREE( line ); if (result) return 1; @@ -419,12 +410,12 @@ void execnt_unit_test() } { - char* long_command = malloc(MAXLINE + 10); + char* long_command = BJAM_MALLOC(MAXLINE + 10); assert( long_command != 0 ); memset( long_command, 'x', MAXLINE + 9 ); long_command[MAXLINE + 9] = 0; assert( can_spawn( long_command ) == MAXLINE + 9); - free( long_command ); + BJAM_FREE( long_command ); } { @@ -554,9 +545,7 @@ execcmd( DWORD procID = GetCurrentProcessId(); /* SVA - allocate 64 other just to be safe */ - cmdtab[ slot ].tempfile = malloc( strlen( tempdir ) + 64 ); - if ( DEBUG_PROFILE ) - profile_memory( strlen( tempdir ) + 64 ); + cmdtab[ slot ].tempfile = BJAM_MALLOC( strlen( tempdir ) + 64 ); sprintf( cmdtab[ slot ].tempfile, "%s\\jam%d-%02d.bat", tempdir, procID, slot ); @@ -840,7 +829,7 @@ execwait() /* SVA don't leak temp files */ if(cmdtab[i].tempfile != NULL) { - free(cmdtab[i].tempfile); + BJAM_FREE(cmdtab[i].tempfile); cmdtab[i].tempfile = NULL; } (*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time ); diff --git a/src/engine/execunix.c b/src/engine/execunix.c index 812dfeb8d..b543fbff9 100644 --- a/src/engine/execunix.c +++ b/src/engine/execunix.c @@ -256,9 +256,7 @@ my_wait( int *status ) if (!active_handles) { - active_handles = (HANDLE *)malloc(globs.jobs * sizeof(HANDLE) ); - if ( DEBUG_PROFILE ) - profile_memory( globs.jobs * sizeof(HANDLE) ); + active_handles = (HANDLE *)BJAM_MALLOC(globs.jobs * sizeof(HANDLE) ); } /* first see if any non-waited-for processes are dead, diff --git a/src/engine/filent.c b/src/engine/filent.c index 170a992d4..9c37b4e45 100644 --- a/src/engine/filent.c +++ b/src/engine/filent.c @@ -12,7 +12,6 @@ */ # include "jam.h" -# include "debug.h" # include "filesys.h" # include "pathsys.h" @@ -306,9 +305,7 @@ file_archscan( ** 15 characters (ie. don't fit into a ar_name */ - string_table = malloc(lar_size+1); - if ( DEBUG_PROFILE ) - profile_memory( lar_size+1 ); + string_table = BJAM_MALLOC(lar_size+1); if (read(fd, string_table, lar_size) != lar_size) printf("error reading string table\n"); string_table[lar_size] = '\0'; diff --git a/src/engine/fileunix.c b/src/engine/fileunix.c index 01eaad398..1f86d7d0f 100644 --- a/src/engine/fileunix.c +++ b/src/engine/fileunix.c @@ -12,7 +12,6 @@ */ # include "jam.h" -# include "debug.h" # include "filesys.h" # include "strings.h" # include "pathsys.h" @@ -326,9 +325,7 @@ file_archscan( ** 15 characters (ie. don't fit into a ar_name */ - string_table = (char *)malloc(lar_size); - if ( DEBUG_PROFILE ) - profile_memory( lar_size ); + string_table = (char *)BJAM_MALLOC(lar_size); lseek(fd, offset + SARHDR, 0); if (read(fd, string_table, lar_size) != lar_size) printf("error reading string table\n"); @@ -365,7 +362,7 @@ file_archscan( } if (string_table) - free(string_table); + BJAM_FREE(string_table); close( fd ); diff --git a/src/engine/hash.c b/src/engine/hash.c index dda649381..5e28dd1f9 100644 --- a/src/engine/hash.c +++ b/src/engine/hash.c @@ -7,7 +7,6 @@ # include "jam.h" # include "hash.h" # include "compile.h" -#include "debug.h" # include /* @@ -225,24 +224,18 @@ static void hashrehash( register struct hash *hp ) { int i = ++hp->items.list; hp->items.more = i ? 2 * hp->items.nel : hp->inel; - hp->items.next = (char *)malloc( hp->items.more * hp->items.size ); + hp->items.next = (char *)BJAM_MALLOC( hp->items.more * hp->items.size ); hp->items.free = 0; - - if ( DEBUG_PROFILE ) - profile_memory( hp->items.more * hp->items.size ); hp->items.lists[i].nel = hp->items.more; hp->items.lists[i].base = hp->items.next; hp->items.nel += hp->items.more; if( hp->tab.base ) - free( (char *)hp->tab.base ); + BJAM_FREE( (char *)hp->tab.base ); hp->tab.nel = hp->items.nel * hp->bloat; - hp->tab.base = (ITEM **)malloc( hp->tab.nel * sizeof(ITEM **) ); - - if ( DEBUG_PROFILE ) - profile_memory( hp->tab.nel * sizeof(ITEM **) ); + hp->tab.base = (ITEM **)BJAM_MALLOC( hp->tab.nel * sizeof(ITEM **) ); memset( (char *)hp->tab.base, '\0', hp->tab.nel * sizeof( ITEM * ) ); @@ -297,10 +290,7 @@ hashinit( int datalen, char *name ) { - struct hash *hp = (struct hash *)malloc( sizeof( *hp ) ); - - if ( DEBUG_PROFILE ) - profile_memory( sizeof( *hp ) ); + struct hash *hp = (struct hash *)BJAM_MALLOC( sizeof( *hp ) ); hp->bloat = 3; hp->tab.nel = 0; @@ -333,10 +323,10 @@ hashdone( struct hash *hp ) hashstat( hp ); if( hp->tab.base ) - free( (char *)hp->tab.base ); + BJAM_FREE( (char *)hp->tab.base ); for( i = 0; i <= hp->items.list; i++ ) - free( hp->items.lists[i].base ); - free( (char *)hp ); + BJAM_FREE( hp->items.lists[i].base ); + BJAM_FREE( (char *)hp ); } /* ---- */ diff --git a/src/engine/hcache.c b/src/engine/hcache.c index 091254684..5d2f24140 100644 --- a/src/engine/hcache.c +++ b/src/engine/hcache.c @@ -137,7 +137,7 @@ read_netstring(FILE* f) unsigned long new_len = buf_len * 2; if (new_len < len) new_len = len; - buf = (char*)realloc(buf, new_len + 1); + buf = (char*)BJAM_REALLOC(buf, new_len + 1); if (buf) buf_len = new_len; } diff --git a/src/engine/jam.c b/src/engine/jam.c index 633f19b1d..a8d4d920d 100644 --- a/src/engine/jam.c +++ b/src/engine/jam.c @@ -121,7 +121,6 @@ # include "make.h" # include "strings.h" # include "expand.h" -# include "debug.h" # include "filesys.h" /* Macintosh is "special" */ @@ -218,6 +217,8 @@ int main( int argc, char **argv, char **arg_environ ) int arg_c = argc; char ** arg_v = argv; const char *progname = argv[0]; + + BJAM_MEM_INIT(); # ifdef OS_MAC InitGraf(&qd.thePort); @@ -485,10 +486,8 @@ int main( int argc, char **argv, char **arg_environ ) else { int targets_count = list_length(targets); - const char **targets2 = (const char **)malloc(targets_count * sizeof(char *)); + const char **targets2 = (const char **)BJAM_MALLOC(targets_count * sizeof(char *)); int n = 0; - if ( DEBUG_PROFILE ) - profile_memory( targets_count * sizeof(char *) ); for ( ; targets; targets = list_next(targets) ) { targets2[n++] = targets->string; @@ -522,6 +521,8 @@ int main( int argc, char **argv, char **arg_environ ) #ifdef HAVE_PYTHON Py_Finalize(); #endif + + BJAM_MEM_CLOSE(); return status ? EXITBAD : EXITOK; diff --git a/src/engine/jam.h b/src/engine/jam.h index 5ecc3ac83..c15df9292 100644 --- a/src/engine/jam.h +++ b/src/engine/jam.h @@ -556,4 +556,10 @@ extern struct globs globs; # define DEBUG_GRAPH ( globs.debug[ 12 ] ) /* debug dependencies */ # define DEBUG_FATE ( globs.debug[ 13 ] ) /* show changes to fate in make0() */ +/* Everyone gets the memory definitions. */ +#include "mem.h" + +/* They also get the profile functions. */ +#include "debug.h" + #endif diff --git a/src/engine/lists.c b/src/engine/lists.c index 92440288c..205c9777b 100644 --- a/src/engine/lists.c +++ b/src/engine/lists.c @@ -7,7 +7,6 @@ # include "jam.h" # include "newstr.h" # include "lists.h" -# include "debug.h" /* * lists.c - maintain lists of strings @@ -81,9 +80,7 @@ list_new( } else { - l = (LIST *)malloc( sizeof( LIST ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( LIST ) ); + l = (LIST *)BJAM_MALLOC( sizeof( LIST ) ); } /* If first on chain, head points here. */ diff --git a/src/engine/make.c b/src/engine/make.c index a112855af..5bb5dc34b 100644 --- a/src/engine/make.c +++ b/src/engine/make.c @@ -126,12 +126,14 @@ make( */ bind_explicitly_located_targets(); + { PROFILE_ENTER(MAKE_MAKE0); for( i = 0; i < n_targets; i++ ) { TARGET *t = bindtarget( targets[i] ); make0( t, 0, 0, counts, anyhow ); } + PROFILE_EXIT(MAKE_MAKE0); } #ifdef OPT_GRAPH_DEBUG_EXT if( DEBUG_GRAPH ) @@ -169,8 +171,10 @@ make( status = counts->cantfind || counts->cantmake; + { PROFILE_ENTER(MAKE_MAKE1); for( i = 0; i < n_targets; i++ ) status |= make1( bindtarget( targets[i] ) ); + PROFILE_EXIT(MAKE_MAKE1); } return status; } @@ -795,6 +799,7 @@ dependGraphOutput( TARGET *t, int depth ) static TARGETS * make0sort( TARGETS *chain ) { + PROFILE_ENTER(MAKE_MAKE0SORT); TARGETS *result = 0; /* We walk chain, taking each item and inserting it on the */ @@ -829,6 +834,7 @@ make0sort( TARGETS *chain ) s->tail = c; /* make next's prev us */ } + PROFILE_EXIT(MAKE_MAKE0SORT); return result; } diff --git a/src/engine/make1.c b/src/engine/make1.c index 030009e78..2636ad116 100644 --- a/src/engine/make1.c +++ b/src/engine/make1.c @@ -127,9 +127,7 @@ static state *alloc_state() } else { - if ( DEBUG_PROFILE ) - profile_memory( sizeof(state) ); - return (state *)malloc(sizeof(state)); + return (state *)BJAM_MALLOC(sizeof(state)); } } @@ -145,7 +143,7 @@ static void clear_state_freelist() { state *pState = state_freelist; state_freelist = state_freelist->prev; - free(pState); + BJAM_FREE(pState); } } @@ -650,7 +648,7 @@ make1c( state *pState ) if( DEBUG_EXECCMD ) printf( "SEM: placing %s on stack\n", first->target->name); push_state(&temp_stack, first->target, NULL, T_STATE_MAKE1B); - free( first ); + BJAM_FREE( first ); } } #endif diff --git a/src/engine/mem.h b/src/engine/mem.h new file mode 100644 index 000000000..ed6f2ea52 --- /dev/null +++ b/src/engine/mem.h @@ -0,0 +1,74 @@ +/* +Copyright Rene Rivera 2006. +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at +http://www.boost.org/LICENSE_1_0.txt) +*/ + +#ifndef BJAM_MEM_H +#define BJAM_MEM_H + + +#ifdef OPT_BOEHM_GC + + /* Use Boehm GC memory allocator. */ + #include + #define bjam_malloc_x(s) GC_malloc(s) + #define bjam_malloc_atomic_x(s) GC_malloc_atomic(s) + #define bjam_calloc_x(n,s) memset(GC_malloc((n)*(s)),0,(n)*(s)) + #define bjam_calloc_atomic_x(n,s) memset(GC_malloc_atomic((n)*(s)),0,(n)*(s)) + #define bjam_realloc_x(p,s) GC_realloc(p,s) + #define bjam_free_x(p) GC_free(p) + #define bjam_mem_init_x() GC_init() + +#else + + /* Standard C memory allocation. */ + #define bjam_malloc_x(s) malloc(s) + #define bjam_calloc_x(n,s) calloc(n,s) + #define bjam_realloc_x(p,s) realloc(p,s) + #define bjam_free_x(p) free(p) + +#endif + +#ifndef bjam_malloc_atomic_x + #define bjam_malloc_atomic_x(s) bjam_malloc_x(s) +#endif +#ifndef bjam_calloc_atomic_x + #define bjam_calloc_atomic_x(s) bjam_calloc_x(s) +#endif +#ifndef bjam_mem_init_x + #define bjam_mem_init_x() +#endif +#ifndef bjam_mem_close_x + #define bjam_mem_close_x() +#endif + +#ifdef OPT_DEBUG_PROFILE + + /* Profile tracing of memory allocations. */ + #define BJAM_MALLOC(s) (profile_memory(s), bjam_malloc_x(s)) + #define BJAM_MALLOC_ATOMIC(s) (profile_memory(s), bjam_malloc_atomic_x(s)) + #define BJAM_CALLOC(n,s) (profile_memory(n*s), bjam_calloc_x(n,s)) + #define BJAM_CALLOC_ATOMIC(n,s) (profile_memory(n*s), bjam_calloc_atomic_x(n,s)) + #define BJAM_REALLOC(p,s) (profile_memory(s), bjam_realloc_x(p,s)) + #define BJAM_FREE(p) bjam_free_x(p) + #define BJAM_MEM_INIT() bjam_mem_init_x() + #define BJAM_MEM_CLOSE() bjam_mem_close_x() + +#else + + /* No mem tracing. */ + #define BJAM_MALLOC(s) bjam_malloc_x(s) + #define BJAM_MALLOC_ATOMIC(s) bjam_malloc_atomic_x(s) + #define BJAM_CALLOC(n,s) bjam_calloc_x(n,s) + #define BJAM_CALLOC_ATOMIC(n,s) bjam_calloc_atomic_x(n,s) + #define BJAM_REALLOC(p,s) bjam_realloc_x(p,s) + #define BJAM_FREE(p) bjam_free_x(p) + #define BJAM_MEM_INIT() bjam_mem_init_x() + #define BJAM_MEM_CLOSE() bjam_mem_close_x() + +#endif + + +#endif diff --git a/src/engine/modules.c b/src/engine/modules.c index ea874b640..938802ae0 100644 --- a/src/engine/modules.c +++ b/src/engine/modules.c @@ -4,7 +4,6 @@ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) */ #include "jam.h" -#include "debug.h" #include "modules.h" #include "string.h" diff --git a/src/engine/modules/order.c b/src/engine/modules/order.c index 848c35ee1..48761e80d 100644 --- a/src/engine/modules/order.c +++ b/src/engine/modules/order.c @@ -7,7 +7,6 @@ #include "../strings.h" #include "../newstr.h" #include "../variable.h" -#include "../debug.h" /* Use quite klugy approach: when we add order dependency from 'a' to 'b', @@ -62,9 +61,7 @@ void do_ts(int** graph, int current_vertex, int* colors, int** result_ptr) void topological_sort(int** graph, int num_vertices, int* result) { int i; - int* colors = (int*)calloc(num_vertices, sizeof(int)); - if ( DEBUG_PROFILE ) - profile_memory( num_vertices*sizeof(int) ); + int* colors = (int*)BJAM_CALLOC(num_vertices, sizeof(int)); for (i = 0; i < num_vertices; ++i) colors[i] = white; @@ -72,7 +69,7 @@ void topological_sort(int** graph, int num_vertices, int* result) if (colors[i] == white) do_ts(graph, i, colors, &result); - free(colors); + BJAM_FREE(colors); } LIST *order( PARSE *parse, FRAME *frame ) @@ -87,10 +84,8 @@ LIST *order( PARSE *parse, FRAME *frame ) passed to 'add_pair'. */ int length = list_length(arg); - int** graph = (int**)calloc(length, sizeof(int*)); - int* order = (int*)malloc((length+1)*sizeof(int)); - if ( DEBUG_PROFILE ) - profile_memory( length*sizeof(int*) + (length+1)*sizeof(int) ); + int** graph = (int**)BJAM_CALLOC(length, sizeof(int*)); + int* order = (int*)BJAM_MALLOC((length+1)*sizeof(int)); for(tmp = arg, src = 0; tmp; tmp = tmp->next, ++src) { /* For all object this one depend upon, add elements @@ -98,9 +93,7 @@ LIST *order( PARSE *parse, FRAME *frame ) LIST* dependencies = var_get(tmp->string); int index = 0; - graph[src] = (int*)calloc(list_length(dependencies)+1, sizeof(int)); - if ( DEBUG_PROFILE ) - profile_memory( (list_length(dependencies)+1)*sizeof(int) ); + graph[src] = (int*)BJAM_CALLOC(list_length(dependencies)+1, sizeof(int)); for(; dependencies; dependencies = dependencies->next) { int dst = list_index(arg, dependencies->string); if (dst != -1) @@ -125,9 +118,9 @@ LIST *order( PARSE *parse, FRAME *frame ) { int i; for(i = 0; i < length; ++i) - free(graph[i]); - free(graph); - free(order); + BJAM_FREE(graph[i]); + BJAM_FREE(graph); + BJAM_FREE(order); } return result; diff --git a/src/engine/modules/regex.c b/src/engine/modules/regex.c index 4f3cc8f46..d048ba1de 100644 --- a/src/engine/modules/regex.c +++ b/src/engine/modules/regex.c @@ -41,7 +41,7 @@ LIST *regex_transform( PARSE *parse, FRAME *frame ) if (indices_list) { size = list_length(indices_list); - indices = (int*)malloc(size*sizeof(int)); + indices = (int*)BJAM_MALLOC(size*sizeof(int)); for(p = indices; indices_list; indices_list = indices_list->next) { *p++ = atoi(indices_list->string); @@ -50,7 +50,7 @@ LIST *regex_transform( PARSE *parse, FRAME *frame ) else { size = 1; - indices = (int*)malloc(sizeof(int)); + indices = (int*)BJAM_MALLOC(sizeof(int)); *indices = 1; } @@ -82,7 +82,7 @@ LIST *regex_transform( PARSE *parse, FRAME *frame ) string_free( buf ); } - free(indices); + BJAM_FREE(indices); return result; } diff --git a/src/engine/newstr.c b/src/engine/newstr.c index 670cee504..c7265c1b9 100644 --- a/src/engine/newstr.c +++ b/src/engine/newstr.c @@ -68,7 +68,7 @@ static char* storage_finish = 0; static char* allocate(size_t n) { #if SIMPLE_ALLOC - return (char*)malloc(n); + return (char*)BJAM_MALLOC(n); #else /* See if we can grab storage from an existing block */ size_t remaining = storage_finish - storage_start; @@ -86,7 +86,7 @@ static char* allocate(size_t n) nalloc = STRING_BLOCK; /* allocate a new block and link into the chain */ - new_block = (strblock*)malloc( offsetof( strblock, data[0] ) + nalloc * sizeof(new_block->data[0]) ); + new_block = (strblock*)BJAM_MALLOC( offsetof( strblock, data[0] ) + nalloc * sizeof(new_block->data[0]) ); if ( new_block == 0 ) return 0; new_block->next = strblock_chain; @@ -125,9 +125,6 @@ newstr( char *string ) strtotal += l + 1; memcpy( m, string, l + 1 ); *s = m; - - if ( DEBUG_PROFILE ) - profile_memory( l+1 ); } strcount_in += 1; @@ -166,7 +163,7 @@ donestr() while ( strblock_chain != 0 ) { strblock* n = strblock_chain->next; - free(strblock_chain); + BJAM_FREE(strblock_chain); strblock_chain = n; } diff --git a/src/engine/parse.c b/src/engine/parse.c index 606112ec8..fc92ce95f 100644 --- a/src/engine/parse.c +++ b/src/engine/parse.c @@ -17,7 +17,6 @@ # include "newstr.h" # include "modules.h" # include "frames.h" -# include "debug.h" /* * parse.c - make and destroy parse trees as driven by the parser @@ -78,9 +77,7 @@ parse_make( char *string1, int num ) { - PARSE *p = (PARSE *)malloc( sizeof( PARSE ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( PARSE ) ); + PARSE *p = (PARSE *)BJAM_MALLOC( sizeof( PARSE ) ); p->func = func; p->left = left; @@ -130,7 +127,7 @@ parse_free( PARSE *p ) if ( p->rulename ) freestr( p->rulename ); - free( (char *)p ); + BJAM_FREE( (char *)p ); } LIST* parse_evaluate( PARSE *p, FRAME* frame ) diff --git a/src/engine/regexp.c b/src/engine/regexp.c index 33cd9f968..ea2875109 100644 --- a/src/engine/regexp.c +++ b/src/engine/regexp.c @@ -41,8 +41,8 @@ * precedence is structured in regular expressions. Serious changes in * regular-expression syntax might require a total rethink. */ +#include "jam.h" #include "regexp.h" -#include "debug.h" #include #include #ifndef ultrix @@ -239,11 +239,9 @@ regcomp( char *exp ) FAIL("regexp too big"); /* Allocate space. */ - r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize); + r = (regexp *)BJAM_MALLOC(sizeof(regexp) + (unsigned)regsize); if (r == NULL) FAIL("out of space"); - if ( DEBUG_PROFILE ) - profile_memory( sizeof(regexp) + (unsigned)regsize ); /* Second pass: emit code. */ regparse = (char *)exp; diff --git a/src/engine/rules.c b/src/engine/rules.c index 2902995c3..0c044aba5 100644 --- a/src/engine/rules.c +++ b/src/engine/rules.c @@ -16,7 +16,6 @@ # include "lists.h" # include "pathsys.h" # include "timestamp.h" -# include "debug.h" /* This file is ALSO: * Copyright 2001-2004 David Abrahams. @@ -265,9 +264,7 @@ copytarget( const TARGET *ot ) { TARGET *t; - t = (TARGET *)malloc( sizeof( *t ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( *t ) ); + t = (TARGET *)BJAM_MALLOC( sizeof( *t ) ); memset( (char *)t, '\0', sizeof( *t ) ); t->name = copystr( ot->name ); t->boundname = t->name; @@ -321,9 +318,7 @@ targetentry( { TARGETS *c; - c = (TARGETS *)malloc( sizeof( TARGETS ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( TARGETS ) ); + c = (TARGETS *)BJAM_MALLOC( sizeof( TARGETS ) ); c->target = target; if( !chain ) chain = c; @@ -369,9 +364,7 @@ actionlist( ACTIONS *chain, ACTION *action ) { - ACTIONS *actions = (ACTIONS *)malloc( sizeof( ACTIONS ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( ACTIONS ) ); + ACTIONS *actions = (ACTIONS *)BJAM_MALLOC( sizeof( ACTIONS ) ); actions->action = action; @@ -421,9 +414,7 @@ addsettings( settings_freelist = v->next; else { - v = (SETTINGS *)malloc( sizeof( *v ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( *v ) ); + v = (SETTINGS *)BJAM_MALLOC( sizeof( *v ) ); } v->symbol = newstr( symbol ); @@ -489,7 +480,7 @@ void freetargets( TARGETS *chain ) while( chain ) { TARGETS* n = chain->next; - free( chain ); + BJAM_FREE( chain ); chain = n; } } @@ -502,7 +493,7 @@ void freeactions( ACTIONS *chain ) while( chain ) { ACTIONS* n = chain->next; - free( chain ); + BJAM_FREE( chain ); chain = n; } } @@ -553,7 +544,7 @@ donerules() while ( settings_freelist ) { SETTINGS* n = settings_freelist->next; - free( settings_freelist ); + BJAM_FREE( settings_freelist ); settings_freelist = n; } } @@ -563,9 +554,7 @@ donerules() */ argument_list* args_new() { - argument_list* r = (argument_list*)malloc( sizeof(argument_list) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof(argument_list) ); + argument_list* r = (argument_list*)BJAM_MALLOC( sizeof(argument_list) ); r->reference_count = 0; lol_init(r->data); return r; @@ -587,7 +576,7 @@ void args_free( argument_list* a ) if (--a->reference_count <= 0) { lol_free(a->data); - free(a); + BJAM_FREE(a); } } @@ -608,7 +597,7 @@ void actions_free(rule_actions* a) { freestr(a->command); list_free(a->bindlist); - free(a); + BJAM_FREE(a); } } @@ -702,9 +691,7 @@ static void set_rule_actions( RULE* rule, rule_actions* actions ) static rule_actions* actions_new( char* command, LIST* bindlist, int flags ) { - rule_actions* result = (rule_actions*)malloc(sizeof(rule_actions)); - if ( DEBUG_PROFILE ) - profile_memory( sizeof(rule_actions) ); + rule_actions* result = (rule_actions*)BJAM_MALLOC(sizeof(rule_actions)); result->command = copystr( command ); result->bindlist = bindlist; result->flags = flags; diff --git a/src/engine/scan.c b/src/engine/scan.c index 1145ac858..fd198b68d 100644 --- a/src/engine/scan.c +++ b/src/engine/scan.c @@ -11,7 +11,6 @@ # include "jamgram.h" # include "jambase.h" # include "newstr.h" -# include "debug.h" /* * scan.c - the jam yacc scanner @@ -82,9 +81,7 @@ yyanyerrors() void yyfparse( char *s ) { - struct include *i = (struct include *)malloc( sizeof( *i ) ); - if ( DEBUG_PROFILE ) - profile_memory( sizeof( *i ) ); + struct include *i = (struct include *)BJAM_MALLOC( sizeof( *i ) ); /* Push this onto the incp chain. */ @@ -171,7 +168,7 @@ yyline() if( i->file && i->file != stdin ) fclose( i->file ); freestr( i->fname ); - free( (char *)i ); + BJAM_FREE( (char *)i ); return EOF; } diff --git a/src/engine/strings.c b/src/engine/strings.c index 6c093c6b7..67c8dc75e 100644 --- a/src/engine/strings.c +++ b/src/engine/strings.c @@ -2,8 +2,8 @@ /* Software License, Version 1.0. (See accompanying */ /* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ +#include "jam.h" #include "strings.h" -#include "debug.h" #include #include #include @@ -48,23 +48,21 @@ void string_free( string* s ) { assert_invariants( s ); if ( s->value != s->opt ) - free( s->value ); + BJAM_FREE( s->value ); } static void string_reserve_internal( string* self, size_t capacity ) { if ( self->value == self->opt ) { - self->value = (char*)malloc( capacity + JAM_STRING_MAGIC_SIZE ); - if ( DEBUG_PROFILE ) - profile_memory( capacity + JAM_STRING_MAGIC_SIZE ); + self->value = (char*)BJAM_MALLOC( capacity + JAM_STRING_MAGIC_SIZE ); self->value[0] = 0; strncat( self->value, self->opt, sizeof(self->opt) ); assert( strlen( self->value ) <= self->capacity ); /* This is a regression test */ } else { - self->value = (char*)realloc( self->value, capacity + JAM_STRING_MAGIC_SIZE ); + self->value = (char*)BJAM_REALLOC( self->value, capacity + JAM_STRING_MAGIC_SIZE ); } #ifndef NDEBUG memcpy( self->value + capacity, self->magic, JAM_STRING_MAGIC_SIZE ); diff --git a/src/engine/timestamp.c b/src/engine/timestamp.c index 3c5643108..14a16d9af 100644 --- a/src/engine/timestamp.c +++ b/src/engine/timestamp.c @@ -11,7 +11,6 @@ */ # include "jam.h" -# include "debug.h" # include "hash.h" # include "filesys.h"