preproc.c: expand_smacro -- break endless loop for interminable macro recursion
commitbd38c8f231d938ffdf0916809bf2a6b65e62ea61
authorCyrill Gorcunov <gorcunov@gmail.com>
Sat, 21 Nov 2009 08:11:23 +0000 (21 11:11 +0300)
committerCyrill Gorcunov <gorcunov@gmail.com>
Sat, 21 Nov 2009 08:11:29 +0000 (21 11:11 +0300)
treed81995bb53d82c8a73e4516d660052e0a3cce58b
parentbc0113d977f33ccb1b1ff50120efacb4fa63e91a
preproc.c: expand_smacro -- break endless loop for interminable macro recursion

Frank reported:
|
| From the "expert questions" forum comes this:
|
| ---------------------
| By: jasper_neumann
|
| How can I delegate %undef?
|
| In the example below the assembler (called with "nasm.exe -t -f rdf q.asm")
| bemoans my code, displays
|
| "q.asm:19: error: interminable macro recursion"
|
| and hangs.
|
| q.asm
| -----
| bits 32
| CPU P4
|
| %macro my_def 2
|  %xdefine %1 esp+%2
| %endmacro
|
| %macro my_undef 1
|  %undef %1
| %endmacro
|
| global check_it
| check_it:
|  my_def x,4
|  mov eax,[x]
|  my_undef x
|
|  my_def x,8
|  add eax,[x]
|  my_undef x
|  ret
|

So in case of interminable macro recursion we should break
the expansion procedure that way to not return back and start
expand macro again.

This address a part of the original problem.
Nasm64developer pointed out:
|
| Btw, after you manage to fix this recursion problem, the code
| in question still faces the same fundamental issue -- the arg
| to the my_undef invocations (i.e. x) gets expanded first; thus
| the %undef inside the macro sees esp+4 and esp+8 instead
| of x, and fails. What you'd need is a means to prevent the ex-
| pansion -- look for e.g. %# in 4.1.4 of the manual.txt which is
| attached to SF #1842438; it implements exactly that -- I once
| filed SF #829879 for this feature.
|

In turn Keith Kanios said:
|
| Anon is also correct in that we would need a special directive to instruct
| the delay of macro expansion, although I don't see this as critical or even
| high priority at the moment. The intermediate solution for this is, don't
| use indirection if it is not needed... an inline %undef should be
| sufficient.
|

Reported-by: Frank Kotler <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Keith Kanios <keith@kanios.net>
preproc.c