snappy 0.0.12-java → 0.1.0-java

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 (57) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +28 -1
  3. data/Gemfile +6 -1
  4. data/README.md +28 -4
  5. data/Rakefile +1 -0
  6. data/ext/extconf.rb +21 -24
  7. data/lib/snappy.rb +3 -1
  8. data/lib/snappy/hadoop.rb +22 -0
  9. data/lib/snappy/hadoop/reader.rb +58 -0
  10. data/lib/snappy/hadoop/writer.rb +51 -0
  11. data/lib/snappy/reader.rb +11 -7
  12. data/lib/snappy/shim.rb +30 -0
  13. data/lib/snappy/version.rb +3 -1
  14. data/lib/snappy/writer.rb +14 -9
  15. data/smoke.sh +8 -0
  16. data/snappy.gemspec +6 -30
  17. data/test/hadoop/test-snappy-hadoop-reader.rb +103 -0
  18. data/test/hadoop/test-snappy-hadoop-writer.rb +48 -0
  19. data/test/test-snappy-hadoop.rb +22 -0
  20. data/vendor/snappy/CMakeLists.txt +174 -0
  21. data/vendor/snappy/CONTRIBUTING.md +26 -0
  22. data/vendor/snappy/COPYING +1 -1
  23. data/vendor/snappy/NEWS +52 -0
  24. data/vendor/snappy/{README → README.md} +23 -9
  25. data/vendor/snappy/cmake/SnappyConfig.cmake +1 -0
  26. data/vendor/snappy/cmake/config.h.in +62 -0
  27. data/vendor/snappy/snappy-c.h +3 -3
  28. data/vendor/snappy/snappy-internal.h +101 -27
  29. data/vendor/snappy/snappy-sinksource.cc +33 -0
  30. data/vendor/snappy/snappy-sinksource.h +51 -6
  31. data/vendor/snappy/snappy-stubs-internal.h +107 -37
  32. data/vendor/snappy/snappy-stubs-public.h.in +16 -20
  33. data/vendor/snappy/snappy-test.cc +15 -9
  34. data/vendor/snappy/snappy-test.h +34 -43
  35. data/vendor/snappy/snappy.cc +529 -320
  36. data/vendor/snappy/snappy.h +23 -4
  37. data/vendor/snappy/snappy_unittest.cc +240 -185
  38. metadata +27 -74
  39. data/vendor/snappy/ChangeLog +0 -1916
  40. data/vendor/snappy/Makefile.am +0 -23
  41. data/vendor/snappy/autogen.sh +0 -7
  42. data/vendor/snappy/configure.ac +0 -133
  43. data/vendor/snappy/m4/gtest.m4 +0 -74
  44. data/vendor/snappy/testdata/alice29.txt +0 -3609
  45. data/vendor/snappy/testdata/asyoulik.txt +0 -4122
  46. data/vendor/snappy/testdata/baddata1.snappy +0 -0
  47. data/vendor/snappy/testdata/baddata2.snappy +0 -0
  48. data/vendor/snappy/testdata/baddata3.snappy +0 -0
  49. data/vendor/snappy/testdata/fireworks.jpeg +0 -0
  50. data/vendor/snappy/testdata/geo.protodata +0 -0
  51. data/vendor/snappy/testdata/html +0 -1
  52. data/vendor/snappy/testdata/html_x_4 +0 -1
  53. data/vendor/snappy/testdata/kppkn.gtb +0 -0
  54. data/vendor/snappy/testdata/lcet10.txt +0 -7519
  55. data/vendor/snappy/testdata/paper-100k.pdf +2 -600
  56. data/vendor/snappy/testdata/plrabn12.txt +0 -10699
  57. data/vendor/snappy/testdata/urls.10K +0 -10000
@@ -28,8 +28,8 @@
28
28
  //
29
29
  // Various stubs for the open-source version of Snappy.
30
30
 
31
- #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
32
- #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
31
+ #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
32
+ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
33
33
 
34
34
  #ifdef HAVE_CONFIG_H
35
35
  #include "config.h"
@@ -45,6 +45,14 @@
45
45
  #include <sys/mman.h>
46
46
  #endif
47
47
 
48
+ #ifdef HAVE_UNISTD_H
49
+ #include <unistd.h>
50
+ #endif
51
+
52
+ #if defined(_MSC_VER)
53
+ #include <intrin.h>
54
+ #endif // defined(_MSC_VER)
55
+
48
56
  #include "snappy-stubs-public.h"
49
57
 
50
58
  #if defined(__x86_64__)
@@ -52,6 +60,14 @@
52
60
  // Enable 64-bit optimized versions of some routines.
53
61
  #define ARCH_K8 1
54
62
 
63
+ #elif defined(__ppc64__)
64
+
65
+ #define ARCH_PPC 1
66
+
67
+ #elif defined(__aarch64__)
68
+
69
+ #define ARCH_ARM 1
70
+
55
71
  #endif
56
72
 
57
73
  // Needed by OS X, among others.
@@ -59,10 +75,6 @@
59
75
  #define MAP_ANONYMOUS MAP_ANON
60
76
  #endif
61
77
 
62
- // Pull in std::min, std::ostream, and the likes. This is safe because this
63
- // header file is never used from any public header files.
64
- using namespace std;
65
-
66
78
  // The size of an array, if known at compile-time.
67
79
  // Will give unexpected results if used on a pointer.
68
80
  // We undefine it first, since some compilers already have a definition.
@@ -73,11 +85,11 @@ using namespace std;
73
85
 
74
86
  // Static prediction hints.
75
87
  #ifdef HAVE_BUILTIN_EXPECT
76
- #define PREDICT_FALSE(x) (__builtin_expect(x, 0))
77
- #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
88
+ #define SNAPPY_PREDICT_FALSE(x) (__builtin_expect(x, 0))
89
+ #define SNAPPY_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
78
90
  #else
79
- #define PREDICT_FALSE(x) x
80
- #define PREDICT_TRUE(x) x
91
+ #define SNAPPY_PREDICT_FALSE(x) x
92
+ #define SNAPPY_PREDICT_TRUE(x) x
81
93
  #endif
82
94
 
83
95
  // This is only used for recomputing the tag byte table used during
@@ -96,9 +108,10 @@ static const int64 kint64max = static_cast<int64>(0x7FFFFFFFFFFFFFFFLL);
96
108
 
97
109
  // Potentially unaligned loads and stores.
98
110
 
99
- // x86 and PowerPC can simply do these loads and stores native.
111
+ // x86, PowerPC, and ARM64 can simply do these loads and stores native.
100
112
 
101
- #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
113
+ #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || \
114
+ defined(__aarch64__)
102
115
 
103
116
  #define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
104
117
  #define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
@@ -116,6 +129,15 @@ static const int64 kint64max = static_cast<int64>(0x7FFFFFFFFFFFFFFFLL);
116
129
  // sub-architectures.
117
130
  //
118
131
  // This is a mess, but there's not much we can do about it.
132
+ //
133
+ // To further complicate matters, only LDR instructions (single reads) are
134
+ // allowed to be unaligned, not LDRD (two reads) or LDM (many reads). Unless we
135
+ // explicitly tell the compiler that these accesses can be unaligned, it can and
136
+ // will combine accesses. On armcc, the way to signal this is done by accessing
137
+ // through the type (uint32 __packed *), but GCC has no such attribute
138
+ // (it ignores __attribute__((packed)) on individual variables). However,
139
+ // we can tell it that a _struct_ is unaligned, which has the same effect,
140
+ // so we do that.
119
141
 
120
142
  #elif defined(__arm__) && \
121
143
  !defined(__ARM_ARCH_4__) && \
@@ -131,11 +153,39 @@ static const int64 kint64max = static_cast<int64>(0x7FFFFFFFFFFFFFFFLL);
131
153
  !defined(__ARM_ARCH_6ZK__) && \
132
154
  !defined(__ARM_ARCH_6T2__)
133
155
 
134
- #define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
135
- #define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
156
+ #if __GNUC__
157
+ #define ATTRIBUTE_PACKED __attribute__((__packed__))
158
+ #else
159
+ #define ATTRIBUTE_PACKED
160
+ #endif
136
161
 
137
- #define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val))
138
- #define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val))
162
+ namespace base {
163
+ namespace internal {
164
+
165
+ struct Unaligned16Struct {
166
+ uint16 value;
167
+ uint8 dummy; // To make the size non-power-of-two.
168
+ } ATTRIBUTE_PACKED;
169
+
170
+ struct Unaligned32Struct {
171
+ uint32 value;
172
+ uint8 dummy; // To make the size non-power-of-two.
173
+ } ATTRIBUTE_PACKED;
174
+
175
+ } // namespace internal
176
+ } // namespace base
177
+
178
+ #define UNALIGNED_LOAD16(_p) \
179
+ ((reinterpret_cast<const ::snappy::base::internal::Unaligned16Struct *>(_p))->value)
180
+ #define UNALIGNED_LOAD32(_p) \
181
+ ((reinterpret_cast<const ::snappy::base::internal::Unaligned32Struct *>(_p))->value)
182
+
183
+ #define UNALIGNED_STORE16(_p, _val) \
184
+ ((reinterpret_cast< ::snappy::base::internal::Unaligned16Struct *>(_p))->value = \
185
+ (_val))
186
+ #define UNALIGNED_STORE32(_p, _val) \
187
+ ((reinterpret_cast< ::snappy::base::internal::Unaligned32Struct *>(_p))->value = \
188
+ (_val))
139
189
 
140
190
  // TODO(user): NEON supports unaligned 64-bit loads and stores.
141
191
  // See if that would be more efficient on platforms supporting it,
@@ -188,22 +238,8 @@ inline void UNALIGNED_STORE64(void *p, uint64 v) {
188
238
 
189
239
  #endif
190
240
 
191
- // This can be more efficient than UNALIGNED_LOAD64 + UNALIGNED_STORE64
192
- // on some platforms, in particular ARM.
193
- inline void UnalignedCopy64(const void *src, void *dst) {
194
- if (sizeof(void *) == 8) {
195
- UNALIGNED_STORE64(dst, UNALIGNED_LOAD64(src));
196
- } else {
197
- const char *src_char = reinterpret_cast<const char *>(src);
198
- char *dst_char = reinterpret_cast<char *>(dst);
199
-
200
- UNALIGNED_STORE32(dst_char, UNALIGNED_LOAD32(src_char));
201
- UNALIGNED_STORE32(dst_char + 4, UNALIGNED_LOAD32(src_char + 4));
202
- }
203
- }
204
-
205
241
  // The following guarantees declaration of the byte swap functions.
206
- #ifdef WORDS_BIGENDIAN
242
+ #if defined(SNAPPY_IS_BIG_ENDIAN)
207
243
 
208
244
  #ifdef HAVE_SYS_BYTEORDER_H
209
245
  #include <sys/byteorder.h>
@@ -260,7 +296,7 @@ inline uint64 bswap_64(uint64 x) {
260
296
 
261
297
  #endif
262
298
 
263
- #endif // WORDS_BIGENDIAN
299
+ #endif // defined(SNAPPY_IS_BIG_ENDIAN)
264
300
 
265
301
  // Convert to little-endian storage, opposite of network format.
266
302
  // Convert x from host to little endian: x = LittleEndian.FromHost(x);
@@ -274,7 +310,7 @@ inline uint64 bswap_64(uint64 x) {
274
310
  class LittleEndian {
275
311
  public:
276
312
  // Conversion functions.
277
- #ifdef WORDS_BIGENDIAN
313
+ #if defined(SNAPPY_IS_BIG_ENDIAN)
278
314
 
279
315
  static uint16 FromHost16(uint16 x) { return bswap_16(x); }
280
316
  static uint16 ToHost16(uint16 x) { return bswap_16(x); }
@@ -284,7 +320,7 @@ class LittleEndian {
284
320
 
285
321
  static bool IsLittleEndian() { return false; }
286
322
 
287
- #else // !defined(WORDS_BIGENDIAN)
323
+ #else // !defined(SNAPPY_IS_BIG_ENDIAN)
288
324
 
289
325
  static uint16 FromHost16(uint16 x) { return x; }
290
326
  static uint16 ToHost16(uint16 x) { return x; }
@@ -294,7 +330,7 @@ class LittleEndian {
294
330
 
295
331
  static bool IsLittleEndian() { return true; }
296
332
 
297
- #endif // !defined(WORDS_BIGENDIAN)
333
+ #endif // !defined(SNAPPY_IS_BIG_ENDIAN)
298
334
 
299
335
  // Functions to do unaligned loads and stores in little-endian order.
300
336
  static uint16 Load16(const void *p) {
@@ -324,10 +360,15 @@ class Bits {
324
360
  // undefined value if n == 0. FindLSBSetNonZero() is similar to ffs() except
325
361
  // that it's 0-indexed.
326
362
  static int FindLSBSetNonZero(uint32 n);
363
+
364
+ #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
327
365
  static int FindLSBSetNonZero64(uint64 n);
366
+ #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
328
367
 
329
368
  private:
330
- DISALLOW_COPY_AND_ASSIGN(Bits);
369
+ // No copying
370
+ Bits(const Bits&);
371
+ void operator=(const Bits&);
331
372
  };
332
373
 
333
374
  #ifdef HAVE_BUILTIN_CTZ
@@ -340,9 +381,36 @@ inline int Bits::FindLSBSetNonZero(uint32 n) {
340
381
  return __builtin_ctz(n);
341
382
  }
342
383
 
384
+ #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
343
385
  inline int Bits::FindLSBSetNonZero64(uint64 n) {
344
386
  return __builtin_ctzll(n);
345
387
  }
388
+ #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
389
+
390
+ #elif defined(_MSC_VER)
391
+
392
+ inline int Bits::Log2Floor(uint32 n) {
393
+ unsigned long where;
394
+ if (_BitScanReverse(&where, n)) {
395
+ return where;
396
+ } else {
397
+ return -1;
398
+ }
399
+ }
400
+
401
+ inline int Bits::FindLSBSetNonZero(uint32 n) {
402
+ unsigned long where;
403
+ if (_BitScanForward(&where, n)) return static_cast<int>(where);
404
+ return 32;
405
+ }
406
+
407
+ #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
408
+ inline int Bits::FindLSBSetNonZero64(uint64 n) {
409
+ unsigned long where;
410
+ if (_BitScanForward64(&where, n)) return static_cast<int>(where);
411
+ return 64;
412
+ }
413
+ #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
346
414
 
347
415
  #else // Portable versions.
348
416
 
@@ -376,6 +444,7 @@ inline int Bits::FindLSBSetNonZero(uint32 n) {
376
444
  return rc;
377
445
  }
378
446
 
447
+ #if defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
379
448
  // FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero().
380
449
  inline int Bits::FindLSBSetNonZero64(uint64 n) {
381
450
  const uint32 bottombits = static_cast<uint32>(n);
@@ -386,6 +455,7 @@ inline int Bits::FindLSBSetNonZero64(uint64 n) {
386
455
  return FindLSBSetNonZero(bottombits);
387
456
  }
388
457
  }
458
+ #endif // defined(ARCH_K8) || defined(ARCH_PPC) || defined(ARCH_ARM)
389
459
 
390
460
  #endif // End portable versions.
391
461
 
@@ -488,4 +558,4 @@ inline char* string_as_array(string* str) {
488
558
 
489
559
  } // namespace snappy
490
560
 
491
- #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
561
+ #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
@@ -33,24 +33,24 @@
33
33
  // which is a public header. Instead, snappy-stubs-public.h is generated by
34
34
  // from snappy-stubs-public.h.in at configure time.
35
35
 
36
- #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37
- #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
36
+ #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
37
+ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
38
38
 
39
- #if @ac_cv_have_stdint_h@
39
+ #if ${HAVE_STDINT_H_01} // HAVE_STDINT_H
40
40
  #include <stdint.h>
41
- #endif
41
+ #endif // HAVE_STDDEF_H
42
42
 
43
- #if @ac_cv_have_stddef_h@
43
+ #if ${HAVE_STDDEF_H_01} // HAVE_STDDEF_H
44
44
  #include <stddef.h>
45
- #endif
45
+ #endif // HAVE_STDDEF_H
46
46
 
47
- #if @ac_cv_have_sys_uio_h@
47
+ #if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H
48
48
  #include <sys/uio.h>
49
- #endif
49
+ #endif // HAVE_SYS_UIO_H
50
50
 
51
- #define SNAPPY_MAJOR @SNAPPY_MAJOR@
52
- #define SNAPPY_MINOR @SNAPPY_MINOR@
53
- #define SNAPPY_PATCHLEVEL @SNAPPY_PATCHLEVEL@
51
+ #define SNAPPY_MAJOR ${SNAPPY_MAJOR}
52
+ #define SNAPPY_MINOR ${SNAPPY_MINOR}
53
+ #define SNAPPY_PATCHLEVEL ${SNAPPY_PATCHLEVEL}
54
54
  #define SNAPPY_VERSION \
55
55
  ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
56
56
 
@@ -58,7 +58,7 @@
58
58
 
59
59
  namespace snappy {
60
60
 
61
- #if @ac_cv_have_stdint_h@
61
+ #if ${HAVE_STDINT_H_01} // HAVE_STDINT_H
62
62
  typedef int8_t int8;
63
63
  typedef uint8_t uint8;
64
64
  typedef int16_t int16;
@@ -76,23 +76,19 @@ typedef int int32;
76
76
  typedef unsigned int uint32;
77
77
  typedef long long int64;
78
78
  typedef unsigned long long uint64;
79
- #endif
79
+ #endif // HAVE_STDINT_H
80
80
 
81
81
  typedef std::string string;
82
82
 
83
- #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
84
- TypeName(const TypeName&); \
85
- void operator=(const TypeName&)
86
-
87
- #if !@ac_cv_have_sys_uio_h@
83
+ #if !${HAVE_SYS_UIO_H_01} // !HAVE_SYS_UIO_H
88
84
  // Windows does not have an iovec type, yet the concept is universally useful.
89
85
  // It is simple to define it ourselves, so we put it inside our own namespace.
90
86
  struct iovec {
91
87
  void* iov_base;
92
88
  size_t iov_len;
93
89
  };
94
- #endif
90
+ #endif // !HAVE_SYS_UIO_H
95
91
 
96
92
  } // namespace snappy
97
93
 
98
- #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
94
+ #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
@@ -28,13 +28,19 @@
28
28
  //
29
29
  // Various stubs for the unit tests for the open-source version of Snappy.
30
30
 
31
- #include "snappy-test.h"
31
+ #ifdef HAVE_CONFIG_H
32
+ #include "config.h"
33
+ #endif
32
34
 
33
35
  #ifdef HAVE_WINDOWS_H
34
- #define WIN32_LEAN_AND_MEAN
36
+ // Needed to be able to use std::max without workarounds in the source code.
37
+ // https://support.microsoft.com/en-us/help/143208/prb-using-stl-in-windows-program-can-cause-min-max-conflicts
38
+ #define NOMINMAX
35
39
  #include <windows.h>
36
40
  #endif
37
41
 
42
+ #include "snappy-test.h"
43
+
38
44
  #include <algorithm>
39
45
 
40
46
  DEFINE_bool(run_microbenchmarks, true,
@@ -198,7 +204,7 @@ void Benchmark::Run() {
198
204
  if (benchmark_real_time_us > 0) {
199
205
  num_iterations = 200000 * kCalibrateIterations / benchmark_real_time_us;
200
206
  }
201
- num_iterations = max(num_iterations, kCalibrateIterations);
207
+ num_iterations = std::max(num_iterations, kCalibrateIterations);
202
208
  BenchmarkRun benchmark_runs[kNumRuns];
203
209
 
204
210
  for (int run = 0; run < kNumRuns; ++run) {
@@ -214,10 +220,10 @@ void Benchmark::Run() {
214
220
  string heading = StringPrintf("%s/%d", name_.c_str(), test_case_num);
215
221
  string human_readable_speed;
216
222
 
217
- nth_element(benchmark_runs,
218
- benchmark_runs + kMedianPos,
219
- benchmark_runs + kNumRuns,
220
- BenchmarkCompareCPUTime());
223
+ std::nth_element(benchmark_runs,
224
+ benchmark_runs + kMedianPos,
225
+ benchmark_runs + kNumRuns,
226
+ BenchmarkCompareCPUTime());
221
227
  int64 real_time_us = benchmark_runs[kMedianPos].real_time_us;
222
228
  int64 cpu_time_us = benchmark_runs[kMedianPos].cpu_time_us;
223
229
  if (cpu_time_us <= 0) {
@@ -520,8 +526,8 @@ int ZLib::UncompressAtMostOrAll(Bytef *dest, uLongf *destLen,
520
526
  LOG(WARNING)
521
527
  << "UncompressChunkOrAll: Received some extra data, bytes total: "
522
528
  << uncomp_stream_.avail_in << " bytes: "
523
- << string(reinterpret_cast<const char *>(uncomp_stream_.next_in),
524
- min(int(uncomp_stream_.avail_in), 20));
529
+ << std::string(reinterpret_cast<const char *>(uncomp_stream_.next_in),
530
+ std::min(int(uncomp_stream_.avail_in), 20));
525
531
  UncompressErrorInit();
526
532
  return Z_DATA_ERROR; // what's the extra data for?
527
533
  } else if (err != Z_OK && err != Z_STREAM_END && err != Z_BUF_ERROR) {
@@ -28,8 +28,8 @@
28
28
  //
29
29
  // Various stubs for the unit tests for the open-source version of Snappy.
30
30
 
31
- #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
32
- #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
31
+ #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
32
+ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
33
33
 
34
34
  #include <iostream>
35
35
  #include <string>
@@ -52,7 +52,6 @@
52
52
  #endif
53
53
 
54
54
  #ifdef HAVE_WINDOWS_H
55
- #define WIN32_LEAN_AND_MEAN
56
55
  #include <windows.h>
57
56
  #endif
58
57
 
@@ -111,35 +110,18 @@
111
110
  #include "lzo/lzo1x.h"
112
111
  #endif
113
112
 
114
- #ifdef HAVE_LIBLZF
115
- extern "C" {
116
- #include "lzf.h"
117
- }
118
- #endif
119
-
120
- #ifdef HAVE_LIBFASTLZ
121
- #include "fastlz.h"
122
- #endif
123
-
124
- #ifdef HAVE_LIBQUICKLZ
125
- #include "quicklz.h"
126
- #endif
127
-
128
113
  namespace {
129
114
 
130
- namespace File {
131
- void Init() { }
132
- } // namespace File
133
-
134
115
  namespace file {
135
- int Defaults() { }
116
+ int Defaults() { return 0; }
136
117
 
137
118
  class DummyStatus {
138
119
  public:
139
120
  void CheckSuccess() { }
140
121
  };
141
122
 
142
- DummyStatus GetContents(const string& filename, string* data, int unused) {
123
+ DummyStatus GetContents(
124
+ const std::string& filename, std::string* data, int unused) {
143
125
  FILE* fp = fopen(filename.c_str(), "rb");
144
126
  if (fp == NULL) {
145
127
  perror(filename.c_str());
@@ -154,15 +136,16 @@ namespace file {
154
136
  perror("fread");
155
137
  exit(1);
156
138
  }
157
- data->append(string(buf, ret));
139
+ data->append(std::string(buf, ret));
158
140
  }
159
141
 
160
142
  fclose(fp);
143
+
144
+ return DummyStatus();
161
145
  }
162
146
 
163
- DummyStatus SetContents(const string& filename,
164
- const string& str,
165
- int unused) {
147
+ inline DummyStatus SetContents(
148
+ const std::string& filename, const std::string& str, int unused) {
166
149
  FILE* fp = fopen(filename.c_str(), "wb");
167
150
  if (fp == NULL) {
168
151
  perror(filename.c_str());
@@ -176,6 +159,8 @@ namespace file {
176
159
  }
177
160
 
178
161
  fclose(fp);
162
+
163
+ return DummyStatus();
179
164
  }
180
165
  } // namespace file
181
166
 
@@ -193,6 +178,7 @@ void Test_Snappy_RandomData();
193
178
  void Test_Snappy_FourByteOffset();
194
179
  void Test_SnappyCorruption_TruncatedVarint();
195
180
  void Test_SnappyCorruption_UnterminatedVarint();
181
+ void Test_SnappyCorruption_OverflowingVarint();
196
182
  void Test_Snappy_ReadPastEndOfBuffer();
197
183
  void Test_Snappy_FindMatchLength();
198
184
  void Test_Snappy_FindMatchLengthRandom();
@@ -463,7 +449,7 @@ class ZLib {
463
449
 
464
450
  DECLARE_bool(run_microbenchmarks);
465
451
 
466
- static void RunSpecifiedBenchmarks() {
452
+ static inline void RunSpecifiedBenchmarks() {
467
453
  if (!FLAGS_run_microbenchmarks) {
468
454
  return;
469
455
  }
@@ -497,6 +483,7 @@ static inline int RUN_ALL_TESTS() {
497
483
  snappy::Test_Snappy_FourByteOffset();
498
484
  snappy::Test_SnappyCorruption_TruncatedVarint();
499
485
  snappy::Test_SnappyCorruption_UnterminatedVarint();
486
+ snappy::Test_SnappyCorruption_OverflowingVarint();
500
487
  snappy::Test_Snappy_ReadPastEndOfBuffer();
501
488
  snappy::Test_Snappy_FindMatchLength();
502
489
  snappy::Test_Snappy_FindMatchLengthRandom();
@@ -510,10 +497,6 @@ static inline int RUN_ALL_TESTS() {
510
497
  // For main().
511
498
  namespace snappy {
512
499
 
513
- static void CompressFile(const char* fname);
514
- static void UncompressFile(const char* fname);
515
- static void MeasureFile(const char* fname);
516
-
517
500
  // Logging.
518
501
 
519
502
  #define LOG(level) LogMessage()
@@ -524,15 +507,15 @@ class LogMessage {
524
507
  public:
525
508
  LogMessage() { }
526
509
  ~LogMessage() {
527
- cerr << endl;
510
+ std::cerr << std::endl;
528
511
  }
529
512
 
530
513
  LogMessage& operator<<(const std::string& msg) {
531
- cerr << msg;
514
+ std::cerr << msg;
532
515
  return *this;
533
516
  }
534
517
  LogMessage& operator<<(int x) {
535
- cerr << x;
518
+ std::cerr << x;
536
519
  return *this;
537
520
  }
538
521
  };
@@ -541,18 +524,29 @@ class LogMessage {
541
524
  // and ones that are always active.
542
525
 
543
526
  #define CRASH_UNLESS(condition) \
544
- PREDICT_TRUE(condition) ? (void)0 : \
527
+ SNAPPY_PREDICT_TRUE(condition) ? (void)0 : \
545
528
  snappy::LogMessageVoidify() & snappy::LogMessageCrash()
546
529
 
530
+ #ifdef _MSC_VER
531
+ // ~LogMessageCrash calls abort() and therefore never exits. This is by design
532
+ // so temporarily disable warning C4722.
533
+ #pragma warning(push)
534
+ #pragma warning(disable:4722)
535
+ #endif
536
+
547
537
  class LogMessageCrash : public LogMessage {
548
538
  public:
549
539
  LogMessageCrash() { }
550
540
  ~LogMessageCrash() {
551
- cerr << endl;
541
+ std::cerr << std::endl;
552
542
  abort();
553
543
  }
554
544
  };
555
545
 
546
+ #ifdef _MSC_VER
547
+ #pragma warning(pop)
548
+ #endif
549
+
556
550
  // This class is used to explicitly ignore values in the conditional
557
551
  // logging macros. This avoids compiler warnings like "value computed
558
552
  // is not used" and "statement has no effect".
@@ -572,11 +566,8 @@ class LogMessageVoidify {
572
566
  #define CHECK_NE(a, b) CRASH_UNLESS((a) != (b))
573
567
  #define CHECK_LT(a, b) CRASH_UNLESS((a) < (b))
574
568
  #define CHECK_GT(a, b) CRASH_UNLESS((a) > (b))
569
+ #define CHECK_OK(cond) (cond).CheckSuccess()
575
570
 
576
- } // namespace
577
-
578
- using snappy::CompressFile;
579
- using snappy::UncompressFile;
580
- using snappy::MeasureFile;
571
+ } // namespace snappy
581
572
 
582
- #endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
573
+ #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_