An empty %{} becomes % which is simply the arithmetic
operator. Although that is consistent, it might be surprising for
users, to issue a warning.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
%[] amounts to an empty token; this needs to be handled specially so
that it gets properly dropped.
Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392806
Reported-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Regression in commit 20e0d616dc954d567c8bf2c7e11cc5d6c10ac544.
Independently discovered and fixed by C. Masloch:
https://bugzilla.nasm.us/show_bug.cgi?id=3392747
Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
Make the pasting behavior of TOKEN_QMARK, TOKEN_HERE and TOKEN_BASE
match the NASM 2.15 behavior: ? is a keyword and pastes as an ID, $
and $$ are treated as operators (which doesn't seem to make much
sense, but it is the current legacy behavior.)
Reported-by: C. Masloch <pushbx@ulukai.org>
Bugzilla: https://bugzilla.nasm.us/show_bug.cgi?id=3392733
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If macro is undefined while it's being expanded, use after free occurs,
since the MMacro instance is released, but it is still used to proceed
the expansion.
This change forbids macro undefinition: non-fatal error is raised and
the MMacro instance is not released if it is being processed by NASM
preprocessor.
Consider the following example:
| $ cat test.asm
| %macro m 0
| %unmacro m 0
| %endmacro
| m
| $ ./nasm test.asm
| test.asm:4: error: `%unmacro' can't undefine the macro being expanded
| test.asm:2: ... from macro `m' defined here
Fixes BR3392531 and BR3392716.
Signed-off-by: Igor Munkin <imun@cpan.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Better point out explicitly that SMacro::next member
is untouched, thus do not use SMacro::next and an array.
CID 1432925
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
When we process a TOKEN_QMARK we also need to advance p, in order to
get the proper start for the next token.
This fixes travis test br3392707.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The operation of the ',' and ')' tokens are very similar, except for:
',' issues a error if the processed parameter is greedy;
')' sets the "done" variable.
The code would incorrectly set "done" for a ',' token. This fixes
travis test br3392711.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
When pasting and stripping %+ and whitespace tokens, we either need to
set *nextp in the loop, or treat next as a separate variable and
update *nextp after the loop finishes. This implements the second
option.
This fixes travis test "amx".
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add the %eval() preprocessor function. It evaluates each of its
arguments like a number and expands to a comma-separated lists of the
evaluated arguments.
To support this, add the concept of "true varadic" macros, which are
only used internally. True varadic macros differ from greedy macros in
that the parameter list is still parsed as individual parameters and
provided to the expansion function. As this isn't meaningful for
user-defined macros, there is no way to specify it from a directive.
Add back the %isnfoo() functions. Although one could just as well write
!%isfoo(), it doesn't cost much to provide them, and might help avoid
programmer confusion.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
%ifid $ and %ifid $$ has traditionally been false, revert to that
behavior.
Reported-by: Mike Hommey <mh+anfz@glandium.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
NASM 2.15.04
Conflicts:
asm/listing.h
asm/pptok.pl
asm/preproc.c
version
This doesn't pass travis test 3392711, which is using an extremely odd
construct of %?? in the middle of an argument sequence for an smacro
while not being in a macro itself, and expecting it to expand to the
macro name. This seems to *really* confuse the master branch.
Resolve this later...
At least DWARF can encode C-style macros. In doing so, it wants the
file include hierarchy, so give the debug format backend the option of
receiving that information from the preprocessor.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The mempcpy helper returns *last* byte pointer thus when
we call set_text_free we have to pass a pointer to the
start of the string.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Make sure the data being freed get double
freed after -- the pointers must be zapped
(actually nasm_free and free_tlist support
being called with NULL pointer as an argument).
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
After issuing an error message for a missing %stacksize argument, need
to quit rather than continuing to try to access the pointer.
Fold uses of tok_text() while we are at it.
Reported-by: Suhwan <prada960808@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The %? and %?? tokens are ambiguous when used inside a multi-line
macro. Add tokens %*? and %*?? that only expand during single-macro
expansion.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If macros are nolisted, *or* they don't have any filename associated
with them, it is absolutely pointless to try to descend into them for
error messages, so just don't, even if -Lb is provided.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The previous code to fix whitespace around and multiple %+ symbols in
a row (checkin 122c5fb75986adc37dfb147cc2a613e3ebc66e80) had some
seriously broken pointer handling when zapping tokens. This could
cause paste_tokens() to go into an infinite loop because it would
attach %+ to another token and then immediately break them apart
again, over and over.
Reported-by: <alexfru@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The different token codes between the preprocessor and the assembler
is a completely unnecessary headache. Furthermore, lumping all the
operators under TOK_OTHER in the preprocessor causes a whole bunch of
unnecessary headaches.
In combining them, the only tricky part is that PP_CONCAT_MASK() is no
longer usable, as the range of token codes is too large. Replace with
dedicated category masks.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
To handle escape codes in filename strings after # markers correctly,
we need nasm_unquote() to be aware that it is using C escapes;
otherwise things like "foo`bar" will break.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
In 41e9682efed7cd1df133b1b4ac806e07723f1486 we've
changed the nasm_quote arguments still not all callers
were converted which could lead to nil dereference.
[hpa: no need to call strlen() for the asm/preproc.c chunk]
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add the first "preprocessor functions". These are simply "magic"
single-line macros with a suitable expansion function. The first
application is functions equal to the %if directives, e.g.
%ifdef blah == %if %isdef(blah) except can be used anywhere (not just
in %if statements like defined() in C.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In 41e9682efed7cd1df133b1b4ac806e07723f1486 we've
changed the nasm_quote arguments still not all callers
were converted which could lead to nil dereference.
[hpa: no need to call strlen() for the asm/preproc.c chunk]
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In 41e9682efed7cd1df133b1b4ac806e07723f1486 we've
changed the nasm_quote arguments still not all callers
were converted which could lead to nil dereference.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
NASM now supports a proper superset of cpp line number markers, so
there is no need to hack around them using the
"prepreprocessor". Instead, just put a quick test in do_directive()
treating it just like %line, except convert a "-quoted string into a
`-quoted string.
(This can break if there is a ` or \" sequence in the string... fix
that at some point. This is still much better than what there is now.)
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
When generating list output, preserve %[...] in the output if we list
a TOK_INDIRECT. The tokenization process removes these deliminators,
so we have to explicitly put them back.
This doesn't affect assembly output, which will only ever be generated
after all TOK_INDIRECT tokens have been removed, but it does affect
some of the listing modes.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Instead of %pragma ignore, use a new %null directive which ignores the
rest of the line, without bothering to expand it.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
defining->dstk.mmac should point back to "defining" when the topmost
definition block is a %macro block.
Otherwise %00 will not inhibit label emission.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The hacky %arg and %local directives build directives as strings which
they then tokenize and call do_directive() recursively with. Factor
these out and remove the recursion.
It is too bad that %arg and %local didn't include the [] brackets in
the created macros; if so it would have been possible to do something
sane with 64-bit register operands. Sigh.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
ERR_PASS1 only remains in three places:
a. Unterminated %! string, an error
- Should be signalled no matter which pass it is encountered in
b. Two cases of map file problems in outbin
- The buffered warning system take care of that issue
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
A negative number is two tokens: a minus sign and a positive
number. For most uses we still want to generate signed numbers; for
specific uses there might be motivation for an unsigned output, but in
most cases it would be confusing.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The fact that smac->expansion is stored in reverse order is a detail
of the implementation, and should not be forced on the caller of
define_smacro().
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Fold the prepreprocessor and the nop preprocessor into the main
preprocessor. This means handling # cpp-like lines and TASM
compatibility tokens in the preprocessor proper, but that is really
not very hard to do.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Reverse the invocation lists once each list is complete, so that the
lists passed to the macro backend are in true invocation order.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
We need the exact match in the rbtree for the current section. An
approximate match is not acceptable.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Collect macro call/nesting information for the benefit of the debug
back end. So far, the only backend for which this is provided is the
debug back end, to show what information is present.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
%+ tokens can end up next to each other, or at the beginning or the
end of an expansion if we try to paste the output of empty
macros. This is perhaps particularly likely to happen in %[]
expressions.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1. Error messages would issue with the line number of %endrep.
2. Debug line information would ignore both macros and reps.
This is doubly wrong; macros are semantically equivalent to
inline functions, and it is expected that debuggers trace
into these functions.
These changes finishes the last parts of moving all responsibility for
the listing enable/disable into the preprocessor, so remove the
way over-complicated macro inhibit facility from the listing module
entirely.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>