Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Sick macros (was: Action, not words (Re: bug (?) in 3.0-pre1))



Bart wrote:
>2.  Introduce macros for heapalloc/permalloc that start with an open
>    brace, and a macro for lastalloc that ends with a close brace, so
>    it's syntatically required that every heapalloc/permalloc have a
>    matching lastalloc.  As this introduces a new block context, use a
>    block-local variable in heapalloc/permalloc to remember the state
>    of the useheap global, and test the block-local in lastalloc to
>    reset the global state appropriately.

Probably a good idea, but as these macros now introduce new syntax
let's make them *look* like syntax, rather than function calls.

The 3.0-pre2-test patch contains:
:+ # define heapalloc() do { \
:+ 			int nonlocal_useheap = useheap; \
:+ 			global_heapalloc()

I recommend changing heapalloc() to heapalloc, and similarly removing
the parentheses for permalloc and lastalloc.

:+ # define lastalloc_return \
:+ 			if (nonlocal_useheap) global_heapalloc(); \
:+ 			else global_permalloc(); \
:+ 			return

This won't work as the body of an if or while.  The following is always
safe:

#define lastalloc_return \
  if( (nonlocal_useheap ? global_heapalloc() : global_permalloc()) , 0 ) \
    ; \
  else \
    return

On a related point, I've been meaning to clean up execerr() in exec.c
for a while:

exec.c contains:
$#define execerr() { if (forked) _exit(1); \
$	closemnodes(mfds); lastval = 1; return; }

This should be

#define execerr \
  do { \
    if(forked) _exit(1); \
    closemnodes(mfds); \
    lastval = 1; \
    return; \
  } while(0)

It should then be invoked as "execerr;", rather than "execerr()"
(whereas it's currently *actually* being invoked as "execerr();").

YYERROR and YYERRORV in parse.c have a similar problem (they need do
... while(0) bracketing -- and this actually affected me when producing
a recent patch).

-zefram




Messages sorted by: Reverse Date, Date, Thread, Author