lz4rip 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca8b2f012551b63cf5efaaee91d49b319486300a9bb1e22f0d79d64d868ba076
4
- data.tar.gz: ff7f8c704a56fa29e80ade1d046f3e7fb93eac22bca44d8b684a4727db69355d
3
+ metadata.gz: 67a8b9bf2a0abb6a7630773720ae606dc1729be0aa56bdf4b851bf523beb2d4f
4
+ data.tar.gz: 55a3745ca8e940589a6659d68c41f2af81d82b3edf6a6ca22d9f496d4c331fd4
5
5
  SHA512:
6
- metadata.gz: 689b55762fed92109d07f280cc1d534e3f4e71ba76c63c1a6c149441ded0ae08d21e4d134a7000f1b4fb40941e7768856113e82272ce88e359bfedcc1b97e3ff
7
- data.tar.gz: 7f0a1a29b634874f60bde320df035aa14e6cd0080758a3dbd7e3147a74e88e3c1327ee77d1cf383448f591c6162d76e6355637286eed3ee74958e0315eb3d3fc
6
+ metadata.gz: b56524f4b6c057d47a31f5e4e411c7e155a70d4027cb9de42b54e61d2d97c10a6aa94f31473d4ec73afa282eaef786e10497d9d1b73e6db5142a322eec1c4820
7
+ data.tar.gz: 5e5a4186fcfbcfdfc254bc33768f63469868182ed898716ea7e6161f69ec744f9c285306810b982178e52d2d713b674a5fdd9b60f373607c29dceaf100b51961
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.2] - 2026-11-26
6
+
7
+ - Update the `lz4rip` crate dependency to 0.12.7. Block decompression caps
8
+ its output buffer at what the input can decode to, so a large
9
+ `decompressed_size:` no longer allocates that much up front. Dictionary
10
+ compression output differs from 0.2.1.
11
+ - `DictTrainer#train` no longer raises `RuntimeError` (native Rust panic)
12
+ for a `max_dict_size` of 4 to 31.
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
+ - Check the LZ4 frame magic before releasing the GVL.
18
+
5
19
  ## [0.2.1] - 2026-10-11
6
20
 
7
21
  - Update the `lz4rip` crate dependency to 0.11.10 and `rb-sys` to 0.9.130.
data/Cargo.lock CHANGED
@@ -90,9 +90,9 @@ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
90
90
 
91
91
  [[package]]
92
92
  name = "libc"
93
- version = "0.2.190"
93
+ version = "0.2.191"
94
94
  source = "registry+https://github.com/rust-lang/crates.io-index"
95
- checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"
95
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
96
96
 
97
97
  [[package]]
98
98
  name = "libloading"
@@ -106,17 +106,17 @@ dependencies = [
106
106
 
107
107
  [[package]]
108
108
  name = "lz4rip"
109
- version = "0.2.1"
109
+ version = "0.2.2"
110
110
  dependencies = [
111
- "lz4rip 0.11.10",
111
+ "lz4rip 0.12.7",
112
112
  "rb-sys",
113
113
  ]
114
114
 
115
115
  [[package]]
116
116
  name = "lz4rip"
117
- version = "0.11.10"
117
+ version = "0.12.7"
118
118
  source = "registry+https://github.com/rust-lang/crates.io-index"
119
- checksum = "37d8ecd80125a8e67ebcaacd9fad5757efa2b6f5b875e1b4ce567814d758a419"
119
+ checksum = "ba714cda4452679bec0dd3910f3979a3a803d51dbb490c237aa15dcb95432dd1"
120
120
  dependencies = [
121
121
  "lz4rip-core",
122
122
  "lz4rip-decode",
@@ -126,24 +126,24 @@ dependencies = [
126
126
 
127
127
  [[package]]
128
128
  name = "lz4rip-core"
129
- version = "0.5.6"
129
+ version = "0.6.2"
130
130
  source = "registry+https://github.com/rust-lang/crates.io-index"
131
- checksum = "edb50206b4d66e3ec849d2e7ac9257d79c19733c435909a0a46cbb34f9ec7107"
131
+ checksum = "052afa89a977207a207f3e074b1518b0fb5767dab3274464fd1ee5fc7699a30b"
132
132
 
133
133
  [[package]]
134
134
  name = "lz4rip-decode"
135
- version = "0.10.4"
135
+ version = "0.11.2"
136
136
  source = "registry+https://github.com/rust-lang/crates.io-index"
137
- checksum = "d89c54c126f2acb3979c7d8fc9482506d6371438f514f2e83ef96ede9b585594"
137
+ checksum = "1b0652316d9108ecf75802ddc55f4174a836f2c93c3ab3b06ed009e211d9f9c7"
138
138
  dependencies = [
139
139
  "lz4rip-core",
140
140
  ]
141
141
 
142
142
  [[package]]
143
143
  name = "lz4rip-encode"
144
- version = "0.10.8"
144
+ version = "0.10.17"
145
145
  source = "registry+https://github.com/rust-lang/crates.io-index"
146
- checksum = "51a3509ddaac04400136c19f6a2d8427c18c46357eb584c9908b3ff476dcd13e"
146
+ checksum = "ff6d1b221814509df4735ac32847dc169e6a8b0375683e6c5bc8139c4dd620c2"
147
147
  dependencies = [
148
148
  "lz4rip-core",
149
149
  ]
@@ -214,9 +214,9 @@ dependencies = [
214
214
 
215
215
  [[package]]
216
216
  name = "regex"
217
- version = "1.13.1"
217
+ version = "1.13.2"
218
218
  source = "registry+https://github.com/rust-lang/crates.io-index"
219
- checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
219
+ checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
220
220
  dependencies = [
221
221
  "aho-corasick",
222
222
  "memchr",
@@ -226,9 +226,9 @@ dependencies = [
226
226
 
227
227
  [[package]]
228
228
  name = "regex-automata"
229
- version = "0.4.18"
229
+ version = "0.4.19"
230
230
  source = "registry+https://github.com/rust-lang/crates.io-index"
231
- checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
231
+ checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
232
232
  dependencies = [
233
233
  "aho-corasick",
234
234
  "memchr",
@@ -237,9 +237,9 @@ dependencies = [
237
237
 
238
238
  [[package]]
239
239
  name = "regex-syntax"
240
- version = "0.8.11"
240
+ version = "0.8.12"
241
241
  source = "registry+https://github.com/rust-lang/crates.io-index"
242
- checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
242
+ checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
243
243
 
244
244
  [[package]]
245
245
  name = "rustc-hash"
@@ -278,9 +278,9 @@ checksum = "86a801b3cea342a06d468c8710662aa29e5e05e4f5c0d62f00bbb7f2ad7941c2"
278
278
 
279
279
  [[package]]
280
280
  name = "unicode-ident"
281
- version = "1.0.26"
281
+ version = "1.0.27"
282
282
  source = "registry+https://github.com/rust-lang/crates.io-index"
283
- checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
283
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
284
284
 
285
285
  [[package]]
286
286
  name = "windows-link"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "lz4rip"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  edition = "2021"
5
5
  build = "build.rs"
6
6
 
@@ -9,7 +9,7 @@ name = "lz4rip"
9
9
  crate-type = ["cdylib", "rlib"]
10
10
 
11
11
  [dependencies]
12
- lz4 = { version = "0.11.10", package = "lz4rip" }
12
+ lz4 = { version = "0.12.7", package = "lz4rip" }
13
13
  rb-sys = "0.9.130"
14
14
 
15
15
  [build-dependencies]
@@ -51,7 +51,7 @@ where
51
51
  F: FnOnce(&mut T, &[u8]) -> RbResult<R>,
52
52
  {
53
53
  if release_gvl {
54
- input.lock_for_without_gvl(true)?;
54
+ input.freeze_for_without_gvl(true)?;
55
55
  return rb::maybe_without_gvl(true, || {
56
56
  let mut guard = mutex
57
57
  .lock()
@@ -64,7 +64,7 @@ where
64
64
  Ok(mut guard) => func(&mut guard, input.as_slice()),
65
65
  Err(TryLockError::WouldBlock) => {
66
66
  // Even a small input needs protection when contention releases GVL.
67
- input.lock_for_without_gvl(true)?;
67
+ input.freeze_for_without_gvl(true)?;
68
68
  rb::maybe_without_gvl(true, || {
69
69
  let mut guard = mutex
70
70
  .lock()
@@ -268,7 +268,7 @@ fn block_codec_compress_impl(rb_self: VALUE, rb_input: VALUE) -> RbResult<VALUE>
268
268
  let rb_self = unsafe { block_codec_ref(rb_self)? };
269
269
  let mut input = rb::input_bytes(rb_input)?;
270
270
  let release_gvl = should_release_compress_gvl(input.len());
271
- input.lock_for_without_gvl(release_gvl)?;
271
+ input.freeze_for_without_gvl(release_gvl)?;
272
272
 
273
273
  let out = match &rb_self.compressor {
274
274
  None => rb::maybe_without_gvl(release_gvl, || block::compress(input.as_slice()))?,
@@ -366,7 +366,7 @@ fn frame_codec_compress_impl(rb_self: VALUE, rb_input: VALUE) -> RbResult<VALUE>
366
366
  let rb_self = unsafe { frame_codec_ref(rb_self)? };
367
367
  let mut input = rb::input_bytes(rb_input)?;
368
368
  let release_gvl = should_release_compress_gvl(input.len());
369
- input.lock_for_without_gvl(release_gvl)?;
369
+ input.freeze_for_without_gvl(release_gvl)?;
370
370
 
371
371
  let out = rb::maybe_without_gvl(release_gvl, || compress_frame(rb_self, input.as_slice()))?
372
372
  .map_err(RubyErr::runtime)?;
@@ -403,8 +403,6 @@ fn frame_codec_decompress_impl(
403
403
  let rb_self = unsafe { frame_codec_ref(rb_self)? };
404
404
  let max_decompressed_size = rb::value_to_option_usize(max_decompressed_size)?;
405
405
  let mut input = rb::input_bytes(rb_input)?;
406
- let release_gvl = should_release_frame_decompress_gvl(input.len());
407
- input.lock_for_without_gvl(release_gvl)?;
408
406
 
409
407
  if input.len() < 4 || input.as_slice()[..4] != LZ4_FRAME_MAGIC {
410
408
  return Err(RubyErr::new(
@@ -413,6 +411,9 @@ fn frame_codec_decompress_impl(
413
411
  ));
414
412
  }
415
413
 
414
+ let release_gvl = should_release_frame_decompress_gvl(input.len());
415
+ input.freeze_for_without_gvl(release_gvl)?;
416
+
416
417
  let out = rb::maybe_without_gvl(release_gvl, || {
417
418
  decompress_frame(rb_self, input.as_slice(), max_decompressed_size)
418
419
  })?
data/ext/lz4rip/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 unlocks borrowed strings.
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,19 +270,19 @@ 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
 
280
- pub fn value_to_option_bytes(value: VALUE) -> RbResult<Option<Vec<u8>>> {
273
+ pub fn value_to_option_usize(value: VALUE) -> RbResult<Option<usize>> {
281
274
  if value == qnil() {
282
275
  Ok(None)
283
276
  } else {
284
- value_to_bytes(value).map(Some)
277
+ value_to_usize(value).map(Some)
285
278
  }
286
279
  }
287
280
 
288
- pub fn value_to_option_usize(value: VALUE) -> RbResult<Option<usize>> {
281
+ pub fn value_to_option_bytes(value: VALUE) -> RbResult<Option<Vec<u8>>> {
289
282
  if value == qnil() {
290
283
  Ok(None)
291
284
  } else {
292
- value_to_usize(value).map(Some)
285
+ value_to_bytes(value).map(Some)
293
286
  }
294
287
  }
295
288
 
@@ -314,14 +307,14 @@ impl InputBytes {
314
307
  self.as_slice().len()
315
308
  }
316
309
 
317
- pub fn lock_for_without_gvl(&mut self, release_gvl: bool) -> RbResult<()> {
310
+ pub fn freeze_for_without_gvl(&mut self, release_gvl: bool) -> RbResult<()> {
318
311
  if !release_gvl {
319
312
  return Ok(());
320
313
  }
321
314
 
322
315
  match self {
323
316
  #[cfg(ruby_engine = "mri")]
324
- Self::Borrowed(bytes) => bytes.lock_tmp(),
317
+ Self::Borrowed(bytes) => bytes.freeze(),
325
318
  #[cfg(not(ruby_engine = "mri"))]
326
319
  Self::Owned(_) => Ok(()),
327
320
  }
@@ -333,7 +326,7 @@ pub struct BorrowedStringBytes {
333
326
  value: VALUE,
334
327
  ptr: *const u8,
335
328
  len: usize,
336
- locked: bool,
329
+ frozen: bool,
337
330
  }
338
331
 
339
332
  #[cfg(ruby_engine = "mri")]
@@ -345,7 +338,7 @@ impl BorrowedStringBytes {
345
338
  value: string,
346
339
  ptr: bytes.as_ptr(),
347
340
  len: bytes.len(),
348
- locked: false,
341
+ frozen: false,
349
342
  })
350
343
  }
351
344
 
@@ -357,13 +350,20 @@ impl BorrowedStringBytes {
357
350
  }
358
351
  }
359
352
 
360
- fn lock_tmp(&mut self) -> RbResult<()> {
361
- if self.locked || unsafe { rb_obj_frozen_p(self.value) } == qtrue() {
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 {
362
358
  return Ok(());
363
359
  }
364
360
 
365
- protect_value(|| unsafe { rb_str_locktmp(self.value) })?;
366
- self.locked = true;
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;
367
367
  Ok(())
368
368
  }
369
369
  }
@@ -371,11 +371,6 @@ impl BorrowedStringBytes {
371
371
  #[cfg(ruby_engine = "mri")]
372
372
  impl Drop for BorrowedStringBytes {
373
373
  fn drop(&mut self) {
374
- if self.locked {
375
- unsafe {
376
- rb_str_unlocktmp(self.value);
377
- }
378
- }
379
374
  let _ = rb_sys::rb_gc_guard!(self.value);
380
375
  }
381
376
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lz4rip
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lz4rip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger