Skip to content

Commit b25433d

Browse files
committed
Fix string reloption handling, per KaiGai Kohei.
1 parent 40e01e2 commit b25433d

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/backend/access/common/reloptions.c

Lines changed: 3 additions & 2 deletions
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.15 2009/01/06 03:15:51 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.16 2009/01/06 14:47:37 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -769,7 +769,8 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
769769

770770
for (i = 0; i < numoptions; i++)
771771
{
772-
HANDLE_INT_RELOPTION("fillfactor", lopts.fillfactor, options[i]);
772+
HANDLE_INT_RELOPTION("fillfactor", lopts.fillfactor, options[i],
773+
(char *) NULL);
773774
}
774775

775776
pfree(options);

src/include/access/reloptions.h

Lines changed: 39 additions & 11 deletions
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.7 2009/01/05 17:14:28 alvherre Exp $
14+
* $PostgreSQL: pgsql/src/include/access/reloptions.h,v 1.8 2009/01/06 14:47:37 alvherre Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -106,58 +106,86 @@ typedef struct relopt_string
106106
* Most of the time there's no need to call HAVE_RELOPTION manually, but it's
107107
* possible that an amoptions routine needs to walk the array with a different
108108
* purpose (say, to compute the size of a struct to allocate beforehand.)
109+
*
110+
* The last argument in the HANDLE_*_RELOPTION macros allows the caller to
111+
* determine whether the option was set (true), or its value acquired from
112+
* defaults (false); it can be passed as (char *) NULL if the caller does not
113+
* need this information.
109114
*/
110115
#define HAVE_RELOPTION(optname, option) \
111116
(pg_strncasecmp(option.gen->name, optname, option.gen->namelen) == 0)
112117

113-
#define HANDLE_INT_RELOPTION(optname, var, option) \
118+
#define HANDLE_INT_RELOPTION(optname, var, option, wasset) \
114119
do { \
115120
if (HAVE_RELOPTION(optname, option)) \
116121
{ \
117122
if (option.isset) \
118123
var = option.values.int_val; \
119124
else \
120125
var = ((relopt_int *) option.gen)->default_val; \
126+
(wasset) != NULL ? *(wasset) = option.isset : (dummyret)NULL; \
121127
continue; \
122128
} \
123129
} while (0)
124130

125-
#define HANDLE_BOOL_RELOPTION(optname, var, option) \
131+
#define HANDLE_BOOL_RELOPTION(optname, var, option, wasset) \
126132
do { \
127133
if (HAVE_RELOPTION(optname, option)) \
128134
{ \
129135
if (option.isset) \
130136
var = option.values.bool_val; \
131137
else \
132138
var = ((relopt_bool *) option.gen)->default_val; \
139+
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
133140
continue; \
134141
} \
135142
} while (0)
136143

137-
#define HANDLE_REAL_RELOPTION(optname, var, option) \
144+
#define HANDLE_REAL_RELOPTION(optname, var, option, wasset) \
138145
do { \
139146
if (HAVE_RELOPTION(optname, option)) \
140147
{ \
141148
if (option.isset) \
142149
var = option.values.real_val; \
143150
else \
144151
var = ((relopt_real *) option.gen)->default_val; \
152+
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
145153
continue; \
146154
} \
147155
} while (0)
148156

149-
/* Note that this assumes that the variable is already allocated! */
150-
#define HANDLE_STRING_RELOPTION(optname, var, option) \
157+
/*
158+
* Note that this assumes that the variable is already allocated at the tail of
159+
* reloptions structure (StdRdOptions or other).
160+
*
161+
* "base" is a pointer to the reloptions structure, and "offset" is an integer
162+
* variable that must be initialized to sizeof(reloptions structure). This
163+
* struct must have been allocated with enough space to hold any string option
164+
* present, including terminating \0 for every option. SET_VARSIZE() must be
165+
* called on the struct with this offset as the second argument, after all the
166+
* string options have been processed.
167+
*/
168+
#define HANDLE_STRING_RELOPTION(optname, var, option, base, offset, wasset) \
151169
do { \
152170
if (HAVE_RELOPTION(optname, option)) \
153171
{ \
154172
relopt_string *optstring = (relopt_string *) option.gen;\
155-
if (optstring->default_isnull) \
156-
var[0] = '\0'; \
173+
char *string_val = NULL; \
174+
\
175+
if (option.isset) \
176+
string_val = option.values.string_val; \
177+
else if (!optstring->default_isnull) \
178+
string_val = optstring->default_val; \
179+
(wasset) != NULL ? *(wasset) = option.isset : (dummyret) NULL; \
180+
\
181+
if (!string_val) \
182+
var = 0; \
157183
else \
158-
strcpy(var, \
159-
option.isset ? option.values.string_val : \
160-
optstring->default_val); \
184+
{ \
185+
strcpy((char *)(base) + (offset), string_val); \
186+
var = (offset); \
187+
(offset) += strlen(string_val) + 1; \
188+
} \
161189
continue; \
162190
} \
163191
} while (0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy