Simplify the nasm_malloc() code by moving the pointer check into a
common subroutine.
We can now issue a filename error even for failures like malloc().
Add support for the gcc sentinel attribute (verify that a list ends
with NULL).
Add a handful of safe_alloc attributes.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Some older versions of gcc (gcc 4.2.1 at least) produce a warning,
promoted to error, on C99 inlines. Do some work to figure out if we
need to fall back to GNU inline syntax.
Fix some issues with GNU inline syntax.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.
Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Add macro is_constant() to return true if and only if the value is a
compile-time constant. It may never return true, however.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For many (most?) targets these will be very small functions, so inline
them. However, just in case make these external library functions.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Move byte order handling functions to their own header file, and try
to be more specific about how exactly to handle things.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add a redundant cast in watcom_switch_hack() to quiet a Watcom
warning, and remove open-coded implementation of the Watcom switch
hack.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
HAVE_DECL_* are 0/1 not ifdef; use HAVE_DECL_STRNLEN to see if we need
to declare this, lest stdlib/strnlen.c fails to compile.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Avoid type promotion due to ?:, and put in a comment to explain what
the heck the purpose is of wrapping default in a macro.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Use sizeof() to prevent the compiler from invoking
watcom_switch_hack() unnecessarily. Hopefully the optimizer would be
smart enough to recognize this inherently, but this is an old compiler
we are dealing with, so make life a little easier for it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
OpenWatcom still doesn't have proper support for 64-bit switch
statements. Hack around it in a truly vile way.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Instead of using hacks or compiler-specific features, if we have
standard features as defined in ISO C11, use them.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Use autoconf to detect function attributes; some compilers like Sun CC
do support some gcc-style attributes, but don't define __GNUC__. Also
-U__STRICT_ANSI__ already in configure.ac so our tests match what we
might eventually encounter.
Add const_func and pure_func attributes.
Decorate functions in nasmlib.h with const_func and pure_func.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Move the canned OpenWatcom configuration file to config/watcom.h.
Also exclude config/config.h from being a dependency for MSVC.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Apparently, at least on some OS/2 compilers, <sys/types.h> needs to be
included for off_t to be defined. This seems like a generically good
idea to include this header whenever it is available.
Remove reference to <types.h>. This was supposedly for MSVC, but
there is no actual evidence that it is useful beyond <sys/types.h>.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For newer gcc attributes, we can use __has_attribute() to test for
attribute presence. This improves compatibility both with older gcc
and with clang, at least with -Werror enabled.
Reported-by: Daniel Lundqvist <daniel@malarhojden.nu>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Instead of trying to do hacks in the Makefiles, define header files
for specific compilers if they can't use autoconf. Currently defined
for Microsoft Visual Studio, based on MSDN documentation. It is
currently untested.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>