deprecated NDEBUG and introduced HCL_BUILD_DEBUG and HCL_BUILD_RELEASE

This commit is contained in:
hyung-hwan 2018-02-21 09:30:18 +00:00
parent 5128c1a99f
commit 67a334bc26
10 changed files with 46 additions and 28 deletions

20
configure vendored
View File

@ -19400,13 +19400,19 @@ fi
if test "$enable_debug_is" = "yes" if test "$enable_debug_is" = "yes"
then then
CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -DHCL_BUILD_DEBUG -U_FORTIFY_SOURCE" CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -U_FORTIFY_SOURCE"
CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -DHCL_BUILD_DEBUG -U_FORTIFY_SOURCE" CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -U_FORTIFY_SOURCE"
$as_echo "#define HCL_BUILD_DEBUG 1" >>confdefs.h
BUILD_MODE="debug" BUILD_MODE="debug"
else else
CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -DHCL_BUILD_RELEASE -U_FORTIFY_SOURCE" CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -U_FORTIFY_SOURCE"
CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -DHCL_BUILD_RELEASE -U_FORTIFY_SOURCE" CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -U_FORTIFY_SOURCE"
$as_echo "#define HCL_BUILD_RELEASE 1" >>confdefs.h
BUILD_MODE="release" BUILD_MODE="release"
fi fi
@ -19460,7 +19466,7 @@ fi
if test "${enable_unicode}" = "yes" if test "${enable_unicode}" = "yes"
then then
$as_echo "#define HCL_ENABLE_UNICODE /**/" >>confdefs.h $as_echo "#define HCL_ENABLE_UNICODE 1" >>confdefs.h
fi fi
@ -19499,7 +19505,7 @@ test "${enable_shared}" = "no" && enable_dynamic_module_is="no"
if test "${enable_dynamic_module_is}" = "yes" if test "${enable_dynamic_module_is}" = "yes"
then then
$as_echo "#define HCL_ENABLE_DYNAMIC_MODULE /**/" >>confdefs.h $as_echo "#define HCL_ENABLE_DYNAMIC_MODULE 1" >>confdefs.h
fi fi
if test "${enable_dynamic_module_is}" = "yes"; then if test "${enable_dynamic_module_is}" = "yes"; then
@ -19524,7 +19530,7 @@ test "${enable_shared}" = "no" -a "${enable_static}" = "yes" && enable_static_mo
if test "${enable_static_module_is}" = "yes" if test "${enable_static_module_is}" = "yes"
then then
$as_echo "#define HCL_ENABLE_STATIC_MODULE /**/" >>confdefs.h $as_echo "#define HCL_ENABLE_STATIC_MODULE 1" >>confdefs.h
fi fi
if test "${enable_static_module_is}" = "yes"; then if test "${enable_static_module_is}" = "yes"; then

View File

@ -397,12 +397,14 @@ AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],[build the library in th
enable_debug_is=$enableval,enable_debug_is=no) enable_debug_is=$enableval,enable_debug_is=no)
if test "$enable_debug_is" = "yes" if test "$enable_debug_is" = "yes"
then then
[CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -DHCL_BUILD_DEBUG -U_FORTIFY_SOURCE"] [CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -U_FORTIFY_SOURCE"]
[CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -DHCL_BUILD_DEBUG -U_FORTIFY_SOURCE"] [CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -U_FORTIFY_SOURCE"]
AC_DEFINE([HCL_BUILD_DEBUG],[1],[build release/debug])
AC_SUBST(BUILD_MODE, "debug") AC_SUBST(BUILD_MODE, "debug")
else else
[CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -DHCL_BUILD_RELEASE -U_FORTIFY_SOURCE"] [CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -U_FORTIFY_SOURCE"]
[CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -DHCL_BUILD_RELEASE -U_FORTIFY_SOURCE"] [CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -U_FORTIFY_SOURCE"]
AC_DEFINE([HCL_BUILD_RELEASE],[1],[build release/debug])
AC_SUBST(BUILD_MODE, "release") AC_SUBST(BUILD_MODE, "release")
fi fi
@ -442,7 +444,7 @@ AC_ARG_ENABLE([unicode],
) )
if test "${enable_unicode}" = "yes" if test "${enable_unicode}" = "yes"
then then
AC_DEFINE([HCL_ENABLE_UNICODE],[],[Use the unicode character type as the default character type]) AC_DEFINE([HCL_ENABLE_UNICODE],[1],[Use the unicode character type as the default character type])
fi fi
AC_ARG_ENABLE([cxx], AC_ARG_ENABLE([cxx],
@ -469,7 +471,7 @@ test "${enable_shared}" = "no" && enable_dynamic_module_is="no"
if test "${enable_dynamic_module_is}" = "yes" if test "${enable_dynamic_module_is}" = "yes"
then then
AC_DEFINE([HCL_ENABLE_DYNAMIC_MODULE],[],[enable dynamic module capability]) AC_DEFINE([HCL_ENABLE_DYNAMIC_MODULE],[1],[enable dynamic module capability])
fi fi
AM_CONDITIONAL(ENABLE_DYNAMIC_MODULE, test "${enable_dynamic_module_is}" = "yes") AM_CONDITIONAL(ENABLE_DYNAMIC_MODULE, test "${enable_dynamic_module_is}" = "yes")
@ -483,7 +485,7 @@ test "${enable_shared}" = "no" -a "${enable_static}" = "yes" && enable_static_mo
if test "${enable_static_module_is}" = "yes" if test "${enable_static_module_is}" = "yes"
then then
AC_DEFINE([HCL_ENABLE_STATIC_MODULE],[],[link modules statically into the main library]) AC_DEFINE([HCL_ENABLE_STATIC_MODULE],[1],[link modules statically into the main library])
fi fi
AM_CONDITIONAL(ENABLE_STATIC_MODULE, test "${enable_static_module_is}" = "yes") AM_CONDITIONAL(ENABLE_STATIC_MODULE, test "${enable_static_module_is}" = "yes")

View File

@ -1060,7 +1060,7 @@ static HCL_INLINE void multiply_unsigned_array (const hcl_liw_t* x, hcl_oow_t xs
* -------------------------------------------------------------------- * --------------------------------------------------------------------
*/ */
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
#define CANNOT_KARATSUBA(hcl,xs,ys) \ #define CANNOT_KARATSUBA(hcl,xs,ys) \
((xs) < (hcl)->option.karatsuba_cutoff || (ys) < (hcl)->option.karatsuba_cutoff || \ ((xs) < (hcl)->option.karatsuba_cutoff || (ys) < (hcl)->option.karatsuba_cutoff || \
((xs) > (ys) && (ys) <= (((xs) + 1) / 2)) || \ ((xs) > (ys) && (ys) <= (((xs) + 1) / 2)) || \

View File

@ -28,7 +28,7 @@
#define DECODE_LOG_MASK (HCL_LOG_MNEMONIC | HCL_LOG_INFO) #define DECODE_LOG_MASK (HCL_LOG_MNEMONIC | HCL_LOG_INFO)
#if defined(NDEBUG) #if defined(HCL_BUILD_RELEASE)
/* get rid of instruction logging regardless of the log mask /* get rid of instruction logging regardless of the log mask
* in the release build */ * in the release build */
# define LOG_INST_0(hcl,fmt) # define LOG_INST_0(hcl,fmt)

View File

@ -216,6 +216,12 @@
/* __va_copy is available */ /* __va_copy is available */
#undef HAVE___VA_COPY #undef HAVE___VA_COPY
/* build release/debug */
#undef HCL_BUILD_DEBUG
/* build release/debug */
#undef HCL_BUILD_RELEASE
/* enable dynamic module capability */ /* enable dynamic module capability */
#undef HCL_ENABLE_DYNAMIC_MODULE #undef HCL_ENABLE_DYNAMIC_MODULE

View File

@ -58,7 +58,7 @@
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
#define HCL_DEBUG_VM_PROCESSOR 1 #define HCL_DEBUG_VM_PROCESSOR 1
#define HCL_DEBUG_VM_EXEC 1 #define HCL_DEBUG_VM_EXEC 1
#define HCL_DEBUG_BIGINT 1 #define HCL_DEBUG_BIGINT 1

View File

@ -103,7 +103,9 @@ int hcl_init (hcl_t* hcl, hcl_mmgr_t* mmgr, hcl_oow_t heapsz, const hcl_vmprim_t
hcl->option.dfl_symtab_size = HCL_DFL_SYMTAB_SIZE; hcl->option.dfl_symtab_size = HCL_DFL_SYMTAB_SIZE;
hcl->option.dfl_sysdic_size = HCL_DFL_SYSDIC_SIZE; hcl->option.dfl_sysdic_size = HCL_DFL_SYSDIC_SIZE;
hcl->option.dfl_procstk_size = HCL_DFL_PROCSTK_SIZE; hcl->option.dfl_procstk_size = HCL_DFL_PROCSTK_SIZE;
#if defined(HCL_BUILD_DEBUG)
hcl->option.karatsuba_cutoff = HCL_KARATSUBA_CUTOFF; /* this won't be used when NDEBUG is set */ hcl->option.karatsuba_cutoff = HCL_KARATSUBA_CUTOFF; /* this won't be used when NDEBUG is set */
#endif
hcl->log.capa = HCL_ALIGN_POW2(1, HCL_LOG_CAPA_ALIGN); /* TODO: is this a good initial size? */ hcl->log.capa = HCL_ALIGN_POW2(1, HCL_LOG_CAPA_ALIGN); /* TODO: is this a good initial size? */
/* alloate the log buffer in advance though it may get reallocated /* alloate the log buffer in advance though it may get reallocated
@ -265,7 +267,7 @@ int hcl_setoption (hcl_t* hcl, hcl_option_t id, const void* value)
{ {
case HCL_TRAIT: case HCL_TRAIT:
hcl->option.trait = *(const unsigned int*)value; hcl->option.trait = *(const unsigned int*)value;
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
hcl->option.karatsuba_cutoff = ((hcl->option.trait & HCL_DEBUG_BIGINT)? HCL_KARATSUBA_CUTOFF_DEBUG: HCL_KARATSUBA_CUTOFF); hcl->option.karatsuba_cutoff = ((hcl->option.trait & HCL_DEBUG_BIGINT)? HCL_KARATSUBA_CUTOFF_DEBUG: HCL_KARATSUBA_CUTOFF);
#endif #endif
return 0; return 0;

View File

@ -165,7 +165,7 @@ typedef enum hcl_option_dflval_t hcl_option_dflval_t;
enum hcl_trait_t enum hcl_trait_t
{ {
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
HCL_DEBUG_GC = (1 << 0), HCL_DEBUG_GC = (1 << 0),
HCL_DEBUG_BIGINT = (1 << 1), HCL_DEBUG_BIGINT = (1 << 1),
#endif #endif
@ -963,8 +963,10 @@ struct hcl_t
hcl_oow_t dfl_sysdic_size; hcl_oow_t dfl_sysdic_size;
hcl_oow_t dfl_procstk_size; hcl_oow_t dfl_procstk_size;
#if defined(HCL_BUILD_DEBUG)
/* set automatically when trait is set */ /* set automatically when trait is set */
int karatsuba_cutoff; /* used when NDEBUG is not set only. but keep it here regardless */ int karatsuba_cutoff;
#endif
} option; } option;
hcl_vmprim_t vmprim; hcl_vmprim_t vmprim;
@ -1181,7 +1183,7 @@ typedef enum hcl_log_mask_t hcl_log_mask_t;
#define HCL_LOG5(hcl,mask,fmt,a1,a2,a3,a4,a5) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5); } while(0) #define HCL_LOG5(hcl,mask,fmt,a1,a2,a3,a4,a5) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5); } while(0)
#define HCL_LOG6(hcl,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0) #define HCL_LOG6(hcl,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (HCL_LOG_ENABLED(hcl,mask)) hcl_logbfmt(hcl, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0)
#if defined(NDEBUG) #if defined(HCL_BUILD_RELEASE)
/* [NOTE] /* [NOTE]
* get rid of debugging message totally regardless of * get rid of debugging message totally regardless of
* the log mask in the release build. * the log mask in the release build.
@ -1215,7 +1217,7 @@ typedef enum hcl_log_mask_t hcl_log_mask_t;
/* ========================================================================= /* =========================================================================
* HCL ASSERTION * HCL ASSERTION
* ========================================================================= */ * ========================================================================= */
#if defined(NDEBUG) #if defined(HCL_BUILD_RELEASE)
# define HCL_ASSERT(hcl,expr) ((void)0) # define HCL_ASSERT(hcl,expr) ((void)0)
#else #else
# define HCL_ASSERT(hcl,expr) ((void)((expr) || (hcl_assertfailed (hcl, #expr, __FILE__, __LINE__), 0))) # define HCL_ASSERT(hcl,expr) ((void)((expr) || (hcl_assertfailed (hcl, #expr, __FILE__, __LINE__), 0)))

View File

@ -1242,7 +1242,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
return 0; return 0;
} }
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
static int handle_dbgopt (hcl_t* hcl, const hcl_bch_t* str) static int handle_dbgopt (hcl_t* hcl, const hcl_bch_t* str)
{ {
xtn_t* xtn = hcl_getxtn (hcl); xtn_t* xtn = hcl_getxtn (hcl);
@ -1435,7 +1435,7 @@ int main (int argc, char* argv[])
{ {
{ ":log", 'l' }, { ":log", 'l' },
{ ":memsize", 'm' }, { ":memsize", 'm' },
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
{ ":debug", '\0' }, /* NOTE: there is no short option for --debug */ { ":debug", '\0' }, /* NOTE: there is no short option for --debug */
#endif #endif
{ HCL_NULL, '\0' } { HCL_NULL, '\0' }
@ -1449,7 +1449,7 @@ int main (int argc, char* argv[])
const char* logopt = HCL_NULL; const char* logopt = HCL_NULL;
hcl_oow_t memsize = MIN_MEMSIZE; hcl_oow_t memsize = MIN_MEMSIZE;
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
const char* dbgopt = HCL_NULL; const char* dbgopt = HCL_NULL;
#endif #endif
@ -1478,7 +1478,7 @@ int main (int argc, char* argv[])
case '\0': case '\0':
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
if (hcl_compbcstr(opt.lngopt, "debug") == 0) if (hcl_compbcstr(opt.lngopt, "debug") == 0)
{ {
dbgopt = opt.arg; dbgopt = opt.arg;
@ -1568,7 +1568,7 @@ int main (int argc, char* argv[])
xtn->logmask = HCL_LOG_ALL_TYPES | HCL_LOG_ERROR | HCL_LOG_FATAL; xtn->logmask = HCL_LOG_ALL_TYPES | HCL_LOG_ERROR | HCL_LOG_FATAL;
} }
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
if (dbgopt) if (dbgopt)
{ {
if (handle_dbgopt (hcl, dbgopt) <= -1) if (handle_dbgopt (hcl, dbgopt) <= -1)

View File

@ -31,7 +31,7 @@ void* hcl_allocbytes (hcl_t* hcl, hcl_oow_t size)
{ {
hcl_uint8_t* ptr; hcl_uint8_t* ptr;
#if !defined(NDEBUG) #if defined(HCL_BUILD_DEBUG)
if ((hcl->option.trait & HCL_DEBUG_GC) && !(hcl->option.trait & HCL_NOGC)) hcl_gc (hcl); if ((hcl->option.trait & HCL_DEBUG_GC) && !(hcl->option.trait & HCL_NOGC)) hcl_gc (hcl);
#endif #endif