snappy 0.0.17 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.github/workflows/main.yml +34 -0
  4. data/.github/workflows/publish.yml +34 -0
  5. data/.gitignore +2 -1
  6. data/.gitmodules +1 -1
  7. data/Dockerfile +13 -0
  8. data/Gemfile +4 -0
  9. data/README.md +45 -5
  10. data/Rakefile +32 -29
  11. data/ext/api.c +6 -1
  12. data/ext/extconf.rb +31 -22
  13. data/lib/snappy/hadoop/reader.rb +62 -0
  14. data/lib/snappy/hadoop/writer.rb +51 -0
  15. data/lib/snappy/hadoop.rb +22 -0
  16. data/lib/snappy/reader.rb +14 -10
  17. data/lib/snappy/shim.rb +1 -1
  18. data/lib/snappy/version.rb +1 -1
  19. data/lib/snappy.rb +5 -4
  20. data/snappy.gemspec +14 -13
  21. data/test/hadoop/snappy_hadoop_reader_test.rb +115 -0
  22. data/test/hadoop/snappy_hadoop_writer_test.rb +48 -0
  23. data/test/snappy_hadoop_test.rb +26 -0
  24. data/test/snappy_reader_test.rb +148 -0
  25. data/test/snappy_test.rb +95 -0
  26. data/test/snappy_writer_test.rb +55 -0
  27. data/test/test_helper.rb +7 -0
  28. data/test.sh +3 -0
  29. data/vendor/snappy/CMakeLists.txt +420 -0
  30. data/vendor/snappy/CONTRIBUTING.md +31 -0
  31. data/vendor/snappy/NEWS +52 -0
  32. data/vendor/snappy/{README → README.md} +75 -49
  33. data/vendor/snappy/cmake/SnappyConfig.cmake.in +33 -0
  34. data/vendor/snappy/cmake/config.h.in +66 -0
  35. data/vendor/snappy/docs/README.md +72 -0
  36. data/vendor/snappy/snappy-internal.h +200 -32
  37. data/vendor/snappy/snappy-sinksource.cc +26 -9
  38. data/vendor/snappy/snappy-sinksource.h +11 -11
  39. data/vendor/snappy/snappy-stubs-internal.cc +1 -1
  40. data/vendor/snappy/snappy-stubs-internal.h +299 -302
  41. data/vendor/snappy/snappy-stubs-public.h.in +10 -47
  42. data/vendor/snappy/snappy-test.cc +94 -200
  43. data/vendor/snappy/snappy-test.h +101 -358
  44. data/vendor/snappy/snappy.cc +1437 -474
  45. data/vendor/snappy/snappy.h +31 -12
  46. data/vendor/snappy/snappy_benchmark.cc +378 -0
  47. data/vendor/snappy/snappy_compress_fuzzer.cc +60 -0
  48. data/vendor/snappy/snappy_test_data.cc +57 -0
  49. data/vendor/snappy/snappy_test_data.h +68 -0
  50. data/vendor/snappy/snappy_test_tool.cc +471 -0
  51. data/vendor/snappy/snappy_uncompress_fuzzer.cc +58 -0
  52. data/vendor/snappy/snappy_unittest.cc +271 -792
  53. metadata +42 -92
  54. data/.travis.yml +0 -26
  55. data/smoke.sh +0 -8
  56. data/test/test-snappy-reader.rb +0 -129
  57. data/test/test-snappy-writer.rb +0 -55
  58. data/test/test-snappy.rb +0 -58
  59. data/vendor/snappy/ChangeLog +0 -2468
  60. data/vendor/snappy/INSTALL +0 -370
  61. data/vendor/snappy/Makefile +0 -982
  62. data/vendor/snappy/Makefile.am +0 -26
  63. data/vendor/snappy/Makefile.in +0 -982
  64. data/vendor/snappy/aclocal.m4 +0 -9738
  65. data/vendor/snappy/autogen.sh +0 -12
  66. data/vendor/snappy/autom4te.cache/output.0 +0 -18856
  67. data/vendor/snappy/autom4te.cache/output.1 +0 -18852
  68. data/vendor/snappy/autom4te.cache/requests +0 -297
  69. data/vendor/snappy/autom4te.cache/traces.0 +0 -2689
  70. data/vendor/snappy/autom4te.cache/traces.1 +0 -714
  71. data/vendor/snappy/config.guess +0 -1530
  72. data/vendor/snappy/config.h +0 -135
  73. data/vendor/snappy/config.h.in +0 -134
  74. data/vendor/snappy/config.log +0 -1640
  75. data/vendor/snappy/config.status +0 -2318
  76. data/vendor/snappy/config.sub +0 -1773
  77. data/vendor/snappy/configure +0 -18852
  78. data/vendor/snappy/configure.ac +0 -134
  79. data/vendor/snappy/depcomp +0 -688
  80. data/vendor/snappy/install-sh +0 -527
  81. data/vendor/snappy/libtool +0 -10246
  82. data/vendor/snappy/ltmain.sh +0 -9661
  83. data/vendor/snappy/m4/gtest.m4 +0 -74
  84. data/vendor/snappy/m4/libtool.m4 +0 -8001
  85. data/vendor/snappy/m4/ltoptions.m4 +0 -384
  86. data/vendor/snappy/m4/ltsugar.m4 +0 -123
  87. data/vendor/snappy/m4/ltversion.m4 +0 -23
  88. data/vendor/snappy/m4/lt~obsolete.m4 +0 -98
  89. data/vendor/snappy/missing +0 -331
  90. data/vendor/snappy/snappy-stubs-public.h +0 -100
  91. data/vendor/snappy/snappy.pc +0 -10
  92. data/vendor/snappy/snappy.pc.in +0 -10
  93. data/vendor/snappy/stamp-h1 +0 -1
@@ -1,5 +1,4 @@
1
1
  // Copyright 2011 Google Inc. All Rights Reserved.
2
- // Author: sesse@google.com (Steinar H. Gunderson)
3
2
  //
4
3
  // Redistribution and use in source and binary forms, with or without
5
4
  // modification, are permitted provided that the following conditions are
@@ -36,64 +35,28 @@
36
35
  #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37
36
  #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38
37
 
39
- #if @ac_cv_have_stdint_h@
40
- #include <stdint.h>
41
- #endif
38
+ #include <cstddef>
42
39
 
43
- #if @ac_cv_have_stddef_h@
44
- #include <stddef.h>
45
- #endif
46
-
47
- #if @ac_cv_have_sys_uio_h@
40
+ #if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H
48
41
  #include <sys/uio.h>
49
- #endif
42
+ #endif // HAVE_SYS_UIO_H
50
43
 
51
- #define SNAPPY_MAJOR @SNAPPY_MAJOR@
52
- #define SNAPPY_MINOR @SNAPPY_MINOR@
53
- #define SNAPPY_PATCHLEVEL @SNAPPY_PATCHLEVEL@
44
+ #define SNAPPY_MAJOR ${PROJECT_VERSION_MAJOR}
45
+ #define SNAPPY_MINOR ${PROJECT_VERSION_MINOR}
46
+ #define SNAPPY_PATCHLEVEL ${PROJECT_VERSION_PATCH}
54
47
  #define SNAPPY_VERSION \
55
48
  ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56
49
 
57
- #include <string>
58
-
59
50
  namespace snappy {
60
51
 
61
- #if @ac_cv_have_stdint_h@
62
- typedef int8_t int8;
63
- typedef uint8_t uint8;
64
- typedef int16_t int16;
65
- typedef uint16_t uint16;
66
- typedef int32_t int32;
67
- typedef uint32_t uint32;
68
- typedef int64_t int64;
69
- typedef uint64_t uint64;
70
- #else
71
- typedef signed char int8;
72
- typedef unsigned char uint8;
73
- typedef short int16;
74
- typedef unsigned short uint16;
75
- typedef int int32;
76
- typedef unsigned int uint32;
77
- typedef long long int64;
78
- typedef unsigned long long uint64;
79
- #endif
80
-
81
- typedef std::string string;
82
-
83
- #ifndef DISALLOW_COPY_AND_ASSIGN
84
- #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
85
- TypeName(const TypeName&); \
86
- void operator=(const TypeName&)
87
- #endif
88
-
89
- #if !@ac_cv_have_sys_uio_h@
52
+ #if !${HAVE_SYS_UIO_H_01} // !HAVE_SYS_UIO_H
90
53
  // Windows does not have an iovec type, yet the concept is universally useful.
91
54
  // It is simple to define it ourselves, so we put it inside our own namespace.
92
55
  struct iovec {
93
- void* iov_base;
94
- size_t iov_len;
56
+ void* iov_base;
57
+ size_t iov_len;
95
58
  };
96
- #endif
59
+ #endif // !HAVE_SYS_UIO_H
97
60
 
98
61
  } // namespace snappy
99
62
 
@@ -28,236 +28,130 @@
28
28
  //
29
29
  // Various stubs for the unit tests for the open-source version of Snappy.
30
30
 
31
- #ifdef HAVE_CONFIG_H
32
- #include "config.h"
33
- #endif
34
-
35
- #ifdef HAVE_WINDOWS_H
36
- #include <windows.h>
37
- #endif
38
-
39
31
  #include "snappy-test.h"
40
32
 
41
33
  #include <algorithm>
34
+ #include <cstdarg>
35
+ #include <cstdio>
36
+ #include <cstdlib>
37
+ #include <iostream>
38
+ #include <string>
42
39
 
43
- DEFINE_bool(run_microbenchmarks, true,
44
- "Run microbenchmarks before doing anything else.");
40
+ namespace file {
45
41
 
46
- namespace snappy {
42
+ OptionsStub::OptionsStub() = default;
43
+ OptionsStub::~OptionsStub() = default;
47
44
 
48
- string ReadTestDataFile(const string& base, size_t size_limit) {
49
- string contents;
50
- const char* srcdir = getenv("srcdir"); // This is set by Automake.
51
- string prefix;
52
- if (srcdir) {
53
- prefix = string(srcdir) + "/";
54
- }
55
- file::GetContents(prefix + "testdata/" + base, &contents, file::Defaults()
56
- ).CheckSuccess();
57
- if (size_limit > 0) {
58
- contents = contents.substr(0, size_limit);
59
- }
60
- return contents;
61
- }
62
-
63
- string ReadTestDataFile(const string& base) {
64
- return ReadTestDataFile(base, 0);
45
+ const OptionsStub &Defaults() {
46
+ static OptionsStub defaults;
47
+ return defaults;
65
48
  }
66
49
 
67
- string StringPrintf(const char* format, ...) {
68
- char buf[4096];
69
- va_list ap;
70
- va_start(ap, format);
71
- vsnprintf(buf, sizeof(buf), format, ap);
72
- va_end(ap);
73
- return buf;
74
- }
50
+ StatusStub::StatusStub() = default;
51
+ StatusStub::StatusStub(const StatusStub &) = default;
52
+ StatusStub &StatusStub::operator=(const StatusStub &) = default;
53
+ StatusStub::~StatusStub() = default;
75
54
 
76
- bool benchmark_running = false;
77
- int64 benchmark_real_time_us = 0;
78
- int64 benchmark_cpu_time_us = 0;
79
- string *benchmark_label = NULL;
80
- int64 benchmark_bytes_processed = 0;
55
+ bool StatusStub::ok() { return true; }
81
56
 
82
- void ResetBenchmarkTiming() {
83
- benchmark_real_time_us = 0;
84
- benchmark_cpu_time_us = 0;
85
- }
57
+ StatusStub GetContents(const std::string &filename, std::string *output,
58
+ const OptionsStub & /* options */) {
59
+ std::FILE *fp = std::fopen(filename.c_str(), "rb");
60
+ if (fp == nullptr) {
61
+ std::perror(filename.c_str());
62
+ std::exit(1);
63
+ }
86
64
 
87
- #ifdef WIN32
88
- LARGE_INTEGER benchmark_start_real;
89
- FILETIME benchmark_start_cpu;
90
- #else // WIN32
91
- struct timeval benchmark_start_real;
92
- struct rusage benchmark_start_cpu;
93
- #endif // WIN32
94
-
95
- void StartBenchmarkTiming() {
96
- #ifdef WIN32
97
- QueryPerformanceCounter(&benchmark_start_real);
98
- FILETIME dummy;
99
- CHECK(GetProcessTimes(
100
- GetCurrentProcess(), &dummy, &dummy, &dummy, &benchmark_start_cpu));
101
- #else
102
- gettimeofday(&benchmark_start_real, NULL);
103
- if (getrusage(RUSAGE_SELF, &benchmark_start_cpu) == -1) {
104
- perror("getrusage(RUSAGE_SELF)");
105
- exit(1);
65
+ output->clear();
66
+ while (!std::feof(fp)) {
67
+ char buffer[4096];
68
+ size_t bytes_read = std::fread(buffer, 1, sizeof(buffer), fp);
69
+ if (bytes_read == 0 && std::ferror(fp)) {
70
+ std::perror("fread");
71
+ std::exit(1);
72
+ }
73
+ output->append(buffer, bytes_read);
106
74
  }
107
- #endif
108
- benchmark_running = true;
75
+
76
+ std::fclose(fp);
77
+ return StatusStub();
109
78
  }
110
79
 
111
- void StopBenchmarkTiming() {
112
- if (!benchmark_running) {
113
- return;
80
+ StatusStub SetContents(const std::string &file_name, const std::string &content,
81
+ const OptionsStub & /* options */) {
82
+ std::FILE *fp = std::fopen(file_name.c_str(), "wb");
83
+ if (fp == nullptr) {
84
+ std::perror(file_name.c_str());
85
+ std::exit(1);
114
86
  }
115
87
 
116
- #ifdef WIN32
117
- LARGE_INTEGER benchmark_stop_real;
118
- LARGE_INTEGER benchmark_frequency;
119
- QueryPerformanceCounter(&benchmark_stop_real);
120
- QueryPerformanceFrequency(&benchmark_frequency);
121
-
122
- double elapsed_real = static_cast<double>(
123
- benchmark_stop_real.QuadPart - benchmark_start_real.QuadPart) /
124
- benchmark_frequency.QuadPart;
125
- benchmark_real_time_us += elapsed_real * 1e6 + 0.5;
126
-
127
- FILETIME benchmark_stop_cpu, dummy;
128
- CHECK(GetProcessTimes(
129
- GetCurrentProcess(), &dummy, &dummy, &dummy, &benchmark_stop_cpu));
130
-
131
- ULARGE_INTEGER start_ulargeint;
132
- start_ulargeint.LowPart = benchmark_start_cpu.dwLowDateTime;
133
- start_ulargeint.HighPart = benchmark_start_cpu.dwHighDateTime;
134
-
135
- ULARGE_INTEGER stop_ulargeint;
136
- stop_ulargeint.LowPart = benchmark_stop_cpu.dwLowDateTime;
137
- stop_ulargeint.HighPart = benchmark_stop_cpu.dwHighDateTime;
138
-
139
- benchmark_cpu_time_us +=
140
- (stop_ulargeint.QuadPart - start_ulargeint.QuadPart + 5) / 10;
141
- #else // WIN32
142
- struct timeval benchmark_stop_real;
143
- gettimeofday(&benchmark_stop_real, NULL);
144
- benchmark_real_time_us +=
145
- 1000000 * (benchmark_stop_real.tv_sec - benchmark_start_real.tv_sec);
146
- benchmark_real_time_us +=
147
- (benchmark_stop_real.tv_usec - benchmark_start_real.tv_usec);
148
-
149
- struct rusage benchmark_stop_cpu;
150
- if (getrusage(RUSAGE_SELF, &benchmark_stop_cpu) == -1) {
151
- perror("getrusage(RUSAGE_SELF)");
152
- exit(1);
88
+ size_t bytes_written = std::fwrite(content.data(), 1, content.size(), fp);
89
+ if (bytes_written != content.size()) {
90
+ std::perror("fwrite");
91
+ std::exit(1);
153
92
  }
154
- benchmark_cpu_time_us += 1000000 * (benchmark_stop_cpu.ru_utime.tv_sec -
155
- benchmark_start_cpu.ru_utime.tv_sec);
156
- benchmark_cpu_time_us += (benchmark_stop_cpu.ru_utime.tv_usec -
157
- benchmark_start_cpu.ru_utime.tv_usec);
158
- #endif // WIN32
159
93
 
160
- benchmark_running = false;
94
+ std::fclose(fp);
95
+ return StatusStub();
161
96
  }
162
97
 
163
- void SetBenchmarkLabel(const string& str) {
164
- if (benchmark_label) {
165
- delete benchmark_label;
98
+ } // namespace file
99
+
100
+ namespace snappy {
101
+
102
+ std::string ReadTestDataFile(const std::string& base, size_t size_limit) {
103
+ std::string contents;
104
+ const char* srcdir = getenv("srcdir"); // This is set by Automake.
105
+ std::string prefix;
106
+ if (srcdir) {
107
+ prefix = std::string(srcdir) + "/";
166
108
  }
167
- benchmark_label = new string(str);
109
+ file::GetContents(prefix + "testdata/" + base, &contents, file::Defaults()
110
+ ).ok();
111
+ if (size_limit > 0) {
112
+ contents = contents.substr(0, size_limit);
113
+ }
114
+ return contents;
168
115
  }
169
116
 
170
- void SetBenchmarkBytesProcessed(int64 bytes) {
171
- benchmark_bytes_processed = bytes;
117
+ std::string StrFormat(const char* format, ...) {
118
+ char buffer[4096];
119
+ std::va_list ap;
120
+ va_start(ap, format);
121
+ std::vsnprintf(buffer, sizeof(buffer), format, ap);
122
+ va_end(ap);
123
+ return buffer;
172
124
  }
173
125
 
174
- struct BenchmarkRun {
175
- int64 real_time_us;
176
- int64 cpu_time_us;
177
- };
126
+ LogMessage::~LogMessage() { std::cerr << std::endl; }
178
127
 
179
- struct BenchmarkCompareCPUTime {
180
- bool operator() (const BenchmarkRun& a, const BenchmarkRun& b) const {
181
- return a.cpu_time_us < b.cpu_time_us;
182
- }
183
- };
184
-
185
- void Benchmark::Run() {
186
- for (int test_case_num = start_; test_case_num <= stop_; ++test_case_num) {
187
- // Run a few iterations first to find out approximately how fast
188
- // the benchmark is.
189
- const int kCalibrateIterations = 100;
190
- ResetBenchmarkTiming();
191
- StartBenchmarkTiming();
192
- (*function_)(kCalibrateIterations, test_case_num);
193
- StopBenchmarkTiming();
194
-
195
- // Let each test case run for about 200ms, but at least as many
196
- // as we used to calibrate.
197
- // Run five times and pick the median.
198
- const int kNumRuns = 5;
199
- const int kMedianPos = kNumRuns / 2;
200
- int num_iterations = 0;
201
- if (benchmark_real_time_us > 0) {
202
- num_iterations = 200000 * kCalibrateIterations / benchmark_real_time_us;
203
- }
204
- num_iterations = max(num_iterations, kCalibrateIterations);
205
- BenchmarkRun benchmark_runs[kNumRuns];
128
+ LogMessage &LogMessage::operator<<(const std::string &message) {
129
+ std::cerr << message;
130
+ return *this;
131
+ }
206
132
 
207
- for (int run = 0; run < kNumRuns; ++run) {
208
- ResetBenchmarkTiming();
209
- StartBenchmarkTiming();
210
- (*function_)(num_iterations, test_case_num);
211
- StopBenchmarkTiming();
133
+ LogMessage &LogMessage::operator<<(int number) {
134
+ std::cerr << number;
135
+ return *this;
136
+ }
212
137
 
213
- benchmark_runs[run].real_time_us = benchmark_real_time_us;
214
- benchmark_runs[run].cpu_time_us = benchmark_cpu_time_us;
215
- }
138
+ #ifdef _MSC_VER
139
+ // ~LogMessageCrash calls std::abort() and therefore never exits. This is by
140
+ // design, so temporarily disable warning C4722.
141
+ #pragma warning(push)
142
+ #pragma warning(disable : 4722)
143
+ #endif
216
144
 
217
- string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num);
218
- string human_readable_speed;
219
-
220
- nth_element(benchmark_runs,
221
- benchmark_runs + kMedianPos,
222
- benchmark_runs + kNumRuns,
223
- BenchmarkCompareCPUTime());
224
- int64 real_time_us = benchmark_runs[kMedianPos].real_time_us;
225
- int64 cpu_time_us = benchmark_runs[kMedianPos].cpu_time_us;
226
- if (cpu_time_us <= 0) {
227
- human_readable_speed = "?";
228
- } else {
229
- int64 bytes_per_second =
230
- benchmark_bytes_processed * 1000000 / cpu_time_us;
231
- if (bytes_per_second < 1024) {
232
- human_readable_speed = StringPrintf("%dB/s", bytes_per_second);
233
- } else if (bytes_per_second < 1024 * 1024) {
234
- human_readable_speed = StringPrintf(
235
- "%.1fkB/s", bytes_per_second / 1024.0f);
236
- } else if (bytes_per_second < 1024 * 1024 * 1024) {
237
- human_readable_speed = StringPrintf(
238
- "%.1fMB/s", bytes_per_second / (1024.0f * 1024.0f));
239
- } else {
240
- human_readable_speed = StringPrintf(
241
- "%.1fGB/s", bytes_per_second / (1024.0f * 1024.0f * 1024.0f));
242
- }
243
- }
145
+ LogMessageCrash::~LogMessageCrash() {
146
+ std::cerr << std::endl;
147
+ std::abort();
148
+ }
244
149
 
245
- fprintf(stderr,
246
- #ifdef WIN32
247
- "%-18s %10I64d %10I64d %10d %s %s\n",
248
- #else
249
- "%-18s %10lld %10lld %10d %s %s\n",
150
+ #ifdef _MSC_VER
151
+ #pragma warning(pop)
250
152
  #endif
251
- heading.c_str(),
252
- static_cast<long long>(real_time_us * 1000 / num_iterations),
253
- static_cast<long long>(cpu_time_us * 1000 / num_iterations),
254
- num_iterations,
255
- human_readable_speed.c_str(),
256
- benchmark_label->c_str());
257
- }
258
- }
259
153
 
260
- #ifdef HAVE_LIBZ
154
+ #if HAVE_LIBZ
261
155
 
262
156
  ZLib::ZLib()
263
157
  : comp_init_(false),
@@ -523,8 +417,8 @@ int ZLib::UncompressAtMostOrAll(Bytef *dest, uLongf *destLen,
523
417
  LOG(WARNING)
524
418
  << "UncompressChunkOrAll: Received some extra data, bytes total: "
525
419
  << uncomp_stream_.avail_in << " bytes: "
526
- << string(reinterpret_cast<const char *>(uncomp_stream_.next_in),
527
- min(int(uncomp_stream_.avail_in), 20));
420
+ << std::string(reinterpret_cast<const char *>(uncomp_stream_.next_in),
421
+ std::min(int(uncomp_stream_.avail_in), 20));
528
422
  UncompressErrorInit();
529
423
  return Z_DATA_ERROR; // what's the extra data for?
530
424
  } else if (err != Z_OK && err != Z_STREAM_END && err != Z_BUF_ERROR) {