From 2a311b72fa252873809ae4f92047d61adbb62e98 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 11 Aug 2017 21:04:04 -0400 Subject: [PATCH v2 7/7] isn: Fix debug code The ISN_DEBUG code did not compile. Fix that code, don't hide it behind an #ifdef, make it run when building with asserts, and make it error out instead of just logging if it fails. --- contrib/isn/isn.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c index 4d845b716f..0148f9549f 100644 --- a/contrib/isn/isn.c +++ b/contrib/isn/isn.c @@ -26,6 +26,12 @@ PG_MODULE_MAGIC; +#ifdef USE_ASSERT_CHECKING +#define ISN_DEBUG 1 +#else +#define ISN_DEBUG 0 +#endif + #define MAXEAN13LEN 18 enum isn_type @@ -36,7 +42,6 @@ enum isn_type static const char *const isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC"}; static bool g_weak = false; -static bool g_initialized = false; /*********************************************************************** @@ -56,7 +61,7 @@ static bool g_initialized = false; /* * Check if the table and its index is correct (just for debugging) */ -#ifdef ISN_DEBUG +pg_attribute_unused() static bool check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2]) { @@ -68,7 +73,6 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2]) y = -1, i = 0, j, - cnt = 0, init = 0; if (TABLE == NULL || TABLE_index == NULL) @@ -131,7 +135,6 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2]) elog(DEBUG1, "index %d is invalid", j); return false; } -#endif /* ISN_DEBUG */ /*---------------------------------------------------------- * Formatting and conversion routines. @@ -922,22 +925,24 @@ string2ean(const char *str, bool errorOK, ean13 *result, * Exported routines. *---------------------------------------------------------*/ +void _PG_init(void); + void -initialize(void) +_PG_init(void) { -#ifdef ISN_DEBUG - if (!check_table(EAN13, EAN13_index)) - elog(LOG, "EAN13 failed check"); - if (!check_table(ISBN, ISBN_index)) - elog(LOG, "ISBN failed check"); - if (!check_table(ISMN, ISMN_index)) - elog(LOG, "ISMN failed check"); - if (!check_table(ISSN, ISSN_index)) - elog(LOG, "ISSN failed check"); - if (!check_table(UPC, UPC_index)) - elog(LOG, "UPC failed check"); -#endif - g_initialized = true; + if (ISN_DEBUG) + { + if (!check_table(EAN13_range, EAN13_index)) + elog(ERROR, "EAN13 failed check"); + if (!check_table(ISBN_range, ISBN_index)) + elog(ERROR, "ISBN failed check"); + if (!check_table(ISMN_range, ISMN_index)) + elog(ERROR, "ISMN failed check"); + if (!check_table(ISSN_range, ISSN_index)) + elog(ERROR, "ISSN failed check"); + if (!check_table(UPC_range, UPC_index)) + elog(ERROR, "UPC failed check"); + } } /* isn_out -- 2.11.0 (Apple Git-81)