--- boost_1_54_0/tools/build/v2/engine/function.c.~1~ 2013-05-21 06:14:18.000000000 +0200 +++ boost_1_54_0/tools/build/v2/engine/function.c 2013-08-13 13:46:01.000000000 +0200 @@ -216,6 +216,16 @@ struct _stack static void * stack; +static size_t align_down( size_t n ) +{ + return n & ~( sizeof( LIST * ) - 1 ); +} + +static size_t align_up( size_t n ) +{ + return align_down( n + sizeof( LIST * ) - 1 ); +} + STACK * stack_global() { static STACK result; @@ -223,7 +233,7 @@ STACK * stack_global() { int const size = 1 << 21; stack = BJAM_MALLOC( size ); - result.data = (char *)stack + size; + result.data = (void *)align_down( (size_t)( (char *)stack + size ) ); } return &result; } @@ -854,7 +864,7 @@ static int expand_modifiers( STACK * s, if ( total != 0 ) { - VAR_EDITS * out = stack_allocate( s, total * sizeof( VAR_EDITS ) ); + VAR_EDITS * out = stack_allocate( s, align_up( total * sizeof( VAR_EDITS ) ) ); LISTITER * iter = stack_allocate( s, n * sizeof( LIST * ) ); for ( i = 0; i < n; ++i ) iter[ i ] = list_begin( args[ i ] ); @@ -4263,7 +4273,7 @@ LIST * function_run( FUNCTION * function stack_push( s, l ); l = apply_modifiers( s, n ); list_free( stack_pop( s ) ); - stack_deallocate( s, n * sizeof( VAR_EDITS ) ); + stack_deallocate( s, align_up( n * sizeof( VAR_EDITS ) ) ); for ( i = 0; i < code->arg; ++i ) list_free( stack_pop( s ) ); /* pop modifiers */ stack_push( s, l ); @@ -4289,7 +4299,7 @@ LIST * function_run( FUNCTION * function l = apply_subscript_and_modifiers( s, n ); list_free( stack_pop( s ) ); list_free( stack_pop( s ) ); - stack_deallocate( s, n * sizeof( VAR_EDITS ) ); + stack_deallocate( s, align_up( n * sizeof( VAR_EDITS ) ) ); for ( i = 0; i < code->arg; ++i ) list_free( stack_pop( s ) ); /* pop modifiers */ stack_push( s, l ); @@ -4312,7 +4322,7 @@ LIST * function_run( FUNCTION * function list_free( stack_pop( s ) ); } list_free( vars ); - stack_deallocate( s, n * sizeof( VAR_EDITS ) ); + stack_deallocate( s, align_up( n * sizeof( VAR_EDITS ) ) ); for ( i = 0; i < code->arg; ++i ) list_free( stack_pop( s ) ); /* pop modifiers */ stack_push( s, result ); @@ -4358,7 +4368,7 @@ LIST * function_run( FUNCTION * function } list_free( stack_pop( s ) ); list_free( vars ); - stack_deallocate( s, n * sizeof( VAR_EDITS ) ); + stack_deallocate( s, align_up( n * sizeof( VAR_EDITS ) ) ); for ( i = 0; i < code->arg; ++i ) list_free( stack_pop( s ) ); /* pop modifiers */ stack_push( s, result );