diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-06 10:34:41 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-06 11:05:07 -0500 |
commit | 358b609e9dfd503cc25985d197a92610cbbe9f3d (patch) | |
tree | f057b4566edfea7cbae68cd75312058045aa4176 /src/common/compress_zstd.c | |
parent | b5a8fd1566e137f27c49d132755d2ad9e5c74f4e (diff) | |
download | tor-358b609e9dfd503cc25985d197a92610cbbe9f3d.tar.gz tor-358b609e9dfd503cc25985d197a92610cbbe9f3d.zip |
Enable (safe) use of zstd static-only APIs
We'll only use these when the compile-time version and the run-time
version of the zstd library match. Part of ticket 25162.
Diffstat (limited to 'src/common/compress_zstd.c')
-rw-r--r-- | src/common/compress_zstd.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index 0db87d61b7..7994487446 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -18,6 +18,13 @@ #include "compress.h" #include "compress_zstd.h" +/* This is a lie, but we make sure it doesn't get us in trouble by wrapping + * all invocations of zstd's static-only functions in a check to make sure + * that the compile-time version matches the run-time version. + * + * Note: Make sure that this file still builds with this macro disabled. */ +#define ZSTD_STATIC_LINKING_ONLY + #ifdef HAVE_ZSTD #include <zstd.h> #endif @@ -85,6 +92,26 @@ tor_zstd_get_header_version_str(void) #endif } +#ifdef TOR_UNIT_TESTS +static int static_apis_disable_for_testing = 0; +#endif + +/** Return true iff we can use the "static-only" APIs. */ +int +tor_zstd_can_use_static_apis(void) +{ +#if defined(ZSTD_STATIC_LINKING_ONLY) && defined(HAVE_ZSTD) +#ifdef TOR_UNIT_TESTS + if (static_apis_disable_for_testing) { + return 0; + } +#endif + return (ZSTD_VERSION_NUMBER == ZSTD_versionNumber()); +#else + return 0; +#endif +} + /** Internal Zstandard state for incremental compression/decompression. * The body of this struct is not exposed. */ struct tor_zstd_compress_state_t { @@ -440,3 +467,12 @@ tor_zstd_init(void) atomic_counter_init(&total_zstd_allocation); } +#ifdef TOR_UNIT_TESTS +/** Testing only: disable usage of static-only APIs, so we can make sure that + * we still work without them. */ +void +tor_zstd_set_static_apis_disabled_for_testing(int disabled) +{ + static_apis_disable_for_testing = disabled; +} +#endif |