From 81f053c68109d85ae657f6d9f652d90f1d55fb2a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut 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 #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