Skip to content

Commit

Permalink
build: use standard HAVE_ pattern for ZSTD compression check (#2111)
Browse files Browse the repository at this point in the history
Follow-on to #1649: this just changes the name of the preprocessor macro
to use the standard pattern HAVE_<function name>

In particular: newer ZSTD implementations have a growing variety of
compression functions; the standard pattern will make it easier to
select among those someday.
  • Loading branch information
kientzle authored and mmatuska committed Apr 7, 2024
1 parent bbc7467 commit 771f434
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ IF(ZSTD_FOUND)
SET(CMAKE_REQUIRED_LIBRARIES ${ZSTD_LIBRARY})
SET(CMAKE_REQUIRED_INCLUDES ${ZSTD_INCLUDE_DIR})
CHECK_FUNCTION_EXISTS(ZSTD_decompressStream HAVE_LIBZSTD)
CHECK_FUNCTION_EXISTS(ZSTD_compressStream HAVE_LIBZSTD_COMPRESSOR)
CHECK_FUNCTION_EXISTS(ZSTD_compressStream HAVE_ZSTD_compressStream)
#
# TODO: test for static library.
#
Expand Down
5 changes: 2 additions & 3 deletions build/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,8 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `zstd' library (-lzstd). */
#cmakedefine HAVE_LIBZSTD 1

/* Define to 1 if you have the `zstd' library (-lzstd) with compression
support. */
#cmakedefine HAVE_LIBZSTD_COMPRESSOR 1
/* Define to 1 if you have the ZSTD_compressStream function. */
#cmakedefine HAVE_ZSTD_compressStream 1

/* Define to 1 if you have the <limits.h> header file. */
#cmakedefine HAVE_LIMITS_H 1
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ if test "x$with_zstd" != "xno"; then
AC_CHECK_HEADERS([zstd.h])
AC_CHECK_LIB(zstd,ZSTD_decompressStream)
AC_CHECK_LIB(zstd,ZSTD_compressStream,
AC_DEFINE([HAVE_LIBZSTD_COMPRESSOR], [1], [Define to 1 if you have the `zstd' library (-lzstd) with compression support.]))
AC_DEFINE([HAVE_ZSTD_compressStream], [1], [Define to 1 if you have the `zstd' library (-lzstd) with compression support.]))
fi

AC_ARG_WITH([lzma],
Expand Down
20 changes: 10 additions & 10 deletions libarchive/archive_write_add_filter_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct private_data {
int compression_level;
int threads;
int long_distance;
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
enum {
running,
finishing,
Expand Down Expand Up @@ -96,7 +96,7 @@ static int archive_compressor_zstd_write(struct archive_write_filter *,
static int archive_compressor_zstd_flush(struct archive_write_filter *);
static int archive_compressor_zstd_close(struct archive_write_filter *);
static int archive_compressor_zstd_free(struct archive_write_filter *);
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
static int drive_compressor(struct archive_write_filter *,
struct private_data *, int, const void *, size_t);
#endif
Expand Down Expand Up @@ -130,7 +130,7 @@ archive_write_add_filter_zstd(struct archive *_a)
data->compression_level = CLEVEL_DEFAULT;
data->threads = 0;
data->long_distance = 0;
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
data->frame_per_file = 0;
data->min_frame_in = 0;
data->max_frame_in = SIZE_MAX;
Expand Down Expand Up @@ -164,7 +164,7 @@ static int
archive_compressor_zstd_free(struct archive_write_filter *f)
{
struct private_data *data = (struct private_data *)f->data;
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
ZSTD_freeCStream(data->cstream);
free(data->out.dst);
#else
Expand Down Expand Up @@ -242,7 +242,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
/* If we don't have the library, hard-code the max level */
int minimum = CLEVEL_MIN;
int maximum = CLEVEL_MAX;
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
maximum = ZSTD_maxCLevel();
#if ZSTD_VERSION_NUMBER >= MINVER_MINCLEVEL
if (ZSTD_versionNumber() >= MINVER_MINCLEVEL) {
Expand All @@ -269,7 +269,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
}
data->threads = (int)threads;
return (ARCHIVE_OK);
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
} else if (strcmp(key, "frame-per-file") == 0) {
data->frame_per_file = 1;
return (ARCHIVE_OK);
Expand Down Expand Up @@ -304,7 +304,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
if (string_to_number(value, &long_distance) != ARCHIVE_OK) {
return (ARCHIVE_WARN);
}
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR && ZSTD_VERSION_NUMBER >= MINVER_LONG
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream && ZSTD_VERSION_NUMBER >= MINVER_LONG
ZSTD_bounds bounds = ZSTD_cParam_getBounds(ZSTD_c_windowLog);
if (ZSTD_isError(bounds.error)) {
int max_distance = ((int)(sizeof(size_t) == 4 ? 30 : 31));
Expand All @@ -329,7 +329,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
return (ARCHIVE_WARN);
}

#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
/*
* Setup callback.
*/
Expand Down Expand Up @@ -485,7 +485,7 @@ drive_compressor(struct archive_write_filter *f,
return (ARCHIVE_FATAL);
}

#else /* HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR */
#else /* HAVE_ZSTD_H && HAVE_ZSTD_compressStream */

static int
archive_compressor_zstd_open(struct archive_write_filter *f)
Expand Down Expand Up @@ -547,4 +547,4 @@ archive_compressor_zstd_close(struct archive_write_filter *f)
return __archive_write_program_close(f, data->pdata);
}

#endif /* HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR */
#endif /* HAVE_ZSTD_H && HAVE_ZSTD_compressStream */
2 changes: 1 addition & 1 deletion libarchive/test/test_write_filter_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ DEFINE_TEST(test_write_filter_zstd)
archive_write_set_filter_option(a, NULL, "threads", "-1")); /* negative */
assertEqualIntA(a, ARCHIVE_OK,
archive_write_set_filter_option(a, NULL, "threads", "4"));
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream
/* frame-per-file: boolean */
assertEqualIntA(a, ARCHIVE_OK,
archive_write_set_filter_option(a, NULL, "frame-per-file", ""));
Expand Down

0 comments on commit 771f434

Please sign in to comment.