Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75792 - trunk/tools/build/v2/engine
From: steven_at_[hidden]
Date: 2011-12-03 14:54:28


Author: steven_watanabe
Date: 2011-12-03 14:54:28 EST (Sat, 03 Dec 2011)
New Revision: 75792
URL: http://svn.boost.org/trac/boost/changeset/75792

Log:
More thorough asserts.
Text files modified:
   trunk/tools/build/v2/engine/function.c | 74 ++++++++++++++++++++++++++++++++-------
   1 files changed, 61 insertions(+), 13 deletions(-)

Modified: trunk/tools/build/v2/engine/function.c
==============================================================================
--- trunk/tools/build/v2/engine/function.c (original)
+++ trunk/tools/build/v2/engine/function.c 2011-12-03 14:54:28 EST (Sat, 03 Dec 2011)
@@ -170,47 +170,62 @@
     return &result;
 }
 
+static void check_alignment( STACK * s )
+{
+ assert( (unsigned long)s->data % sizeof( LIST * ) == 0 );
+}
+
+void * stack_allocate( STACK * s, int size )
+{
+ check_alignment( s );
+ s->data = (char *)s->data - size;
+ check_alignment( s );
+ return s->data;
+}
+
+void stack_deallocate( STACK * s, int size )
+{
+ check_alignment( s );
+ s->data = (char *)s->data + size;
+ check_alignment( s );
+}
+
 void stack_push( STACK * s, LIST * l )
 {
- *--(*(LIST * * *)&s->data) = l;
+ *(LIST * *)stack_allocate( s, sizeof( LIST * ) ) = l;
 }
 
 LIST * stack_pop( STACK * s )
 {
- return *(*(LIST * * *)&s->data)++;
+ LIST * result = *(LIST * *)s->data;
+ stack_deallocate( s, sizeof( LIST * ) );
+ return result;
 }
 
 LIST * stack_top(STACK * s)
 {
+ check_alignment( s );
     return *(LIST * *)s->data;
 }
 
 LIST * stack_at( STACK * s, int n )
 {
+ check_alignment( s );
     return *((LIST * *)s->data + n);
 }
 
 void stack_set( STACK * s, int n, LIST * value )
 {
+ check_alignment( s );
     *((LIST * *)s->data + n) = value;
 }
 
 void * stack_get( STACK * s )
 {
+ check_alignment( s );
     return (LIST * *)s->data;
 }
 
-void * stack_allocate( STACK * s, int size )
-{
- *(char * *)&s->data -= size;
- return s->data;
-}
-
-void stack_deallocate( STACK * s, int size )
-{
- *(char * *)&s->data += size;
-}
-
 LIST * frame_get_local( FRAME * frame, int idx )
 {
     /* The only local variables are the arguments */
@@ -2450,6 +2465,27 @@
     BJAM_FREE( function_ );
 }
 
+
+/* Alignment check for stack */
+
+struct align_var_edits
+{
+ char ch;
+ VAR_EDITS e;
+};
+
+struct align_expansion_item
+{
+ char ch;
+ expansion_item e;
+};
+
+static char check_align_var_edits[ sizeof(struct align_var_edits) <= sizeof(VAR_EDITS) + sizeof(void *) ? 1 : -1 ];
+static char check_align_expansion_item[ sizeof(struct align_expansion_item) <= sizeof(expansion_item) + sizeof(void *) ? 1 : -1 ];
+
+static char check_ptr_size1[ sizeof(LIST *) <= sizeof(void *) ? 1 : -1 ];
+static char check_ptr_size2[ sizeof(char *) <= sizeof(void *) ? 1 : -1 ];
+
 /*
  * WARNING: The instruction set is tuned for Jam and
  * is not really generic. Be especially careful about
@@ -2714,6 +2750,18 @@
 
         case INSTR_RETURN:
         {
+#ifndef NDEBUG
+
+ if ( !( saved_stack == s->data ) )
+ {
+ frame->file = function->file;
+ frame->line = function->line;
+ backtrace_line( frame );
+ printf( "error: stack check failed.\n" );
+ backtrace( frame );
+ assert( saved_stack == s->data );
+ }
+#endif
             assert( saved_stack == s->data );
             return result;
         }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk