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
/* ----------------

0 commit comments

Comments
 (0)