Change config_generic.vartype to be initialized at compile time
authorPeter Eisentraut <[email protected]>
Fri, 17 Oct 2025 08:33:54 +0000 (10:33 +0200)
committerPeter Eisentraut <[email protected]>
Fri, 17 Oct 2025 08:33:54 +0000 (10:33 +0200)
Previously, this was initialized at run time so that it did not have
to be maintained by hand in guc_tables.c.  But since that table is now
generated anyway, we might as well generate this bit as well.

Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/8fdfb91e-60fb-44fa-8df6-f5dea47353c9@eisentraut.org

src/backend/utils/misc/gen_guc_tables.pl
src/backend/utils/misc/guc.c
src/include/utils/guc_tables.h

index a48a9ebd0eb258125aed27cd3211ace3baf8452c..b187259bf1e62227a1b9471d93e27d926f826acf 100644 (file)
@@ -68,6 +68,7 @@ sub print_one_table
          if $entry->{long_desc};
        printf $ofh "\t\t\t.flags = %s,\n", $entry->{flags}
          if $entry->{flags};
+       printf $ofh "\t\t\t.vartype = %s,\n", ('PGC_' . uc($type));
        print $ofh "\t\t},\n";
        printf $ofh "\t\t.variable = &%s,\n", $entry->{variable};
        printf $ofh "\t\t.boot_val = %s,\n", $entry->{boot_val};
index a64427ac979b7d5bc54d3c5fa48cca5c6d1c449c..a82286cc98affd2e5d34c1c8c9d2dd75c6f24966 100644 (file)
@@ -890,48 +890,22 @@ build_guc_variables(void)
                                             ALLOCSET_DEFAULT_SIZES);
 
    /*
-    * Count all the built-in variables, and set their vartypes correctly.
+    * Count all the built-in variables.
     */
    for (int i = 0; ConfigureNamesBool[i].gen.name; i++)
-   {
-       struct config_bool *conf = &ConfigureNamesBool[i];
-
-       /* Rather than requiring vartype to be filled in by hand, do this: */
-       conf->gen.vartype = PGC_BOOL;
        num_vars++;
-   }
 
    for (int i = 0; ConfigureNamesInt[i].gen.name; i++)
-   {
-       struct config_int *conf = &ConfigureNamesInt[i];
-
-       conf->gen.vartype = PGC_INT;
        num_vars++;
-   }
 
    for (int i = 0; ConfigureNamesReal[i].gen.name; i++)
-   {
-       struct config_real *conf = &ConfigureNamesReal[i];
-
-       conf->gen.vartype = PGC_REAL;
        num_vars++;
-   }
 
    for (int i = 0; ConfigureNamesString[i].gen.name; i++)
-   {
-       struct config_string *conf = &ConfigureNamesString[i];
-
-       conf->gen.vartype = PGC_STRING;
        num_vars++;
-   }
 
    for (int i = 0; ConfigureNamesEnum[i].gen.name; i++)
-   {
-       struct config_enum *conf = &ConfigureNamesEnum[i];
-
-       conf->gen.vartype = PGC_ENUM;
        num_vars++;
-   }
 
    /*
     * Create hash table with 20% slack
index c5776be029bb4ac9368cb35372e702bd3f1968e6..3de3d8095456eba198d4502cf8045e56c1ce1310 100644 (file)
@@ -177,8 +177,8 @@ struct config_generic
    const char *short_desc;     /* short desc. of this variable's purpose */
    const char *long_desc;      /* long desc. of this variable's purpose */
    int         flags;          /* flag bits, see guc.h */
+   enum config_type vartype;   /* type of variable */
    /* variable fields, initialized at runtime: */
-   enum config_type vartype;   /* type of variable (set only at startup) */
    int         status;         /* status bits, see below */
    GucSource   source;         /* source of the current actual value */
    GucSource   reset_source;   /* source of the reset_value */