git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fdd79d8)
Improve const use in zlib-using code
Mon, 7 Aug 2023 07:06:52 +0000 (09:06 +0200)
Mon, 7 Aug 2023 07:34:38 +0000 (09:34 +0200)
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). When
compiling with older zlib releases, you might now get compiler
warnings about discarding qualifiers.

CentOS 6 has zlib 1.2.3, but in 8e278b6576, we removed support for the
OpenSSL release in CentOS 6, so it seems ok to de-support the zlib
release in CentOS 6 as well.

Reviewed-by: Tristan Partin <tristan@neon.tech>
Discussion: https://www.postgresql.org/message-id/flat/33462926-bb1e-7cc9-8d92-d86318e8ed1d%40eisentraut.org


diff --git a/contrib/pgcrypto/pgp-compress.c b/contrib/pgcrypto/pgp-compress.c
index 086bec31ae2ccfcfb9aee0bdfa4d1fff04227d05..961cf21e748913b66b9e35b3ecaddc39403f738c 100644 (file)
--- 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 3bdbfa0bc43ef31a2534a645a4f642368e59f0b0..fb25fef150034e9d5595b3840ddee6bf4d38ff19 100644 (file)
--- 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 d780c4055cd99d64d62b7ec3f7e786bc8e8f7534..2de11ce9b1c45c8ab4db15855a25eea03e01ac87 100644 (file)
--- 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 f69d739be5711e40f3b2081b86bcfd98abd02795..82f8e9d4c7b88251cef27a42863d15d1ab0c7ee5 100644 (file)
--- 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
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /