Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1079564

Browse files
committed
Const-ify the parse table passed to fillRelOptions. The previous coding
meant it had to be built on-the-fly at each entry to default_reloptions.
1 parent 5c617f4 commit 1079564

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/backend/access/common/reloptions.c

+14-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.22 2009/02/28 00:10:51 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.23 2009/03/23 16:36:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -175,7 +175,7 @@ static relopt_real realRelOpts[] =
175175
{ { NULL } }
176176
};
177177

178-
static relopt_string stringRelOpts[] =
178+
static relopt_string stringRelOpts[] =
179179
{
180180
/* list terminator */
181181
{ { NULL } }
@@ -739,7 +739,7 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc, Oid amoptions)
739739
options = NULL; /* keep compiler quiet */
740740
break;
741741
}
742-
742+
743743
return options;
744744
}
745745

@@ -972,16 +972,17 @@ allocateReloptStruct(Size base, relopt_value *options, int numoptions)
972972
* struct (previously allocated with allocateReloptStruct) with the parsed
973973
* values.
974974
*
975-
* rdopts is the pointer to the allocated struct to be filled; basesize is
976-
* the sizeof(struct) that was passed to allocateReloptStruct. options and
977-
* numoptions are parseRelOptions' output. elems and numelems is the array
978-
* of elements to be parsed. Note that when validate is true, it is expected
979-
* that all options are also in elems.
975+
* rdopts is the pointer to the allocated struct to be filled.
976+
* basesize is the sizeof(struct) that was passed to allocateReloptStruct.
977+
* options, of length numoptions, is parseRelOptions' output.
978+
* elems, of length numelems, is the table describing the allowed options.
979+
* When validate is true, it is expected that all options appear in elems.
980980
*/
981981
void
982-
fillRelOptions(void *rdopts, Size basesize, relopt_value *options,
983-
int numoptions, bool validate, relopt_parse_elt *elems,
984-
int numelems)
982+
fillRelOptions(void *rdopts, Size basesize,
983+
relopt_value *options, int numoptions,
984+
bool validate,
985+
const relopt_parse_elt *elems, int numelems)
985986
{
986987
int i;
987988
int offset = basesize;
@@ -1044,7 +1045,7 @@ fillRelOptions(void *rdopts, Size basesize, relopt_value *options,
10441045
}
10451046
}
10461047
if (validate && !found)
1047-
elog(ERROR, "storate parameter \"%s\" not found in parse table",
1048+
elog(ERROR, "reloption \"%s\" not found in parse table",
10481049
options[i].gen->name);
10491050
}
10501051
SET_VARSIZE(rdopts, offset);
@@ -1061,7 +1062,7 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
10611062
relopt_value *options;
10621063
StdRdOptions *rdopts;
10631064
int numoptions;
1064-
relopt_parse_elt tab[] = {
1065+
static const relopt_parse_elt tab[] = {
10651066
{"fillfactor", RELOPT_TYPE_INT, offsetof(StdRdOptions, fillfactor)},
10661067
{"autovacuum_enabled", RELOPT_TYPE_BOOL,
10671068
offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, enabled)},

src/include/access/reloptions.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.12 2009/02/02 19:31:39 alvherre Exp $
14+
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.13 2009/03/23 16:36:27 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -106,12 +106,12 @@ typedef struct relopt_string
106106
char default_val[1]; /* variable length, zero-terminated */
107107
} relopt_string;
108108

109-
/* This is the input type for fillRelOptions */
109+
/* This is the table datatype for fillRelOptions */
110110
typedef struct
111111
{
112-
char *optname;
113-
relopt_type opttype;
114-
int offset;
112+
const char *optname; /* option's name */
113+
relopt_type opttype; /* option's datatype */
114+
int offset; /* offset of field in result struct */
115115
} relopt_parse_elt;
116116

117117

@@ -149,8 +149,8 @@ typedef struct
149149
* }
150150
*
151151
* Note that this is more or less the same that fillRelOptions does, so only
152-
* use this if you need to do something non-standard within some options'
153-
* block.
152+
* use this if you need to do something non-standard within some option's
153+
* code block.
154154
*/
155155
#define HAVE_RELOPTION(optname, option) \
156156
(pg_strncasecmp(option.gen->name, optname, option.gen->namelen + 1) == 0)
@@ -252,9 +252,10 @@ extern relopt_value *parseRelOptions(Datum options, bool validate,
252252
relopt_kind kind, int *numrelopts);
253253
extern void *allocateReloptStruct(Size base, relopt_value *options,
254254
int numoptions);
255-
extern void fillRelOptions(void *rdopts, Size basesize, relopt_value *options,
256-
int numoptions, bool validate, relopt_parse_elt *elems,
257-
int nelems);
255+
extern void fillRelOptions(void *rdopts, Size basesize,
256+
relopt_value *options, int numoptions,
257+
bool validate,
258+
const relopt_parse_elt *elems, int nelems);
258259

259260
extern bytea *default_reloptions(Datum reloptions, bool validate,
260261
relopt_kind kind);

0 commit comments

Comments
 (0)