snappy 0.5.1-java → 0.5.2-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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3c13bc6b72ceae5f5dcb06879dff05d6578ba1d49b958004f67d1f718a8b2fe
4
- data.tar.gz: de0b570cae46150d338f2930cd712f7fb09f6449a17cf7a60bb51fdaac9f83d9
3
+ metadata.gz: ae5b7ee86b107cc63c631dd7f5bd8f6c3c1b529b9f1a6711a1a9bb77f62e3cce
4
+ data.tar.gz: 24520d57dedb0ecba6811fc91829edcfbed06c4acafbf047d11b5c59e9b0c068
5
5
  SHA512:
6
- metadata.gz: 96a873bc0a17c8b3a591286092d4ff2882ee542dedb062fe29695bd02036c961c9b8fc4b82623fc9e9ba9ebd9798e57a815ad86fa671b24fd0e2e28a1029e042
7
- data.tar.gz: 251a267ed244d386a2ffdf4c710648aa6ef6950a44d0f5ab48365f34c7881e8aa85e101be91ec81e39857688ddd11fc5ba389d894545715fdbfbfec1916f6134
6
+ metadata.gz: e9dc63637f9c75a90a199a6ab364964337a1383ceea72c4d5bcdbb9dd6a05aab3da96bfae440b52d9c6164b14cd84e5a92b8f77a5258d6a5e7166b4578a6caeb
7
+ data.tar.gz: 7582e5bffc506c2789d689bb1f06773dab8d84489720822e20c61a15c9f4d02bd3833857e243339b5d9105e459c5b8a3e17a573ea51f98eeef5d30aa55d1fd54
data/ext/api.c CHANGED
@@ -1,6 +1,8 @@
1
1
  #include "ruby.h"
2
2
  #include "snappy-c.h"
3
3
 
4
+ #define SNAPPY_MAX_EXPANSION 22
5
+
4
6
  static VALUE rb_eSnappy;
5
7
 
6
8
  static VALUE
@@ -59,6 +61,13 @@ snappy_inflate(int argc, VALUE *argv, VALUE self)
59
61
  return snappy_raise(result);
60
62
  }
61
63
 
64
+ /* The header is untrusted. No element expands by more than 64/3
65
+ * (a 3-byte copy of 64 bytes), so a larger claim cannot be valid and
66
+ * must not decide the allocation size. */
67
+ if (output_length / SNAPPY_MAX_EXPANSION > (size_t)RSTRING_LEN(src)) {
68
+ return snappy_raise(SNAPPY_INVALID_INPUT);
69
+ }
70
+
62
71
  if (NIL_P(dst)) {
63
72
  dst = rb_str_new(NULL, output_length);
64
73
  } else {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snappy
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  end
data/lib/snappy_ext.jar CHANGED
Binary file
data/snappy.gemspec CHANGED
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.files = `git ls-files -z`.split("\x0")
22
22
  spec.files -= spec.test_files
23
23
  spec.files -= ["vendor/snappy"]
24
- spec.files += Dir["vendor/snappy/**/*"].reject { |e| e.start_with? "vendor/snappy/testdata" }
24
+ # third_party is only for snappy's own tests/benchmarks, and build is cmake output left by extconf.rb
25
+ spec.files += Dir["vendor/snappy/**/*"].reject { |e| e.start_with?(*%w[testdata third_party build].map { |d| "vendor/snappy/#{d}" }) }
25
26
 
26
27
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
28
  spec.require_paths = ["lib"]
data/test/snappy_test.rb CHANGED
@@ -59,6 +59,23 @@ class SnappyTest < Test::Unit::TestCase
59
59
  r = Snappy.inflate(s, d)
60
60
  assert_equal r.object_id, d.object_id
61
61
  end
62
+
63
+ test "reject a header that claims more than the input can expand to" do
64
+ if defined? JRUBY_VERSION
65
+ notify "cannot pass buffer in jruby"
66
+ omit
67
+ end
68
+ # varint header claiming 0xFFFFFFFF bytes, with no elements behind it
69
+ s = "\xFF\xFF\xFF\xFF\x0F".b
70
+ d = +""
71
+ assert_raise(Snappy::Error) { Snappy.inflate(s, d) }
72
+ assert_equal 0, d.bytesize
73
+ end
74
+
75
+ test "inflate data compressed at the maximum ratio" do
76
+ s = "\0" * (1024 * 1024)
77
+ assert_equal s, Snappy.inflate(Snappy.deflate(s))
78
+ end
62
79
  end
63
80
 
64
81
  sub_test_case ".valid?" do
@@ -26,11 +26,21 @@
26
26
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
27
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
 
29
+ load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
30
+ load("@bazel_skylib//rules:write_file.bzl", "write_file")
31
+ load("@rules_cc//cc:cc_library.bzl", "cc_library")
32
+ load("@rules_cc//cc:cc_test.bzl", "cc_test")
33
+
29
34
  package(default_visibility = ["//visibility:public"])
30
35
 
31
36
  licenses(["notice"])
32
37
 
33
- SNAPPY_VERSION = (1, 2, 2)
38
+ exports_files([
39
+ "COPYING",
40
+ "COPYING.notestdata",
41
+ ])
42
+
43
+ SNAPPY_VERSION = (1, 3, 1)
34
44
 
35
45
  config_setting(
36
46
  name = "windows",
@@ -52,8 +62,10 @@ cc_library(
52
62
  name = "snappy-stubs-internal",
53
63
  srcs = ["snappy-stubs-internal.cc"],
54
64
  hdrs = ["snappy-stubs-internal.h"],
55
- deps = [
65
+ implementation_deps = [
56
66
  ":config",
67
+ ],
68
+ deps = [
57
69
  ":snappy-stubs-public",
58
70
  ],
59
71
  )
@@ -75,8 +87,10 @@ cc_library(
75
87
  "-Wno-sign-compare",
76
88
  ],
77
89
  }),
78
- deps = [
90
+ implementation_deps = [
79
91
  ":config",
92
+ ],
93
+ deps = [
80
94
  ":snappy-stubs-internal",
81
95
  ":snappy-stubs-public",
82
96
  ],
@@ -133,10 +147,10 @@ cc_test(
133
147
  )
134
148
 
135
149
  # Generate a config.h similar to what cmake would produce.
136
- genrule(
150
+ write_file(
137
151
  name = "config_h",
138
- outs = ["config.h"],
139
- cmd = """cat <<EOF >$@
152
+ out = "config.h",
153
+ content = """\
140
154
  #define HAVE_STDDEF_H 1
141
155
  #define HAVE_STDINT_H 1
142
156
  #ifdef __has_builtin
@@ -193,19 +207,17 @@ genrule(
193
207
  # define SNAPPY_IS_BIG_ENDIAN 1
194
208
  # endif
195
209
  #endif
196
- EOF
197
- """,
210
+ """.splitlines(),
198
211
  )
199
212
 
200
- genrule(
213
+ expand_template(
201
214
  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),
215
+ out = "snappy-stubs-public.h",
216
+ substitutions = {
217
+ "${HAVE_SYS_UIO_H_01}": "!_WIN32",
218
+ "${PROJECT_VERSION_MAJOR}": str(SNAPPY_VERSION[0]),
219
+ "${PROJECT_VERSION_MINOR}": str(SNAPPY_VERSION[1]),
220
+ "${PROJECT_VERSION_PATCH}": str(SNAPPY_VERSION[2]),
221
+ },
222
+ template = "snappy-stubs-public.h.in",
211
223
  )
@@ -27,7 +27,12 @@
27
27
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
 
29
29
  cmake_minimum_required(VERSION 3.10)
30
- project(Snappy VERSION 1.2.2 LANGUAGES C CXX)
30
+
31
+ if(POLICY CMP0091)
32
+ cmake_policy(SET CMP0091 NEW)
33
+ endif()
34
+
35
+ project(Snappy VERSION 1.3.1 LANGUAGES C CXX)
31
36
 
32
37
  # C++ standard can be overridden when this is used as a sub-project.
33
38
  if(NOT CMAKE_CXX_STANDARD)
@@ -55,6 +60,21 @@ if(MSVC)
55
60
  # Disable RTTI.
56
61
  string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
57
62
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
63
+
64
+ # Support static MSVC runtime when building static library.
65
+ option(SNAPPY_MSVC_STATIC_RUNTIME "Link to static MSVC runtime (/MT or /MTd)" OFF)
66
+ if(SNAPPY_MSVC_STATIC_RUNTIME)
67
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
68
+ foreach(flag_var
69
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
70
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
71
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
72
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
73
+ if(${flag_var} MATCHES "/MD")
74
+ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
75
+ endif()
76
+ endforeach()
77
+ endif()
58
78
  else(MSVC)
59
79
  # Use -Wall for clang and gcc.
60
80
  if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
@@ -155,10 +175,20 @@ int main() {
155
175
  return __builtin_expect(0, 1);
156
176
  }" HAVE_BUILTIN_EXPECT)
157
177
 
178
+ # Check if the built-in __builtin_ctz (count trailing zeros) is available.
179
+ # Require either a non-RISC-V target, or a RISC-V core that implements
180
+ # the Zbb bit-manipulation extension where ctz is guaranteed.
158
181
  check_cxx_source_compiles("
159
- int main() {
160
- return __builtin_ctzll(0);
161
- }" HAVE_BUILTIN_CTZ)
182
+ #ifdef __riscv
183
+ #ifdef __riscv_zbb
184
+ int main() { return __builtin_ctzll(0); }
185
+ #else
186
+ #error \"ZBB not enabled in current config\"
187
+ #endif
188
+ #else
189
+ int main() { return __builtin_ctzll(0); }
190
+ #endif
191
+ " HAVE_BUILTIN_CTZ)
162
192
 
163
193
  check_cxx_source_compiles("
164
194
  int main() {
@@ -216,6 +246,31 @@ int main() {
216
246
  return 0;
217
247
  }" SNAPPY_HAVE_NEON)
218
248
 
249
+ #check RVV 1.0 need __riscv_ prefix
250
+ check_cxx_source_compiles("
251
+ #include <riscv_vector.h>
252
+ #include <stdint.h>
253
+ #include <stddef.h>
254
+ int main() {
255
+ uint8_t val = 3, dup[8];
256
+ size_t vl = __riscv_vsetvl_e8m1(8);
257
+ vuint8m1_t v = __riscv_vmv_v_x_u8m1(val, vl);
258
+ return 0;
259
+ }" SNAPPY_RVV_1)
260
+
261
+
262
+ #check RVV 0.7.1 not __riscv_ prefix
263
+ check_cxx_source_compiles("
264
+ #include <riscv_vector.h>
265
+ #include <stdint.h>
266
+ #include <stddef.h>
267
+ int main() {
268
+ uint8_t val = 3, dup[8];
269
+ size_t vl = vsetvl_e8m1(8);
270
+ vuint8m1_t v = vmv_v_x_u8m1(val, vl);
271
+ return 0;
272
+ }" SNAPPY_RVV_0_7)
273
+
219
274
  include(CheckSymbolExists)
220
275
  check_symbol_exists("mmap" "sys/mman.h" HAVE_FUNC_MMAP)
221
276
  check_symbol_exists("sysconf" "unistd.h" HAVE_FUNC_SYSCONF)
@@ -251,6 +306,9 @@ configure_file(
251
306
  "snappy-stubs-public.h.in"
252
307
  "${PROJECT_BINARY_DIR}/snappy-stubs-public.h")
253
308
 
309
+ # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
310
+ include(GNUInstallDirs)
311
+
254
312
  add_library(snappy "")
255
313
  target_sources(snappy
256
314
  PRIVATE
@@ -263,19 +321,19 @@ target_sources(snappy
263
321
  "${PROJECT_BINARY_DIR}/config.h"
264
322
  PUBLIC
265
323
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-c.h>
266
- $<INSTALL_INTERFACE:include/snappy-c.h>
324
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/snappy-c.h>
267
325
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy-sinksource.h>
268
- $<INSTALL_INTERFACE:include/snappy-sinksource.h>
326
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/snappy-sinksource.h>
269
327
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/snappy.h>
270
- $<INSTALL_INTERFACE:include/snappy.h>
328
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/snappy.h>
271
329
  $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/snappy-stubs-public.h>
272
- $<INSTALL_INTERFACE:include/snappy-stubs-public.h>
330
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/snappy-stubs-public.h>
273
331
  )
274
332
  target_include_directories(snappy
275
333
  PUBLIC
276
334
  $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
277
335
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
278
- $<INSTALL_INTERFACE:include>
336
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
279
337
  )
280
338
  set_target_properties(snappy
281
339
  PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
@@ -399,9 +457,6 @@ if(SNAPPY_FUZZING_BUILD)
399
457
  )
400
458
  endif(SNAPPY_FUZZING_BUILD)
401
459
 
402
- # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
403
- include(GNUInstallDirs)
404
-
405
460
  if(SNAPPY_INSTALL)
406
461
  install(TARGETS snappy
407
462
  EXPORT SnappyTargets
@@ -0,0 +1,28 @@
1
+ Copyright 2011, Google Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above
11
+ copyright notice, this list of conditions and the following disclaimer
12
+ in the documentation and/or other materials provided with the
13
+ distribution.
14
+ * Neither the name of Google Inc. nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,23 +1,26 @@
1
1
  module(
2
2
  name = "snappy",
3
- version = "1.2.2",
3
+ version = "1.3.1",
4
4
  compatibility_level = 1,
5
5
  )
6
6
 
7
+ bazel_dep(name = "rules_cc", version = "0.2.4")
8
+ bazel_dep(name = "bazel_skylib", version = "1.8.2")
9
+
7
10
  bazel_dep(
8
11
  name = "googletest",
9
- version = "1.14.0.bcr.1",
12
+ version = "1.17.0.bcr.2",
10
13
  dev_dependency = True,
11
14
  repo_name = "com_google_googletest",
12
15
  )
13
16
  bazel_dep(
14
17
  name = "google_benchmark",
15
- version = "1.9.0",
18
+ version = "1.9.5",
16
19
  dev_dependency = True,
17
20
  repo_name = "com_google_benchmark",
18
21
  )
19
22
 
20
23
  bazel_dep(
21
24
  name = "platforms",
22
- version = "0.0.9",
25
+ version = "1.0.0",
23
26
  )
data/vendor/snappy/NEWS CHANGED
@@ -1,3 +1,15 @@
1
+ Snappy v1.3.1, Sep 18th 2026:
2
+
3
+ * Fixed a uint32_t overflow when decompressor accepted an input with incorrect format
4
+
5
+ * Significant RISC-V efficiency improvements
6
+
7
+ * New API on providing your own memory context
8
+
9
+ * Supporting compression levels (1-2) in C API
10
+
11
+ * Various other small fixes
12
+
1
13
  Snappy v1.2.2, Mar 26th 2025:
2
14
 
3
15
  * We added a new compression level in v1.2.1 which compresses a bit
@@ -75,6 +75,10 @@ mkdir build
75
75
  cd build && cmake ../ && make
76
76
  ```
77
77
 
78
+ MSVC users must manually set `SNAPPY_HAVE_SSSE3`, `SNAPPY_HAVE_X86_CRC32`,
79
+ `SNAPPY_HAVE_BMI2`, `SNAPPY_HAVE_NEON_CRC32`, and `SNAPPY_HAVE_NEON` due to
80
+ MSVC's incorrect architecture detection, if using pre-`/arch:AVX2`.
81
+
78
82
  Usage
79
83
  =====
80
84
 
@@ -140,10 +144,10 @@ explicitly supports the following:
140
144
  1. C++11
141
145
  2. Clang (gcc and MSVC are best-effort).
142
146
  3. Low level optimizations (e.g. assembly or equivalent intrinsics) for:
143
- - [x86](https://en.wikipedia.org/wiki/X86)
144
- - [x86-64](https://en.wikipedia.org/wiki/X86-64)
145
- - ARMv7 (32-bit)
146
- - ARMv8 (AArch64)
147
+ - [x86](https://en.wikipedia.org/wiki/X86)
148
+ - [x86-64](https://en.wikipedia.org/wiki/X86-64)
149
+ - ARMv7 (32-bit)
150
+ - ARMv8 (AArch64)
147
151
  4. Supports only the Snappy compression scheme as described in
148
152
  [format_description.txt](format_description.txt).
149
153
  5. CMake for building
@@ -58,6 +58,12 @@
58
58
  /* Define to 1 if you target processors with NEON and have <arm_neon.h>. */
59
59
  #cmakedefine01 SNAPPY_HAVE_NEON
60
60
 
61
+ /* Define to 1 if you target processors with RVV1.0 and have <riscv_vector.h>. */
62
+ #cmakedefine01 SNAPPY_RVV_1
63
+
64
+ /* Define to 1 if you target processors with RVV0.7 and have <riscv_vector.h>. */
65
+ #cmakedefine01 SNAPPY_RVV_0_7
66
+
61
67
  /* Define to 1 if you have <arm_neon.h> and <arm_acle.h> and want to optimize
62
68
  compression speed by using __crc32cw from <arm_acle.h>. */
63
69
  #cmakedefine01 SNAPPY_HAVE_NEON_CRC32
@@ -22,7 +22,8 @@ stored as a little-endian varint. Varints consist of a series of bytes,
22
22
  where the lower 7 bits are data and the upper bit is set iff there are
23
23
  more bytes to be read. In other words, an uncompressed length of 64 would
24
24
  be stored as 0x40, and an uncompressed length of 2097150 (0x1FFFFE)
25
- would be stored as 0xFE 0xFF 0x7F.
25
+ would be stored as 0xFE 0xFF 0x7F. Given the maximum, 5 bytes are sufficient for
26
+ any value.
26
27
 
27
28
 
28
29
  2. The compressed stream itself
@@ -39,6 +39,28 @@ snappy_status snappy_compress(const char* input,
39
39
  return SNAPPY_BUFFER_TOO_SMALL;
40
40
  }
41
41
  snappy::RawCompress(input, input_length, compressed, compressed_length);
42
+ if (*compressed_length == 0) {
43
+ return SNAPPY_INVALID_INPUT;
44
+ }
45
+ return SNAPPY_OK;
46
+ }
47
+
48
+ snappy_status snappy_compress_with_level(const char* input, size_t input_length,
49
+ int compression_level,
50
+ char* compressed,
51
+ size_t* compressed_length) {
52
+ if (*compressed_length < snappy_max_compressed_length(input_length)) {
53
+ return SNAPPY_BUFFER_TOO_SMALL;
54
+ }
55
+ if (compression_level < SNAPPY_MIN_COMPRESSION_LEVEL ||
56
+ compression_level > SNAPPY_MAX_COMPRESSION_LEVEL) {
57
+ return SNAPPY_INVALID_INPUT;
58
+ }
59
+ snappy::RawCompress(input, input_length, compressed, compressed_length,
60
+ snappy::CompressionOptions{/*level=*/compression_level});
61
+ if (*compressed_length == 0) {
62
+ return SNAPPY_INVALID_INPUT;
63
+ }
42
64
  return SNAPPY_OK;
43
65
  }
44
66
 
@@ -57,7 +57,11 @@ typedef enum {
57
57
  * If it is not at least equal to "snappy_max_compressed_length(input_length)",
58
58
  * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression,
59
59
  * <compressed_length> contains the true length of the compressed output,
60
- * and SNAPPY_OK is returned.
60
+ * and SNAPPY_OK is returned. Compression level is 1. For using other
61
+ * compression levels, call snappy_compress_with_level.
62
+ *
63
+ * An <input_length> of 2^32 or more returns SNAPPY_INVALID_INPUT with
64
+ * <compressed_length> set to 0 and nothing written.
61
65
  *
62
66
  * Example:
63
67
  * size_t output_length = snappy_max_compressed_length(input_length);
@@ -68,10 +72,20 @@ typedef enum {
68
72
  * }
69
73
  * free(output);
70
74
  */
71
- snappy_status snappy_compress(const char* input,
72
- size_t input_length,
73
- char* compressed,
74
- size_t* compressed_length);
75
+ snappy_status snappy_compress(const char* input, size_t input_length,
76
+ char* compressed, size_t* compressed_length);
77
+
78
+ /*
79
+ * Same as above but uses compression_level which must be between
80
+ * SNAPPY_MIN_COMPRESSION_LEVEL and SNAPPY_MAX_COMPRESSION_LEVEL.
81
+ */
82
+ #define SNAPPY_MIN_COMPRESSION_LEVEL 1
83
+ #define SNAPPY_MAX_COMPRESSION_LEVEL 2
84
+
85
+ snappy_status snappy_compress_with_level(const char* input, size_t input_length,
86
+ int compression_level,
87
+ char* compressed,
88
+ size_t* compressed_length);
75
89
 
76
90
  /*
77
91
  * Given data in "compressed[0..compressed_length-1]" generated by
@@ -46,6 +46,19 @@
46
46
  #include <arm_neon.h>
47
47
  #endif
48
48
 
49
+ #if SNAPPY_RVV_1 || SNAPPY_RVV_0_7
50
+ #define SNAPPY_HAVE_RVV 1
51
+ #include <riscv_vector.h>
52
+ #else
53
+ #define SNAPPY_HAVE_RVV 0
54
+ #endif
55
+
56
+ #if SNAPPY_RVV_1 || SNAPPY_RVV_0_7
57
+ #define VSETVL_E8M2 __riscv_vsetvl_e8m2
58
+ #define VLE8_V_U8M2 __riscv_vle8_v_u8m2
59
+ #define VSE8_V_U8M2 __riscv_vse8_v_u8m2
60
+ #endif
61
+
49
62
  #if SNAPPY_HAVE_SSSE3 || SNAPPY_HAVE_NEON
50
63
  #define SNAPPY_HAVE_VECTOR_BYTE_SHUFFLE 1
51
64
  #else
@@ -110,6 +123,8 @@ inline V128 V128_Shuffle(V128 input, V128 shuffle_mask) {
110
123
  }
111
124
 
112
125
  inline V128 V128_DupChar(char c) { return vdupq_n_u8(c); }
126
+
127
+
113
128
  #endif
114
129
  #endif // SNAPPY_HAVE_VECTOR_BYTE_SHUFFLE
115
130
 
@@ -118,8 +133,16 @@ inline V128 V128_DupChar(char c) { return vdupq_n_u8(c); }
118
133
  class WorkingMemory {
119
134
  public:
120
135
  explicit WorkingMemory(size_t input_size);
136
+
137
+ // Non-allocating: lays out the scratch space in the caller-provided
138
+ // buffer, which must be at least RequiredSize(input_size) bytes, aligned
139
+ // at least as strictly as uint16_t, and must outlive "*this".
140
+ WorkingMemory(size_t input_size, char* buffer);
121
141
  ~WorkingMemory();
122
142
 
143
+ // The buffer size required by the non-allocating constructor above.
144
+ static size_t RequiredSize(size_t input_size);
145
+
123
146
  // Allocates and clears a hash table using memory in "*this",
124
147
  // stores the number of buckets in "*table_size" and returns a pointer to
125
148
  // the base of the hash table.
@@ -130,6 +153,7 @@ class WorkingMemory {
130
153
  private:
131
154
  char* mem_; // the allocated memory, never nullptr
132
155
  size_t size_; // the size of the allocated memory, never 0
156
+ bool owns_mem_;
133
157
  uint16_t* table_; // the pointer to the hashtable
134
158
  char* input_; // the pointer to the input scratch buffer
135
159
  char* output_; // the pointer to the output scratch buffer
@@ -172,9 +196,10 @@ char* CompressFragment(const char* input,
172
196
  // loading from s2 + n.
173
197
  //
174
198
  // Separate implementation for 64-bit, little-endian cpus.
199
+ // riscv and little-endian cpu choose this routinue can be done faster too.
175
200
  #if !SNAPPY_IS_BIG_ENDIAN && \
176
201
  (defined(__x86_64__) || defined(_M_X64) || defined(ARCH_PPC) || \
177
- defined(ARCH_ARM))
202
+ defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64)))
178
203
  static inline std::pair<size_t, bool> FindMatchLength(const char* s1,
179
204
  const char* s2,
180
205
  const char* s2_limit,
@@ -304,6 +304,7 @@ class Bits {
304
304
  void operator=(const Bits&);
305
305
  };
306
306
 
307
+ // In RISC-V, CLZ is supported by instructions from the ZBB bit-manipulation extension.
307
308
  #if HAVE_BUILTIN_CTZ
308
309
 
309
310
  inline int Bits::Log2FloorNonZero(uint32_t n) {
@@ -393,6 +394,7 @@ inline int Bits::FindLSBSetNonZero(uint32_t n) {
393
394
 
394
395
  #endif // End portable versions.
395
396
 
397
+ // In RISC-V, CLZ is supported by instructions from the ZBB bit-manipulation extension.
396
398
  #if HAVE_BUILTIN_CTZ
397
399
 
398
400
  inline int Bits::FindLSBSetNonZero64(uint64_t n) {
@@ -464,7 +464,8 @@ bool ZLib::UncompressChunkDone() {
464
464
  // Make sure we're at the end-of-compressed-data point. This means
465
465
  // if we call inflate with Z_FINISH we won't consume any input or
466
466
  // write any output
467
- Bytef dummyin, dummyout;
467
+ Bytef dummyout;
468
+ Bytef dummyin = 0;
468
469
  uLongf dummylen = 0;
469
470
  if ( UncompressChunkOrAll(&dummyout, &dummylen, &dummyin, 0, Z_FINISH)
470
471
  != Z_OK ) {