Re: Convert *GetDatum() and DatumGet*() macros to inline functions

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Convert *GetDatum() and DatumGet*() macros to inline functions
Date: 2022-09-05 12:57:10
Message-ID: 812568f2-ff1d-ebd9-aee6-e00d8f2e0fb6@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 30.08.22 20:15, Aleksander Alekseev wrote:
>> Here is v3 with silenced compiler warnings.
>
> Some more warnings were reported by cfbot, so here is v4. Apologies
> for the noise.

Looking at these warnings you are fixing, I think there is a small
problem we need to address.

I have defined PointerGetDatum() with a const argument:

PointerGetDatum(const void *X)

This is because in some places the thing that is being passed into that
is itself defined as const, so this is the clean way to avoid warnings
about dropping constness.

However, some support functions for gist and text search pass back
return values via pointer arguments, like

DirectFunctionCall3(g_int_same,
entry->key,
PointerGetDatum(query),
PointerGetDatum(&retval));

The compiler you are using apparently thinks that passing &retval to a
const pointer argument cannot change retval, which seems quite
reasonable. But that isn't actually what's happening here, so we're
lying a bit.

(Which compiler is that, by the way?)

I think to resolve that we could either

1. Not define PointerGetDatum() with a const argument, and just sprinkle
in a few unconstify calls where necessary.

2. Maybe add a NonconstPointerGetDatum() for those few cases where
pointer arguments are used for return values.

3. Go with your patch and just fix up the warnings about uninitialized
variables. But that seems the least principled to me.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2022-09-05 13:02:35 Re: Different compression methods for FPI
Previous Message Drouvot, Bertrand 2022-09-05 12:46:55 Re: Patch to address creation of PgStat* contexts with null parent context