Ticket #105: headerizer-asserts-as-local-variable-decl.patch

File headerizer-asserts-as-local-variable-decl.patch, 2.2 KB (added by Infinoid, 13 years ago)
  • include/parrot/exceptions.h

    [headerizer] Make the ASSERT_ARGS declaration look like the declaration
    
    From: Mark Glines <mark@glines.org>
    
    of a local variable.  This means we can put it at the very top of every
    function, for maximum usefulness.
    ---
    
     include/parrot/exceptions.h |   10 ++++++++++
     tools/build/headerizer.pl   |    8 ++++----
     2 files changed, 14 insertions(+), 4 deletions(-)
    
    
    diff --git a/include/parrot/exceptions.h b/include/parrot/exceptions.h
    index eb6f494..f46b404 100644
    a b  
    259259#  define PARROT_ASSERT(x) (x) ? ((void)0) : Parrot_confess(#x, __FILE__, __LINE__) 
    260260#endif 
    261261 
     262/* having a function version of this lets us put ASSERT_ARGS() at the top 
     263 * of the list of local variables.  Thus, we can catch bad pointers before 
     264 * any of the local initialization logic is run.  And it always returns 0, 
     265 * so headerizer can define the ASSERT_ARGS_* macros like: 
     266 * int _ASSERT_ARGS = PARROT_ASSERT_ARG(a) || PARROT_ASSERT_ARG(b) || ... 
     267 */ 
     268static inline int PARROT_ASSERT_ARG(const void *x) { 
     269    PARROT_ASSERT(x); 
     270    return 0; 
     271} 
    262272#define ASSERT_ARGS(a) ASSERT_ARGS_ ## a 
    263273 
    264274 
  • tools/build/headerizer.pl

    diff --git a/tools/build/headerizer.pl b/tools/build/headerizer.pl
    index 8f7413b..a58ab8c 100644
    a b  
    311311                # strip off everything before the final space or asterisk. 
    312312                $var =~ s[.+[* ]([^* ]+)$][$1]; 
    313313            } 
    314             push( @asserts, "assert($var);" ); 
     314            push( @asserts, "PARROT_ASSERT_ARG($var)" ); 
    315315        } 
    316316        if( $arg eq 'PARROT_INTERP' ) { 
    317             push( @asserts, "assert(interp);" ); 
     317            push( @asserts, "PARROT_ASSERT_ARG(interp)" ); 
    318318        } 
    319319    } 
    320320 
     
    380380 
    381381        my $assert = "#define ASSERT_ARGS_" . $func->{name}; 
    382382        if(@asserts) { 
    383             $assert .= ' '; 
    384             $assert .= join(" \\\n" . ' ' x length($assert), @asserts); 
     383            $assert .= " __attribute__unused__ int _ASSERT_ARGS_CHECK = \\\n       "; 
     384            $assert .= join(" \\\n    || ", @asserts); 
    385385        } 
    386386        push(@decls, $assert); 
    387387    }