review request (M) 6888954 - arg formatting for assert

John Coomes John.Coomes at sun.com
Tue Oct 13 14:52:59 PDT 2009


I (John.Coomes at Sun.COM) wrote:
> Tom Rodriguez (Thomas.Rodriguez at Sun.COM) wrote:
> ...
> > I'm don't think fatal(err_msg(a, b)) is an improvement over fatal1(a,  
> > b) but then I would have been fine with assert1 and friends. ...
> 
> I'd rather not count arguments.  If it were just fatal1, I might live
> with it.  But when you get to fatal4, fatal5, ..., and then multiply
> that by guarantee and assert, there should be something better.
> 
> > ...                                                           You  
> > could make fatal appear variadic with some other macro tricks.
> > 
> > #define fatal \
> >    begin_failure(__FILE__, __LINE__) && report_fatal
> > 
> > report_fatal would expect to get file and line from some thread local  
> > buffer where it was cached by begin_failure.  Alternatively you could  
> > have a stack allocated object with a report_fatal method and use dot  
> > instead of and.
> 
> The syntax at the use point is better.  Of the two, I like the latter
> as it's more localized.
> 
> Both would treat the current string literals as format strings, which
> would require auditing; the gcc __attribute__((format)) mechanism
> (suggested by Ian Rogers) would help for shared and linux-specific
> code.  Also, using a normal macro instead of a function-like macro
> would replace non-function-like uses:
> 
> $ cat x.cc
> #define fatal(a) printf(a)
> #define fatalx   printf
> int main(int argc, char **argv) { int fatal = 0; int fatalx = 0; return 0; }
> $ CC -E x.cc
> int main ( int argc , char * * argv ) { int fatal = 0 ; int printf = 0 ; return 0 ; } 
> 
> So it would prohibit variables and fields named assert, fatal,
> guarantee, etc.  We could probably live with it, but it's worth
> pointing out.

Scratch the assert and guarantee from the above paragraph.  The
suggestion would only work with fatal, which doesn't have a condition
to evaluate.  I'm not too fond of the assymetry.

I could just add

#define fatal1(p, msg, arg)  fatal(p, err_msg(msg, arg))

to the proposed changes.  Then you can choose which style you want to
use:  numbered macro or err_msg().

-John

> > On Oct 10, 2009, at 4:21 PM, John Coomes wrote:
> > 
> > > 6888954: argument formatting for assert() and friends
> > >
> > > Enable argument formatting for assert(), guarantee() and related
> > > macros.
> > >
> > > http://cr.openjdk.java.net/~jcoomes/6888954-assert-args/
> > >
> > > -John
> > >
> > 
> 



More information about the hotspot-dev mailing list