Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50d22de

Browse files
committed
Cleanup code in reloptions.h regarding reloption handling
reloptions.h includes sinceba748f7 a set of macros to handle reloptiontypes in a way similar to how parseRelOptions() works. They have neverbeen used in the core code, and we have more simple methods now to parseand fill in rd_options for a given relation depending on its relkind, soremove 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 parent1bbd608 commit50d22de

File tree

2 files changed

+17
-124
lines changed

2 files changed

+17
-124
lines changed

‎src/backend/access/common/reloptions.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ static void initialize_reloptions(void);
496496
staticvoidparse_one_reloption(relopt_value*option,char*text_str,
497497
inttext_len,boolvalidate);
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+
#defineGET_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+
staticrelopt_value*
11461155
parseRelOptions(Datumoptions,boolvalidate,relopt_kindkind,
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+
staticvoid*
13711380
allocateReloptStruct(Sizebase,relopt_value*options,intnumoptions)
13721381
{
13731382
Sizesize=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+
staticvoid
13951404
fillRelOptions(void*rdopts,Sizebasesize,
13961405
relopt_value*options,intnumoptions,
13971406
boolvalidate,

‎src/include/access/reloptions.h

Lines changed: 5 additions & 121 deletions
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 forfillRelOptions */
143+
/* This is the table datatype forbuild_reloptions() */
144144
typedefstruct
145145
{
146146
constchar*optname;/* option's name */
147147
relopt_typeopttype;/* option's datatype */
148148
intoffset;/* 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-
#defineHAVE_RELOPTION(optname,option) \
190-
(strncmp(option.gen->name, optname, option.gen->namelen + 1) == 0)
191-
192-
#defineHANDLE_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-
#defineHANDLE_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-
#defineHANDLE_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-
#defineHANDLE_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-
#defineGET_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
#defineGET_STRING_RELOPTION(optstruct,member) \
265158
((optstruct)->member == 0 ? NULL : \
266159
(char *)(optstruct) + (optstruct)->member)
267160

268-
269161
externrelopt_kindadd_reloption_kind(void);
270162
externvoidadd_bool_reloption(bits32kinds,constchar*name,constchar*desc,
271163
booldefault_val,LOCKMODElockmode);
@@ -288,14 +180,6 @@ extern Datum transformRelOptions(Datum oldOptions, List *defList,
288180
externList*untransformRelOptions(Datumoptions);
289181
externbytea*extractRelOptions(HeapTupletuple,TupleDesctupdesc,
290182
amoptions_functionamoptions);
291-
externrelopt_value*parseRelOptions(Datumoptions,boolvalidate,
292-
relopt_kindkind,int*numrelopts);
293-
externvoid*allocateReloptStruct(Sizebase,relopt_value*options,
294-
intnumoptions);
295-
externvoidfillRelOptions(void*rdopts,Sizebasesize,
296-
relopt_value*options,intnumoptions,
297-
boolvalidate,
298-
constrelopt_parse_elt*elems,intnelems);
299183
externvoid*build_reloptions(Datumreloptions,boolvalidate,
300184
relopt_kindkind,
301185
Sizerelopt_struct_size,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp