snappy 0.3.0 → 0.5.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +2 -2
  3. data/.github/workflows/publish.yml +7 -13
  4. data/Dockerfile +1 -1
  5. data/Gemfile +1 -0
  6. data/README.md +20 -1
  7. data/Rakefile +1 -1
  8. data/ext/extconf.rb +13 -11
  9. data/lib/snappy/shim.rb +3 -23
  10. data/lib/snappy/version.rb +1 -1
  11. data/lib/snappy/writer.rb +1 -1
  12. data/snappy.gemspec +1 -0
  13. data/test/snappy_test.rb +29 -4
  14. data/vendor/snappy/BUILD.bazel +211 -0
  15. data/vendor/snappy/CMakeLists.txt +176 -31
  16. data/vendor/snappy/CONTRIBUTING.md +9 -4
  17. data/vendor/snappy/MODULE.bazel +23 -0
  18. data/vendor/snappy/NEWS +27 -0
  19. data/vendor/snappy/README.md +52 -35
  20. data/vendor/snappy/WORKSPACE +27 -0
  21. data/vendor/snappy/WORKSPACE.bzlmod +0 -0
  22. data/vendor/snappy/cmake/config.h.in +30 -23
  23. data/vendor/snappy/snappy-internal.h +218 -25
  24. data/vendor/snappy/snappy-sinksource.cc +26 -9
  25. data/vendor/snappy/snappy-sinksource.h +11 -11
  26. data/vendor/snappy/snappy-stubs-internal.cc +1 -1
  27. data/vendor/snappy/snappy-stubs-internal.h +231 -306
  28. data/vendor/snappy/snappy-stubs-public.h.in +0 -11
  29. data/vendor/snappy/snappy-test.cc +88 -198
  30. data/vendor/snappy/snappy-test.h +102 -285
  31. data/vendor/snappy/snappy.cc +1412 -425
  32. data/vendor/snappy/snappy.h +60 -10
  33. data/vendor/snappy/snappy_benchmark.cc +398 -0
  34. data/vendor/snappy/snappy_compress_fuzzer.cc +21 -16
  35. data/vendor/snappy/snappy_test_data.cc +57 -0
  36. data/vendor/snappy/snappy_test_data.h +68 -0
  37. data/vendor/snappy/snappy_test_tool.cc +471 -0
  38. data/vendor/snappy/snappy_uncompress_fuzzer.cc +3 -2
  39. data/vendor/snappy/snappy_unittest.cc +183 -666
  40. metadata +12 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4866cfb8c9b7b1e16e5d6c8ba7044d8e003d5a03274575a09d60227bbdf4c603
4
- data.tar.gz: dfd8a8d4cdb51bce5a988b55c61940d9717fb95a9f9377f32db93708d43805ce
3
+ metadata.gz: b2895775124f25371d6d97fb3e0be40aba03493c5f7d9347826611c2b574f708
4
+ data.tar.gz: '0195162d3971e799cd011db55304b19a9a63a02411644d82f063f6a594f9664b'
5
5
  SHA512:
6
- metadata.gz: 1f3f35f369f73dee25075f72dc48693833d084d6bc6844243ef82585f41255bbf6bedaece227b05aa3ecc8bd9f9db2a13c98ea9ee1f9894204a719b9e0e0f57c
7
- data.tar.gz: 36af767eded664e7bb25e120e807897d47a6d6c5a86d6f655970030a20636b14143ae8e1df84d9032aa175987b2d97a21c31d1c048f0422f7da00079bce38d23
6
+ metadata.gz: 5bcc0284ef578c7e0545e0fc1865351d8b1a2ef162244b9aa9bb41b0aac2a601a53d0d51badbbd1204e3b17162088a083130ab2635171a44efd0d5e3600b527b
7
+ data.tar.gz: 7a8c04e18c08ef4e981f8658c4abfdb6be004be3684d5e618a42668f305b5408dc85385e05b472250a04731b30eccaeaa2d3f3902e6b7d7a754d7c573ed3a3d8
@@ -7,10 +7,10 @@ jobs:
7
7
  strategy:
8
8
  fail-fast: false
9
9
  matrix:
10
- ruby: [2.5, 2.6, 2.7, 3.0, 3.1, jruby]
10
+ ruby: [2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0, jruby]
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
13
+ - uses: actions/checkout@v4
14
14
  with:
15
15
  submodules: true
16
16
  - name: Set up Ruby
@@ -10,10 +10,14 @@ jobs:
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
- ruby: [2.7, jruby]
13
+ ruby: [4.0, jruby]
14
+ if: github.repository == 'miyucy/snappy'
14
15
  runs-on: ubuntu-latest
16
+ permissions:
17
+ contents: write
18
+ id-token: write
15
19
  steps:
16
- - uses: actions/checkout@v2
20
+ - uses: actions/checkout@v4
17
21
  with:
18
22
  submodules: true
19
23
  - name: Set up Ruby
@@ -21,14 +25,4 @@ jobs:
21
25
  with:
22
26
  ruby-version: ${{ matrix.ruby }}
23
27
  bundler-cache: true
24
- - name: Run release task
25
- run: |
26
- mkdir -p ~/.gem
27
- cat << EOF > ~/.gem/credentials
28
- ---
29
- :github: Bearer ${{secrets.GITHUB_TOKEN}}
30
- :rubygems_api_key: ${{secrets.RUBYGEMS_API_KEY}}
31
- EOF
32
- chmod 600 ~/.gem/credentials
33
- bundle exec rake release[remote]
34
- rm -f ~/.gem/credentials
28
+ - uses: rubygems/release-gem@v1
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # syntax = docker/dockerfile:labs
2
- ARG RUBY_VERSION=3.1
2
+ ARG RUBY_VERSION=3.4
3
3
  FROM ruby:${RUBY_VERSION}
4
4
 
5
5
  ENV BUNDLE_JOBS=4
data/Gemfile CHANGED
@@ -4,5 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "rake", "~> 13.0"
7
+ gem "ostruct"
7
8
  gem "test-unit", "~> 3.0"
8
9
  gem "test-unit-rr"
data/README.md CHANGED
@@ -9,7 +9,10 @@ see https://github.com/google/snappy
9
9
 
10
10
  ```bash
11
11
  $ brew install snappy
12
- $ brew install autoconf automake libtool
12
+ $ brew install autoconf automake cmake libtool
13
+
14
+ # This step may be needed if gem installation fails
15
+ bundle config build.snappy --with-snappy-dir=/opt/homebrew/opt/snappy
13
16
  ```
14
17
 
15
18
  ### Ubuntu
@@ -26,6 +29,22 @@ $ apk install snappy
26
29
  $ apk install build-base libexecinfo automake autoconf libtool
27
30
  ```
28
31
 
32
+ ### Windows
33
+
34
+ [Ruby Installer](https://rubyinstaller.org/) 3.0 and earlier:
35
+
36
+ ```bash
37
+ (in MSYS2 shell)
38
+ $ pacman -S mingw-w64-x86_64-snappy
39
+ ```
40
+
41
+ Ruby Installer 3.1 and later:
42
+
43
+ ```bash
44
+ (in MSYS2 shell)
45
+ pacman -S mingw-w64-ucrt-x86_64-snappy
46
+ ```
47
+
29
48
  ## Installation
30
49
 
31
50
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ if defined?(JRUBY_VERSION)
31
31
 
32
32
  desc "Compile the extension"
33
33
  task compile: :setup do
34
- ant.javac destdir: "${build.dir}", includeantruntime: "no", target: "1.6", source: "1.6", debug: "on" do
34
+ ant.javac destdir: "${build.dir}", includeantruntime: "no", target: "1.8", source: "1.8", debug: "on" do
35
35
  classpath refid: "compile.class.path"
36
36
  src { pathelement location: "${src.dir}" }
37
37
  end
data/ext/extconf.rb CHANGED
@@ -1,25 +1,27 @@
1
- require 'mkmf'
2
- require 'fileutils'
1
+ require "mkmf"
2
+ require "fileutils"
3
3
 
4
4
  $CXXFLAGS += " -std=c++11 "
5
5
 
6
- unless pkg_config('libsnappy') || have_library('snappy')
6
+ have_libsnappy = pkg_config("libsnappy") || have_library("snappy")
7
+ unless have_libsnappy
7
8
  # build vendor/snappy
8
9
  pwd = File.dirname File.expand_path __FILE__
9
- dir = File.join pwd, '..', 'vendor', 'snappy'
10
+ dir = File.join pwd, "..", "vendor", "snappy"
10
11
 
11
12
  Dir.chdir(dir) do
12
- FileUtils.mkdir_p 'build'
13
- Dir.chdir(File.join(dir, 'build')) do
14
- `cmake .. -DCMAKE_BUILD_TYPE=Release`
13
+ FileUtils.rm_rf "build"
14
+ FileUtils.mkdir_p "build"
15
+ Dir.chdir(File.join(dir, "build")) do
16
+ `cmake .. -DCMAKE_BUILD_TYPE=Release -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF`
15
17
  end
16
18
  end
17
19
 
18
20
  src = %w[
19
21
  config.h
20
22
  snappy-stubs-public.h
21
- ].map { |e| File.join dir, 'build', e }
22
- FileUtils.cp src, pwd, :verbose => true
23
+ ].map { |e| File.join dir, "build", e }
24
+ FileUtils.cp src, pwd, verbose: true
23
25
  src = %w[
24
26
  snappy-c.cc
25
27
  snappy-c.h
@@ -31,7 +33,7 @@ unless pkg_config('libsnappy') || have_library('snappy')
31
33
  snappy-stubs-internal.cc
32
34
  snappy-stubs-internal.h
33
35
  ].map { |e| File.join dir, e }
34
- FileUtils.cp src, pwd, :verbose => true
36
+ FileUtils.cp src, pwd, verbose: true
35
37
  end
36
38
 
37
- create_makefile 'snappy_ext'
39
+ create_makefile "snappy_ext"
data/lib/snappy/shim.rb CHANGED
@@ -3,28 +3,8 @@
3
3
  module Snappy
4
4
  module_function
5
5
 
6
- if RUBY_VERSION[0..2] == "1.8"
7
- def set_encoding(io)
8
- io
9
- end
10
-
11
- def b(str)
12
- str
13
- end
14
- else
15
- def set_encoding(io)
16
- io.set_encoding Encoding::ASCII_8BIT
17
- io
18
- end
19
-
20
- if ::String.instance_methods.include? :b
21
- def b(str)
22
- str.b
23
- end
24
- else
25
- def b(str)
26
- str.force_encoding Encoding::ASCII_8BIT
27
- end
28
- end
6
+ def set_encoding(io)
7
+ io.set_encoding Encoding::ASCII_8BIT
8
+ io
29
9
  end
30
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snappy
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/snappy/writer.rb CHANGED
@@ -4,7 +4,7 @@ require 'snappy/shim'
4
4
 
5
5
  module Snappy
6
6
  class Writer
7
- MAGIC = Snappy.b("\x82SNAPPY\x0")
7
+ MAGIC = "\x82SNAPPY\x0".b
8
8
  DEFAULT_VERSION = 1
9
9
  MINIMUM_COMPATIBLE_VERSION = 1
10
10
  DEFAULT_BLOCK_SIZE = 32 * 1024
data/snappy.gemspec CHANGED
@@ -32,5 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "snappy-jars", "~> 1.1.0"
33
33
  else
34
34
  spec.extensions = ["ext/extconf.rb"]
35
+ spec.metadata['msys2_mingw_dependencies'] = 'snappy'
35
36
  end
36
37
  end
data/test/snappy_test.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "test_helper"
4
+ require "securerandom"
4
5
 
5
6
  class SnappyTest < Test::Unit::TestCase
6
- T = [*"a".."z", *"A".."Z", *"0".."9"].freeze
7
-
8
7
  def random_data(length = 1024)
9
- Array.new(length) { T.sample }.join
8
+ SecureRandom.alphanumeric(length)
10
9
  end
11
10
 
12
11
  test "VERSION" do
@@ -20,6 +19,11 @@ class SnappyTest < Test::Unit::TestCase
20
19
  assert_equal s, Snappy.inflate(Snappy.deflate(s))
21
20
  end
22
21
 
22
+ test "binary data" do
23
+ s = SecureRandom.random_bytes(1024)
24
+ assert_equal s, Snappy.inflate(Snappy.deflate(s))
25
+ end
26
+
23
27
  test "well done (pair)" do
24
28
  s = random_data
25
29
  [
@@ -83,13 +87,34 @@ class SnappyTest < Test::Unit::TestCase
83
87
  notify "Ractor not defined"
84
88
  omit
85
89
  end
90
+ unless RUBY_VERSION.start_with?("4")
91
+ omit
92
+ end
86
93
  s = random_data
87
94
  a = Array.new(2) do
88
95
  Ractor.new(s) do |s|
89
96
  Snappy.inflate(Snappy.deflate(s)) == s
90
97
  end
91
98
  end
92
- assert_equal [true, true], a.map(&:take)
99
+ assert_equal [true, true], a.map(&:value)
100
+ end
101
+
102
+ test "take2" do
103
+ unless defined? ::Ractor
104
+ notify "Ractor not defined"
105
+ omit
106
+ end
107
+ unless RUBY_VERSION.start_with?("4")
108
+ omit
109
+ end
110
+ s = random_data
111
+ i = Ractor.new(s) do |s|
112
+ Snappy.deflate(s)
113
+ end.value
114
+ j = Ractor.new(i) do |i|
115
+ Snappy.inflate(i)
116
+ end.value
117
+ assert_equal s, j
93
118
  end
94
119
  end
95
120
  end
@@ -0,0 +1,211 @@
1
+ # Copyright 2023 Google Inc. All Rights Reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are
5
+ # met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above
10
+ # copyright notice, this list of conditions and the following disclaimer
11
+ # in the documentation and/or other materials provided with the
12
+ # distribution.
13
+ # * Neither the name of Google Inc. nor the names of its
14
+ # contributors may be used to endorse or promote products derived from
15
+ # this software without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ package(default_visibility = ["//visibility:public"])
30
+
31
+ licenses(["notice"])
32
+
33
+ SNAPPY_VERSION = (1, 2, 2)
34
+
35
+ config_setting(
36
+ name = "windows",
37
+ constraint_values = ["@platforms//os:windows"],
38
+ )
39
+
40
+ cc_library(
41
+ name = "config",
42
+ hdrs = ["config.h"],
43
+ defines = ["HAVE_CONFIG_H"],
44
+ )
45
+
46
+ cc_library(
47
+ name = "snappy-stubs-public",
48
+ hdrs = [":snappy-stubs-public.h"],
49
+ )
50
+
51
+ cc_library(
52
+ name = "snappy-stubs-internal",
53
+ srcs = ["snappy-stubs-internal.cc"],
54
+ hdrs = ["snappy-stubs-internal.h"],
55
+ deps = [
56
+ ":config",
57
+ ":snappy-stubs-public",
58
+ ],
59
+ )
60
+
61
+ cc_library(
62
+ name = "snappy",
63
+ srcs = [
64
+ "snappy.cc",
65
+ "snappy-internal.h",
66
+ "snappy-sinksource.cc",
67
+ ],
68
+ hdrs = [
69
+ "snappy.h",
70
+ "snappy-sinksource.h",
71
+ ],
72
+ copts = select({
73
+ ":windows": [],
74
+ "//conditions:default": [
75
+ "-Wno-sign-compare",
76
+ ],
77
+ }),
78
+ deps = [
79
+ ":config",
80
+ ":snappy-stubs-internal",
81
+ ":snappy-stubs-public",
82
+ ],
83
+ )
84
+
85
+ cc_library(
86
+ name = "snappy-c",
87
+ srcs = ["snappy-c.cc"],
88
+ hdrs = ["snappy-c.h"],
89
+ deps = [":snappy"],
90
+ )
91
+
92
+ filegroup(
93
+ name = "testdata",
94
+ srcs = glob(["testdata/*"]),
95
+ )
96
+
97
+ cc_library(
98
+ name = "snappy-test",
99
+ testonly = True,
100
+ srcs = [
101
+ "snappy-test.cc",
102
+ "snappy_test_data.cc",
103
+ ],
104
+ hdrs = [
105
+ "snappy-test.h",
106
+ "snappy_test_data.h",
107
+ ],
108
+ deps = [":snappy-stubs-internal"],
109
+ )
110
+
111
+ cc_test(
112
+ name = "snappy_benchmark",
113
+ srcs = ["snappy_benchmark.cc"],
114
+ data = [":testdata"],
115
+ deps = [
116
+ ":snappy",
117
+ ":snappy-test",
118
+ "@com_google_benchmark//:benchmark_main",
119
+ ],
120
+ )
121
+
122
+ cc_test(
123
+ name = "snappy_unittest",
124
+ srcs = [
125
+ "snappy_unittest.cc",
126
+ ],
127
+ data = [":testdata"],
128
+ deps = [
129
+ ":snappy",
130
+ ":snappy-test",
131
+ "@com_google_googletest//:gtest_main",
132
+ ],
133
+ )
134
+
135
+ # Generate a config.h similar to what cmake would produce.
136
+ genrule(
137
+ name = "config_h",
138
+ outs = ["config.h"],
139
+ cmd = """cat <<EOF >$@
140
+ #define HAVE_STDDEF_H 1
141
+ #define HAVE_STDINT_H 1
142
+ #ifdef __has_builtin
143
+ # if !defined(HAVE_BUILTIN_EXPECT) && __has_builtin(__builtin_expect)
144
+ # define HAVE_BUILTIN_EXPECT 1
145
+ # endif
146
+ # if !defined(HAVE_BUILTIN_CTZ) && __has_builtin(__builtin_ctzll)
147
+ # define HAVE_BUILTIN_CTZ 1
148
+ # endif
149
+ # if !defined(HAVE_BUILTIN_PREFETCH) && __has_builtin(__builtin_prefetech)
150
+ # define HAVE_BUILTIN_PREFETCH 1
151
+ # endif
152
+ #elif defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
153
+ # ifndef HAVE_BUILTIN_EXPECT
154
+ # define HAVE_BUILTIN_EXPECT 1
155
+ # endif
156
+ # ifndef HAVE_BUILTIN_CTZ
157
+ # define HAVE_BUILTIN_CTZ 1
158
+ # endif
159
+ # ifndef HAVE_BUILTIN_PREFETCH
160
+ # define HAVE_BUILTIN_PREFETCH 1
161
+ # endif
162
+ #endif
163
+
164
+ #if defined(_WIN32) && !defined(HAVE_WINDOWS_H)
165
+ #define HAVE_WINDOWS_H 1
166
+ #endif
167
+
168
+ #ifdef __has_include
169
+ # if !defined(HAVE_BYTESWAP_H) && __has_include(<byteswap.h>)
170
+ # define HAVE_BYTESWAP_H 1
171
+ # endif
172
+ # if !defined(HAVE_UNISTD_H) && __has_include(<unistd.h>)
173
+ # define HAVE_UNISTD_H 1
174
+ # endif
175
+ # if !defined(HAVE_SYS_ENDIAN_H) && __has_include(<sys/endian.h>)
176
+ # define HAVE_SYS_ENDIAN_H 1
177
+ # endif
178
+ # if !defined(HAVE_SYS_MMAN_H) && __has_include(<sys/mman.h>)
179
+ # define HAVE_SYS_MMAN_H 1
180
+ # endif
181
+ # if !defined(HAVE_SYS_UIO_H) && __has_include(<sys/uio.h>)
182
+ # define HAVE_SYS_UIO_H 1
183
+ # endif
184
+ # if !defined(HAVE_SYS_TIME_H) && __has_include(<sys/time.h>)
185
+ # define HAVE_SYS_TIME_H 1
186
+ # endif
187
+ #endif
188
+
189
+ #ifndef SNAPPY_IS_BIG_ENDIAN
190
+ # ifdef __s390x__
191
+ # define SNAPPY_IS_BIG_ENDIAN 1
192
+ # elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
193
+ # define SNAPPY_IS_BIG_ENDIAN 1
194
+ # endif
195
+ #endif
196
+ EOF
197
+ """,
198
+ )
199
+
200
+ genrule(
201
+ name = "snappy_stubs_public_h",
202
+ srcs = ["snappy-stubs-public.h.in"],
203
+ outs = ["snappy-stubs-public.h"],
204
+ # Assume sys/uio.h is available on non-Windows.
205
+ # Set the version numbers.
206
+ cmd = ("""sed -e 's/$${HAVE_SYS_UIO_H_01}/!_WIN32/g' \
207
+ -e 's/$${PROJECT_VERSION_MAJOR}/%d/g' \
208
+ -e 's/$${PROJECT_VERSION_MINOR}/%d/g' \
209
+ -e 's/$${PROJECT_VERSION_PATCH}/%d/g' \
210
+ $< >$@""" % SNAPPY_VERSION),
211
+ )