Skip to content

Commit b8f44a4

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/[email protected] Backpatch-through: 16
1 parent ee3a551 commit b8f44a4

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
@@ -2031,7 +2035,7 @@ pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
20312035
#endif
20322036
else
20332037
/* shouldn't happen */
2034-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2038+
PGLOCALE_SUPPORT_ERROR(locale->provider);
20352039

20362040
return result;
20372041
}
@@ -2067,7 +2071,7 @@ pg_strncoll(const char *arg1, size_t len1, const char *arg2, size_t len2,
20672071
#endif
20682072
else
20692073
/* shouldn't happen */
2070-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2074+
PGLOCALE_SUPPORT_ERROR(locale->provider);
20712075

20722076
return result;
20732077
}
@@ -2086,7 +2090,7 @@ pg_strxfrm_libc(char *dest, const char *src, size_t destsize,
20862090
return strxfrm(dest, src, destsize);
20872091
#else
20882092
/* shouldn't happen */
2089-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2093+
PGLOCALE_SUPPORT_ERROR(locale->provider);
20902094
return 0; /* keep compiler quiet */
20912095
#endif
20922096
}
@@ -2282,7 +2286,7 @@ pg_strxfrm_enabled(pg_locale_t locale)
22822286
return true;
22832287
else
22842288
/* shouldn't happen */
2285-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2289+
PGLOCALE_SUPPORT_ERROR(locale->provider);
22862290

22872291
return false; /* keep compiler quiet */
22882292
}
@@ -2314,7 +2318,7 @@ pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
23142318
#endif
23152319
else
23162320
/* shouldn't happen */
2317-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2321+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23182322

23192323
return result;
23202324
}
@@ -2351,7 +2355,7 @@ pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen,
23512355
#endif
23522356
else
23532357
/* shouldn't happen */
2354-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2358+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23552359

23562360
return result;
23572361
}
@@ -2369,7 +2373,7 @@ pg_strxfrm_prefix_enabled(pg_locale_t locale)
23692373
return true;
23702374
else
23712375
/* shouldn't happen */
2372-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2376+
PGLOCALE_SUPPORT_ERROR(locale->provider);
23732377

23742378
return false; /* keep compiler quiet */
23752379
}
@@ -2393,16 +2397,14 @@ pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,
23932397
{
23942398
size_t result = 0; /* keep compiler quiet */
23952399

2396-
if (!locale || locale->provider == COLLPROVIDER_LIBC)
2397-
elog(ERROR, "collprovider '%c' does not support pg_strxfrm_prefix()",
2398-
locale->provider);
2400+
if (!locale)
2401+
PGLOCALE_SUPPORT_ERROR(COLLPROVIDER_LIBC);
23992402
#ifdef USE_ICU
24002403
else if (locale->provider == COLLPROVIDER_ICU)
24012404
result = pg_strnxfrm_prefix_icu(dest, src, -1, destsize, locale);
24022405
#endif
24032406
else
2404-
/* shouldn't happen */
2405-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2407+
PGLOCALE_SUPPORT_ERROR(locale->provider);
24062408

24072409
return result;
24082410
}
@@ -2430,16 +2432,14 @@ pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
24302432
{
24312433
size_t result = 0; /* keep compiler quiet */
24322434

2433-
if (!locale || locale->provider == COLLPROVIDER_LIBC)
2434-
elog(ERROR, "collprovider '%c' does not support pg_strnxfrm_prefix()",
2435-
locale->provider);
2435+
if (!locale)
2436+
PGLOCALE_SUPPORT_ERROR(COLLPROVIDER_LIBC);
24362437
#ifdef USE_ICU
24372438
else if (locale->provider == COLLPROVIDER_ICU)
24382439
result = pg_strnxfrm_prefix_icu(dest, src, -1, destsize, locale);
24392440
#endif
24402441
else
2441-
/* shouldn't happen */
2442-
elog(ERROR, "unsupported collprovider: %c", locale->provider);
2442+
PGLOCALE_SUPPORT_ERROR(locale->provider);
24432443

24442444
return result;
24452445
}

0 commit comments

Comments
 (0)