Improve const use in zlib-using code

Started by Peter Eisentrautover 2 years ago5 messageshackers
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Now that we have effectively de-supported CentOS 6, by removing support
for its OpenSSL version, I think we could also modernize the use of some
other libraries, such as zlib.

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); CentOS 6 has
zlib-1.2.3-29.el6.x86_64.

Note that if you use this patch and compile on CentOS 6, it still works,
you just get a few compiler warnings about discarding qualifiers. Old
environments tend to produce more compiler warnings anyway, so this
doesn't seem so bad.

Attachments:

0001-Improve-const-use-in-zlib-using-code.patchtext/plain; charset=UTF-8; name=0001-Improve-const-use-in-zlib-using-code.patchDownload+12-6
#2Tristan Partin
tristan@neon.tech
In reply to: Peter Eisentraut (#1)
Re: Improve const use in zlib-using code

Peter,

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.

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. I am wondering if we
could remove the `z_streamp` check too. The version that it was added
isn't obvious.

--
Tristan Partin
Neon (https://neon.tech)

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Tristan Partin (#2)
Re: Improve const use in zlib-using code

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.

Attachments:

v2-0001-Improve-const-use-in-zlib-using-code.patchtext/plain; charset=UTF-8; name=v2-0001-Improve-const-use-in-zlib-using-code.patchDownload+9-6
v2-0002-Remove-check-for-z_streamp.patchtext/plain; charset=UTF-8; name=v2-0002-Remove-check-for-z_streamp.patchDownload+0-33
#4Tristan Partin
tristan@neon.tech
In reply to: Peter Eisentraut (#3)
Re: Improve const use in zlib-using code

Both patches look good to me.

--
Tristan Partin
Neon (https://neon.tech)

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Tristan Partin (#4)
Re: Improve const use in zlib-using code

On 03.08.23 16:30, Tristan Partin wrote:

Both patches look good to me.

committed, thanks