snappy 0.4.0-java → 0.5.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.
@@ -31,12 +31,10 @@
31
31
  #include <string>
32
32
  #include <vector>
33
33
 
34
- #include "snappy-test.h"
35
-
36
34
  #include "benchmark/benchmark.h"
37
-
38
35
  #include "snappy-internal.h"
39
36
  #include "snappy-sinksource.h"
37
+ #include "snappy-test.h"
40
38
  #include "snappy.h"
41
39
  #include "snappy_test_data.h"
42
40
 
@@ -44,6 +42,15 @@ namespace snappy {
44
42
 
45
43
  namespace {
46
44
 
45
+ void FilesAndLevels(benchmark::internal::Benchmark* benchmark) {
46
+ for (int i = 0; i < ARRAYSIZE(kTestDataFiles); ++i) {
47
+ for (int level = snappy::CompressionOptions::MinCompressionLevel();
48
+ level <= snappy::CompressionOptions::MaxCompressionLevel(); ++level) {
49
+ benchmark->ArgPair(i, level);
50
+ }
51
+ }
52
+ }
53
+
47
54
  void BM_UFlat(benchmark::State& state) {
48
55
  // Pick file to process based on state.range(0).
49
56
  int file_index = state.range(0);
@@ -55,7 +62,9 @@ void BM_UFlat(benchmark::State& state) {
55
62
  kTestDataFiles[file_index].size_limit);
56
63
 
57
64
  std::string zcontents;
58
- snappy::Compress(contents.data(), contents.size(), &zcontents);
65
+ snappy::Compress(
66
+ contents.data(), contents.size(), &zcontents,
67
+ snappy::CompressionOptions{/*level=*/static_cast<int>(state.range(1))});
59
68
  char* dst = new char[contents.size()];
60
69
 
61
70
  for (auto s : state) {
@@ -68,7 +77,7 @@ void BM_UFlat(benchmark::State& state) {
68
77
 
69
78
  delete[] dst;
70
79
  }
71
- BENCHMARK(BM_UFlat)->DenseRange(0, ARRAYSIZE(kTestDataFiles) - 1);
80
+ BENCHMARK(BM_UFlat)->Apply(FilesAndLevels);
72
81
 
73
82
  struct SourceFiles {
74
83
  SourceFiles() {
@@ -119,7 +128,9 @@ void BM_UValidate(benchmark::State& state) {
119
128
  kTestDataFiles[file_index].size_limit);
120
129
 
121
130
  std::string zcontents;
122
- snappy::Compress(contents.data(), contents.size(), &zcontents);
131
+ snappy::Compress(
132
+ contents.data(), contents.size(), &zcontents,
133
+ snappy::CompressionOptions{/*level=*/static_cast<int>(state.range(1))});
123
134
 
124
135
  for (auto s : state) {
125
136
  CHECK(snappy::IsValidCompressedBuffer(zcontents.data(), zcontents.size()));
@@ -128,7 +139,7 @@ void BM_UValidate(benchmark::State& state) {
128
139
  static_cast<int64_t>(contents.size()));
129
140
  state.SetLabel(kTestDataFiles[file_index].label);
130
141
  }
131
- BENCHMARK(BM_UValidate)->DenseRange(0, ARRAYSIZE(kTestDataFiles) - 1);
142
+ BENCHMARK(BM_UValidate)->Apply(FilesAndLevels);
132
143
 
133
144
  void BM_UValidateMedley(benchmark::State& state) {
134
145
  static const SourceFiles* const source = new SourceFiles();
@@ -152,6 +163,7 @@ BENCHMARK(BM_UValidateMedley);
152
163
  void BM_UIOVecSource(benchmark::State& state) {
153
164
  // Pick file to process based on state.range(0).
154
165
  int file_index = state.range(0);
166
+ int level = state.range(1);
155
167
 
156
168
  CHECK_GE(file_index, 0);
157
169
  CHECK_LT(file_index, ARRAYSIZE(kTestDataFiles));
@@ -180,7 +192,8 @@ void BM_UIOVecSource(benchmark::State& state) {
180
192
  char* dst = new char[snappy::MaxCompressedLength(contents.size())];
181
193
  size_t zsize = 0;
182
194
  for (auto s : state) {
183
- snappy::RawCompressFromIOVec(iov, contents.size(), dst, &zsize);
195
+ snappy::RawCompressFromIOVec(iov, contents.size(), dst, &zsize,
196
+ snappy::CompressionOptions{/*level=*/level});
184
197
  benchmark::DoNotOptimize(iov);
185
198
  }
186
199
  state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) *
@@ -195,7 +208,7 @@ void BM_UIOVecSource(benchmark::State& state) {
195
208
 
196
209
  delete[] dst;
197
210
  }
198
- BENCHMARK(BM_UIOVecSource)->DenseRange(0, ARRAYSIZE(kTestDataFiles) - 1);
211
+ BENCHMARK(BM_UIOVecSource)->Apply(FilesAndLevels);
199
212
 
200
213
  void BM_UIOVecSink(benchmark::State& state) {
201
214
  // Pick file to process based on state.range(0).
@@ -213,7 +226,7 @@ void BM_UIOVecSink(benchmark::State& state) {
213
226
  // Uncompress into an iovec containing ten entries.
214
227
  const int kNumEntries = 10;
215
228
  struct iovec iov[kNumEntries];
216
- char *dst = new char[contents.size()];
229
+ char* dst = new char[contents.size()];
217
230
  size_t used_so_far = 0;
218
231
  for (int i = 0; i < kNumEntries; ++i) {
219
232
  iov[i].iov_base = dst + used_so_far;
@@ -254,7 +267,9 @@ void BM_UFlatSink(benchmark::State& state) {
254
267
  kTestDataFiles[file_index].size_limit);
255
268
 
256
269
  std::string zcontents;
257
- snappy::Compress(contents.data(), contents.size(), &zcontents);
270
+ snappy::Compress(
271
+ contents.data(), contents.size(), &zcontents,
272
+ snappy::CompressionOptions{/*level=*/static_cast<int>(state.range(1))});
258
273
  char* dst = new char[contents.size()];
259
274
 
260
275
  for (auto s : state) {
@@ -273,11 +288,12 @@ void BM_UFlatSink(benchmark::State& state) {
273
288
  delete[] dst;
274
289
  }
275
290
 
276
- BENCHMARK(BM_UFlatSink)->DenseRange(0, ARRAYSIZE(kTestDataFiles) - 1);
291
+ BENCHMARK(BM_UFlatSink)->Apply(FilesAndLevels);
277
292
 
278
293
  void BM_ZFlat(benchmark::State& state) {
279
294
  // Pick file to process based on state.range(0).
280
295
  int file_index = state.range(0);
296
+ int level = state.range(1);
281
297
 
282
298
  CHECK_GE(file_index, 0);
283
299
  CHECK_LT(file_index, ARRAYSIZE(kTestDataFiles));
@@ -288,7 +304,8 @@ void BM_ZFlat(benchmark::State& state) {
288
304
 
289
305
  size_t zsize = 0;
290
306
  for (auto s : state) {
291
- snappy::RawCompress(contents.data(), contents.size(), dst, &zsize);
307
+ snappy::RawCompress(contents.data(), contents.size(), dst, &zsize,
308
+ snappy::CompressionOptions{/*level=*/level});
292
309
  benchmark::DoNotOptimize(dst);
293
310
  }
294
311
  state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) *
@@ -302,10 +319,12 @@ void BM_ZFlat(benchmark::State& state) {
302
319
  zsize);
303
320
  delete[] dst;
304
321
  }
305
- BENCHMARK(BM_ZFlat)->DenseRange(0, ARRAYSIZE(kTestDataFiles) - 1);
322
+
323
+ BENCHMARK(BM_ZFlat)->Apply(FilesAndLevels);
306
324
 
307
325
  void BM_ZFlatAll(benchmark::State& state) {
308
326
  const int num_files = ARRAYSIZE(kTestDataFiles);
327
+ int level = state.range(0);
309
328
 
310
329
  std::vector<std::string> contents(num_files);
311
330
  std::vector<char*> dst(num_files);
@@ -322,7 +341,7 @@ void BM_ZFlatAll(benchmark::State& state) {
322
341
  for (auto s : state) {
323
342
  for (int i = 0; i < num_files; ++i) {
324
343
  snappy::RawCompress(contents[i].data(), contents[i].size(), dst[i],
325
- &zsize);
344
+ &zsize, snappy::CompressionOptions{/*level=*/level});
326
345
  benchmark::DoNotOptimize(dst);
327
346
  }
328
347
  }
@@ -335,10 +354,11 @@ void BM_ZFlatAll(benchmark::State& state) {
335
354
  }
336
355
  state.SetLabel(StrFormat("%d kTestDataFiles", num_files));
337
356
  }
338
- BENCHMARK(BM_ZFlatAll);
357
+ BENCHMARK(BM_ZFlatAll)->DenseRange(1, 2);
339
358
 
340
359
  void BM_ZFlatIncreasingTableSize(benchmark::State& state) {
341
360
  CHECK_GT(ARRAYSIZE(kTestDataFiles), 0);
361
+ int level = state.range(0);
342
362
  const std::string base_content = ReadTestDataFile(
343
363
  kTestDataFiles[0].filename, kTestDataFiles[0].size_limit);
344
364
 
@@ -358,7 +378,7 @@ void BM_ZFlatIncreasingTableSize(benchmark::State& state) {
358
378
  for (auto s : state) {
359
379
  for (size_t i = 0; i < contents.size(); ++i) {
360
380
  snappy::RawCompress(contents[i].data(), contents[i].size(), dst[i],
361
- &zsize);
381
+ &zsize, snappy::CompressionOptions{/*level=*/level});
362
382
  benchmark::DoNotOptimize(dst);
363
383
  }
364
384
  }
@@ -371,7 +391,7 @@ void BM_ZFlatIncreasingTableSize(benchmark::State& state) {
371
391
  }
372
392
  state.SetLabel(StrFormat("%d tables", contents.size()));
373
393
  }
374
- BENCHMARK(BM_ZFlatIncreasingTableSize);
394
+ BENCHMARK(BM_ZFlatIncreasingTableSize)->DenseRange(1, 2);
375
395
 
376
396
  } // namespace
377
397
 
@@ -39,22 +39,26 @@
39
39
  // Entry point for LibFuzzer.
40
40
  extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
41
41
  std::string input(reinterpret_cast<const char*>(data), size);
42
+ for (int level = snappy::CompressionOptions::MinCompressionLevel();
43
+ level <= snappy::CompressionOptions::MaxCompressionLevel(); ++level) {
44
+ std::string compressed;
45
+ size_t compressed_size =
46
+ snappy::Compress(input.data(), input.size(), &compressed,
47
+ snappy::CompressionOptions{/*level=*/level});
42
48
 
43
- std::string compressed;
44
- size_t compressed_size =
45
- snappy::Compress(input.data(), input.size(), &compressed);
49
+ (void)compressed_size; // Variable only used in debug builds.
50
+ assert(compressed_size == compressed.size());
51
+ assert(compressed.size() <= snappy::MaxCompressedLength(input.size()));
52
+ assert(
53
+ snappy::IsValidCompressedBuffer(compressed.data(), compressed.size()));
46
54
 
47
- (void)compressed_size; // Variable only used in debug builds.
48
- assert(compressed_size == compressed.size());
49
- assert(compressed.size() <= snappy::MaxCompressedLength(input.size()));
50
- assert(snappy::IsValidCompressedBuffer(compressed.data(), compressed.size()));
55
+ std::string uncompressed_after_compress;
56
+ bool uncompress_succeeded = snappy::Uncompress(
57
+ compressed.data(), compressed.size(), &uncompressed_after_compress);
51
58
 
52
- std::string uncompressed_after_compress;
53
- bool uncompress_succeeded = snappy::Uncompress(
54
- compressed.data(), compressed.size(), &uncompressed_after_compress);
55
-
56
- (void)uncompress_succeeded; // Variable only used in debug builds.
57
- assert(uncompress_succeeded);
58
- assert(input == uncompressed_after_compress);
59
+ (void)uncompress_succeeded; // Variable only used in debug builds.
60
+ assert(uncompress_succeeded);
61
+ assert(input == uncompressed_after_compress);
62
+ }
59
63
  return 0;
60
64
  }
@@ -27,6 +27,7 @@
27
27
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
 
29
29
  #include <algorithm>
30
+ #include <cinttypes>
30
31
  #include <cmath>
31
32
  #include <cstdlib>
32
33
  #include <random>
@@ -484,6 +485,18 @@ TEST(Snappy, MaxBlowup) {
484
485
  Verify(input);
485
486
  }
486
487
 
488
+ // Issue #201, when output is more than 4GB, we had a data corruption bug.
489
+ // We cannot run this test always because of CI constraints.
490
+ TEST(Snappy, DISABLED_MoreThan4GB) {
491
+ std::mt19937 rng;
492
+ std::uniform_int_distribution<int> uniform_byte(0, 255);
493
+ std::string input;
494
+ input.resize((1ull << 32) - 1);
495
+ for (uint64_t i = 0; i < ((1ull << 32) - 1); ++i)
496
+ input[i] = static_cast<char>(uniform_byte(rng));
497
+ Verify(input);
498
+ }
499
+
487
500
  TEST(Snappy, RandomData) {
488
501
  std::minstd_rand0 rng(snappy::GetFlag(FLAGS_test_random_seed));
489
502
  std::uniform_int_distribution<int> uniform_0_to_3(0, 3);
metadata CHANGED
@@ -1,22 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snappy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: java
6
6
  authors:
7
7
  - miyucy
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
13
+ name: snappy-jars
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: 1.1.0
19
- name: snappy-jars
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
@@ -64,11 +63,15 @@ files:
64
63
  - test/snappy_writer_test.rb
65
64
  - test/test_helper.rb
66
65
  - vendor/snappy/AUTHORS
66
+ - vendor/snappy/BUILD.bazel
67
67
  - vendor/snappy/CMakeLists.txt
68
68
  - vendor/snappy/CONTRIBUTING.md
69
69
  - vendor/snappy/COPYING
70
+ - vendor/snappy/MODULE.bazel
70
71
  - vendor/snappy/NEWS
71
72
  - vendor/snappy/README.md
73
+ - vendor/snappy/WORKSPACE
74
+ - vendor/snappy/WORKSPACE.bzlmod
72
75
  - vendor/snappy/cmake/SnappyConfig.cmake.in
73
76
  - vendor/snappy/cmake/config.h.in
74
77
  - vendor/snappy/docs/README.md
@@ -99,7 +102,6 @@ licenses:
99
102
  metadata:
100
103
  homepage_uri: http://github.com/miyucy/snappy
101
104
  source_code_uri: http://github.com/miyucy/snappy
102
- post_install_message:
103
105
  rdoc_options: []
104
106
  require_paths:
105
107
  - lib
@@ -114,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  - !ruby/object:Gem::Version
115
117
  version: '0'
116
118
  requirements: []
117
- rubygems_version: 3.3.26
118
- signing_key:
119
+ rubygems_version: 3.6.9
119
120
  specification_version: 4
120
121
  summary: libsnappy binding for Ruby
121
122
  test_files: