|
|
|
#if !defined(DUK_VA_COPY)
|
|
|
|
/* We need va_copy() which is defined in C99 / C++11, so an awkward
|
|
|
|
* replacement is needed for pre-C99 / pre-C++11 environments. This
|
|
|
|
* will quite likely need portability hacks for some non-C99
|
|
|
|
* environments.
|
|
|
|
*/
|
|
|
|
#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
|
|
|
|
/* C99 / C++11 and above: rely on va_copy() which is required.
|
|
|
|
* Omit parenthesis on macro right side on purpose to minimize differences
|
|
|
|
* to direct use.
|
|
|
|
*/
|
|
|
|
#define DUK_VA_COPY(dest,src) va_copy(dest,src)
|
|
|
|
#else
|
|
|
|
/* Pre-C99: va_list type is implementation dependent. This replacement
|
|
|
|
* assumes it is a plain value so that a simple assignment will work.
|
|
|
|
* This is not the case on all platforms (it may be a single-array element,
|
|
|
|
* for instance).
|
|
|
|
*/
|
|
|
|
#define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_MACRO_STRINGIFY)
|
|
|
|
/* Macro hackery to convert e.g. __LINE__ to a string without formatting,
|
|
|
|
* see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
|
|
|
|
*/
|
|
|
|
#define DUK_MACRO_STRINGIFY_HELPER(x) #x
|
|
|
|
#define DUK_MACRO_STRINGIFY(x) DUK_MACRO_STRINGIFY_HELPER(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_CAUSE_SEGFAULT)
|
|
|
|
/* This is used by the default fatal error handling to cause the program to
|
|
|
|
* intentionally segfault on a fatal error. Valgrind will then indicate the
|
|
|
|
* C call stack leading to the error.
|
|
|
|
*/
|
|
|
|
#define DUK_CAUSE_SEGFAULT() do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_UNREF)
|
|
|
|
/* Macro for suppressing warnings for potentially unreferenced variables.
|
|
|
|
* The variables can be actually unreferenced or unreferenced in some
|
|
|
|
* specific cases only; for instance, if a variable is only debug printed,
|
|
|
|
* it is unreferenced when debug printing is disabled.
|
|
|
|
*/
|
|
|
|
#define DUK_UNREF(x) do { (void) (x); } while (0)
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_NORETURN)
|
|
|
|
#define DUK_NORETURN(decl) decl
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_UNREACHABLE)
|
|
|
|
/* Don't know how to declare unreachable point, so don't do it; this
|
|
|
|
* may cause some spurious compilation warnings (e.g. "variable used
|
|
|
|
* uninitialized").
|
|
|
|
*/
|
|
|
|
#define DUK_UNREACHABLE() do { } while (0)
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_LOSE_CONST)
|
|
|
|
/* Convert any input pointer into a "void *", losing a const qualifier.
|
|
|
|
* This is not fully portable because casting through duk_uintptr_t may
|
|
|
|
* not work on all architectures (e.g. those with long, segmented pointers).
|
|
|
|
*/
|
|
|
|
#define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_LIKELY)
|
|
|
|
#define DUK_LIKELY(x) (x)
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_UNLIKELY)
|
|
|
|
#define DUK_UNLIKELY(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_NOINLINE)
|
|
|
|
#define DUK_NOINLINE /*nop*/
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_INLINE)
|
|
|
|
#define DUK_INLINE /*nop*/
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_ALWAYS_INLINE)
|
|
|
|
#define DUK_ALWAYS_INLINE /*nop*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_EXTERNAL_DECL)
|
|
|
|
#define DUK_EXTERNAL_DECL extern
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_EXTERNAL)
|
|
|
|
#define DUK_EXTERNAL /*empty*/
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_INTERNAL_DECL)
|
|
|
|
#if defined(DUK_SINGLE_FILE)
|
|
|
|
#define DUK_INTERNAL_DECL static
|
|
|
|
#else
|
|
|
|
#define DUK_INTERNAL_DECL extern
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_INTERNAL)
|
|
|
|
#if defined(DUK_SINGLE_FILE)
|
|
|
|
#define DUK_INTERNAL static
|
|
|
|
#else
|
|
|
|
#define DUK_INTERNAL /*empty*/
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_LOCAL_DECL)
|
|
|
|
#define DUK_LOCAL_DECL static
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_LOCAL)
|
|
|
|
#define DUK_LOCAL static
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_FILE_MACRO)
|
|
|
|
#define DUK_FILE_MACRO __FILE__
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_LINE_MACRO)
|
|
|
|
#define DUK_LINE_MACRO __LINE__
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_FUNC_MACRO)
|
|
|
|
#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
|
|
|
|
#define DUK_FUNC_MACRO __func__
|
|
|
|
#elif defined(__FUNCTION__)
|
|
|
|
#define DUK_FUNC_MACRO __FUNCTION__
|
|
|
|
#else
|
|
|
|
#define DUK_FUNC_MACRO "unknown"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(DUK_BSWAP32)
|
|
|
|
#define DUK_BSWAP32(x) \
|
|
|
|
((((duk_uint32_t) (x)) >> 24) | \
|
|
|
|
((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
|
|
|
|
((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
|
|
|
|
(((duk_uint32_t) (x)) << 24))
|
|
|
|
#endif
|
|
|
|
#if !defined(DUK_BSWAP16)
|
|
|
|
#define DUK_BSWAP16(x) \
|
|
|
|
((duk_uint16_t) (x) >> 8) | \
|
|
|
|
((duk_uint16_t) (x) << 8)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
|
|
|
|
/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
|
|
|
|
|
|
|
|
#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
|
|
|
|
#if defined(DUK_F_C99)
|
|
|
|
#define DUK_USE_FLEX_C99
|
|
|
|
#else
|
|
|
|
#define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
|
|
|
|
defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
|
|
|
|
#define DUK_USE_PACK_DUMMY_MEMBER
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0 /* not defined by default */
|
|
|
|
#undef DUK_USE_GCC_PRAGMAS
|
|
|
|
#endif
|