[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
|
|
| 259 | 259 | # define PARROT_ASSERT(x) (x) ? ((void)0) : Parrot_confess(#x, __FILE__, __LINE__) |
| 260 | 260 | #endif |
| 261 | 261 | |
| | 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 | */ |
| | 268 | static inline int PARROT_ASSERT_ARG(const void *x) { |
| | 269 | PARROT_ASSERT(x); |
| | 270 | return 0; |
| | 271 | } |
| 262 | 272 | #define ASSERT_ARGS(a) ASSERT_ARGS_ ## a |
| 263 | 273 | |
| 264 | 274 | |
diff --git a/tools/build/headerizer.pl b/tools/build/headerizer.pl
index 8f7413b..a58ab8c 100644
|
a
|
b
|
|
| 311 | 311 | # strip off everything before the final space or asterisk. |
| 312 | 312 | $var =~ s[.+[* ]([^* ]+)$][$1]; |
| 313 | 313 | } |
| 314 | | push( @asserts, "assert($var);" ); |
| | 314 | push( @asserts, "PARROT_ASSERT_ARG($var)" ); |
| 315 | 315 | } |
| 316 | 316 | if( $arg eq 'PARROT_INTERP' ) { |
| 317 | | push( @asserts, "assert(interp);" ); |
| | 317 | push( @asserts, "PARROT_ASSERT_ARG(interp)" ); |
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
| … |
… |
|
| 380 | 380 | |
| 381 | 381 | my $assert = "#define ASSERT_ARGS_" . $func->{name}; |
| 382 | 382 | 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); |
| 385 | 385 | } |
| 386 | 386 | push(@decls, $assert); |
| 387 | 387 | } |