1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

Rename pg_builtin_integer_constant_p to pg_integer_constant_p

Since it's not builtin.  Also fix a related typo.

Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAApHDvom02B_XNVSkvxznVUyZbjGAR%2B5myA89ZcbEd3%3DPA9UcA%40mail.gmail.com
This commit is contained in:
Peter Eisentraut
2025-09-30 21:15:46 +02:00
parent 19d4f9ffc2
commit 8e2acda2b0
2 changed files with 14 additions and 15 deletions

View File

@@ -336,14 +336,13 @@
* compile-time integer const. We don't define this macro to return 0 when * compile-time integer const. We don't define this macro to return 0 when
* unsupported due to the risk of users of the macro misbehaving if we return * unsupported due to the risk of users of the macro misbehaving if we return
* 0 when the expression *is* an integer constant. Callers may check if this * 0 when the expression *is* an integer constant. Callers may check if this
* macro is defined by checking if HAVE_PG_BUILTIN_INTEGER_CONSTANT_P is * macro is defined by checking if HAVE_PG_INTEGER_CONSTANT_P is defined.
* defined.
*/ */
#if defined(HAVE__BUILTIN_CONSTANT_P) #if defined(HAVE__BUILTIN_CONSTANT_P)
/* When __builtin_const_p() is available, use it. */ /* When __builtin_constant_p() is available, use it. */
#define pg_builtin_integer_constant_p(x) __builtin_constant_p(x) #define pg_integer_constant_p(x) __builtin_constant_p(x)
#define HAVE_PG_BUILTIN_INTEGER_CONSTANT_P #define HAVE_PG_INTEGER_CONSTANT_P
#elif defined(_MSC_VER) && defined(__STDC_VERSION__) #elif defined(_MSC_VER) && defined(__STDC_VERSION__)
/* /*
@@ -353,9 +352,9 @@
* and only works with integer constants. Compilation will fail if given a * and only works with integer constants. Compilation will fail if given a
* constant or variable of any type other than an integer. * constant or variable of any type other than an integer.
*/ */
#define pg_builtin_integer_constant_p(x) \ #define pg_integer_constant_p(x) \
_Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0) _Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0)
#define HAVE_PG_BUILTIN_INTEGER_CONSTANT_P #define HAVE_PG_INTEGER_CONSTANT_P
#endif #endif
/* /*

View File

@@ -119,11 +119,11 @@ struct Node;
* ereport_domain() directly, or preferably they can override the TEXTDOMAIN * ereport_domain() directly, or preferably they can override the TEXTDOMAIN
* macro. * macro.
* *
* When pg_builtin_integer_constant_p is available and elevel >= ERROR we make * When pg_integer_constant_p is available and elevel >= ERROR we make
* a call to errstart_cold() instead of errstart(). This version of the * a call to errstart_cold() instead of errstart(). This version of the
* function is marked with pg_attribute_cold which will coax supporting * function is marked with pg_attribute_cold which will coax supporting
* compilers into generating code which is more optimized towards non-ERROR * compilers into generating code which is more optimized towards non-ERROR
* cases. Because we use pg_builtin_integer_constant_p() in the condition, * cases. Because we use pg_integer_constant_p() in the condition,
* when elevel is not a compile-time constant, or if it is, but it's < ERROR, * when elevel is not a compile-time constant, or if it is, but it's < ERROR,
* the compiler has no need to generate any code for this branch. It can * the compiler has no need to generate any code for this branch. It can
* simply call errstart() unconditionally. * simply call errstart() unconditionally.
@@ -131,25 +131,25 @@ struct Node;
* If elevel >= ERROR, the call will not return; we try to inform the compiler * If elevel >= ERROR, the call will not return; we try to inform the compiler
* of that via pg_unreachable(). However, no useful optimization effect is * of that via pg_unreachable(). However, no useful optimization effect is
* obtained unless the compiler sees elevel as a compile-time constant, else * obtained unless the compiler sees elevel as a compile-time constant, else
* we're just adding code bloat. So, if pg_builtin_integer_constant_p is * we're just adding code bloat. So, if pg_integer_constant_p is
* available, use that to cause the second if() to vanish completely for * available, use that to cause the second if() to vanish completely for
* non-constant cases. We avoid using a local variable because it's not * non-constant cases. We avoid using a local variable because it's not
* necessary and prevents gcc from making the unreachability deduction at * necessary and prevents gcc from making the unreachability deduction at
* optlevel -O0. * optlevel -O0.
*---------- *----------
*/ */
#ifdef HAVE_PG_BUILTIN_INTEGER_CONSTANT_P #ifdef HAVE_PG_INTEGER_CONSTANT_P
#define ereport_domain(elevel, domain, ...) \ #define ereport_domain(elevel, domain, ...) \
do { \ do { \
pg_prevent_errno_in_scope(); \ pg_prevent_errno_in_scope(); \
if (pg_builtin_integer_constant_p(elevel) && (elevel) >= ERROR ? \ if (pg_integer_constant_p(elevel) && (elevel) >= ERROR ? \
errstart_cold(elevel, domain) : \ errstart_cold(elevel, domain) : \
errstart(elevel, domain)) \ errstart(elevel, domain)) \
__VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \ __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
if (pg_builtin_integer_constant_p(elevel) && (elevel) >= ERROR) \ if (pg_integer_constant_p(elevel) && (elevel) >= ERROR) \
pg_unreachable(); \ pg_unreachable(); \
} while(0) } while(0)
#else /* !HAVE_PG_BUILTIN_INTEGER_CONSTANT_P */ #else /* !HAVE_PG_INTEGER_CONSTANT_P */
#define ereport_domain(elevel, domain, ...) \ #define ereport_domain(elevel, domain, ...) \
do { \ do { \
const int elevel_ = (elevel); \ const int elevel_ = (elevel); \
@@ -159,7 +159,7 @@ struct Node;
if (elevel_ >= ERROR) \ if (elevel_ >= ERROR) \
pg_unreachable(); \ pg_unreachable(); \
} while(0) } while(0)
#endif /* HAVE_PG_BUILTIN_INTEGER_CONSTANT_P */ #endif /* HAVE_PG_INTEGER_CONSTANT_P */
#define ereport(elevel, ...) \ #define ereport(elevel, ...) \
ereport_domain(elevel, TEXTDOMAIN, __VA_ARGS__) ereport_domain(elevel, TEXTDOMAIN, __VA_ARGS__)