Thread: libpq: make PGresult* "const" in PQcmdStatus()/PQcmdTuples()?

libpq: make PGresult* "const" in PQcmdStatus()/PQcmdTuples()?

From
Jeroen Vermeulen
Date:
Any objections to changing these two libpq functions' PGresult* parameters to be const?

So "char * PQcmdStatus(PGresult *)" would become "char *PQcmdStatus(const PGresult *)", and "char *PQcmdTuples(PGresult *)" would become "char *PQcmdTuples(const PGresult *)".


Jeroen


Re: libpq: make PGresult* "const" in PQcmdStatus()/PQcmdTuples()?

From
Tom Lane
Date:
Jeroen Vermeulen <jtvjtv@gmail.com> writes:
> Any objections to changing these two libpq functions' PGresult* parameters
> to be const?

> So "char * PQcmdStatus(PGresult *)" would become "char *PQcmdStatus(const
> PGresult *)", and "char *PQcmdTuples(PGresult *)" would become "char
> *PQcmdTuples(const PGresult *)".

Both of those return pointers to res->cmdStatus, so it would not make
any sense to const-ify the argument unless you also const-ify the
result; which would cause compiler warnings for users.  I'm pretty
sure we've explicitly rejected making this change for that reason.

            regards, tom lane



Re: libpq: make PGresult* "const" in PQcmdStatus()/PQcmdTuples()?

From
Jeroen Vermeulen
Date:

Ah, that explains.  Thanks.

On Sat, Dec 21, 2024, 16:56 Tom Lane <tgl@sss.pgh.pa.us> wrote:
Jeroen Vermeulen <jtvjtv@gmail.com> writes:
> Any objections to changing these two libpq functions' PGresult* parameters
> to be const?

> So "char * PQcmdStatus(PGresult *)" would become "char *PQcmdStatus(const
> PGresult *)", and "char *PQcmdTuples(PGresult *)" would become "char
> *PQcmdTuples(const PGresult *)".

Both of those return pointers to res->cmdStatus, so it would not make
any sense to const-ify the argument unless you also const-ify the
result; which would cause compiler warnings for users.  I'm pretty
sure we've explicitly rejected making this change for that reason.

                        regards, tom lane

Re: libpq: make PGresult* "const" in PQcmdStatus()/PQcmdTuples()?

From
Tom Lane
Date:
I wrote:
> Both of those return pointers to res->cmdStatus, so it would not make
> any sense to const-ify the argument unless you also const-ify the
> result; which would cause compiler warnings for users.  I'm pretty
> sure we've explicitly rejected making this change for that reason.

[ digs in archives... ]

See previous discussions here:

https://www.postgresql.org/message-id/flat/NCBBLFLGLEIDHCJLONHNKEDGFJAA.mdklatt%40ou.edu

and here:

https://www.postgresql.org/message-id/flat/E1RaRtZ-0008aS-MK%40hans3

            regards, tom lane