Author: infinoid
Date: Fri Jan  2 21:11:22 2009
New Revision: 34849

Modified:
   branches/assert_args/include/parrot/exceptions.h
   branches/assert_args/tools/build/headerizer.pl

Log:
[headerizer] Fix so we can put ASSERT_ARGS at the very top of functions

Make the ASSERT_ARGS declaration look like the declaration of a local
variable.  This means we can put it at the very top of every function,
for maximum usefulness, and without causing GCC to emit warnings about
ISO C90 prohibiting mixed declarations and code.

Modified: branches/assert_args/include/parrot/exceptions.h
==============================================================================
--- branches/assert_args/include/parrot/exceptions.h    (original)
+++ branches/assert_args/include/parrot/exceptions.h    Fri Jan  2 21:11:22 2009
@@ -259,6 +259,16 @@
 #  define PARROT_ASSERT(x) (x) ? ((void)0) : Parrot_confess(#x, __FILE__, 
__LINE__)
 #endif
 
+/* having a function version of this lets us put ASSERT_ARGS() at the top
+ * of the list of local variables.  Thus, we can catch bad pointers before
+ * any of the local initialization logic is run.  And it always returns 0,
+ * so headerizer can define the ASSERT_ARGS_* macros like:
+ * int _ASSERT_ARGS = PARROT_ASSERT_ARG(a) || PARROT_ASSERT_ARG(b) || ...
+ */
+static inline int PARROT_ASSERT_ARG(const void *x) {
+    PARROT_ASSERT(x);
+    return 0;
+}
 #define ASSERT_ARGS(a) ASSERT_ARGS_ ## a
 
 

Modified: branches/assert_args/tools/build/headerizer.pl
==============================================================================
--- branches/assert_args/tools/build/headerizer.pl      (original)
+++ branches/assert_args/tools/build/headerizer.pl      Fri Jan  2 21:11:22 2009
@@ -311,10 +311,10 @@
                 # strip off everything before the final space or asterisk.
                 $var =~ s[.+[* ]([^* ]+)$][$1];
             }
-            push( @asserts, "assert($var);" );
+            push( @asserts, "PARROT_ASSERT_ARG($var)" );
         }
         if( $arg eq 'PARROT_INTERP' ) {
-            push( @asserts, "assert(interp);" );
+            push( @asserts, "PARROT_ASSERT_ARG(interp)" );
         }
     }
 
@@ -379,9 +379,12 @@
         my @asserts = asserts_from_args( @args );
 
         my $assert = "#define ASSERT_ARGS_" . $func->{name};
+            $assert .= " __attribute__unused__ int _ASSERT_ARGS_CHECK = ";
         if(@asserts) {
-            $assert .= ' ';
-            $assert .= join(" \\\n" . ' ' x length($assert), @asserts);
+            $assert .= "\\\n       ";
+            $assert .= join(" \\\n    || ", @asserts);
+        } else {
+            $assert .= "0";
         }
         push(@decls, $assert);
     }

Reply via email to