Skip to content

Commit 67c0ef9

Browse files
committed
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). When compiling with older zlib releases, you might now get compiler warnings about discarding qualifiers. CentOS 6 has zlib 1.2.3, but in 8e278b6, 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
1 parent fdd79d8 commit 67c0ef9

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

contrib/pgcrypto/pgp-compress.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ compress_process(PushFilter *next, void *priv, const uint8 *data, int len)
113113
/*
114114
* process data
115115
*/
116-
st->stream.next_in = unconstify(uint8 *, data);
116+
st->stream.next_in = data;
117117
st->stream.avail_in = len;
118118
while (st->stream.avail_in > 0)
119119
{

src/bin/pg_basebackup/bbstreamer_gzip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ bbstreamer_gzip_decompressor_content(bbstreamer *streamer,
269269
mystreamer = (bbstreamer_gzip_decompressor *) streamer;
270270

271271
zs = &mystreamer->zstream;
272-
zs->next_in = (uint8 *) data;
272+
zs->next_in = (const uint8 *) data;
273273
zs->avail_in = len;
274274

275275
/* Process the current chunk */

src/bin/pg_basebackup/walmethods.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ typedef struct TarMethodData
705705

706706
#ifdef HAVE_LIBZ
707707
static bool
708-
tar_write_compressed_data(TarMethodData *tar_data, void *buf, size_t count,
708+
tar_write_compressed_data(TarMethodData *tar_data, const void *buf, size_t count,
709709
bool flush)
710710
{
711711
tar_data->zp->next_in = buf;
@@ -782,8 +782,7 @@ tar_write(Walfile *f, const void *buf, size_t count)
782782
#ifdef HAVE_LIBZ
783783
else if (f->wwmethod->compression_algorithm == PG_COMPRESSION_GZIP)
784784
{
785-
if (!tar_write_compressed_data(tar_data, unconstify(void *, buf),
786-
count, false))
785+
if (!tar_write_compressed_data(tar_data, buf, count, false))
787786
return -1;
788787
f->currpos += count;
789788
return count;

src/include/c.h

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
#include <libintl.h>
7676
#endif
7777

78+
/* Define before including zlib.h to add const decorations to zlib API. */
79+
#ifdef HAVE_LIBZ
80+
#define ZLIB_CONST
81+
#endif
82+
7883

7984
/* ----------------------------------------------------------------
8085
* Section 1: compiler characteristics

0 commit comments

Comments
 (0)