diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e252f5..ed7b17c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,11 +182,6 @@ include(CheckSymbolExists) check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP) check_symbol_exists("sysconf" "unistd.h" HAVE_FUNC_SYSCONF) -find_package(Gflags QUIET) -if(GFLAGS_FOUND OR GFLAGS_TARGET) - set(HAVE_GFLAGS 1) -endif(GFLAGS_FOUND OR GFLAGS_TARGET) - configure_file( "cmake/config.h.in" "${PROJECT_BINARY_DIR}/config.h" @@ -268,7 +263,7 @@ if(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS) # Test files include snappy-test.h, HAVE_CONFIG_H must be defined. target_compile_definitions(snappy_test_support PUBLIC -DHAVE_CONFIG_H) - target_link_libraries(snappy_test_support snappy ${GFLAGS_LIBRARIES}) + target_link_libraries(snappy_test_support snappy) if(HAVE_LIBZ) target_link_libraries(snappy_test_support z) @@ -283,7 +278,6 @@ if(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS) target_include_directories(snappy_test_support BEFORE PUBLIC "${PROJECT_SOURCE_DIR}" - "${GFLAGS_INCLUDE_DIRS}" ) endif(SNAPPY_BUILD_TESTS OR SNAPPY_BUILD_BENCHMARKS) diff --git a/README.md b/README.md index 52735f0..7917d1b 100644 --- a/README.md +++ b/README.md @@ -132,11 +132,6 @@ should provide a reasonably balanced starting point for benchmarking. (Note that baddata[1-3].snappy are not intended as benchmarks; they are used to verify correctness in the presence of corrupted data in the unit test.) -The gflags library for handling of command-line flags is used if it's installed. -You can find it at - - https://gflags.github.io/gflags/ - Contact ======= diff --git a/cmake/config.h.in b/cmake/config.h.in index 76b24f7..872bd3c 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -16,9 +16,6 @@ /* Define to 1 if you have a definition for sysconf() in . */ #cmakedefine HAVE_FUNC_SYSCONF 1 -/* Define to 1 to use the gflags package for command-line parsing. */ -#cmakedefine HAVE_GFLAGS 1 - /* Define to 1 if you have the `lzo2' library (-llzo2). */ #cmakedefine HAVE_LIBLZO2 1 diff --git a/snappy-stubs-internal.h b/snappy-stubs-internal.h index 5936cb7..c2a838f 100644 --- a/snappy-stubs-internal.h +++ b/snappy-stubs-internal.h @@ -105,17 +105,18 @@ #define SNAPPY_ATTRIBUTE_ALWAYS_INLINE #endif -// This is only used for recomputing the tag byte table used during -// decompression; for simplicity we just remove it from the open-source -// version (anyone who wants to regenerate it can just do the call -// themselves within main()). -#define DEFINE_bool(flag_name, default_value, description) \ - bool FLAGS_ ## flag_name = default_value -#define DECLARE_bool(flag_name) \ - extern bool FLAGS_ ## flag_name +// Stubbed version of ABSL_FLAG. +// +// In the open source version, flags can only be changed at compile time. +#define SNAPPY_FLAG(flag_type, flag_name, default_value, help) \ + flag_type FLAGS_ ## flag_name = default_value namespace snappy { +// Stubbed version of absl::GetFlag(). +template +inline T GetFlag(T flag) { return flag; } + static const uint32_t kuint32max = std::numeric_limits::max(); static const int64_t kint64max = std::numeric_limits::max(); diff --git a/snappy-test.h b/snappy-test.h index c2b2bf4..f80d343 100644 --- a/snappy-test.h +++ b/snappy-test.h @@ -56,27 +56,8 @@ #include #endif -#ifdef HAVE_GFLAGS - -#include - -// This is tricky; both gflags and Google Test want to look at the command line -// arguments. Google Test seems to be the most happy with unknown arguments, -// though, so we call it first and hope for the best. -#define InitGoogle(argv0, argc, argv, remove_flags) \ - google::ParseCommandLineFlags(argc, argv, remove_flags); - -#else - -// If we don't have the gflags package installed, these can only be -// changed at compile time. -#define DEFINE_int32(flag_name, default_value, description) \ - static int FLAGS_ ## flag_name = default_value; - #define InitGoogle(argv0, argc, argv, remove_flags) ((void)(0)) -#endif - #ifdef HAVE_LIBZ #include "zlib.h" #endif diff --git a/snappy_test_tool.cc b/snappy_test_tool.cc index f566167..c6ca5fa 100644 --- a/snappy_test_tool.cc +++ b/snappy_test_tool.cc @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -41,23 +42,24 @@ #include "snappy.h" #include "snappy_test_data.h" -DEFINE_int32(start_len, -1, - "Starting prefix size for testing (-1: just full file contents)"); -DEFINE_int32(end_len, -1, - "Starting prefix size for testing (-1: just full file contents)"); -DEFINE_int32(bytes, 10485760, - "How many bytes to compress/uncompress per file for timing"); +SNAPPY_FLAG(int32_t, start_len, -1, + "Starting prefix size for testing (-1: just full file contents)"); +SNAPPY_FLAG(int32_t, end_len, -1, + "Starting prefix size for testing (-1: just full file contents)"); +SNAPPY_FLAG(int32_t, bytes, 10485760, + "How many bytes to compress/uncompress per file for timing"); -DEFINE_bool(zlib, true, +SNAPPY_FLAG(bool, zlib, true, "Run zlib compression (http://www.zlib.net)"); -DEFINE_bool(lzo, true, +SNAPPY_FLAG(bool, lzo, true, "Run LZO compression (http://www.oberhumer.com/opensource/lzo/)"); -DEFINE_bool(lz4, true, "Run LZ4 compression (https://github.com/lz4/lz4)"); -DEFINE_bool(snappy, true, "Run snappy compression"); +SNAPPY_FLAG(bool, lz4, true, + "Run LZ4 compression (https://github.com/lz4/lz4)"); +SNAPPY_FLAG(bool, snappy, true, "Run snappy compression"); -DEFINE_bool(write_compressed, false, +SNAPPY_FLAG(bool, write_compressed, false, "Write compressed versions of each file to .comp"); -DEFINE_bool(write_uncompressed, false, +SNAPPY_FLAG(bool, write_uncompressed, false, "Write uncompressed versions of each file to .uncomp"); namespace snappy { @@ -416,25 +418,27 @@ void MeasureFile(const char* fname) { CHECK_OK(file::GetContents(fname, &fullinput, file::Defaults())); std::printf("%-40s :\n", fname); - int start_len = (absl::GetFlag(FLAGS_start_len) < 0) + int start_len = (snappy::GetFlag(FLAGS_start_len) < 0) ? fullinput.size() - : absl::GetFlag(FLAGS_start_len); + : snappy::GetFlag(FLAGS_start_len); int end_len = fullinput.size(); - if (absl::GetFlag(FLAGS_end_len) >= 0) { - end_len = std::min(fullinput.size(), absl::GetFlag(FLAGS_end_len)); + if (snappy::GetFlag(FLAGS_end_len) >= 0) { + end_len = std::min(fullinput.size(), snappy::GetFlag(FLAGS_end_len)); } for (int len = start_len; len <= end_len; ++len) { const char* const input = fullinput.data(); - int repeats = (absl::GetFlag(FLAGS_bytes) + len) / (len + 1); - if (absl::GetFlag(FLAGS_zlib)) + int repeats = (snappy::GetFlag(FLAGS_bytes) + len) / (len + 1); + if (snappy::GetFlag(FLAGS_zlib)) Measure(input, len, ZLIB, repeats, 1024 << 10); - if (absl::GetFlag(FLAGS_lzo)) Measure(input, len, LZO, repeats, 1024 << 10); - if (absl::GetFlag(FLAGS_lz4)) Measure(input, len, LZ4, repeats, 1024 << 10); - if (absl::GetFlag(FLAGS_snappy)) + if (snappy::GetFlag(FLAGS_lzo)) + Measure(input, len, LZO, repeats, 1024 << 10); + if (snappy::GetFlag(FLAGS_lz4)) + Measure(input, len, LZ4, repeats, 1024 << 10); + if (snappy::GetFlag(FLAGS_snappy)) Measure(input, len, SNAPPY, repeats, 4096 << 10); // For block-size based measurements - if (0 && absl::GetFlag(FLAGS_snappy)) { + if (0 && snappy::GetFlag(FLAGS_snappy)) { Measure(input, len, SNAPPY, repeats, 8<<10); Measure(input, len, SNAPPY, repeats, 16<<10); Measure(input, len, SNAPPY, repeats, 32<<10); @@ -453,9 +457,9 @@ int main(int argc, char** argv) { InitGoogle(argv[0], &argc, &argv, true); for (int arg = 1; arg < argc; ++arg) { - if (absl::GetFlag(FLAGS_write_compressed)) { + if (snappy::GetFlag(FLAGS_write_compressed)) { snappy::CompressFile(argv[arg]); - } else if (absl::GetFlag(FLAGS_write_uncompressed)) { + } else if (snappy::GetFlag(FLAGS_write_uncompressed)) { snappy::UncompressFile(argv[arg]); } else { snappy::MeasureFile(argv[arg]); diff --git a/snappy_unittest.cc b/snappy_unittest.cc index 14c633c..7a85635 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc @@ -43,7 +43,7 @@ #include "snappy.h" #include "snappy_test_data.h" -DEFINE_bool(snappy_dump_decompression_table, false, +SNAPPY_FLAG(bool, snappy_dump_decompression_table, false, "If true, we print the decompression table during tests."); namespace snappy { @@ -461,7 +461,7 @@ TEST(Snappy, MaxBlowup) { } TEST(Snappy, RandomData) { - std::minstd_rand0 rng(absl::GetFlag(FLAGS_test_random_seed)); + std::minstd_rand0 rng(snappy::GetFlag(FLAGS_test_random_seed)); std::uniform_int_distribution uniform_0_to_3(0, 3); std::uniform_int_distribution uniform_0_to_8(0, 8); std::uniform_int_distribution uniform_byte(0, 255); @@ -834,7 +834,7 @@ TEST(Snappy, FindMatchLength) { TEST(Snappy, FindMatchLengthRandom) { constexpr int kNumTrials = 10000; constexpr int kTypicalLength = 10; - std::minstd_rand0 rng(absl::GetFlag(FLAGS_test_random_seed)); + std::minstd_rand0 rng(snappy::GetFlag(FLAGS_test_random_seed)); std::uniform_int_distribution uniform_byte(0, 255); std::bernoulli_distribution one_in_two(1.0 / 2); std::bernoulli_distribution one_in_typical_length(1.0 / kTypicalLength); @@ -938,7 +938,7 @@ TEST(Snappy, VerifyCharTable) { EXPECT_NE(0xffff, dst[i]) << "Did not assign byte " << i; } - if (absl::GetFlag(FLAGS_snappy_dump_decompression_table)) { + if (snappy::GetFlag(FLAGS_snappy_dump_decompression_table)) { std::printf("static const uint16_t char_table[256] = {\n "); for (int i = 0; i < 256; ++i) { std::printf("0x%04x%s",