pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Subject: Feature-test macros for new-in-v17 libpq features
Date: Thu, 22 Aug 2024 13:16:10 -0400
Message-ID: <2042418.1724346970@sss.pgh.pa.us> (raw)

Back in commit 6991e774e we established a policy that, well,
I'll just quote the commit message:

    Provide feature-test macros for libpq features added in v14.
    
    We had a request to provide a way to test at compile time for the
    availability of the new pipeline features.  More generally, it
    seems like a good idea to provide a way to test via #ifdef for
    all new libpq API features.  People have been using the version
    from pg_config.h for that; but that's more likely to represent the
    server version than the libpq version, in the increasingly-common
    scenario where they're different.  It's safer if libpq-fe.h itself
    is the source of truth about what features it offers.
    
    Hence, establish a policy that starting in v14 we'll add a suitable
    feature-is-present macro to libpq-fe.h when we add new API there.
    (There doesn't seem to be much point in applying this policy
    retroactively, but it's not too late for v14.)

libpq has grown a bunch of new features in v17, and not one of
them adhered to this policy.  That was complained of at [1],
so I looked into fixing it.  After diff'ing v16 and v17 libpq-fe.h,
it looks like we need roughly this set of new feature-test macros:

LIBPQ_HAS_ASYNC_CANCEL          PGcancelConn typedef and associated routines
LIBPQ_HAS_CHANGE_PASSWORD       PQchangePassword
LIBPQ_HAS_CHUNK_MODE            PQsetChunkedRowsMode, PGRES_TUPLES_CHUNK
LIBPQ_HAS_CLOSE_PREPARED        PQclosePrepared, PQclosePortal, etc
LIBPQ_HAS_SEND_PIPELINE_SYNC    PQsendPipelineSync
LIBPQ_HAS_SOCKET_POLL           PQsocketPoll, PQgetCurrentTimeUSec

(Feel free to bikeshed on the names, but I think we don't want 'em
to get too much longer than these.)

Alternatively we could decide that people can use configure probes
to see if these functions are there, but I still think that there's
a good rationale for the feature-test-macro approach.  It saves
people from re-inventing that wheel, it standardizes the way to
check these things (in particular, discouraging people from abusing
the server version number for this), and it provides some handy
documentation about what's new or not so new.

In connection with that last point, I wonder if we should include
commentary about when things came in.  I'd originally thought of
just inserting the above names in alphabetical order, but now I
wonder if the patch ought to look more like

  */
+/* Features added in PostgreSQL v14: */
 /* Indicates presence of PQenterPipelineMode and friends */
 #define LIBPQ_HAS_PIPELINING 1
 /* Indicates presence of PQsetTraceFlags; also new PQtrace output format */
 #define LIBPQ_HAS_TRACE_FLAGS 1
+/* Features added in PostgreSQL v15: */
 /* Indicates that PQsslAttribute(NULL, "library") is useful */
 #define LIBPQ_HAS_SSL_LIBRARY_DETECTION 1
+/* Features added in PostgreSQL v17: */
+ ... as above ...

Thoughts?

			regards, tom lane

[1] https://www.postgresql.org/message-id/flat/CAFCRh-_Fz4HDKt_y%2Bqr-Gztrh%2BvMiJ4EFxFHDLgC6AePJpWOzQ%4...





view thread (2+ messages)  latest in thread

Message-ID: <2042418.1724346970@sss.pgh.pa.us>
Permalink:  ../2042418.1724346970@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2042418.1724346970@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: Feature-test macros for new-in-v17 libpq features
  In-Reply-To: <2042418.1724346970@sss.pgh.pa.us>
  References: <2042418.1724346970@sss.pgh.pa.us>

* 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