Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b6cb46

Browse files
committed
isn: Fix debug code
The ISN_DEBUG code did not compile. Fix that code, don't hide it behindan #ifdef, make it run when building with asserts, and make it error outinstead of just logging if it fails.Reviewed-by: David Steele <david@pgmasters.net>
1 parent98470fd commit9b6cb46

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

‎contrib/isn/isn.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
PG_MODULE_MAGIC;
2828

29+
#ifdefUSE_ASSERT_CHECKING
30+
#defineISN_DEBUG 1
31+
#else
32+
#defineISN_DEBUG 0
33+
#endif
34+
2935
#defineMAXEAN13LEN 18
3036

3137
enumisn_type
@@ -36,7 +42,6 @@ enum isn_type
3642
staticconstchar*constisn_names[]= {"EAN13/UPC/ISxN","EAN13/UPC/ISxN","EAN13","ISBN","ISMN","ISSN","UPC"};
3743

3844
staticboolg_weak= false;
39-
staticboolg_initialized= false;
4045

4146

4247
/***********************************************************************
@@ -56,7 +61,7 @@ static bool g_initialized = false;
5661
/*
5762
* Check if the table and its index is correct (just for debugging)
5863
*/
59-
#ifdefISN_DEBUG
64+
pg_attribute_unused()
6065
staticbool
6166
check_table(constchar*(*TABLE)[2],constunsignedTABLE_index[10][2])
6267
{
@@ -68,7 +73,6 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
6873
y=-1,
6974
i=0,
7075
j,
71-
cnt=0,
7276
init=0;
7377

7478
if (TABLE==NULL||TABLE_index==NULL)
@@ -131,7 +135,6 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
131135
elog(DEBUG1,"index %d is invalid",j);
132136
return false;
133137
}
134-
#endif/* ISN_DEBUG */
135138

136139
/*----------------------------------------------------------
137140
* Formatting and conversion routines.
@@ -922,22 +925,24 @@ string2ean(const char *str, bool errorOK, ean13 *result,
922925
* Exported routines.
923926
*---------------------------------------------------------*/
924927

928+
void_PG_init(void);
929+
925930
void
926-
initialize(void)
931+
_PG_init(void)
927932
{
928-
#ifdefISN_DEBUG
929-
if (!check_table(EAN13,EAN13_index))
930-
elog(LOG,"EAN13 failed check");
931-
if (!check_table(ISBN,ISBN_index))
932-
elog(LOG,"ISBN failed check");
933-
if (!check_table(ISMN,ISMN_index))
934-
elog(LOG,"ISMN failed check");
935-
if (!check_table(ISSN,ISSN_index))
936-
elog(LOG,"ISSN failed check");
937-
if (!check_table(UPC,UPC_index))
938-
elog(LOG,"UPC failed check");
939-
#endif
940-
g_initialized= true;
933+
if (ISN_DEBUG)
934+
{
935+
if (!check_table(EAN13_range,EAN13_index))
936+
elog(ERROR,"EAN13 failed check");
937+
if (!check_table(ISBN_range,ISBN_index))
938+
elog(ERROR,"ISBN failed check");
939+
if (!check_table(ISMN_range,ISMN_index))
940+
elog(ERROR,"ISMN failed check");
941+
if (!check_table(ISSN_range,ISSN_index))
942+
elog(ERROR,"ISSN failed check");
943+
if (!check_table(UPC_range,UPC_index))
944+
elog(ERROR,"UPC failed check");
945+
}
941946
}
942947

943948
/* isn_out

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp