pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: Andres Freund <andres@anarazel.de>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: Jeff Davis <jdavis@postgresql.org>
Cc: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: CREATE SUBSCRIPTION ... SERVER.
Date: Thu, 12 Mar 2026 18:15:09 -0700
Message-ID: <f48610c90e69de4b30841361c568c3765e8f3dfe.camel@j-davis.com> (raw)
In-Reply-To: <03d52b80fd264bb683fb2c46ad7a2934cb656f1a.camel@j-davis.com>
References: <E1vyYHQ-002hOV-0R@gemulon.postgresql.org>
	<1bb21c7d-885f-4f07-a3ed-21b60d7c92c6@eisentraut.org>
	<xvdjrdqnpap3uq7owbaox3r7p5gf7sv62aaqf2ju3vb6yglatr@kvvwhoudrlxq>
	<03d52b80fd264bb683fb2c46ad7a2934cb656f1a.camel@j-davis.com>

On Wed, 2026-03-11 at 17:59 -0700, Jeff Davis wrote:
> That leaves some awkwardness, but I don't immediately see a cleaner
> way
> to do it. Suggestions welcome.

I did see a way to avoid the volatile entirely, it just needs a
redundant MemoryContextSwtichTo(). I think this is cleaner overall,
attached.

Regards,
	Jeff Davis

Attachments:

v21-0001-Clean-up-PG_TRY-PG_FINALLY.patch (text/x-patch, 1.7K) download From ae3beb8493888e1ff8c23813bb56e4abc4e8b723 Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Thu, 12 Mar 2026 18:04:35 -0700 Subject: [PATCH v21] Clean up PG_TRY()/PG_FINALLY(). In ForeignServerConnectionString(), refactor the PG_TRY()/PG_FINALLY() blocks to avoid the need for volatile at all. The only downside is a redundant MemoryContextSwitchTo() in the success case. Reported-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/xvdjrdqnpap3uq7owbaox3r7p5gf7sv62aaqf2ju3vb6yglatr@kvvwhoudrlxq --- src/backend/foreign/foreign.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/backend/foreign/foreign.c b/src/backend/foreign/foreign.c index 160cf6f51c9..cf10a8c00f9 100644 --- a/src/backend/foreign/foreign.c +++ b/src/backend/foreign/foreign.c @@ -225,7 +225,6 @@ ForeignServerConnectionString(Oid userid, Oid serverid) { MemoryContext tempContext; MemoryContext oldcxt; - text *volatile connection_text = NULL; char *result = NULL; /* @@ -243,6 +242,7 @@ ForeignServerConnectionString(Oid userid, Oid serverid) { ForeignServer *server; ForeignDataWrapper *fdw; + text *connection_text = NULL; Datum connection_datum; server = GetForeignServer(serverid); @@ -262,14 +262,15 @@ ForeignServerConnectionString(Oid userid, Oid serverid) PointerGetDatum(NULL)); connection_text = DatumGetTextPP(connection_datum); + + MemoryContextSwitchTo(oldcxt); + result = text_to_cstring((text *) connection_text); } PG_FINALLY(); { + /* no-op on success path */ MemoryContextSwitchTo(oldcxt); - if (connection_text) - result = text_to_cstring((text *) connection_text); - MemoryContextDelete(tempContext); } PG_END_TRY(); -- 2.43.0

view thread (9+ messages)  latest in thread

Message-ID: <f48610c90e69de4b30841361c568c3765e8f3dfe.camel@j-davis.com>
Permalink:  ../f48610c90e69de4b30841361c568c3765e8f3dfe.camel@j-davis.com/
Also on:    postgresql.org/message-id/f48610c90e69de4b30841361c568c3765e8f3dfe.camel@j-davis.com

 ·  · 

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-committers@postgresql.org
  Cc: pgsql@j-davis.com, andres@anarazel.de, peter@eisentraut.org, jdavis@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: CREATE SUBSCRIPTION ... SERVER.
  In-Reply-To: <f48610c90e69de4b30841361c568c3765e8f3dfe.camel@j-davis.com>

* 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