pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Boris Kolpackov <boris@codesynthesis.com>
To: pgsql-hackers@lists.postgresql.org
Cc: alvaro.herrera@2ndquadrant.com
Subject: Add version macro to libpq-fe.h
Date: Thu, 17 Jun 2021 11:04:06 +0200
Message-ID: <boris.20210617102439@codesynthesis.com> (raw)

I am making use of the new pipeline mode added to libpq in
PostgreSQL 14. At the same time I would still like to support
older libpq versions by not providing the extended functionality
that depends on this mode.

The natural way to achieve this in C/C++ is to conditionally
enable code that depends on the additional APIs based on the
preprocessor macro. And I could easily do this if libpq-fe.h
provided a macro containing its version.

Now, such a macro (PG_VERSION_NUM) is provided by pg_config.h
that normally accompanies libpq-fe.h. However, I don't believe
the presence of this file is guaranteed. All the documentation
says[1] about headers is this:

"Client programs that use libpq must include the header file 
libpq-fe.h and must link with the libpq library."

And there are good reasons why packagers of libpq may decide to
omit this header (in a nutshell, it embeds target architecture-
specific information, see this discussion for background[2]). And
I may not want to include it in my code (it defines a lot of free-
named macros that may clash with my names).

So I am wondering if it would make sense to provide a better way
to obtain the libpq version as a macro?

To me, as a user, the simplest way would be to have such a macro
defined by libpq-fe.h. This would also provide a reasonable
fallback for previous versions: if this macro is not defined, I
know I am dealing with version prior to 14 and if I need to know
which exactly I can try to include pg_config.h (perhaps with the
help of __has_include if I am using C++).

If simply moving this macro to libpq-fe.h is not desirable (for
example, because it is auto-generated), then perhaps we could
move this (and a few other version-related macros[3]) to a
separate header (for example, libpq-version.h) and either include
it from libpq-fe.h or define a macro in libpq-fe.h that signals
its presence (e.g., PG_HAS_VERSION or some such).

What do you think?


[1] https://www.postgresql.org/docs/9.3/libpq.html

[2] https://bugzilla.redhat.com/show_bug.cgi?id=828467

[3] PG_MAJORVERSION
    PG_MAJORVERSION_NUM
    PG_MINORVERSION_NUM
    PG_VERSION
    PG_VERSION_NUM
    PG_VERSION_STR (this one includes target so maybe leave it in pg_config.h)





view thread (26+ messages)  latest in thread

Message-ID: <boris.20210617102439@codesynthesis.com>
Permalink:  ../boris.20210617102439@codesynthesis.com/
Also on:    postgresql.org/message-id/boris.20210617102439@codesynthesis.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 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: boris@codesynthesis.com, alvaro.herrera@2ndquadrant.com
  Subject: Re: Add version macro to libpq-fe.h
  In-Reply-To: <boris.20210617102439@codesynthesis.com>
  References: <boris.20210617102439@codesynthesis.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