pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jelte Fennema-Nio <postgres@jeltef.nl>
Cc: Noah Misch <noah@leadboat.com>
Cc: Jacob Champion <jacob.champion@enterprisedb.com>
Cc: Denis Laxalde <denis.laxalde@dalibo.com>
Cc: vignesh C <vignesh21@gmail.com>
Cc: Thomas Munro <thomas.munro@gmail.com>
Cc: Greg Stark <stark@mit.edu>
Cc: Gregory Stark (as CFM) <stark.cfm@gmail.com>
Cc: Jelte Fennema <Jelte.Fennema@microsoft.com>
Cc: Daniel Gustafsson <daniel@yesql.se>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: Andres Freund <andres@anarazel.de>
Cc: Justin Pryzby <pryzby@telsasoft.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org, Etsuro Fujita <etsuro.fujita@gmail.com>
Subject: Re: [EXTERNAL] Re: Add non-blocking version of PQcancel
Date: Thu, 4 Apr 2024 10:45:33 +0200
Message-ID: <202404040845.i355zg4oimbw@alvherre.pgsql> (raw)
In-Reply-To: <372769.1712179784@sss.pgh.pa.us>

On 2024-Apr-03, Tom Lane wrote:

> On my machine, headerscheck does not like this:
> 
> $ src/tools/pginclude/headerscheck --cplusplus
> In file included from /tmp/headerscheck.4gTaW5/test.cpp:3:
> ./src/include/libpq/libpq-be-fe-helpers.h: In function 'char* libpqsrv_cancel(PGconn*, TimestampTz)':
> ./src/include/libpq/libpq-be-fe-helpers.h:393:10: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
>    return "out of memory";
>           ^~~~~~~~~~~~~~~
> ./src/include/libpq/libpq-be-fe-helpers.h:421:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
>      error = "cancel request timed out";
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The second part of that could easily be fixed by declaring "error" as
> "const char *".  As for the first part, can we redefine the whole
> function as returning "const char *"?  (If not, this coding is very
> questionable anyway.)

Yeah, this seems to work and I no longer get that complaint from
headerscheck.

-- 
Álvaro Herrera        Breisgau, Deutschland  —  https://www.EnterpriseDB.com/

Attachments:

  [text/x-diff] 0001-Make-libpqsrv_cancel-s-return-type-const-char.patch (1.9K, ../202404040845.i355zg4oimbw@alvherre.pgsql/2-0001-Make-libpqsrv_cancel-s-return-type-const-char.patch)
  download | inline diff:
From 0af8c7039b2c8ed80bc0bddacfe4a9abb8f527b3 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Thu, 4 Apr 2024 10:13:07 +0200
Subject: [PATCH] Make libpqsrv_cancel's return type const char *

---
 contrib/dblink/dblink.c                 | 2 +-
 contrib/postgres_fdw/connection.c       | 2 +-
 src/include/libpq/libpq-be-fe-helpers.h | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index de858e165a..755293456f 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -1347,7 +1347,7 @@ Datum
 dblink_cancel_query(PG_FUNCTION_ARGS)
 {
 	PGconn	   *conn;
-	char	   *msg;
+	const char *msg;
 	TimestampTz endtime;
 
 	dblink_init();
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 2532e453c4..cac9d96d33 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1332,7 +1332,7 @@ pgfdw_cancel_query(PGconn *conn)
 static bool
 pgfdw_cancel_query_begin(PGconn *conn, TimestampTz endtime)
 {
-	char	   *errormsg = libpqsrv_cancel(conn, endtime);
+	const char *errormsg = libpqsrv_cancel(conn, endtime);
 
 	if (errormsg != NULL)
 		ereport(WARNING,
diff --git a/src/include/libpq/libpq-be-fe-helpers.h b/src/include/libpq/libpq-be-fe-helpers.h
index 8be9aa1f2f..fe50829274 100644
--- a/src/include/libpq/libpq-be-fe-helpers.h
+++ b/src/include/libpq/libpq-be-fe-helpers.h
@@ -382,11 +382,11 @@ libpqsrv_get_result(PGconn *conn, uint32 wait_event_info)
  * Note: this function leaks a string's worth of memory when reporting
  * libpq errors.  Make sure to call it in a transient memory context.
  */
-static inline char *
+static inline const char *
 libpqsrv_cancel(PGconn *conn, TimestampTz endtime)
 {
 	PGcancelConn *cancel_conn;
-	char	   *error = NULL;
+	const char *error = NULL;
 
 	cancel_conn = PQcancelCreate(conn);
 	if (cancel_conn == NULL)
-- 
2.39.2

view thread (146+ messages)  latest in thread

Message-ID: <202404040845.i355zg4oimbw@alvherre.pgsql>
Permalink:  ../202404040845.i355zg4oimbw@alvherre.pgsql/
Also on:    postgresql.org/message-id/202404040845.i355zg4oimbw@alvherre.pgsql

 ·  · 

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@alvh.no-ip.org, tgl@sss.pgh.pa.us, postgres@jeltef.nl, noah@leadboat.com, jacob.champion@enterprisedb.com, denis.laxalde@dalibo.com, vignesh21@gmail.com, thomas.munro@gmail.com, stark@mit.edu, stark.cfm@gmail.com, Jelte.Fennema@microsoft.com, daniel@yesql.se, peter@eisentraut.org, andres@anarazel.de, pryzby@telsasoft.com, robertmhaas@gmail.com, etsuro.fujita@gmail.com
  Subject: Re: [EXTERNAL] Re: Add non-blocking version of PQcancel
  In-Reply-To: <202404040845.i355zg4oimbw@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