pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Álvaro Herrera <alvherre@kurilemu.de>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: anonymous unions (C11)
Date: Mon, 19 Jan 2026 22:10:25 +0100
Message-ID: <202601192106.zcdi3yu2gzti@alvherre.pgsql> (raw )
In-Reply-To: <f00a9968-388e-4f8c-b5ef-5102e962d997@eisentraut.org >
On 2025-Sep-23, Peter Eisentraut wrote:
> Here is another patch set to sprinkle some C11 features around the
> code. My aim is to make a little bit of use of several C11 features
> as examples and encouragement for future code, and to test compilers
> (although we're not yet at the point where this should really stress
> any compiler).
I was going over patch [1] today and came across the union in
relopt_value. Vaguely remembering this thread, I patched it out
(attached) ... and now that I come here to post it, I realize that it's
probably identical to your patch 0009 here.
Would you push it or can I?
[1] https://postgr.es/m/4047390.3Lj2Plt8kZ@thinkpad-pgpro
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Attachments:
0001-Make-some-use-of-anonymous-unions.patch (text/x-diff, 5.9K) download
From 23d94cc1c30aa00d2340c1368b01856b1fe95ecd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Mon, 19 Jan 2026 18:27:13 +0100
Subject: [PATCH] Make some use of anonymous unions
In the spirit of commit 4b7e6c73b0df and following, which see for more
details; it appears to have been quite an uncontroversial C11 feature to
use.
---
src/backend/access/common/reloptions.c | 34 +++++++++++++-------------
src/include/access/reloptions.h | 2 +-
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 0b83f98ed5f..d9729ebf17f 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -587,7 +587,7 @@ static void parse_one_reloption(relopt_value *option, char *text_str,
* relation options.
*/
#define GET_STRING_RELOPTION_LEN(option) \
- ((option).isset ? strlen((option).values.string_val) : \
+ ((option).isset ? strlen((option).string_val) : \
((relopt_string *) (option).gen)->default_len)
/*
@@ -1618,7 +1618,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
{
case RELOPT_TYPE_BOOL:
{
- parsed = parse_bool(value, &option->values.bool_val);
+ parsed = parse_bool(value, &option->bool_val);
if (validate && !parsed)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -1630,14 +1630,14 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
{
relopt_int *optint = (relopt_int *) option->gen;
- parsed = parse_int(value, &option->values.int_val, 0, NULL);
+ parsed = parse_int(value, &option->int_val, 0, NULL);
if (validate && !parsed)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for integer option \"%s\": %s",
option->gen->name, value)));
- if (validate && (option->values.int_val < optint->min ||
- option->values.int_val > optint->max))
+ if (validate && (option->int_val < optint->min ||
+ option->int_val > optint->max))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("value %s out of bounds for option \"%s\"",
@@ -1650,14 +1650,14 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
{
relopt_real *optreal = (relopt_real *) option->gen;
- parsed = parse_real(value, &option->values.real_val, 0, NULL);
+ parsed = parse_real(value, &option->real_val, 0, NULL);
if (validate && !parsed)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for floating point option \"%s\": %s",
option->gen->name, value)));
- if (validate && (option->values.real_val < optreal->min ||
- option->values.real_val > optreal->max))
+ if (validate && (option->real_val < optreal->min ||
+ option->real_val > optreal->max))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("value %s out of bounds for option \"%s\"",
@@ -1676,7 +1676,7 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
{
if (pg_strcasecmp(value, elt->string_val) == 0)
{
- option->values.enum_val = elt->symbol_val;
+ option->enum_val = elt->symbol_val;
parsed = true;
break;
}
@@ -1694,14 +1694,14 @@ parse_one_reloption(relopt_value *option, char *text_str, int text_len,
* not asked to validate, just use the default numeric value.
*/
if (!parsed)
- option->values.enum_val = optenum->default_val;
+ option->enum_val = optenum->default_val;
}
break;
case RELOPT_TYPE_STRING:
{
relopt_string *optstring = (relopt_string *) option->gen;
- option->values.string_val = value;
+ option->string_val = value;
nofree = true;
if (validate && optstring->validate_cb)
(optstring->validate_cb) (value);
@@ -1743,7 +1743,7 @@ allocateReloptStruct(Size base, relopt_value *options, int numoptions)
if (optstr->fill_cb)
{
- const char *val = optval->isset ? optval->values.string_val :
+ const char *val = optval->isset ? optval->string_val :
optstr->default_isnull ? NULL : optstr->default_val;
size += optstr->fill_cb(val, NULL);
@@ -1804,28 +1804,28 @@ fillRelOptions(void *rdopts, Size basesize,
{
case RELOPT_TYPE_BOOL:
*(bool *) itempos = options[i].isset ?
- options[i].values.bool_val :
+ options[i].bool_val :
((relopt_bool *) options[i].gen)->default_val;
break;
case RELOPT_TYPE_INT:
*(int *) itempos = options[i].isset ?
- options[i].values.int_val :
+ options[i].int_val :
((relopt_int *) options[i].gen)->default_val;
break;
case RELOPT_TYPE_REAL:
*(double *) itempos = options[i].isset ?
- options[i].values.real_val :
+ options[i].real_val :
((relopt_real *) options[i].gen)->default_val;
break;
case RELOPT_TYPE_ENUM:
*(int *) itempos = options[i].isset ?
- options[i].values.enum_val :
+ options[i].enum_val :
((relopt_enum *) options[i].gen)->default_val;
break;
case RELOPT_TYPE_STRING:
optstring = (relopt_string *) options[i].gen;
if (options[i].isset)
- string_val = options[i].values.string_val;
+ string_val = options[i].string_val;
else if (!optstring->default_isnull)
string_val = optstring->default_val;
else
diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.h
index 2f08e1b0cf0..40a1369646b 100644
--- a/src/include/access/reloptions.h
+++ b/src/include/access/reloptions.h
@@ -84,7 +84,7 @@ typedef struct relopt_value
double real_val;
int enum_val;
char *string_val; /* allocated separately */
- } values;
+ };
} relopt_value;
/* reloptions records for specific variable types */
--
2.47.3
view thread (15+ messages) latest in thread
Message-ID: <202601192106.zcdi3yu2gzti@alvherre.pgsql>
Permalink: ../202601192106.zcdi3yu2gzti@alvherre.pgsql/
Also on: postgresql.org/message-id/202601192106.zcdi3yu2gzti@alvherre.pgsql
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvherre@kurilemu.de, peter@eisentraut.org
Subject: Re: anonymous unions (C11)
In-Reply-To: <202601192106.zcdi3yu2gzti@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox