summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Costan <costan@google.com>2021-03-08 17:24:08 +0000
committerVictor Costan <costan@google.com>2021-03-08 17:26:48 +0000
commit5e7c14bd05ee72a4294f413ac386032a47578eac (patch)
tree681d48f8779a35576ad762bb7784c34e3a623f19
parent80a2a10c8c6584c7321ed5259da5251ae030ffa4 (diff)
downloadsnappy-git-5e7c14bd05ee72a4294f413ac386032a47578eac.tar.gz
Add stubs for abseil flags.
This CL also removes support for using the gflags library to modify the flags. PiperOrigin-RevId: 361583626
-rw-r--r--CMakeLists.txt8
-rw-r--r--README.md5
-rw-r--r--cmake/config.h.in3
-rw-r--r--snappy-stubs-internal.h17
-rw-r--r--snappy-test.h19
-rw-r--r--snappy_test_tool.cc52
-rw-r--r--snappy_unittest.cc8
7 files changed, 42 insertions, 70 deletions
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 <unistd.h>. */
#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 <typename T>
+inline T GetFlag(T flag) { return flag; }
+
static const uint32_t kuint32max = std::numeric_limits<uint32_t>::max();
static const int64_t kint64max = std::numeric_limits<int64_t>::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 <windows.h>
#endif
-#ifdef HAVE_GFLAGS
-
-#include <gflags/gflags.h>
-
-// 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 <algorithm>
#include <cmath>
+#include <cstdint>
#include <cstdlib>
#include <random>
#include <string>
@@ -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 <file>.comp");
-DEFINE_bool(write_uncompressed, false,
+SNAPPY_FLAG(bool, write_uncompressed, false,
"Write uncompressed versions of each file to <file>.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<int>(fullinput.size(), absl::GetFlag(FLAGS_end_len));
+ if (snappy::GetFlag(FLAGS_end_len) >= 0) {
+ end_len = std::min<int>(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<int> uniform_0_to_3(0, 3);
std::uniform_int_distribution<int> uniform_0_to_8(0, 8);
std::uniform_int_distribution<int> 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<int> 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",