On 02.08.23 16:39, Tristan Partin wrote:
I like the idea. Though the way you have it implemented at the moment seems like a trap in that any time zlib.h is included someone also has to remember to add this define. I would recommend adding the define to the build systems instead.

Ok, moved to c.h.

Since you put in the work to find the version of zlib that added this, You might also want to add `required: '>= 1.2.5.2'` to the `dependency('zlib')` call in the main meson.build.

Well, it's not a hard requirement, so I think this is not necessary.

I am wondering if we could remove the `z_streamp` check too. The version that it was added isn't obvious.

Yeah, that appears to be very obsolete. I have made an additional patch to remove that.
From 81f053c68109d85ae657f6d9f652d90f1d55fb2a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 3 Aug 2023 08:47:02 +0200
Subject: [PATCH v2 1/2] Improve const use in zlib-using code

If we define ZLIB_CONST before including zlib.h, zlib augments some
interfaces with const decorations.  By doing that we can keep our own
interfaces cleaner and can remove some unconstify calls.

ZLIB_CONST was introduced in zlib 1.2.5.2 (17 Dec 2011).

XXX CentOS 6 has zlib-1.2.3-29.el6.x86_64
---
 contrib/pgcrypto/pgp-compress.c         | 2 +-
 src/bin/pg_basebackup/bbstreamer_gzip.c | 2 +-
 src/bin/pg_basebackup/walmethods.c      | 5 ++---
 src/include/c.h                         | 5 +++++
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/contrib/pgcrypto/pgp-compress.c b/contrib/pgcrypto/pgp-compress.c
index 086bec31ae..961cf21e74 100644
--- a/contrib/pgcrypto/pgp-compress.c
+++ b/contrib/pgcrypto/pgp-compress.c
@@ -113,7 +113,7 @@ compress_process(PushFilter *next, void *priv, const uint8 
*data, int len)
        /*
         * process data
         */
-       st->stream.next_in = unconstify(uint8 *, data);
+       st->stream.next_in = data;
        st->stream.avail_in = len;
        while (st->stream.avail_in > 0)
        {
diff --git a/src/bin/pg_basebackup/bbstreamer_gzip.c 
b/src/bin/pg_basebackup/bbstreamer_gzip.c
index 3bdbfa0bc4..fb25fef150 100644
--- a/src/bin/pg_basebackup/bbstreamer_gzip.c
+++ b/src/bin/pg_basebackup/bbstreamer_gzip.c
@@ -269,7 +269,7 @@ bbstreamer_gzip_decompressor_content(bbstreamer *streamer,
        mystreamer = (bbstreamer_gzip_decompressor *) streamer;
 
        zs = &mystreamer->zstream;
-       zs->next_in = (uint8 *) data;
+       zs->next_in = (const uint8 *) data;
        zs->avail_in = len;
 
        /* Process the current chunk */
diff --git a/src/bin/pg_basebackup/walmethods.c 
b/src/bin/pg_basebackup/walmethods.c
index 376ddf72b7..965d49dec4 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -705,7 +705,7 @@ typedef struct TarMethodData
 
 #ifdef HAVE_LIBZ
 static bool
-tar_write_compressed_data(TarMethodData *tar_data, void *buf, size_t count,
+tar_write_compressed_data(TarMethodData *tar_data, const void *buf, size_t 
count,
                                                  bool flush)
 {
        tar_data->zp->next_in = buf;
@@ -782,8 +782,7 @@ tar_write(Walfile *f, const void *buf, size_t count)
 #ifdef HAVE_LIBZ
        else if (f->wwmethod->compression_algorithm == PG_COMPRESSION_GZIP)
        {
-               if (!tar_write_compressed_data(tar_data, unconstify(void *, 
buf),
-                                                                          
count, false))
+               if (!tar_write_compressed_data(tar_data, buf, count, false))
                        return -1;
                f->currpos += count;
                return count;
diff --git a/src/include/c.h b/src/include/c.h
index f69d739be5..82f8e9d4c7 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -75,6 +75,11 @@
 #include <libintl.h>
 #endif
 
+/* Define before including zlib.h to add const decorations to zlib API. */
+#ifdef HAVE_LIBZ
+#define ZLIB_CONST
+#endif
+
 
 /* ----------------------------------------------------------------
  *                             Section 1: compiler characteristics
-- 
2.41.0

From 76fb004fa151746d584816befb3a070570697298 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 3 Aug 2023 08:52:30 +0200
Subject: [PATCH v2 2/2] Remove check for z_streamp

This is surely obsolete.  zlib version 1.0.4, which includes
z_streamp, was released 1996-07-24.  When this check was put in in
2001 (19c97b8579), it was already labeling that release ancient.
---
 configure    | 15 ---------------
 configure.ac |  9 ---------
 meson.build  |  8 --------
 3 files changed, 32 deletions(-)

diff --git a/configure b/configure
index 2e518c8007..963fbbcf1e 100755
--- a/configure
+++ b/configure
@@ -15162,21 +15162,6 @@ _ACEOF
 fi
 
 
-if test "$with_zlib" = yes; then
-  # Check that <zlib.h> defines z_streamp (versions before about 1.0.4
-  # did not).  While we could work around the lack of z_streamp, it
-  # seems unwise to encourage people to use such old zlib versions...
-  ac_fn_c_check_type "$LINENO" "z_streamp" "ac_cv_type_z_streamp" "#include 
<zlib.h>
-"
-if test "x$ac_cv_type_z_streamp" = xyes; then :
-
-else
-  as_fn_error $? "zlib version is too old
-Use --without-zlib to disable zlib support." "$LINENO" 5
-fi
-
-fi
-
 case $host_cpu in
   x86_64)
     # On x86_64, check if we can compile a popcntq instruction
diff --git a/configure.ac b/configure.ac
index 3ebe1a796d..5153b8b3fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1678,15 +1678,6 @@ AC_CHECK_TYPES([struct option], [], [],
 #include <getopt.h>
 #endif])
 
-if test "$with_zlib" = yes; then
-  # Check that <zlib.h> defines z_streamp (versions before about 1.0.4
-  # did not).  While we could work around the lack of z_streamp, it
-  # seems unwise to encourage people to use such old zlib versions...
-  AC_CHECK_TYPE(z_streamp, [], [AC_MSG_ERROR([zlib version is too old
-Use --without-zlib to disable zlib support.])],
-                [#include <zlib.h>])
-fi
-
 case $host_cpu in
   x86_64)
     # On x86_64, check if we can compile a popcntq instruction
diff --git a/meson.build b/meson.build
index 04ea348852..0a11efc97a 100644
--- a/meson.build
+++ b/meson.build
@@ -1384,14 +1384,6 @@ if not zlibopt.disabled()
       args: test_c_args, include_directories: postgres_inc,
       dependencies: [zlib_t], required: zlibopt)
     warning('zlib header not found')
-  elif not cc.has_type('z_streamp',
-      dependencies: [zlib_t], prefix: '#include <zlib.h>',
-      args: test_c_args, include_directories: postgres_inc)
-    if zlibopt.enabled()
-      error('zlib version is too old')
-    else
-      warning('zlib version is too old')
-    endif
   else
     zlib = zlib_t
   endif
-- 
2.41.0

Reply via email to