mirror of
https://github.com/boostorg/build.git
synced 2026-02-16 01:12:13 +00:00
Implement gc of string only hash entries (note, doesn't work likely because a buffer overrun in var expand). Allocate all character data as atomic.
[SVN r35036]
This commit is contained in:
@@ -55,7 +55,7 @@ cmd_new(
|
||||
{
|
||||
BJAM_FREE(cmd->buf); /* free any buffer from previous iteration */
|
||||
|
||||
cmd->buf = (char*)BJAM_MALLOC(max_line + 1);
|
||||
cmd->buf = (char*)BJAM_MALLOC_ATOMIC(max_line + 1);
|
||||
|
||||
if (cmd->buf == 0)
|
||||
break;
|
||||
|
||||
@@ -149,7 +149,7 @@ string_to_args( const char* string )
|
||||
|
||||
/* Copy the input string into a buffer we can modify
|
||||
*/
|
||||
line = (char*)BJAM_MALLOC( src_len+1 );
|
||||
line = (char*)BJAM_MALLOC_ATOMIC( src_len+1 );
|
||||
if (!line)
|
||||
return 0;
|
||||
|
||||
@@ -280,7 +280,7 @@ process_del( char* command )
|
||||
if ( len <= 0 )
|
||||
return 1;
|
||||
|
||||
line = (char*)BJAM_MALLOC( len+4+1 );
|
||||
line = (char*)BJAM_MALLOC_ATOMIC( len+4+1 );
|
||||
if (!line)
|
||||
return 1;
|
||||
|
||||
@@ -410,7 +410,7 @@ void execnt_unit_test()
|
||||
}
|
||||
|
||||
{
|
||||
char* long_command = BJAM_MALLOC(MAXLINE + 10);
|
||||
char* long_command = BJAM_MALLOC_ATOMIC(MAXLINE + 10);
|
||||
assert( long_command != 0 );
|
||||
memset( long_command, 'x', MAXLINE + 9 );
|
||||
long_command[MAXLINE + 9] = 0;
|
||||
@@ -545,7 +545,7 @@ execcmd(
|
||||
DWORD procID = GetCurrentProcessId();
|
||||
|
||||
/* SVA - allocate 64 other just to be safe */
|
||||
cmdtab[ slot ].tempfile = BJAM_MALLOC( strlen( tempdir ) + 64 );
|
||||
cmdtab[ slot ].tempfile = BJAM_MALLOC_ATOMIC( strlen( tempdir ) + 64 );
|
||||
|
||||
sprintf( cmdtab[ slot ].tempfile, "%s\\jam%d-%02d.bat",
|
||||
tempdir, procID, slot );
|
||||
|
||||
@@ -305,7 +305,7 @@ file_archscan(
|
||||
** 15 characters (ie. don't fit into a ar_name
|
||||
*/
|
||||
|
||||
string_table = BJAM_MALLOC(lar_size+1);
|
||||
string_table = BJAM_MALLOC_ATOMIC(lar_size+1);
|
||||
if (read(fd, string_table, lar_size) != lar_size)
|
||||
printf("error reading string table\n");
|
||||
string_table[lar_size] = '\0';
|
||||
|
||||
@@ -325,7 +325,7 @@ file_archscan(
|
||||
** 15 characters (ie. don't fit into a ar_name
|
||||
*/
|
||||
|
||||
string_table = (char *)BJAM_MALLOC(lar_size);
|
||||
string_table = (char *)BJAM_MALLOC_ATOMIC(lar_size);
|
||||
lseek(fd, offset + SARHDR, 0);
|
||||
if (read(fd, string_table, lar_size) != lar_size)
|
||||
printf("error reading string table\n");
|
||||
|
||||
@@ -90,6 +90,11 @@ struct hash
|
||||
|
||||
static void hashrehash( struct hash *hp );
|
||||
static void hashstat( struct hash *hp );
|
||||
static void * hash_mem_alloc(size_t datalen, size_t size);
|
||||
static void hash_mem_free(size_t datalen, void * data);
|
||||
#ifdef OPT_BOEHM_GC
|
||||
static void hash_mem_finalizer(char * key, struct hash * hp);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* hash_free() - remove the given item from the table if it's there.
|
||||
@@ -207,6 +212,12 @@ hashitem(
|
||||
i->hdr.next = *base;
|
||||
*base = i;
|
||||
*data = &i->data;
|
||||
#ifdef OPT_BOEHM_GC
|
||||
if (sizeof(HASHDATA) == hp->items.datalen)
|
||||
{
|
||||
GC_REGISTER_FINALIZER(i->data.key,&hash_mem_finalizer,hp,0,0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HASH_DEBUG_PROFILE
|
||||
@@ -224,7 +235,7 @@ 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 *)BJAM_MALLOC( hp->items.more * hp->items.size );
|
||||
hp->items.next = (char *)hash_mem_alloc( hp->items.datalen, hp->items.more * hp->items.size );
|
||||
hp->items.free = 0;
|
||||
|
||||
hp->items.lists[i].nel = hp->items.more;
|
||||
@@ -232,10 +243,10 @@ static void hashrehash( register struct hash *hp )
|
||||
hp->items.nel += hp->items.more;
|
||||
|
||||
if( hp->tab.base )
|
||||
BJAM_FREE( (char *)hp->tab.base );
|
||||
hash_mem_free( hp->items.datalen, (char *)hp->tab.base );
|
||||
|
||||
hp->tab.nel = hp->items.nel * hp->bloat;
|
||||
hp->tab.base = (ITEM **)BJAM_MALLOC( hp->tab.nel * sizeof(ITEM **) );
|
||||
hp->tab.base = (ITEM **)hash_mem_alloc( hp->items.datalen, hp->tab.nel * sizeof(ITEM **) );
|
||||
|
||||
memset( (char *)hp->tab.base, '\0', hp->tab.nel * sizeof( ITEM * ) );
|
||||
|
||||
@@ -290,7 +301,7 @@ hashinit(
|
||||
int datalen,
|
||||
char *name )
|
||||
{
|
||||
struct hash *hp = (struct hash *)BJAM_MALLOC( sizeof( *hp ) );
|
||||
struct hash *hp = (struct hash *)hash_mem_alloc( datalen, sizeof( *hp ) );
|
||||
|
||||
hp->bloat = 3;
|
||||
hp->tab.nel = 0;
|
||||
@@ -323,12 +334,46 @@ hashdone( struct hash *hp )
|
||||
hashstat( hp );
|
||||
|
||||
if( hp->tab.base )
|
||||
BJAM_FREE( (char *)hp->tab.base );
|
||||
hash_mem_free( hp->items.datalen, (char *)hp->tab.base );
|
||||
for( i = 0; i <= hp->items.list; i++ )
|
||||
BJAM_FREE( hp->items.lists[i].base );
|
||||
BJAM_FREE( (char *)hp );
|
||||
hash_mem_free( hp->items.datalen, hp->items.lists[i].base );
|
||||
hash_mem_free( hp->items.datalen, (char *)hp );
|
||||
}
|
||||
|
||||
static void * hash_mem_alloc(size_t datalen, size_t size)
|
||||
{
|
||||
if (sizeof(HASHDATA) == datalen)
|
||||
{
|
||||
return BJAM_MALLOC_RAW(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BJAM_MALLOC(size);
|
||||
}
|
||||
}
|
||||
|
||||
static void hash_mem_free(size_t datalen, void * data)
|
||||
{
|
||||
if (sizeof(HASHDATA) == datalen)
|
||||
{
|
||||
BJAM_FREE_RAW(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
BJAM_FREE(data);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPT_BOEHM_GC
|
||||
static void hash_mem_finalizer(char * key, struct hash * hp)
|
||||
{
|
||||
HASHDATA d;
|
||||
d.key = (char*)key;
|
||||
hash_free(hp,&d);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* ---- */
|
||||
|
||||
static void
|
||||
|
||||
@@ -13,8 +13,8 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
/* 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_malloc_x(s) memset(GC_malloc(s),0,s)
|
||||
#define bjam_malloc_atomic_x(s) memset(GC_malloc_atomic(s),0,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)
|
||||
|
||||
@@ -56,19 +56,13 @@ static strblock* strblock_chain = 0;
|
||||
static char* storage_start = 0;
|
||||
static char* storage_finish = 0;
|
||||
|
||||
/* */
|
||||
#define SIMPLE_ALLOC 0
|
||||
/*/
|
||||
#define SIMPLE_ALLOC 1
|
||||
/* */
|
||||
|
||||
/*
|
||||
* allocate() - Allocate n bytes of immortal string storage
|
||||
*/
|
||||
static char* allocate(size_t n)
|
||||
{
|
||||
#if SIMPLE_ALLOC
|
||||
return (char*)BJAM_MALLOC(n);
|
||||
#ifdef OPT_BOEHM_GC
|
||||
return (char*)BJAM_MALLOC_ATOMIC(n);
|
||||
#else
|
||||
/* See if we can grab storage from an existing block */
|
||||
size_t remaining = storage_finish - storage_start;
|
||||
|
||||
@@ -55,7 +55,7 @@ static void string_reserve_internal( string* self, size_t capacity )
|
||||
{
|
||||
if ( self->value == self->opt )
|
||||
{
|
||||
self->value = (char*)BJAM_MALLOC( capacity + JAM_STRING_MAGIC_SIZE );
|
||||
self->value = (char*)BJAM_MALLOC_ATOMIC( 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 */
|
||||
|
||||
Reference in New Issue
Block a user