Skip to content

Commit 8137f2c

Browse files
committed
Hide most variable-length fields from Form_pg_* structs
Those fields only appear in the structs so that genbki.pl can create the BKI bootstrap files for the catalogs. But they are not actually usable from C. So hiding them can prevent coding mistakes, saves stack space, and can help the compiler. In certain catalogs, the first variable-length field has been kept visible after manual inspection. These exceptions are noted in C comments. reviewed by Tom Lane
1 parent 8a3f745 commit 8137f2c

32 files changed

+85
-49
lines changed

src/backend/catalog/Catalog.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ sub Catalogs
143143
elsif ($declaring_attributes)
144144
{
145145
next if (/^{|^$/);
146+
next if (/^#/);
146147
if (/^}/)
147148
{
148149
undef $declaring_attributes;
149150
}
150151
else
151152
{
152153
my ($atttype, $attname) = split /\s+/, $_;
154+
die "parse error ($input_file)" unless $attname;
153155
if (exists $RENAME_ATTTYPE{$atttype})
154156
{
155157
$atttype = $RENAME_ATTTYPE{$atttype};

src/include/catalog/genbki.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
/* Introduces a catalog's structure definition */
2323
#define CATALOG(name,oid) typedef struct CppConcat(FormData_,name)
2424

25+
/*
26+
* This is never defined; it's here only for documentation.
27+
*
28+
* Variable-length catalog fields (except possibly the first not nullable one)
29+
* should not be visible in C structures, so they are made invisible by #ifdefs
30+
* of an undefined symbol. See also MARKNOTNULL in bootstrap.c for how this is
31+
* handled.
32+
*/
33+
#undef CATALOG_VARLEN
34+
2535
/* Options that may appear after CATALOG (on the same line) */
2636
#define BKI_BOOTSTRAP
2737
#define BKI_SHARED_RELATION

src/include/catalog/pg_aggregate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ CATALOG(pg_aggregate,2600) BKI_WITHOUT_OIDS
4444
regproc aggfinalfn;
4545
Oid aggsortop;
4646
Oid aggtranstype;
47-
text agginitval; /* VARIABLE LENGTH FIELD */
47+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
48+
text agginitval;
49+
#endif
4850
} FormData_pg_aggregate;
4951

5052
/* ----------------

src/include/catalog/pg_attrdef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ CATALOG(pg_attrdef,2604)
3232
{
3333
Oid adrelid; /* OID of table containing attribute */
3434
int2 adnum; /* attnum of attribute */
35+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
3536
pg_node_tree adbin; /* nodeToString representation of default */
3637
text adsrc; /* human-readable representation of default */
38+
#endif
3739
} FormData_pg_attrdef;
3840

3941
/* ----------------

src/include/catalog/pg_attribute.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,8 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
145145
/* attribute's collation */
146146
Oid attcollation;
147147

148-
/*
149-
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
150-
*
151-
* NOTE: the following fields are not present in tuple descriptors!
152-
*/
148+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
149+
/* NOTE: The following fields are not present in tuple descriptors. */
153150

154151
/* Column-level access permissions */
155152
aclitem attacl[1];
@@ -159,6 +156,7 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
159156

160157
/* Column-level FDW options */
161158
text attfdwoptions[1];
159+
#endif
162160
} FormData_pg_attribute;
163161

164162
/*

src/include/catalog/pg_class.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,11 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
6868
bool relhassubclass; /* has (or has had) derived classes */
6969
TransactionId relfrozenxid; /* all Xids < this are frozen in this rel */
7070

71-
/*
72-
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
73-
*
74-
* NOTE: these fields are not present in a relcache entry's rd_rel field.
75-
*/
76-
71+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
72+
/* NOTE: These fields are not present in a relcache entry's rd_rel field. */
7773
aclitem relacl[1]; /* access permissions */
7874
text reloptions[1]; /* access-method-specific options */
75+
#endif
7976
} FormData_pg_class;
8077

8178
/* Size of fixed part of pg_class tuples, not counting var-length fields */

src/include/catalog/pg_constraint.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ CATALOG(pg_constraint,2606)
9191
/* Has a local definition and cannot be inherited */
9292
bool conisonly;
9393

94-
/*
95-
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
96-
*/
97-
94+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
9895
/*
9996
* Columns of conrelid that the constraint applies to, if known (this is
10097
* NULL for trigger constraints)
@@ -139,6 +136,7 @@ CATALOG(pg_constraint,2606)
139136
* If a check constraint, source-text representation of expression
140137
*/
141138
text consrc;
139+
#endif
142140
} FormData_pg_constraint;
143141

144142
/* ----------------

src/include/catalog/pg_database.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248) BKI_SCHEMA_M
4242
Oid datlastsysoid; /* highest OID to consider a system OID */
4343
TransactionId datfrozenxid; /* all Xids < this are frozen in this DB */
4444
Oid dattablespace; /* default table space for this DB */
45-
aclitem datacl[1]; /* access permissions (VAR LENGTH) */
45+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
46+
aclitem datacl[1]; /* access permissions */
47+
#endif
4648
} FormData_pg_database;
4749

4850
/* ----------------

src/include/catalog/pg_db_role_setting.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ CATALOG(pg_db_role_setting,2964) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
3535
{
3636
Oid setdatabase; /* database */
3737
Oid setrole; /* role */
38+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
3839
text setconfig[1]; /* GUC settings to apply at login */
40+
#endif
3941
} FormData_pg_db_role_setting;
4042

4143
typedef FormData_pg_db_role_setting *Form_pg_db_role_setting;

src/include/catalog/pg_default_acl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ CATALOG(pg_default_acl,826)
3232
Oid defaclrole; /* OID of role owning this ACL */
3333
Oid defaclnamespace; /* OID of namespace, or 0 for all */
3434
char defaclobjtype; /* see DEFACLOBJ_xxx constants below */
35-
36-
/*
37-
* VARIABLE LENGTH FIELDS start here.
38-
*/
39-
35+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
4036
aclitem defaclacl[1]; /* permissions to add at CREATE time */
37+
#endif
4138
} FormData_pg_default_acl;
4239

4340
/* ----------------

src/include/catalog/pg_description.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ CATALOG(pg_description,2609) BKI_WITHOUT_OIDS
5050
Oid objoid; /* OID of object itself */
5151
Oid classoid; /* OID of table containing object */
5252
int4 objsubid; /* column number, or 0 if not used */
53+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
5354
text description; /* description of object */
55+
#endif
5456
} FormData_pg_description;
5557

5658
/* ----------------

src/include/catalog/pg_extension.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,12 @@ CATALOG(pg_extension,3079)
3434
Oid extowner; /* extension owner */
3535
Oid extnamespace; /* namespace of contained objects */
3636
bool extrelocatable; /* if true, allow ALTER EXTENSION SET SCHEMA */
37-
38-
/*
39-
* VARIABLE LENGTH FIELDS start here.
40-
*
41-
* extversion should never be null, but the others can be.
42-
*/
37+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
38+
/* extversion should never be null, but the others can be. */
4339
text extversion; /* extension version name */
4440
Oid extconfig[1]; /* dumpable configuration tables */
4541
text extcondition[1]; /* WHERE clauses for config tables */
42+
#endif
4643
} FormData_pg_extension;
4744

4845
/* ----------------

src/include/catalog/pg_foreign_data_wrapper.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ CATALOG(pg_foreign_data_wrapper,2328)
3434
Oid fdwowner; /* FDW owner */
3535
Oid fdwhandler; /* handler function, or 0 if none */
3636
Oid fdwvalidator; /* option validation function, or 0 if none */
37-
38-
/* VARIABLE LENGTH FIELDS start here. */
39-
37+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
4038
aclitem fdwacl[1]; /* access permissions */
4139
text fdwoptions[1]; /* FDW options */
40+
#endif
4241
} FormData_pg_foreign_data_wrapper;
4342

4443
/* ----------------

src/include/catalog/pg_foreign_server.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ CATALOG(pg_foreign_server,1417)
3131
NameData srvname; /* foreign server name */
3232
Oid srvowner; /* server owner */
3333
Oid srvfdw; /* server FDW */
34-
35-
/*
36-
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
37-
*/
34+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
3835
text srvtype;
3936
text srvversion;
4037
aclitem srvacl[1]; /* access permissions */
4138
text srvoptions[1]; /* FDW-specific options */
39+
#endif
4240
} FormData_pg_foreign_server;
4341

4442
/* ----------------

src/include/catalog/pg_foreign_table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ CATALOG(pg_foreign_table,3118) BKI_WITHOUT_OIDS
3030
{
3131
Oid ftrelid; /* OID of foreign table */
3232
Oid ftserver; /* OID of foreign server */
33+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
3334
text ftoptions[1]; /* FDW-specific options */
35+
#endif
3436
} FormData_pg_foreign_table;
3537

3638
/* ----------------

src/include/catalog/pg_index.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ CATALOG(pg_index,2610) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO
4242
bool indcheckxmin; /* must we wait for xmin to be old? */
4343
bool indisready; /* is this index ready for inserts? */
4444

45-
/* VARIABLE LENGTH FIELDS: */
45+
/* variable-length fields start here, but we allow direct access to indkey */
4646
int2vector indkey; /* column numbers of indexed cols, or 0 */
47+
#ifdef CATALOG_VARLEN
4748
oidvector indcollation; /* collation identifiers */
4849
oidvector indclass; /* opclass identifiers */
4950
int2vector indoption; /* per-column flags (AM-specific meanings) */
@@ -52,6 +53,7 @@ CATALOG(pg_index,2610) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO
5253
* each zero entry in indkey[] */
5354
pg_node_tree indpred; /* expression tree for predicate, if a partial
5455
* index; else NULL */
56+
#endif
5557
} FormData_pg_index;
5658

5759
/* ----------------

src/include/catalog/pg_language.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ CATALOG(pg_language,2612)
3737
Oid lanplcallfoid; /* Call handler for PL */
3838
Oid laninline; /* Optional anonymous-block handler function */
3939
Oid lanvalidator; /* Optional validation function */
40+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
4041
aclitem lanacl[1]; /* Access privileges */
42+
#endif
4143
} FormData_pg_language;
4244

4345
/* ----------------

src/include/catalog/pg_largeobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ CATALOG(pg_largeobject,2613) BKI_WITHOUT_OIDS
3232
{
3333
Oid loid; /* Identifier of large object */
3434
int4 pageno; /* Page number (starting from 0) */
35+
/* data has variable length, but we allow direct access; see inv_api.c */
3536
bytea data; /* Data for page (may be zero-length) */
3637
} FormData_pg_largeobject;
3738

src/include/catalog/pg_largeobject_metadata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
CATALOG(pg_largeobject_metadata,2995)
3232
{
3333
Oid lomowner; /* OID of the largeobject owner */
34+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
3435
aclitem lomacl[1]; /* access permissions */
36+
#endif
3537
} FormData_pg_largeobject_metadata;
3638

3739
/* ----------------

src/include/catalog/pg_namespace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ CATALOG(pg_namespace,2615)
3737
{
3838
NameData nspname;
3939
Oid nspowner;
40-
aclitem nspacl[1]; /* VARIABLE LENGTH FIELD */
40+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
41+
aclitem nspacl[1];
42+
#endif
4143
} FormData_pg_namespace;
4244

4345
/* ----------------

src/include/catalog/pg_pltemplate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ CATALOG(pg_pltemplate,1136) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
3333
NameData tmplname; /* name of PL */
3434
bool tmpltrusted; /* PL is trusted? */
3535
bool tmpldbacreate; /* PL is installable by db owner? */
36+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
3637
text tmplhandler; /* name of call handler function */
3738
text tmplinline; /* name of anonymous-block handler, or NULL */
3839
text tmplvalidator; /* name of validator function, or NULL */
3940
text tmpllibrary; /* path of shared library */
4041
aclitem tmplacl[1]; /* access privileges for template */
42+
#endif
4143
} FormData_pg_pltemplate;
4244

4345
/* ----------------

src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO
5353
int2 pronargdefaults; /* number of arguments with defaults */
5454
Oid prorettype; /* OID of result type */
5555

56-
/* VARIABLE LENGTH FIELDS: */
56+
/* variable-length fields start here, but we allow direct access to proargtypes */
5757
oidvector proargtypes; /* parameter types (excludes OUT params) */
58+
#ifdef CATALOG_VARLEN
5859
Oid proallargtypes[1]; /* all param types (NULL if IN only) */
5960
char proargmodes[1]; /* parameter modes (NULL if IN only) */
6061
text proargnames[1]; /* parameter names (NULL if no names) */
@@ -64,6 +65,7 @@ CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO
6465
text probin; /* secondary procedure info (can be NULL) */
6566
text proconfig[1]; /* procedure-local GUC settings */
6667
aclitem proacl[1]; /* access permissions */
68+
#endif
6769
} FormData_pg_proc;
6870

6971
/* ----------------

src/include/catalog/pg_rewrite.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ CATALOG(pg_rewrite,2618)
3939
char ev_type;
4040
char ev_enabled;
4141
bool is_instead;
42-
43-
/* NB: remaining fields must be accessed via heap_getattr */
42+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
4443
pg_node_tree ev_qual;
4544
pg_node_tree ev_action;
45+
#endif
4646
} FormData_pg_rewrite;
4747

4848
/* ----------------

src/include/catalog/pg_seclabel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ CATALOG(pg_seclabel,3596) BKI_WITHOUT_OIDS
2525
Oid objoid; /* OID of the object itself */
2626
Oid classoid; /* OID of table containing the object */
2727
int4 objsubid; /* column number, or 0 if not used */
28+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
2829
text provider; /* name of label provider */
2930
text label; /* security label of the object */
31+
#endif
3032
} FormData_pg_seclabel;
3133

3234
/* ----------------

src/include/catalog/pg_shdescription.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ CATALOG(pg_shdescription,2396) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
4242
{
4343
Oid objoid; /* OID of object itself */
4444
Oid classoid; /* OID of table containing object */
45+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
4546
text description; /* description of object */
47+
#endif
4648
} FormData_pg_shdescription;
4749

4850
/* ----------------

src/include/catalog/pg_shseclabel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ CATALOG(pg_shseclabel,3592) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
2424
{
2525
Oid objoid; /* OID of the shared object itself */
2626
Oid classoid; /* OID of table containing the shared object */
27+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
2728
text provider; /* name of label provider */
2829
text label; /* security label of the object */
30+
#endif
2931
} FormData_pg_shseclabel;
3032

3133
/* ----------------

src/include/catalog/pg_statistic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS
116116
float4 stanumbers3[1];
117117
float4 stanumbers4[1];
118118

119+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
119120
/*
120121
* Values in these arrays are values of the column's data type. We
121122
* presently have to cheat quite a bit to allow polymorphic arrays of this
@@ -125,6 +126,7 @@ CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS
125126
anyarray stavalues2;
126127
anyarray stavalues3;
127128
anyarray stavalues4;
129+
#endif
128130
} FormData_pg_statistic;
129131

130132
#define STATISTIC_NUM_SLOTS 4

src/include/catalog/pg_tablespace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ CATALOG(pg_tablespace,1213) BKI_SHARED_RELATION
3232
{
3333
NameData spcname; /* tablespace name */
3434
Oid spcowner; /* owner of tablespace */
35-
aclitem spcacl[1]; /* access permissions (VAR LENGTH) */
35+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
36+
aclitem spcacl[1]; /* access permissions */
3637
text spcoptions[1]; /* per-tablespace options */
38+
#endif
3739
} FormData_pg_tablespace;
3840

3941
/* ----------------

src/include/catalog/pg_trigger.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ CATALOG(pg_trigger,2620)
5050
bool tginitdeferred; /* constraint trigger is deferred initially */
5151
int2 tgnargs; /* # of extra arguments in tgargs */
5252

53-
/* VARIABLE LENGTH FIELDS (note: tgattr and tgargs must not be null) */
53+
/* Variable-length fields start here, but we allow direct access to tgattr.
54+
* Note: tgattr and tgargs must not be null. */
5455
int2vector tgattr; /* column numbers, if trigger is on columns */
56+
#ifdef CATALOG_VARLEN
5557
bytea tgargs; /* first\000second\000tgnargs\000 */
5658
pg_node_tree tgqual; /* WHEN expression, or NULL if none */
59+
#endif
5760
} FormData_pg_trigger;
5861

5962
/* ----------------

0 commit comments

Comments
 (0)