pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgresql.org, Thomas Munro <thomas.munro@enterprisedb.com>
Subject: Re: Large writable variables
Date: Thu, 18 Oct 2018 22:17:55 +0200
Message-ID: <08adbe4e-38f8-2c73-55f0-591392371687@2ndquadrant.com> (raw)
In-Reply-To: <20181017215106.esosgw7qfnfavcdw@alap3.anarazel.de>
References: <20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de>
	<20181016045051.wr35ubb6h7h3ee2b@alap3.anarazel.de>
	<20181016050200.c65yjz2qgxulgouv@alap3.anarazel.de>
	<20181016063013.kigj6e5pqx6n75y3@alap3.anarazel.de>
	<200cf391-4a60-4c69-85d8-c715c7bce4de@2ndquadrant.com>
	<20181017200200.t752esxtgnefktu3@alap3.anarazel.de>
	<e0c988b9-9df8-51f2-b963-94e27816c622@2ndquadrant.com>
	<20181017215106.esosgw7qfnfavcdw@alap3.anarazel.de>

On 17/10/2018 23:51, Andres Freund wrote:
>> __builtin_types_compatible_p(const char *, char *) returns false (0) for me.
> 
> Right, that's why I added a const, inside the macro,  to the type
> specified in the unconstify argument. So typeof() yields a const char *,
> and the return type is specified as char *, and adding a const in the
> argument also yields a const char *.

Yeah, that works.  The C++-inspired version also allowed casting from
not-const to const, which we don't really need.

I'd perhaps change the signature

#define unconstify(underlying_type, var)

because the "var" doesn't actually have to be a variable.

Attached is my previous patch adapted to your macro.

I'm tempted to get rid of the stuff in dfmgr.c and just let the "older
platforms" get the warning.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Apply-unconstify-in-more-places.patch (text/plain, 3.8K) download From 54693f7201aa4768509c5d6939961b50a9021bcf Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter_e@gmx.net> Date: Thu, 18 Oct 2018 22:11:44 +0200 Subject: [PATCH v2] Apply unconstify() in more places --- src/backend/utils/adt/json.c | 4 ++-- src/backend/utils/adt/misc.c | 2 +- src/backend/utils/adt/varlena.c | 4 ++-- src/backend/utils/fmgr/dfmgr.c | 4 ++-- src/port/win32setlocale.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index 6f0fe94d63..f47a498228 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -207,12 +207,12 @@ IsValidJsonNumber(const char *str, int len) */ if (*str == '-') { - dummy_lex.input = (char *) str + 1; + dummy_lex.input = unconstify(char *, str) + 1; dummy_lex.input_length = len - 1; } else { - dummy_lex.input = (char *) str; + dummy_lex.input = unconstify(char *, str); dummy_lex.input_length = len; } diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 6ea3679835..309eb2935c 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -423,7 +423,7 @@ pg_get_keywords(PG_FUNCTION_ARGS) HeapTuple tuple; /* cast-away-const is ugly but alternatives aren't much better */ - values[0] = (char *) ScanKeywords[funcctx->call_cntr].name; + values[0] = unconstify(char *, ScanKeywords[funcctx->call_cntr].name); switch (ScanKeywords[funcctx->call_cntr].category) { diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index a5e812d026..0fd3b15748 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -182,7 +182,7 @@ char * text_to_cstring(const text *t) { /* must cast away the const, unfortunately */ - text *tunpacked = pg_detoast_datum_packed((struct varlena *) t); + text *tunpacked = pg_detoast_datum_packed(unconstify(text *, t)); int len = VARSIZE_ANY_EXHDR(tunpacked); char *result; @@ -213,7 +213,7 @@ void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len) { /* must cast away the const, unfortunately */ - text *srcunpacked = pg_detoast_datum_packed((struct varlena *) src); + text *srcunpacked = pg_detoast_datum_packed(unconstify(text *, src)); size_t src_len = VARSIZE_ANY_EXHDR(srcunpacked); if (dst_len > 0) diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index 4a5cc7cfc7..d200b960d2 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -126,7 +126,7 @@ load_external_function(const char *filename, const char *funcname, * should declare its second argument as "const char *", but older * platforms might not, so for the time being we just cast away const. */ - retval = (PGFunction) dlsym(lib_handle, (char *) funcname); + retval = (PGFunction) dlsym(lib_handle, unconstify(char *, funcname)); if (retval == NULL && signalNotFound) ereport(ERROR, @@ -175,7 +175,7 @@ PGFunction lookup_external_function(void *filehandle, const char *funcname) { /* as above, cast away const for the time being */ - return (PGFunction) dlsym(filehandle, (char *) funcname); + return (PGFunction) dlsym(filehandle, unconstify(char *, funcname)); } diff --git a/src/port/win32setlocale.c b/src/port/win32setlocale.c index 0597c2afca..a8cf170dd1 100644 --- a/src/port/win32setlocale.c +++ b/src/port/win32setlocale.c @@ -183,7 +183,7 @@ pgwin32_setlocale(int category, const char *locale) * forbidden to modify, so casting away the "const" is innocuous. */ if (result) - result = (char *) map_locale(locale_map_result, result); + result = unconstify(char *, map_locale(locale_map_result, result)); return result; } base-commit: e74dd00f53cd6dc1887f76b9672e5f6dcf0fd8a2 -- 2.19.1

view thread (51+ messages)  latest in thread

Message-ID: <08adbe4e-38f8-2c73-55f0-591392371687@2ndquadrant.com>
Permalink:  ../08adbe4e-38f8-2c73-55f0-591392371687@2ndquadrant.com/
Also on:    postgresql.org/message-id/08adbe4e-38f8-2c73-55f0-591392371687@2ndquadrant.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-hackers@postgresql.org
  Cc: peter.eisentraut@2ndquadrant.com, andres@anarazel.de, thomas.munro@enterprisedb.com
  Subject: Re: Large writable variables
  In-Reply-To: <08adbe4e-38f8-2c73-55f0-591392371687@2ndquadrant.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