Skip to content

Commit 50d22de

Browse files
committed
Cleanup code in reloptions.h regarding reloption handling
reloptions.h includes since ba748f7 a set of macros to handle reloption types in a way similar to how parseRelOptions() works. They have never been used in the core code, and we have more simple methods now to parse and fill in rd_options for a given relation depending on its relkind, so remove this interface to simplify things. Per discussion between Amit Langote, Álvaro Herrera and me. Discussion: https://postgr.es/m/CA+HiwqE6zbNO92az6pp5GiTw4tr-9rfCE0t84whQSP+YwSKjMQ@mail.gmail.com
1 parent 1bbd608 commit 50d22de

File tree

2 files changed

+17
-124
lines changed

2 files changed

+17
-124
lines changed

src/backend/access/common/reloptions.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ static void initialize_reloptions(void);
496496
static void parse_one_reloption(relopt_value *option, char *text_str,
497497
int text_len, bool validate);
498498

499+
/*
500+
* Get the length of a string reloption (either default or the user-defined
501+
* value). This is used for allocation purposes when building a set of
502+
* relation options.
503+
*/
504+
#define GET_STRING_RELOPTION_LEN(option) \
505+
((option).isset ? strlen((option).values.string_val) : \
506+
((relopt_string *) (option).gen)->default_len)
507+
499508
/*
500509
* initialize_reloptions
501510
* initialization routine, must be called before parsing
@@ -1142,7 +1151,7 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
11421151
* returned array. Values of type string are allocated separately and must
11431152
* be freed by the caller.
11441153
*/
1145-
relopt_value *
1154+
static relopt_value *
11461155
parseRelOptions(Datum options, bool validate, relopt_kind kind,
11471156
int *numrelopts)
11481157
{
@@ -1367,7 +1376,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
13671376
* "base" should be sizeof(struct) of the reloptions struct (StdRdOptions or
13681377
* equivalent).
13691378
*/
1370-
void *
1379+
static void *
13711380
allocateReloptStruct(Size base, relopt_value *options, int numoptions)
13721381
{
13731382
Size size = base;
@@ -1391,7 +1400,7 @@ allocateReloptStruct(Size base, relopt_value *options, int numoptions)
13911400
* elems, of length numelems, is the table describing the allowed options.
13921401
* When validate is true, it is expected that all options appear in elems.
13931402
*/
1394-
void
1403+
static void
13951404
fillRelOptions(void *rdopts, Size basesize,
13961405
relopt_value *options, int numoptions,
13971406
bool validate,

src/include/access/reloptions.h

+5-121
Original file line numberDiff line numberDiff line change
@@ -140,132 +140,24 @@ typedef struct relopt_string
140140
char *default_val;
141141
} relopt_string;
142142

143-
/* This is the table datatype for fillRelOptions */
143+
/* This is the table datatype for build_reloptions() */
144144
typedef struct
145145
{
146146
const char *optname; /* option's name */
147147
relopt_type opttype; /* option's datatype */
148148
int offset; /* offset of field in result struct */
149149
} relopt_parse_elt;
150150

151-
152151
/*
153-
* These macros exist for the convenience of amoptions writers (but consider
154-
* using fillRelOptions, which is a lot simpler). Beware of multiple
155-
* evaluation of arguments!
156-
*
157-
* The last argument in the HANDLE_*_RELOPTION macros allows the caller to
158-
* determine whether the option was set (true), or its value acquired from
159-
* defaults (false); it can be passed as (char *) NULL if the caller does not
160-
* need this information.
161-
*
162-
* optname is the option name (a string), var is the variable
163-
* on which the value should be stored (e.g. StdRdOptions->fillfactor), and
164-
* option is a relopt_value pointer.
165-
*
166-
* The normal way to use this is to loop on the relopt_value array returned by
167-
* parseRelOptions:
168-
* for (i = 0; options[i].gen->name; i++)
169-
* {
170-
* if (HAVE_RELOPTION("fillfactor", options[i])
171-
* {
172-
* HANDLE_INT_RELOPTION("fillfactor", rdopts->fillfactor, options[i], &isset);
173-
* continue;
174-
* }
175-
* if (HAVE_RELOPTION("default_row_acl", options[i])
176-
* {
177-
* ...
178-
* }
179-
* ...
180-
* if (validate)
181-
* ereport(ERROR,
182-
* (errmsg("unknown option")));
183-
* }
184-
*
185-
* Note that this is more or less the same that fillRelOptions does, so only
186-
* use this if you need to do something non-standard within some option's
187-
* code block.
188-
*/
189-
#define HAVE_RELOPTION(optname, option) \
190-
(strncmp(option.gen->name, optname, option.gen->namelen + 1) == 0)
191-
192-
#define HANDLE_INT_RELOPTION(optname, var, option, wasset) \
193-
do { \
194-
if (option.isset) \
195-
var = option.values.int_val; \
196-
else \
197-
var = ((relopt_int *) option.gen)->default_val; \
198-
(wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \
199-
} while (0)
200-
201-
#define HANDLE_BOOL_RELOPTION(optname, var, option, wasset) \
202-
do { \
203-
if (option.isset) \
204-
var = option.values.bool_val; \
205-
else \
206-
var = ((relopt_bool *) option.gen)->default_val; \
207-
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
208-
} while (0)
209-
210-
#define HANDLE_REAL_RELOPTION(optname, var, option, wasset) \
211-
do { \
212-
if (option.isset) \
213-
var = option.values.real_val; \
214-
else \
215-
var = ((relopt_real *) option.gen)->default_val; \
216-
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
217-
} while (0)
218-
219-
/*
220-
* Note that this assumes that the variable is already allocated at the tail of
221-
* reloptions structure (StdRdOptions or equivalent).
222-
*
223-
* "base" is a pointer to the reloptions structure, and "offset" is an integer
224-
* variable that must be initialized to sizeof(reloptions structure). This
225-
* struct must have been allocated with enough space to hold any string option
226-
* present, including terminating \0 for every option. SET_VARSIZE() must be
227-
* called on the struct with this offset as the second argument, after all the
228-
* string options have been processed.
229-
*/
230-
#define HANDLE_STRING_RELOPTION(optname, var, option, base, offset, wasset) \
231-
do { \
232-
relopt_string *optstring = (relopt_string *) option.gen;\
233-
char *string_val; \
234-
if (option.isset) \
235-
string_val = option.values.string_val; \
236-
else if (!optstring->default_isnull) \
237-
string_val = optstring->default_val; \
238-
else \
239-
string_val = NULL; \
240-
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
241-
if (string_val == NULL) \
242-
var = 0; \
243-
else \
244-
{ \
245-
strcpy(((char *)(base)) + (offset), string_val); \
246-
var = (offset); \
247-
(offset) += strlen(string_val) + 1; \
248-
} \
249-
} while (0)
250-
251-
/*
252-
* For use during amoptions: get the strlen of a string option
253-
* (either default or the user defined value)
254-
*/
255-
#define GET_STRING_RELOPTION_LEN(option) \
256-
((option).isset ? strlen((option).values.string_val) : \
257-
((relopt_string *) (option).gen)->default_len)
258-
259-
/*
260-
* For use by code reading options already parsed: get a pointer to the string
261-
* value itself. "optstruct" is the StdRdOptions struct or equivalent, "member"
262-
* is the struct member corresponding to the string option
152+
* Utility macro to get a value for a string reloption once the options
153+
* are parsed. This gets a pointer to the string value itself. "optstruct"
154+
* is the StdRdOptions struct or equivalent, "member" is the struct member
155+
* corresponding to the string option.
263156
*/
264157
#define GET_STRING_RELOPTION(optstruct, member) \
265158
((optstruct)->member == 0 ? NULL : \
266159
(char *)(optstruct) + (optstruct)->member)
267160

268-
269161
extern relopt_kind add_reloption_kind(void);
270162
extern void add_bool_reloption(bits32 kinds, const char *name, const char *desc,
271163
bool default_val, LOCKMODE lockmode);
@@ -288,14 +180,6 @@ extern Datum transformRelOptions(Datum oldOptions, List *defList,
288180
extern List *untransformRelOptions(Datum options);
289181
extern bytea *extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
290182
amoptions_function amoptions);
291-
extern relopt_value *parseRelOptions(Datum options, bool validate,
292-
relopt_kind kind, int *numrelopts);
293-
extern void *allocateReloptStruct(Size base, relopt_value *options,
294-
int numoptions);
295-
extern void fillRelOptions(void *rdopts, Size basesize,
296-
relopt_value *options, int numoptions,
297-
bool validate,
298-
const relopt_parse_elt *elems, int nelems);
299183
extern void *build_reloptions(Datum reloptions, bool validate,
300184
relopt_kind kind,
301185
Size relopt_struct_size,

0 commit comments

Comments
 (0)