zrip 0.2.1 → 0.2.2
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 +4 -4
- data/CHANGELOG.md +17 -0
- data/Cargo.lock +22 -22
- data/ext/zrip/Cargo.toml +2 -2
- data/ext/zrip/src/lib.rs +33 -18
- data/ext/zrip/src/rb.rs +29 -21
- data/lib/zrip/block_codec.rb +7 -7
- data/lib/zrip/dict_trainer.rb +5 -3
- data/lib/zrip/frame_codec.rb +2 -2
- data/lib/zrip/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76111539af262f323eed635879fede0335f1ee43d0dad1fd1e133545c1196a37
|
|
4
|
+
data.tar.gz: '0650794dae17a3623f7be98c836439c946d0cafc69f5574f957f98405c4a5a8b'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f8e3cd002522f48aaf0644892fb7ced4fc595655d063d5766fa29909224249d53cc41bd7c66ff7ba3218a99d1b898ba9ede80bedf1a0873d7fb82fa8f333644
|
|
7
|
+
data.tar.gz: 7efb3e5cd0eb47480597c456d7da7e12803d6eed17e5135956434fbbf5223d154742c7133326ba39bef27c5ee36110807d400a889ae98d8326a6af22996ec81f
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.2] - 2026-11-26
|
|
6
|
+
|
|
7
|
+
- Update the `zrip` crate dependency to 0.8.29. Levels are retuned, so
|
|
8
|
+
compressed output differs from 0.2.1, and decoding rejects the frames C
|
|
9
|
+
zstd 1.6.0 rejects.
|
|
10
|
+
- `DictTrainer#train` fills `max_dict_size`. Dictionaries came out 110-150
|
|
11
|
+
bytes short. Sizes under 256 now count as 256, and `max_dict_size`
|
|
12
|
+
returns the size used. They gave a dictionary of padding only.
|
|
13
|
+
- Let several threads compress or decompress one mutable String at once.
|
|
14
|
+
Calls that release the GVL now borrow a frozen copy of the input instead
|
|
15
|
+
of locking it, so they no longer raise `RuntimeError` when another call
|
|
16
|
+
holds the same String, and the caller may modify it meanwhile.
|
|
17
|
+
- `max_output_size: 0` now limits output to 0 bytes. It used to disable the
|
|
18
|
+
limit. Omit it or pass `nil` for no limit.
|
|
19
|
+
- Fail on a bad first frame header without releasing the GVL.
|
|
20
|
+
- Document that `BlockCodec` writes and reads Zstandard frames.
|
|
21
|
+
|
|
5
22
|
## [0.2.1] - 2026-10-11
|
|
6
23
|
|
|
7
24
|
- Update the `zrip` crate dependency to 0.8.11 and `rb-sys` to 0.9.130.
|
data/Cargo.lock
CHANGED
|
@@ -69,9 +69,9 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
|
|
|
69
69
|
|
|
70
70
|
[[package]]
|
|
71
71
|
name = "fearless_simd"
|
|
72
|
-
version = "1.
|
|
72
|
+
version = "1.3.0"
|
|
73
73
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
-
checksum = "
|
|
74
|
+
checksum = "6a7107516a8be9a4ffe92495f3dbfe04348be0ad18f17c67a1d846511f99e599"
|
|
75
75
|
|
|
76
76
|
[[package]]
|
|
77
77
|
name = "glob"
|
|
@@ -96,9 +96,9 @@ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
|
|
|
96
96
|
|
|
97
97
|
[[package]]
|
|
98
98
|
name = "libc"
|
|
99
|
-
version = "0.2.
|
|
99
|
+
version = "0.2.191"
|
|
100
100
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
101
|
-
checksum = "
|
|
101
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
102
102
|
|
|
103
103
|
[[package]]
|
|
104
104
|
name = "libloading"
|
|
@@ -176,9 +176,9 @@ dependencies = [
|
|
|
176
176
|
|
|
177
177
|
[[package]]
|
|
178
178
|
name = "regex"
|
|
179
|
-
version = "1.13.
|
|
179
|
+
version = "1.13.2"
|
|
180
180
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
181
|
-
checksum = "
|
|
181
|
+
checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
|
|
182
182
|
dependencies = [
|
|
183
183
|
"aho-corasick",
|
|
184
184
|
"memchr",
|
|
@@ -188,9 +188,9 @@ dependencies = [
|
|
|
188
188
|
|
|
189
189
|
[[package]]
|
|
190
190
|
name = "regex-automata"
|
|
191
|
-
version = "0.4.
|
|
191
|
+
version = "0.4.19"
|
|
192
192
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
193
|
-
checksum = "
|
|
193
|
+
checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
|
|
194
194
|
dependencies = [
|
|
195
195
|
"aho-corasick",
|
|
196
196
|
"memchr",
|
|
@@ -199,9 +199,9 @@ dependencies = [
|
|
|
199
199
|
|
|
200
200
|
[[package]]
|
|
201
201
|
name = "regex-syntax"
|
|
202
|
-
version = "0.8.
|
|
202
|
+
version = "0.8.12"
|
|
203
203
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
204
|
-
checksum = "
|
|
204
|
+
checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
|
|
205
205
|
|
|
206
206
|
[[package]]
|
|
207
207
|
name = "rustc-hash"
|
|
@@ -234,9 +234,9 @@ dependencies = [
|
|
|
234
234
|
|
|
235
235
|
[[package]]
|
|
236
236
|
name = "unicode-ident"
|
|
237
|
-
version = "1.0.
|
|
237
|
+
version = "1.0.27"
|
|
238
238
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
239
|
-
checksum = "
|
|
239
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
240
240
|
|
|
241
241
|
[[package]]
|
|
242
242
|
name = "windows-link"
|
|
@@ -246,17 +246,17 @@ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
|
246
246
|
|
|
247
247
|
[[package]]
|
|
248
248
|
name = "zrip"
|
|
249
|
-
version = "0.2.
|
|
249
|
+
version = "0.2.2"
|
|
250
250
|
dependencies = [
|
|
251
251
|
"rb-sys",
|
|
252
|
-
"zrip 0.8.
|
|
252
|
+
"zrip 0.8.29",
|
|
253
253
|
]
|
|
254
254
|
|
|
255
255
|
[[package]]
|
|
256
256
|
name = "zrip"
|
|
257
|
-
version = "0.8.
|
|
257
|
+
version = "0.8.29"
|
|
258
258
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
-
checksum = "
|
|
259
|
+
checksum = "d886ee8c071aed87a037634815bf1b77d66ec90e02122bc031166f4b218bb291"
|
|
260
260
|
dependencies = [
|
|
261
261
|
"zrip-core",
|
|
262
262
|
"zrip-decode",
|
|
@@ -265,15 +265,15 @@ dependencies = [
|
|
|
265
265
|
|
|
266
266
|
[[package]]
|
|
267
267
|
name = "zrip-core"
|
|
268
|
-
version = "0.
|
|
268
|
+
version = "0.14.4"
|
|
269
269
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
270
|
-
checksum = "
|
|
270
|
+
checksum = "5f6ea7ccd7799d815353fb360e6d2d21207001d58f0a7c02ec9e45d95fe60ae4"
|
|
271
271
|
|
|
272
272
|
[[package]]
|
|
273
273
|
name = "zrip-decode"
|
|
274
|
-
version = "0.8.
|
|
274
|
+
version = "0.8.22"
|
|
275
275
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
276
|
-
checksum = "
|
|
276
|
+
checksum = "89ced3ea49c7e49b32b675294304987c3481f2f7b19f3c60ff6b1e4b73eb2ffd"
|
|
277
277
|
dependencies = [
|
|
278
278
|
"fearless_simd",
|
|
279
279
|
"zrip-core",
|
|
@@ -281,9 +281,9 @@ dependencies = [
|
|
|
281
281
|
|
|
282
282
|
[[package]]
|
|
283
283
|
name = "zrip-encode"
|
|
284
|
-
version = "0.
|
|
284
|
+
version = "0.10.6"
|
|
285
285
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
286
|
-
checksum = "
|
|
286
|
+
checksum = "26cf89a0e00fb1e421a0e1b911cdf593178affc2cbcffae62b6dea25089e6fca"
|
|
287
287
|
dependencies = [
|
|
288
288
|
"fearless_simd",
|
|
289
289
|
"zrip-core",
|
data/ext/zrip/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "zrip"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
build = "build.rs"
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ name = "zrip"
|
|
|
9
9
|
crate-type = ["cdylib", "rlib"]
|
|
10
10
|
|
|
11
11
|
[dependencies]
|
|
12
|
-
zstd = { version = "0.8.
|
|
12
|
+
zstd = { version = "0.8.29", package = "zrip", features = ["frame", "dict_builder"] }
|
|
13
13
|
rb-sys = "0.9.130"
|
|
14
14
|
|
|
15
15
|
[build-dependencies]
|
data/ext/zrip/src/lib.rs
CHANGED
|
@@ -61,7 +61,7 @@ where
|
|
|
61
61
|
F: FnOnce(&mut T, &[u8]) -> RbResult<R>,
|
|
62
62
|
{
|
|
63
63
|
if release_gvl {
|
|
64
|
-
input.
|
|
64
|
+
input.freeze_for_without_gvl(true)?;
|
|
65
65
|
return rb::maybe_without_gvl(true, || {
|
|
66
66
|
let mut guard = mutex
|
|
67
67
|
.lock()
|
|
@@ -74,7 +74,7 @@ where
|
|
|
74
74
|
Ok(mut guard) => func(&mut guard, input.as_slice()),
|
|
75
75
|
Err(TryLockError::WouldBlock) => {
|
|
76
76
|
// Even a small input needs protection when contention releases GVL.
|
|
77
|
-
input.
|
|
77
|
+
input.freeze_for_without_gvl(true)?;
|
|
78
78
|
rb::maybe_without_gvl(true, || {
|
|
79
79
|
let mut guard = mutex
|
|
80
80
|
.lock()
|
|
@@ -108,33 +108,31 @@ fn parse_frame_content_size(input: &[u8]) -> Result<Option<u64>, BoundedError> {
|
|
|
108
108
|
|
|
109
109
|
fn decompress_bounded(
|
|
110
110
|
compressed: &[u8],
|
|
111
|
-
max_output: usize
|
|
111
|
+
max_output: Option<usize>,
|
|
112
112
|
dctx: &mut DecompressContext,
|
|
113
113
|
) -> Result<Vec<u8>, BoundedError> {
|
|
114
114
|
if compressed.len() < ZSTD_FRAME_MAGIC.len() || compressed[..4] != ZSTD_FRAME_MAGIC {
|
|
115
115
|
return Err(BoundedError::BadMagic);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
let limit =
|
|
119
|
-
usize::MAX
|
|
120
|
-
} else {
|
|
121
|
-
max_output
|
|
122
|
-
};
|
|
118
|
+
let limit = max_output.unwrap_or(usize::MAX);
|
|
123
119
|
dctx.decompress_with_limit(compressed, limit)
|
|
124
120
|
.map(|out| out.into_owned())
|
|
125
121
|
.map_err(|err| match err {
|
|
126
122
|
zstd::DecompressError::OutputTooSmall => BoundedError::OutputSizeLimit {
|
|
127
|
-
limit:
|
|
123
|
+
limit: limit as u64,
|
|
128
124
|
},
|
|
129
125
|
_ => BoundedError::DecoderFailed(err.to_string()),
|
|
130
126
|
})
|
|
131
127
|
}
|
|
132
128
|
|
|
133
|
-
fn decompress_work_size(compressed: &[u8], max_output: usize) -> usize {
|
|
129
|
+
fn decompress_work_size(compressed: &[u8], max_output: Option<usize>) -> usize {
|
|
130
|
+
let limit = max_output.unwrap_or(usize::MAX);
|
|
134
131
|
match parse_frame_content_size(compressed) {
|
|
135
|
-
Ok(Some(n)) => usize::try_from(n).unwrap_or(usize::MAX),
|
|
136
|
-
Ok(None)
|
|
137
|
-
|
|
132
|
+
Ok(Some(n)) => usize::try_from(n).unwrap_or(usize::MAX).min(limit),
|
|
133
|
+
Ok(None) => max_output.unwrap_or(compressed.len()),
|
|
134
|
+
// The decoder rejects the first frame header without decoding.
|
|
135
|
+
Err(_) => 0,
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
|
|
@@ -375,7 +373,7 @@ fn frame_codec_decompress_impl(
|
|
|
375
373
|
max_output: VALUE,
|
|
376
374
|
) -> RbResult<VALUE> {
|
|
377
375
|
let rb_self = unsafe { frame_codec_ref(rb_self)? };
|
|
378
|
-
let max_output = rb::
|
|
376
|
+
let max_output = rb::value_to_option_usize(max_output)?;
|
|
379
377
|
let mut compressed = rb::input_bytes(rb_input)?;
|
|
380
378
|
let release_gvl = should_release_frame_decompress_gvl(decompress_work_size(
|
|
381
379
|
compressed.as_slice(),
|
|
@@ -544,7 +542,7 @@ fn block_codec_decompress_impl(
|
|
|
544
542
|
max_output: VALUE,
|
|
545
543
|
) -> RbResult<VALUE> {
|
|
546
544
|
let rb_self = unsafe { block_codec_ref(rb_self)? };
|
|
547
|
-
let max_output = rb::
|
|
545
|
+
let max_output = rb::value_to_option_usize(max_output)?;
|
|
548
546
|
let mut compressed = rb::input_bytes(rb_input)?;
|
|
549
547
|
let out = with_mutex(
|
|
550
548
|
&rb_self.dctx,
|
|
@@ -620,7 +618,8 @@ struct TrainerState {
|
|
|
620
618
|
}
|
|
621
619
|
|
|
622
620
|
fn dict_trainer_new_impl(class: VALUE, max_dict_size: VALUE) -> RbResult<VALUE> {
|
|
623
|
-
|
|
621
|
+
// The trainer gives a MIN_DICT_SIZE dict for smaller sizes.
|
|
622
|
+
let max_dict_size = rb::value_to_usize(max_dict_size)?.max(zstd::dict::MIN_DICT_SIZE);
|
|
624
623
|
unsafe {
|
|
625
624
|
rb::wrap_typed_data(
|
|
626
625
|
class,
|
|
@@ -893,14 +892,30 @@ mod tests {
|
|
|
893
892
|
compressed.extend_from_slice(&zstd::compress(&[b'b'; 100], 1).unwrap());
|
|
894
893
|
|
|
895
894
|
assert!(matches!(
|
|
896
|
-
decompress_bounded(&compressed, 199, &mut dctx),
|
|
895
|
+
decompress_bounded(&compressed, Some(199), &mut dctx),
|
|
897
896
|
Err(BoundedError::OutputSizeLimit { .. })
|
|
898
897
|
));
|
|
899
898
|
assert_eq!(
|
|
900
|
-
decompress_bounded(&compressed, 200, &mut dctx)
|
|
899
|
+
decompress_bounded(&compressed, Some(200), &mut dctx)
|
|
901
900
|
.unwrap()
|
|
902
901
|
.len(),
|
|
903
902
|
200
|
|
904
903
|
);
|
|
905
904
|
}
|
|
905
|
+
|
|
906
|
+
#[test]
|
|
907
|
+
fn bounded_decompress_treats_zero_as_limit() {
|
|
908
|
+
let mut dctx = DecompressContext::new();
|
|
909
|
+
let empty = zstd::compress(b"", 1).unwrap();
|
|
910
|
+
let one = zstd::compress(b"a", 1).unwrap();
|
|
911
|
+
|
|
912
|
+
assert!(decompress_bounded(&empty, Some(0), &mut dctx)
|
|
913
|
+
.unwrap()
|
|
914
|
+
.is_empty());
|
|
915
|
+
assert!(matches!(
|
|
916
|
+
decompress_bounded(&one, Some(0), &mut dctx),
|
|
917
|
+
Err(BoundedError::OutputSizeLimit { limit: 0 })
|
|
918
|
+
));
|
|
919
|
+
assert_eq!(decompress_bounded(&one, None, &mut dctx).unwrap(), b"a");
|
|
920
|
+
}
|
|
906
921
|
}
|
data/ext/zrip/src/rb.rs
CHANGED
|
@@ -6,13 +6,6 @@ use rb_sys::{rb_data_type_t, VALUE};
|
|
|
6
6
|
|
|
7
7
|
pub type RbResult<T = VALUE> = Result<T, RubyErr>;
|
|
8
8
|
|
|
9
|
-
#[cfg(ruby_engine = "mri")]
|
|
10
|
-
unsafe extern "C" {
|
|
11
|
-
fn rb_obj_frozen_p(obj: VALUE) -> VALUE;
|
|
12
|
-
fn rb_str_locktmp(str: VALUE) -> VALUE;
|
|
13
|
-
fn rb_str_unlocktmp(str: VALUE) -> VALUE;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
9
|
#[cfg(ruby_engine = "mri")]
|
|
17
10
|
type RbWithoutGvlFunc = unsafe extern "C" fn(*mut c_void) -> *mut c_void;
|
|
18
11
|
#[cfg(ruby_engine = "mri")]
|
|
@@ -185,7 +178,7 @@ where
|
|
|
185
178
|
output: None,
|
|
186
179
|
};
|
|
187
180
|
// Ruby checks interrupts before and after the callback. Protect the call
|
|
188
|
-
// so an exception still drops native output and
|
|
181
|
+
// so an exception still drops native output and borrowed strings.
|
|
189
182
|
protect_unit(|| unsafe {
|
|
190
183
|
rb_thread_call_without_gvl(
|
|
191
184
|
Some(without_gvl_trampoline::<F, R>),
|
|
@@ -277,6 +270,14 @@ pub fn value_to_bytes(value: VALUE) -> RbResult<Vec<u8>> {
|
|
|
277
270
|
bytes_from_string_value(string).map(|bytes| bytes.to_vec())
|
|
278
271
|
}
|
|
279
272
|
|
|
273
|
+
pub fn value_to_option_usize(value: VALUE) -> RbResult<Option<usize>> {
|
|
274
|
+
if value == qnil() {
|
|
275
|
+
Ok(None)
|
|
276
|
+
} else {
|
|
277
|
+
value_to_usize(value).map(Some)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
280
281
|
pub fn value_to_option_bytes(value: VALUE) -> RbResult<Option<Vec<u8>>> {
|
|
281
282
|
if value == qnil() {
|
|
282
283
|
Ok(None)
|
|
@@ -306,14 +307,14 @@ impl InputBytes {
|
|
|
306
307
|
self.as_slice().len()
|
|
307
308
|
}
|
|
308
309
|
|
|
309
|
-
pub fn
|
|
310
|
+
pub fn freeze_for_without_gvl(&mut self, release_gvl: bool) -> RbResult<()> {
|
|
310
311
|
if !release_gvl {
|
|
311
312
|
return Ok(());
|
|
312
313
|
}
|
|
313
314
|
|
|
314
315
|
match self {
|
|
315
316
|
#[cfg(ruby_engine = "mri")]
|
|
316
|
-
Self::Borrowed(bytes) => bytes.
|
|
317
|
+
Self::Borrowed(bytes) => bytes.freeze(),
|
|
317
318
|
#[cfg(not(ruby_engine = "mri"))]
|
|
318
319
|
Self::Owned(_) => Ok(()),
|
|
319
320
|
}
|
|
@@ -325,7 +326,7 @@ pub struct BorrowedStringBytes {
|
|
|
325
326
|
value: VALUE,
|
|
326
327
|
ptr: *const u8,
|
|
327
328
|
len: usize,
|
|
328
|
-
|
|
329
|
+
frozen: bool,
|
|
329
330
|
}
|
|
330
331
|
|
|
331
332
|
#[cfg(ruby_engine = "mri")]
|
|
@@ -337,7 +338,7 @@ impl BorrowedStringBytes {
|
|
|
337
338
|
value: string,
|
|
338
339
|
ptr: bytes.as_ptr(),
|
|
339
340
|
len: bytes.len(),
|
|
340
|
-
|
|
341
|
+
frozen: false,
|
|
341
342
|
})
|
|
342
343
|
}
|
|
343
344
|
|
|
@@ -349,13 +350,20 @@ impl BorrowedStringBytes {
|
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
352
|
|
|
352
|
-
|
|
353
|
-
|
|
353
|
+
// Borrow from a frozen copy before releasing the GVL. The copy shares the
|
|
354
|
+
// heap buffer, and a write to the caller's String copies that buffer first,
|
|
355
|
+
// so other threads may mutate or borrow the caller's String meanwhile.
|
|
356
|
+
fn freeze(&mut self) -> RbResult<()> {
|
|
357
|
+
if self.frozen {
|
|
354
358
|
return Ok(());
|
|
355
359
|
}
|
|
356
360
|
|
|
357
|
-
protect_value(|| unsafe {
|
|
358
|
-
|
|
361
|
+
let frozen = protect_value(|| unsafe { rb_sys::rb_str_new_frozen(self.value) })?;
|
|
362
|
+
let bytes = bytes_from_string_value(frozen)?;
|
|
363
|
+
self.value = frozen;
|
|
364
|
+
self.ptr = bytes.as_ptr();
|
|
365
|
+
self.len = bytes.len();
|
|
366
|
+
self.frozen = true;
|
|
359
367
|
Ok(())
|
|
360
368
|
}
|
|
361
369
|
}
|
|
@@ -363,11 +371,6 @@ impl BorrowedStringBytes {
|
|
|
363
371
|
#[cfg(ruby_engine = "mri")]
|
|
364
372
|
impl Drop for BorrowedStringBytes {
|
|
365
373
|
fn drop(&mut self) {
|
|
366
|
-
if self.locked {
|
|
367
|
-
unsafe {
|
|
368
|
-
rb_str_unlocktmp(self.value);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
374
|
let _ = rb_sys::rb_gc_guard!(self.value);
|
|
372
375
|
}
|
|
373
376
|
}
|
|
@@ -414,6 +417,7 @@ pub fn value_to_u32(value: VALUE) -> RbResult<u32> {
|
|
|
414
417
|
u32::try_from(value_to_usize(value)?).map_err(|_| RubyErr::arg("integer too large"))
|
|
415
418
|
}
|
|
416
419
|
|
|
420
|
+
#[allow(dead_code)]
|
|
417
421
|
pub fn value_to_i32(value: VALUE) -> RbResult<i32> {
|
|
418
422
|
let mut out = 0i64;
|
|
419
423
|
protect_value(|| {
|
|
@@ -427,10 +431,12 @@ pub fn usize_value(value: usize) -> RbResult<VALUE> {
|
|
|
427
431
|
protect_value(|| unsafe { rb_sys::rb_ull2inum(value as u64) })
|
|
428
432
|
}
|
|
429
433
|
|
|
434
|
+
#[allow(dead_code)]
|
|
430
435
|
pub fn i32_value(value: i32) -> VALUE {
|
|
431
436
|
unsafe { rb_sys::rb_int2inum(value as isize) }
|
|
432
437
|
}
|
|
433
438
|
|
|
439
|
+
#[allow(dead_code)]
|
|
434
440
|
pub fn u64_option_value(value: Option<u64>) -> RbResult<VALUE> {
|
|
435
441
|
match value {
|
|
436
442
|
Some(value) => protect_value(|| unsafe { rb_sys::rb_ull2inum(value) }),
|
|
@@ -540,6 +546,7 @@ pub unsafe fn define_singleton_method_2(
|
|
|
540
546
|
})
|
|
541
547
|
}
|
|
542
548
|
|
|
549
|
+
#[allow(dead_code)]
|
|
543
550
|
pub unsafe fn define_singleton_method_3(
|
|
544
551
|
object: VALUE,
|
|
545
552
|
name: &CStr,
|
|
@@ -612,6 +619,7 @@ unsafe fn transmute_2(
|
|
|
612
619
|
}
|
|
613
620
|
}
|
|
614
621
|
|
|
622
|
+
#[allow(dead_code)]
|
|
615
623
|
unsafe fn transmute_3(
|
|
616
624
|
func: unsafe extern "C" fn(VALUE, VALUE, VALUE, VALUE) -> VALUE,
|
|
617
625
|
) -> unsafe extern "C" fn() -> VALUE {
|
data/lib/zrip/block_codec.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative "dictionary"
|
|
4
4
|
|
|
5
5
|
module Zrip
|
|
6
|
-
# Zstandard
|
|
6
|
+
# Zstandard codec for per-Ractor use.
|
|
7
7
|
#
|
|
8
8
|
# `BlockCodec` keeps mutable native context state and is intended to be used
|
|
9
9
|
# per Ractor.
|
|
@@ -23,14 +23,14 @@ module Zrip
|
|
|
23
23
|
# @raise [CompressError]
|
|
24
24
|
#
|
|
25
25
|
# @!method compress(bytes)
|
|
26
|
-
# Compress bytes to a Zstandard
|
|
26
|
+
# Compress bytes to a Zstandard frame.
|
|
27
27
|
# @param bytes [String] uncompressed bytes
|
|
28
28
|
# @return [String]
|
|
29
29
|
# @raise [CompressError]
|
|
30
30
|
#
|
|
31
31
|
# @!method decompress(bytes, max_output_size: nil)
|
|
32
|
-
# Decompress a Zstandard
|
|
33
|
-
# @param bytes [String] compressed Zstandard
|
|
32
|
+
# Decompress a Zstandard frame.
|
|
33
|
+
# @param bytes [String] compressed Zstandard frame
|
|
34
34
|
# @param max_output_size [Integer, nil] optional output byte limit
|
|
35
35
|
# @return [String]
|
|
36
36
|
# @raise [DecompressError]
|
|
@@ -38,8 +38,8 @@ module Zrip
|
|
|
38
38
|
#
|
|
39
39
|
# @!method _native_decompress(bytes, max_output_size)
|
|
40
40
|
# Native decompression entry used by #decompress.
|
|
41
|
-
# @param bytes [String] compressed Zstandard
|
|
42
|
-
# @param max_output_size [Integer] output byte limit, or `
|
|
41
|
+
# @param bytes [String] compressed Zstandard frame
|
|
42
|
+
# @param max_output_size [Integer, nil] output byte limit, or `nil` for unbounded
|
|
43
43
|
# @return [String]
|
|
44
44
|
# @raise [DecompressError]
|
|
45
45
|
# @raise [OutputSizeLimitError]
|
|
@@ -69,7 +69,7 @@ module Zrip
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
def decompress(bytes, max_output_size: nil)
|
|
72
|
-
_native_decompress(bytes, Integer(max_output_size
|
|
72
|
+
_native_decompress(bytes, max_output_size && Integer(max_output_size))
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
end
|
data/lib/zrip/dict_trainer.rb
CHANGED
|
@@ -5,12 +5,14 @@ module Zrip
|
|
|
5
5
|
#
|
|
6
6
|
# @!method self.new(max_dict_size)
|
|
7
7
|
# Create a dictionary trainer.
|
|
8
|
-
# @param max_dict_size [Integer] maximum dictionary size in bytes
|
|
8
|
+
# @param max_dict_size [Integer] maximum dictionary size in bytes;
|
|
9
|
+
# sizes under 256 count as 256
|
|
9
10
|
# @return [DictTrainer]
|
|
10
11
|
#
|
|
11
12
|
# @!method self._native_new(max_dict_size)
|
|
12
13
|
# Native constructor used by `.new`.
|
|
13
|
-
# @param max_dict_size [Integer] maximum dictionary size in bytes
|
|
14
|
+
# @param max_dict_size [Integer] maximum dictionary size in bytes;
|
|
15
|
+
# sizes under 256 count as 256
|
|
14
16
|
# @return [DictTrainer]
|
|
15
17
|
#
|
|
16
18
|
# @!method add_sample(bytes)
|
|
@@ -32,7 +34,7 @@ module Zrip
|
|
|
32
34
|
# @return [Boolean]
|
|
33
35
|
#
|
|
34
36
|
# @!method max_dict_size
|
|
35
|
-
# @return [Integer]
|
|
37
|
+
# @return [Integer] maximum dictionary size, at least 256
|
|
36
38
|
class DictTrainer
|
|
37
39
|
def self.new(max_dict_size)
|
|
38
40
|
_native_new(max_dict_size)
|
data/lib/zrip/frame_codec.rb
CHANGED
|
@@ -45,7 +45,7 @@ module Zrip
|
|
|
45
45
|
# @!method _native_decompress(bytes, max_output_size)
|
|
46
46
|
# Native decompression entry used by #decompress.
|
|
47
47
|
# @param bytes [String] compressed Zstandard frame
|
|
48
|
-
# @param max_output_size [Integer] output byte limit, or `
|
|
48
|
+
# @param max_output_size [Integer, nil] output byte limit, or `nil` for unbounded
|
|
49
49
|
# @return [String]
|
|
50
50
|
# @raise [DecompressError]
|
|
51
51
|
# @raise [OutputSizeLimitError]
|
|
@@ -78,7 +78,7 @@ module Zrip
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
def decompress(bytes, max_output_size: nil)
|
|
81
|
-
_native_decompress(bytes, Integer(max_output_size
|
|
81
|
+
_native_decompress(bytes, max_output_size && Integer(max_output_size))
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
data/lib/zrip/version.rb
CHANGED