]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Change StaticAssertVariableIsOfType to be a declaration
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Feb 2026 07:36:47 +0000 (08:36 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Feb 2026 07:46:02 +0000 (08:46 +0100)
This allows moving the uses to more natural and useful positions.
Also, a declaration is the more native use of static assertions in C.

Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/2273bc2a-045d-4a75-8584-7cd9396e5534%40eisentraut.org

contrib/hstore_plperl/hstore_plperl.c
contrib/hstore_plpython/hstore_plpython.c
contrib/jsonb_plpython/jsonb_plpython.c
contrib/ltree_plpython/ltree_plpython.c
src/include/c.h

index 1380a1b4367c7922c54e685b24845a41bfacb612..69001191cc0ceb90c88c4eab6666b43bd224d037 100644 (file)
@@ -21,6 +21,13 @@ static hstoreCheckKeyLen_t hstoreCheckKeyLen_p;
 typedef size_t (*hstoreCheckValLen_t) (size_t len);
 static hstoreCheckValLen_t hstoreCheckValLen_p;
 
+/* Static asserts verify that typedefs above match original declarations */
+StaticAssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
+StaticAssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
+StaticAssertVariableIsOfType(&hstorePairs, hstorePairs_t);
+StaticAssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
+StaticAssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
+
 
 /*
  * Module initialize function: fetch function pointers for cross-module calls.
@@ -28,24 +35,18 @@ static hstoreCheckValLen_t hstoreCheckValLen_p;
 void
 _PG_init(void)
 {
-       /* Static asserts verify that typedefs above match original declarations */
-       StaticAssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
        hstoreUpgrade_p = (hstoreUpgrade_t)
                load_external_function("$libdir/hstore", "hstoreUpgrade",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
        hstoreUniquePairs_p = (hstoreUniquePairs_t)
                load_external_function("$libdir/hstore", "hstoreUniquePairs",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstorePairs, hstorePairs_t);
        hstorePairs_p = (hstorePairs_t)
                load_external_function("$libdir/hstore", "hstorePairs",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
        hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t)
                load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
        hstoreCheckValLen_p = (hstoreCheckValLen_t)
                load_external_function("$libdir/hstore", "hstoreCheckValLen",
                                                           true, NULL);
index 3c8ada2a0dcdef11868f4b38df6511e286f46939..d2be030e07cb714b0711d75126427509d20e976c 100644 (file)
@@ -28,6 +28,15 @@ static hstoreCheckKeyLen_t hstoreCheckKeyLen_p;
 typedef size_t (*hstoreCheckValLen_t) (size_t len);
 static hstoreCheckValLen_t hstoreCheckValLen_p;
 
+/* Static asserts verify that typedefs above match original declarations */
+StaticAssertVariableIsOfType(&PLyObject_AsString, PLyObject_AsString_t);
+StaticAssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
+StaticAssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
+StaticAssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
+StaticAssertVariableIsOfType(&hstorePairs, hstorePairs_t);
+StaticAssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
+StaticAssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
+
 
 /*
  * Module initialize function: fetch function pointers for cross-module calls.
@@ -35,32 +44,24 @@ static hstoreCheckValLen_t hstoreCheckValLen_p;
 void
 _PG_init(void)
 {
-       /* Static asserts verify that typedefs above match original declarations */
-       StaticAssertVariableIsOfType(&PLyObject_AsString, PLyObject_AsString_t);
        PLyObject_AsString_p = (PLyObject_AsString_t)
                load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
        PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
                load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
        hstoreUpgrade_p = (hstoreUpgrade_t)
                load_external_function("$libdir/hstore", "hstoreUpgrade",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
        hstoreUniquePairs_p = (hstoreUniquePairs_t)
                load_external_function("$libdir/hstore", "hstoreUniquePairs",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstorePairs, hstorePairs_t);
        hstorePairs_p = (hstorePairs_t)
                load_external_function("$libdir/hstore", "hstorePairs",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
        hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t)
                load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
        hstoreCheckValLen_p = (hstoreCheckValLen_t)
                load_external_function("$libdir/hstore", "hstoreCheckValLen",
                                                           true, NULL);
index 1983bf8c30a90530607b46fdce50ada37d2fadeb..c2c4ce37c0853ad4aed241bf286a33e885536c48 100644 (file)
@@ -33,22 +33,24 @@ typedef PyObject *(*PLyUnicode_FromStringAndSize_t)
                        (const char *s, Py_ssize_t size);
 static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
 
+/* Static asserts verify that typedefs above match original declarations */
+StaticAssertVariableIsOfType(&PLyObject_AsString, PLyObject_AsString_t);
+StaticAssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
+StaticAssertVariableIsOfType(&PLy_elog_impl, PLy_elog_impl_t);
+
+
 /*
  * Module initialize function: fetch function pointers for cross-module calls.
  */
 void
 _PG_init(void)
 {
-       /* Static asserts verify that typedefs above match original declarations */
-       StaticAssertVariableIsOfType(&PLyObject_AsString, PLyObject_AsString_t);
        PLyObject_AsString_p = (PLyObject_AsString_t)
                load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
        PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
                load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
                                                           true, NULL);
-       StaticAssertVariableIsOfType(&PLy_elog_impl, PLy_elog_impl_t);
        PLy_elog_impl_p = (PLy_elog_impl_t)
                load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLy_elog_impl",
                                                           true, NULL);
index a25fb5c5fa5be4ab5d001b669676f08c9c511bc7..d4e7b613fa1e2ac613056ae5508faa28e8fbdadc 100644 (file)
@@ -13,6 +13,9 @@ PG_MODULE_MAGIC_EXT(
 typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
 static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
 
+/* Static asserts verify that typedefs above match original declarations */
+StaticAssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
+
 
 /*
  * Module initialize function: fetch function pointers for cross-module calls.
@@ -20,8 +23,6 @@ static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
 void
 _PG_init(void)
 {
-       /* Static asserts verify that typedefs above match original declarations */
-       StaticAssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
        PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
                load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
                                                           true, NULL);
index 68df93ed423b8eb8795f11f379ff42d876884005..063eac9808c374654baaf8471fbd98a5cdf63db8 100644 (file)
@@ -955,7 +955,7 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
 /*
  * Compile-time checks that a variable (or expression) has the specified type.
  *
- * StaticAssertVariableIsOfType() can be used as a statement.
+ * StaticAssertVariableIsOfType() can be used as a declaration.
  * StaticAssertVariableIsOfTypeMacro() is intended for use in macros, eg
  *             #define foo(x) (StaticAssertVariableIsOfTypeMacro(x, int), bar(x))
  *
@@ -965,14 +965,14 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
  */
 #ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
 #define StaticAssertVariableIsOfType(varname, typename) \
-       StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+       StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
        CppAsString(varname) " does not have type " CppAsString(typename))
 #define StaticAssertVariableIsOfTypeMacro(varname, typename) \
        (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
         CppAsString(varname) " does not have type " CppAsString(typename)))
 #else                                                  /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
 #define StaticAssertVariableIsOfType(varname, typename) \
-       StaticAssertStmt(sizeof(varname) == sizeof(typename), \
+       StaticAssertDecl(sizeof(varname) == sizeof(typename), \
        CppAsString(varname) " does not have type " CppAsString(typename))
 #define StaticAssertVariableIsOfTypeMacro(varname, typename) \
        (StaticAssertExpr(sizeof(varname) == sizeof(typename), \