2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-12 12:02:24 +00:00

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]
This commit is contained in:
Rene Rivera
2006-09-07 03:57:02 +00:00
parent ec9f39dc0e
commit f4efe8b540
27 changed files with 160 additions and 154 deletions

View File

@@ -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 ;

View File

@@ -5,7 +5,6 @@
*/
# include "jam.h"
# include "debug.h"
# include "lists.h"
# include "parse.h"

View File

@@ -20,7 +20,6 @@
# include "parse.h"
# include "variable.h"
# include "rules.h"
# include "debug.h"
# include "command.h"
# include <limits.h>
@@ -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 );
}

View File

@@ -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 ) );

View File

@@ -5,7 +5,6 @@
*/
# include "jam.h"
# include "debug.h"
# include "hash.h"

View File

@@ -14,7 +14,6 @@
# include "lists.h"
# include "execcmd.h"
# include "pathsys.h"
# include "debug.h"
# include <errno.h>
# include <assert.h>
# include <ctype.h>
@@ -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 );

View File

@@ -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,

View File

@@ -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';

View File

@@ -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 );

View File

@@ -7,7 +7,6 @@
# include "jam.h"
# include "hash.h"
# include "compile.h"
#include "debug.h"
# include <assert.h>
/*
@@ -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 );
}
/* ---- */

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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. */

View File

@@ -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;
}

View File

@@ -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

74
src/engine/mem.h Normal file
View File

@@ -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 <gc.h>
#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

View File

@@ -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"

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 )

View File

@@ -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 <stdio.h>
#include <ctype.h>
#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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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 <stdlib.h>
#include <string.h>
#include <assert.h>
@@ -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 );

View File

@@ -11,7 +11,6 @@
*/
# include "jam.h"
# include "debug.h"
# include "hash.h"
# include "filesys.h"