public inbox for [email protected]  
help / color / mirror / Atom feed
From: Jacob Champion <[email protected]>
To: Nathan Bossart <[email protected]>
Cc: Peter Eisentraut <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: anonymous unions (C11)
Date: Thu, 16 Oct 2025 10:40:10 -0700
Message-ID: <CAOYmi+nV25oC5uXFgWodydGrHkfWMDCLUcjbAreM3mNX=F2JWw@mail.gmail.com> (raw)
In-Reply-To: <aNKsDg0fJwqhZdXX@nathan>
References: <[email protected]>
	<aNKsDg0fJwqhZdXX@nathan>

On Tue, Sep 23, 2025 at 7:18 AM Nathan Bossart <[email protected]> wrote:
> I would have used this in the DSM registry if it was available.  Patch
> attached.

Likewise for libpq-oauth, as attached.

Thanks,
--Jacob


Attachments:

  [application/octet-stream] 0001-Make-some-use-of-anonymous-unions-libpq-oauth.patch (2.8K, ../CAOYmi+nV25oC5uXFgWodydGrHkfWMDCLUcjbAreM3mNX=F2JWw@mail.gmail.com/2-0001-Make-some-use-of-anonymous-unions-libpq-oauth.patch)
  download | inline diff:
From 88c96b19715a074ca00e2e3c7b05c60e60d40577 Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Thu, 16 Oct 2025 10:18:44 -0700
Subject: [PATCH] Make some use of anonymous unions [libpq-oauth]

Make some use of anonymous unions, which are allowed as of C11, as
examples and encouragement for future code, and to test compilers.

This commit changes the json_field struct.

Reviewed-by:
Discussion:
---
 src/interfaces/libpq-oauth/oauth-curl.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/interfaces/libpq-oauth/oauth-curl.c b/src/interfaces/libpq-oauth/oauth-curl.c
index aa50b00d053..1287e30b86c 100644
--- a/src/interfaces/libpq-oauth/oauth-curl.c
+++ b/src/interfaces/libpq-oauth/oauth-curl.c
@@ -439,7 +439,7 @@ struct json_field
 	{
 		char	  **scalar;		/* for all scalar types */
 		struct curl_slist **array;	/* for type == JSON_TOKEN_ARRAY_START */
-	}			target;
+	};
 
 	bool		required;		/* REQUIRED field, or just OPTIONAL? */
 };
@@ -561,8 +561,8 @@ oauth_json_object_field_start(void *state, char *name, bool isnull)
 		{
 			field = ctx->active;
 
-			if ((field->type == JSON_TOKEN_ARRAY_START && *field->target.array)
-				|| (field->type != JSON_TOKEN_ARRAY_START && *field->target.scalar))
+			if ((field->type == JSON_TOKEN_ARRAY_START && *field->array)
+				|| (field->type != JSON_TOKEN_ARRAY_START && *field->scalar))
 			{
 				oauth_parse_set_error(ctx, "field \"%s\" is duplicated",
 									  field->name);
@@ -706,7 +706,7 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
 			}
 
 			/* ...and that a result has not already been set. */
-			if (*field->target.scalar)
+			if (*field->scalar)
 			{
 				Assert(false);
 				oauth_parse_set_error(ctx,
@@ -715,8 +715,8 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
 				return JSON_SEM_ACTION_FAILED;
 			}
 
-			*field->target.scalar = strdup(token);
-			if (!*field->target.scalar)
+			*field->scalar = strdup(token);
+			if (!*field->scalar)
 				return JSON_OUT_OF_MEMORY;
 
 			ctx->active = NULL;
@@ -738,11 +738,11 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
 			}
 
 			/* Note that curl_slist_append() makes a copy of the token. */
-			temp = curl_slist_append(*field->target.array, token);
+			temp = curl_slist_append(*field->array, token);
 			if (!temp)
 				return JSON_OUT_OF_MEMORY;
 
-			*field->target.array = temp;
+			*field->array = temp;
 		}
 	}
 	else
@@ -878,8 +878,8 @@ parse_oauth_json(struct async_ctx *actx, const struct json_field *fields)
 	while (fields->name)
 	{
 		if (fields->required
-			&& !*fields->target.scalar
-			&& !*fields->target.array)
+			&& !*fields->scalar
+			&& !*fields->array)
 		{
 			actx_error(actx, "field \"%s\" is missing", fields->name);
 			goto cleanup;
-- 
2.34.1



view thread (13+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: anonymous unions (C11)
  In-Reply-To: <CAOYmi+nV25oC5uXFgWodydGrHkfWMDCLUcjbAreM3mNX=F2JWw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox