When Graphviz was built with support for zlib-based compression, it would only
use `deflateBound` if it was discovered at build time. The `deflateBound` code
path provides a tighter estimate of final compressed size, allowing compression
to minimize its intermediate heap allocations.
The CMake build system did not attempt to discover the presence of
`deflateBound` (config-cmake.in). The Windows build hard coded `deflateBound` as
unavailable (windows/include/config.h). So both these builds would result in a
Graphviz that would use more memory than necessary when writing compressed
output formats.
`deflateBound` arrived in zlib 1.2.0, released on 2003-03-09. It seems safe to
unconditionally assume its existence in 2022. The estimate `deflateBound`
provides has improved in successive releases, with even the latest zlib 1.2.13
released on 2022-10-13 further tightening its estimate. So it is expected that
Graphviz users, with this change, will get lower memory usage during writing
compressed formats, and then lower still as newer zlib releases propagate
through the ecosystem.
## [Unreleased (7.0.1)]
+### Changed
+
+- When built with zlib support, Graphviz will unconditionally use
+ `deflateBound`. The only user-visible effect should be slightly decreased
+ memory usage when using a zlib-compressed output format.
+
### Fixed
- Failure of arrowhead and arrowtail to respect penwidth #372 \
AC_MSG_WARN(Optional z library not available))],
AC_MSG_WARN(Optional z library not available - no zlib.h))
LDFLAGS="$LDFLAGS $Z_LIBS"
- AC_CHECK_FUNCS(deflateBound)
LDFLAGS=$save_LDFLAGS
CPPFLAGS=$save_CPPFLAGS
AC_SUBST([Z_INCLUDES])
if (job->flags & GVDEVICE_COMPRESSED_FORMAT) {
#ifdef HAVE_LIBZ
z_streamp z = &z_strm;
- size_t dflen;
-#ifdef HAVE_DEFLATEBOUND
- dflen = deflateBound(z, len);
-#else
- /* deflateBound() is not available in older libz, e.g. from centos3 */
- dflen = 2 * len + dfallocated - z->avail_out;
-#endif
+ size_t dflen = deflateBound(z, len);
if (dfallocated < dflen) {
dfallocated = (dflen + 1 + PAGE_ALIGN) & ~PAGE_ALIGN;
df = realloc(df, dfallocated);
/* Define if you have the ann library */
#define HAVE_ANN 1
-/* Define to 1 if you have the `deflateBound' function. */
-/* #undef HAVE_DEFLATEBOUND */
-
/* Define if you have the DevIL library */
/* #undef HAVE_DEVIL */