From: Matthew Fernandez Date: Wed, 19 Oct 2022 03:51:44 +0000 (-0700) Subject: unconditionally use 'deflateBound' when zlib is enabled X-Git-Tag: 7.0.1~17^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29c6db96df974bbc591cb9777f2df950d9517a73;p=graphviz unconditionally use 'deflateBound' when zlib is enabled 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. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index aa436bbe3..2ab04f141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [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 \ diff --git a/configure.ac b/configure.ac index 381febd57..75410b07e 100644 --- a/configure.ac +++ b/configure.ac @@ -1620,7 +1620,6 @@ AC_CHECK_HEADER(zlib.h, 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]) diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 0ab0e45b0..32120da07 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -205,14 +205,8 @@ size_t gvwrite (GVJ_t * job, const char *s, size_t len) 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); diff --git a/windows/include/config.h b/windows/include/config.h index c2152ac33..d67a9a25b 100644 --- a/windows/include/config.h +++ b/windows/include/config.h @@ -33,9 +33,6 @@ /* 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 */