Skip to content

Commit 800d5bc

Browse files
committed
Refactor error messages for unsupported providers in pg_locale.c
These code paths should not be reached normally, but if they are an error with "(null)" as information for the collation provider would show up if no locale is set, while we can assume that we are referring to libc. This refactors the code so as the provider is always reported even if no locale is set. The name of the function where the error happens is added, while on it, as it can be helpful for debugging. Issue introduced by d87d548, so backpatch down to 16. Author: Michael Paquier, Ranier Vilela Reviewed-by: Jeff Davis, Kyotaro Horiguchi Discussion: https://postgr.es/m/7073610042fcf97e1bea2ce08b7e0214b5e11094.camel@j-davis.com Backpatch-through: 16
1 parent 1a6900e commit 800d5bc

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
#include <shlwapi.h>
8282
#endif
8383

84+
/* Error triggered for locale-sensitive subroutines */
85+
#define PGLOCALE_SUPPORT_ERROR(provider) \
86+
elog(ERROR, "unsupported collprovider for %s: %c", __func__, provider)
87+
8488
/*
8589
* This should be large enough that most strings will fit, but small enough
8690
* that we feel comfortable putting it on the stack
@@ -2016,7 +2020,7 @@ pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
20162020
#endif
20172021
else
20182022
/* shouldn't happen */
2019-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2023+
PGLOCALE_SUPPORT_ERROR(locale->provider);
20202024

20212025
return result;
20222026
}
@@ -2052,7 +2056,7 @@ pg_strncoll(const char *arg1, size_t len1, const char *arg2, size_t len2,
20522056
#endif
20532057
else
20542058
/* shouldn't happen */
2055-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2059+
PGLOCALE_SUPPORT_ERROR(locale->provider);
20562060

20572061
return result;
20582062
}
@@ -2073,7 +2077,7 @@ pg_strxfrm_libc(char *dest, const char *src, size_t destsize,
20732077
return strxfrm(dest, src, destsize);
20742078
#else
20752079
/* shouldn't happen */
2076-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2080+
PGLOCALE_SUPPORT_ERROR(locale->provider);
20772081
return 0; /* keep compiler quiet */
20782082
#endif
20792083
}
@@ -2269,7 +2273,7 @@ pg_strxfrm_enabled(pg_locale_t locale)
22692273
return true;
22702274
else
22712275
/* shouldn't happen */
2272-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2276+
PGLOCALE_SUPPORT_ERROR(locale->provider);
22732277

22742278
return false; /* keep compiler quiet */
22752279
}
@@ -2301,7 +2305,7 @@ pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
23012305
#endif
23022306
else
23032307
/* shouldn't happen */
2304-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2308+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23052309

23062310
return result;
23072311
}
@@ -2338,7 +2342,7 @@ pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen,
23382342
#endif
23392343
else
23402344
/* shouldn't happen */
2341-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2345+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23422346

23432347
return result;
23442348
}
@@ -2356,7 +2360,7 @@ pg_strxfrm_prefix_enabled(pg_locale_t locale)
23562360
return true;
23572361
else
23582362
/* shouldn't happen */
2359-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2363+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23602364

23612365
return false; /* keep compiler quiet */
23622366
}
@@ -2380,16 +2384,14 @@ pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,
23802384
{
23812385
size_t result = 0; /* keep compiler quiet */
23822386

2383-
if (!locale || locale->provider == COLLPROVIDER_LIBC)
2384-
elog(ERROR, "collprovider '%c' does not support pg_strxfrm_prefix()",
2385-
locale->provider);
2387+
if (!locale)
2388+
PGLOCALE_SUPPORT_ERROR(COLLPROVIDER_LIBC);
23862389
#ifdef USE_ICU
23872390
else if (locale->provider == COLLPROVIDER_ICU)
23882391
result = pg_strnxfrm_prefix_icu(dest, src, -1, destsize, locale);
23892392
#endif
23902393
else
2391-
/* shouldn't happen */
2392-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2394+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23932395

23942396
return result;
23952397
}
@@ -2417,16 +2419,14 @@ pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
24172419
{
24182420
size_t result = 0; /* keep compiler quiet */
24192421

2420-
if (!locale || locale->provider == COLLPROVIDER_LIBC)
2421-
elog(ERROR, "collprovider '%c' does not support pg_strnxfrm_prefix()",
2422-
locale->provider);
2422+
if (!locale)
2423+
PGLOCALE_SUPPORT_ERROR(COLLPROVIDER_LIBC);
24232424
#ifdef USE_ICU
24242425
else if (locale->provider == COLLPROVIDER_ICU)
24252426
result = pg_strnxfrm_prefix_icu(dest, src, -1, destsize, locale);
24262427
#endif
24272428
else
2428-
/* shouldn't happen */
2429-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2429+
PGLOCALE_SUPPORT_ERROR(locale->provider);
24302430

24312431
return result;
24322432
}

0 commit comments

Comments
 (0)