kreuzberg 4.0.0.pre.rc.6 → 4.0.0.rc1

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 (175) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.rubocop.yaml +534 -1
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +11 -11
  6. data/README.md +5 -10
  7. data/examples/async_patterns.rb +0 -1
  8. data/ext/kreuzberg_rb/extconf.rb +0 -10
  9. data/ext/kreuzberg_rb/native/Cargo.toml +15 -23
  10. data/ext/kreuzberg_rb/native/build.rs +2 -0
  11. data/ext/kreuzberg_rb/native/include/ieeefp.h +1 -1
  12. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +1 -1
  13. data/ext/kreuzberg_rb/native/include/strings.h +2 -2
  14. data/ext/kreuzberg_rb/native/include/unistd.h +1 -1
  15. data/ext/kreuzberg_rb/native/src/lib.rs +16 -75
  16. data/kreuzberg.gemspec +14 -57
  17. data/lib/kreuzberg/cache_api.rb +0 -1
  18. data/lib/kreuzberg/cli.rb +2 -2
  19. data/lib/kreuzberg/config.rb +2 -9
  20. data/lib/kreuzberg/errors.rb +7 -75
  21. data/lib/kreuzberg/extraction_api.rb +0 -1
  22. data/lib/kreuzberg/setup_lib_path.rb +0 -1
  23. data/lib/kreuzberg/version.rb +1 -1
  24. data/lib/kreuzberg.rb +0 -21
  25. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  26. data/sig/kreuzberg.rbs +3 -55
  27. data/spec/binding/cli_proxy_spec.rb +4 -2
  28. data/spec/binding/cli_spec.rb +11 -12
  29. data/spec/examples.txt +104 -0
  30. data/spec/fixtures/config.yaml +1 -0
  31. data/spec/spec_helper.rb +1 -1
  32. data/vendor/kreuzberg/Cargo.toml +42 -112
  33. data/vendor/kreuzberg/README.md +2 -2
  34. data/vendor/kreuzberg/build.rs +4 -18
  35. data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
  36. data/vendor/kreuzberg/src/cache/mod.rs +3 -27
  37. data/vendor/kreuzberg/src/core/batch_mode.rs +0 -60
  38. data/vendor/kreuzberg/src/core/extractor.rs +81 -202
  39. data/vendor/kreuzberg/src/core/io.rs +2 -4
  40. data/vendor/kreuzberg/src/core/mime.rs +12 -2
  41. data/vendor/kreuzberg/src/core/mod.rs +1 -4
  42. data/vendor/kreuzberg/src/core/pipeline.rs +33 -111
  43. data/vendor/kreuzberg/src/embeddings.rs +16 -125
  44. data/vendor/kreuzberg/src/error.rs +1 -1
  45. data/vendor/kreuzberg/src/extraction/docx.rs +1 -1
  46. data/vendor/kreuzberg/src/extraction/image.rs +13 -13
  47. data/vendor/kreuzberg/src/extraction/libreoffice.rs +1 -0
  48. data/vendor/kreuzberg/src/extraction/mod.rs +5 -9
  49. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +0 -2
  50. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
  51. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
  52. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
  53. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
  54. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
  55. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
  56. data/vendor/kreuzberg/src/extractors/archive.rs +0 -21
  57. data/vendor/kreuzberg/src/extractors/docx.rs +128 -16
  58. data/vendor/kreuzberg/src/extractors/email.rs +0 -14
  59. data/vendor/kreuzberg/src/extractors/excel.rs +20 -19
  60. data/vendor/kreuzberg/src/extractors/html.rs +154 -137
  61. data/vendor/kreuzberg/src/extractors/image.rs +4 -7
  62. data/vendor/kreuzberg/src/extractors/mod.rs +9 -106
  63. data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
  64. data/vendor/kreuzberg/src/extractors/pdf.rs +15 -12
  65. data/vendor/kreuzberg/src/extractors/pptx.rs +3 -17
  66. data/vendor/kreuzberg/src/extractors/structured.rs +0 -14
  67. data/vendor/kreuzberg/src/extractors/text.rs +5 -23
  68. data/vendor/kreuzberg/src/extractors/xml.rs +0 -7
  69. data/vendor/kreuzberg/src/keywords/rake.rs +1 -0
  70. data/vendor/kreuzberg/src/lib.rs +1 -4
  71. data/vendor/kreuzberg/src/mcp/mod.rs +1 -1
  72. data/vendor/kreuzberg/src/mcp/server.rs +3 -5
  73. data/vendor/kreuzberg/src/ocr/processor.rs +2 -18
  74. data/vendor/kreuzberg/src/pdf/error.rs +1 -1
  75. data/vendor/kreuzberg/src/pdf/table.rs +44 -17
  76. data/vendor/kreuzberg/src/pdf/text.rs +3 -0
  77. data/vendor/kreuzberg/src/plugins/extractor.rs +5 -8
  78. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -2
  79. data/vendor/kreuzberg/src/plugins/processor.rs +1 -2
  80. data/vendor/kreuzberg/src/plugins/registry.rs +0 -13
  81. data/vendor/kreuzberg/src/plugins/validator.rs +8 -9
  82. data/vendor/kreuzberg/src/stopwords/mod.rs +2 -2
  83. data/vendor/kreuzberg/src/types.rs +12 -42
  84. data/vendor/kreuzberg/tests/batch_orchestration.rs +5 -19
  85. data/vendor/kreuzberg/tests/batch_processing.rs +3 -15
  86. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
  87. data/vendor/kreuzberg/tests/concurrency_stress.rs +1 -17
  88. data/vendor/kreuzberg/tests/config_features.rs +0 -18
  89. data/vendor/kreuzberg/tests/config_loading_tests.rs +39 -15
  90. data/vendor/kreuzberg/tests/core_integration.rs +7 -24
  91. data/vendor/kreuzberg/tests/csv_integration.rs +81 -71
  92. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +25 -23
  93. data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
  94. data/vendor/kreuzberg/tests/pipeline_integration.rs +1 -0
  95. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +1 -0
  96. data/vendor/kreuzberg/tests/registry_integration_tests.rs +22 -1
  97. data/vendor/kreuzberg/tests/security_validation.rs +1 -12
  98. metadata +25 -90
  99. data/.rubocop.yml +0 -538
  100. data/ext/kreuzberg_rb/native/Cargo.lock +0 -6535
  101. data/lib/kreuzberg/error_context.rb +0 -32
  102. data/vendor/kreuzberg/benches/otel_overhead.rs +0 -48
  103. data/vendor/kreuzberg/src/extraction/markdown.rs +0 -213
  104. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +0 -287
  105. data/vendor/kreuzberg/src/extractors/bibtex.rs +0 -469
  106. data/vendor/kreuzberg/src/extractors/docbook.rs +0 -502
  107. data/vendor/kreuzberg/src/extractors/epub.rs +0 -707
  108. data/vendor/kreuzberg/src/extractors/fictionbook.rs +0 -491
  109. data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +0 -738
  110. data/vendor/kreuzberg/src/extractors/jats.rs +0 -1051
  111. data/vendor/kreuzberg/src/extractors/jupyter.rs +0 -367
  112. data/vendor/kreuzberg/src/extractors/latex.rs +0 -652
  113. data/vendor/kreuzberg/src/extractors/markdown.rs +0 -700
  114. data/vendor/kreuzberg/src/extractors/odt.rs +0 -628
  115. data/vendor/kreuzberg/src/extractors/opml.rs +0 -634
  116. data/vendor/kreuzberg/src/extractors/orgmode.rs +0 -528
  117. data/vendor/kreuzberg/src/extractors/rst.rs +0 -576
  118. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -810
  119. data/vendor/kreuzberg/src/extractors/security.rs +0 -484
  120. data/vendor/kreuzberg/src/extractors/security_tests.rs +0 -367
  121. data/vendor/kreuzberg/src/extractors/typst.rs +0 -650
  122. data/vendor/kreuzberg/src/panic_context.rs +0 -154
  123. data/vendor/kreuzberg/tests/api_extract_multipart.rs +0 -52
  124. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +0 -421
  125. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +0 -498
  126. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +0 -370
  127. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +0 -275
  128. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +0 -228
  129. data/vendor/kreuzberg/tests/html_table_test.rs +0 -551
  130. data/vendor/kreuzberg/tests/instrumentation_test.rs +0 -139
  131. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +0 -639
  132. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +0 -704
  133. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +0 -496
  134. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +0 -490
  135. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +0 -695
  136. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +0 -616
  137. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +0 -822
  138. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +0 -692
  139. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +0 -776
  140. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +0 -1259
  141. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +0 -647
  142. data/vendor/rb-sys/.cargo-ok +0 -1
  143. data/vendor/rb-sys/.cargo_vcs_info.json +0 -6
  144. data/vendor/rb-sys/Cargo.lock +0 -393
  145. data/vendor/rb-sys/Cargo.toml +0 -70
  146. data/vendor/rb-sys/Cargo.toml.orig +0 -57
  147. data/vendor/rb-sys/LICENSE-APACHE +0 -190
  148. data/vendor/rb-sys/LICENSE-MIT +0 -21
  149. data/vendor/rb-sys/bin/release.sh +0 -21
  150. data/vendor/rb-sys/build/features.rs +0 -108
  151. data/vendor/rb-sys/build/main.rs +0 -246
  152. data/vendor/rb-sys/build/stable_api_config.rs +0 -153
  153. data/vendor/rb-sys/build/version.rs +0 -48
  154. data/vendor/rb-sys/readme.md +0 -36
  155. data/vendor/rb-sys/src/bindings.rs +0 -21
  156. data/vendor/rb-sys/src/hidden.rs +0 -11
  157. data/vendor/rb-sys/src/lib.rs +0 -34
  158. data/vendor/rb-sys/src/macros.rs +0 -371
  159. data/vendor/rb-sys/src/memory.rs +0 -53
  160. data/vendor/rb-sys/src/ruby_abi_version.rs +0 -38
  161. data/vendor/rb-sys/src/special_consts.rs +0 -31
  162. data/vendor/rb-sys/src/stable_api/compiled.c +0 -179
  163. data/vendor/rb-sys/src/stable_api/compiled.rs +0 -257
  164. data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +0 -316
  165. data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +0 -316
  166. data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +0 -324
  167. data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +0 -317
  168. data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +0 -315
  169. data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +0 -326
  170. data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +0 -327
  171. data/vendor/rb-sys/src/stable_api.rs +0 -261
  172. data/vendor/rb-sys/src/symbol.rs +0 -31
  173. data/vendor/rb-sys/src/tracking_allocator.rs +0 -332
  174. data/vendor/rb-sys/src/utils.rs +0 -89
  175. data/vendor/rb-sys/src/value_type.rs +0 -7
@@ -1,332 +0,0 @@
1
- //! Support for reporting Rust memory usage to the Ruby GC.
2
-
3
- use std::{
4
- fmt::Formatter,
5
- sync::{
6
- Arc,
7
- atomic::{AtomicIsize, Ordering},
8
- },
9
- };
10
-
11
- #[cfg(ruby_engine = "mri")]
12
- mod mri {
13
- use crate::{rb_gc_adjust_memory_usage, utils::is_ruby_vm_started};
14
- use std::alloc::{GlobalAlloc, Layout, System};
15
-
16
- /// A simple wrapper over [`System`] which reports memory usage to
17
- /// the Ruby GC. This gives the GC a more accurate picture of the process'
18
- /// memory usage so it can make better decisions about when to run.
19
- #[derive(Debug)]
20
- pub struct TrackingAllocator;
21
-
22
- impl TrackingAllocator {
23
- /// Create a new [`TrackingAllocator`].
24
- #[allow(clippy::new_without_default)]
25
- pub const fn new() -> Self {
26
- Self
27
- }
28
-
29
- /// Create a new [`TrackingAllocator`] with default values.
30
- pub const fn default() -> Self {
31
- Self::new()
32
- }
33
-
34
- /// Adjust the memory usage reported to the Ruby GC by `delta`. Useful for
35
- /// tracking allocations invisible to the Rust allocator, such as `mmap` or
36
- /// direct `malloc` calls.
37
- ///
38
- /// # Example
39
- /// ```
40
- /// use rb_sys::TrackingAllocator;
41
- ///
42
- /// // Allocate 1024 bytes of memory using `mmap` or `malloc`...
43
- /// TrackingAllocator::adjust_memory_usage(1024);
44
- ///
45
- /// // ...and then after the memory is freed, adjust the memory usage again.
46
- /// TrackingAllocator::adjust_memory_usage(-1024);
47
- /// ```
48
- #[inline]
49
- pub fn adjust_memory_usage(delta: isize) -> isize {
50
- if delta == 0 {
51
- return 0;
52
- }
53
-
54
- #[cfg(target_pointer_width = "32")]
55
- let delta = delta as i32;
56
-
57
- #[cfg(target_pointer_width = "64")]
58
- let delta = delta as i64;
59
-
60
- unsafe {
61
- if is_ruby_vm_started() {
62
- // On Windows, ssize_t is i32 even on 64-bit, so cast i64 to i32
63
- #[cfg(all(target_pointer_width = "64", target_os = "windows"))]
64
- rb_gc_adjust_memory_usage(delta as i32);
65
-
66
- #[cfg(not(all(target_pointer_width = "64", target_os = "windows")))]
67
- rb_gc_adjust_memory_usage(delta);
68
-
69
- delta as isize
70
- } else {
71
- 0
72
- }
73
- }
74
- }
75
- }
76
-
77
- unsafe impl GlobalAlloc for TrackingAllocator {
78
- #[inline]
79
- unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
80
- let ret = System.alloc(layout);
81
- let delta = layout.size() as isize;
82
-
83
- if !ret.is_null() && delta != 0 {
84
- Self::adjust_memory_usage(delta);
85
- }
86
-
87
- ret
88
- }
89
-
90
- #[inline]
91
- unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
92
- let ret = System.alloc_zeroed(layout);
93
- let delta = layout.size() as isize;
94
-
95
- if !ret.is_null() && delta != 0 {
96
- Self::adjust_memory_usage(delta);
97
- }
98
-
99
- ret
100
- }
101
-
102
- #[inline]
103
- unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
104
- System.dealloc(ptr, layout);
105
- let delta = -(layout.size() as isize);
106
-
107
- if delta != 0 {
108
- Self::adjust_memory_usage(delta);
109
- }
110
- }
111
-
112
- #[inline]
113
- unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
114
- let ret = System.realloc(ptr, layout, new_size);
115
- let delta = new_size as isize - layout.size() as isize;
116
-
117
- if !ret.is_null() && delta != 0 {
118
- Self::adjust_memory_usage(delta);
119
- }
120
-
121
- ret
122
- }
123
- }
124
- }
125
-
126
- #[cfg(not(ruby_engine = "mri"))]
127
- mod non_mri {
128
- use std::alloc::{GlobalAlloc, Layout, System};
129
-
130
- /// A simple wrapper over [`System`] as a fallback for non-MRI Ruby engines.
131
- pub struct TrackingAllocator;
132
-
133
- impl TrackingAllocator {
134
- #[allow(clippy::new_without_default)]
135
- pub const fn new() -> Self {
136
- Self
137
- }
138
-
139
- pub const fn default() -> Self {
140
- Self::new()
141
- }
142
-
143
- pub fn adjust_memory_usage(_delta: isize) -> isize {
144
- 0
145
- }
146
- }
147
-
148
- unsafe impl GlobalAlloc for TrackingAllocator {
149
- #[inline]
150
- unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
151
- System.alloc(layout)
152
- }
153
-
154
- #[inline]
155
- unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
156
- System.alloc_zeroed(layout)
157
- }
158
-
159
- #[inline]
160
- unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
161
- System.dealloc(ptr, layout)
162
- }
163
-
164
- #[inline]
165
- unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
166
- System.realloc(ptr, layout, new_size)
167
- }
168
- }
169
- }
170
-
171
- #[cfg(ruby_engine = "mri")]
172
- pub use mri::*;
173
-
174
- #[cfg(not(ruby_engine = "mri"))]
175
- pub use non_mri::*;
176
-
177
- /// Set the global allocator to [`TrackingAllocator`].
178
- ///
179
- /// # Example
180
- /// ```
181
- /// // File: ext/my_gem/src/lib.rs
182
- /// use rb_sys::set_global_tracking_allocator;
183
- ///
184
- /// set_global_tracking_allocator!();
185
- /// ```
186
- #[macro_export]
187
- macro_rules! set_global_tracking_allocator {
188
- () => {
189
- #[global_allocator]
190
- static RUBY_GLOBAL_TRACKING_ALLOCATOR: $crate::tracking_allocator::TrackingAllocator =
191
- $crate::tracking_allocator::TrackingAllocator;
192
- };
193
- }
194
-
195
- #[derive(Debug)]
196
- #[repr(transparent)]
197
- struct MemsizeDelta(Arc<AtomicIsize>);
198
-
199
- impl MemsizeDelta {
200
- fn new(delta: isize) -> Self {
201
- let delta = TrackingAllocator::adjust_memory_usage(delta);
202
- Self(Arc::new(AtomicIsize::new(delta)))
203
- }
204
-
205
- fn add(&self, delta: usize) {
206
- if delta == 0 {
207
- return;
208
- }
209
-
210
- let delta = TrackingAllocator::adjust_memory_usage(delta as _);
211
- self.0.fetch_add(delta as _, Ordering::SeqCst);
212
- }
213
-
214
- fn sub(&self, delta: usize) {
215
- if delta == 0 {
216
- return;
217
- }
218
-
219
- let delta = TrackingAllocator::adjust_memory_usage(-(delta as isize));
220
- self.0.fetch_add(delta, Ordering::SeqCst);
221
- }
222
-
223
- fn get(&self) -> isize {
224
- self.0.load(Ordering::SeqCst)
225
- }
226
- }
227
-
228
- impl Clone for MemsizeDelta {
229
- fn clone(&self) -> Self {
230
- Self(Arc::clone(&self.0))
231
- }
232
- }
233
-
234
- impl Drop for MemsizeDelta {
235
- fn drop(&mut self) {
236
- let memsize = self.0.swap(0, Ordering::SeqCst);
237
- TrackingAllocator::adjust_memory_usage(0 - memsize);
238
- }
239
- }
240
-
241
- /// A guard which adjusts the memory usage reported to the Ruby GC by `delta`.
242
- /// This allows you to track resources which are invisible to the Rust
243
- /// allocator, such as items that are known to internally use `mmap` or direct
244
- /// `malloc` in their implementation.
245
- ///
246
- /// Internally, it uses an [`Arc<AtomicIsize>`] to track the memory usage delta,
247
- /// and is safe to clone when `T` is [`Clone`].
248
- ///
249
- /// # Example
250
- /// ```
251
- /// use rb_sys::tracking_allocator::ManuallyTracked;
252
- ///
253
- /// type SomethingThatUsedMmap = ();
254
- ///
255
- /// // Will tell the Ruby GC that 1024 bytes were allocated.
256
- /// let item = ManuallyTracked::new(SomethingThatUsedMmap, 1024);
257
- ///
258
- /// // Will tell the Ruby GC that 1024 bytes were freed.
259
- /// std::mem::drop(item);
260
- /// ```
261
- pub struct ManuallyTracked<T> {
262
- item: T,
263
- memsize_delta: MemsizeDelta,
264
- }
265
-
266
- impl<T> ManuallyTracked<T> {
267
- /// Create a new `ManuallyTracked<T>`, and immediately report that `memsize`
268
- /// bytes were allocated.
269
- pub fn wrap(item: T, memsize: usize) -> Self {
270
- Self {
271
- item,
272
- memsize_delta: MemsizeDelta::new(memsize as _),
273
- }
274
- }
275
-
276
- /// Increase the memory usage reported to the Ruby GC by `memsize` bytes.
277
- pub fn increase_memory_usage(&self, memsize: usize) {
278
- self.memsize_delta.add(memsize);
279
- }
280
-
281
- /// Decrease the memory usage reported to the Ruby GC by `memsize` bytes.
282
- pub fn decrease_memory_usage(&self, memsize: usize) {
283
- self.memsize_delta.sub(memsize);
284
- }
285
-
286
- /// Get the current memory usage delta.
287
- pub fn memsize_delta(&self) -> isize {
288
- self.memsize_delta.get()
289
- }
290
-
291
- /// Get a shared reference to the inner `T`.
292
- pub fn get(&self) -> &T {
293
- &self.item
294
- }
295
-
296
- /// Get a mutable reference to the inner `T`.
297
- pub fn get_mut(&mut self) -> &mut T {
298
- &mut self.item
299
- }
300
- }
301
-
302
- impl ManuallyTracked<()> {
303
- /// Create a new `ManuallyTracked<()>`, and immediately report that
304
- /// `memsize` bytes were allocated.
305
- pub fn new(memsize: usize) -> Self {
306
- Self::wrap((), memsize)
307
- }
308
- }
309
-
310
- impl Default for ManuallyTracked<()> {
311
- fn default() -> Self {
312
- Self::wrap((), 0)
313
- }
314
- }
315
-
316
- impl<T: Clone> Clone for ManuallyTracked<T> {
317
- fn clone(&self) -> Self {
318
- Self {
319
- item: self.item.clone(),
320
- memsize_delta: self.memsize_delta.clone(),
321
- }
322
- }
323
- }
324
-
325
- impl<T: std::fmt::Debug> std::fmt::Debug for ManuallyTracked<T> {
326
- fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
327
- f.debug_struct("ManuallyTracked")
328
- .field("item", &self.item)
329
- .field("memsize_delta", &self.memsize_delta)
330
- .finish()
331
- }
332
- }
@@ -1,89 +0,0 @@
1
- //! Internal utility functions.
2
-
3
- /// Check if the Ruby VM is globally available.
4
- ///
5
- /// Unfortunately there is no public API for this check, but there's a hidden
6
- /// `ruby_current_vm_ptr` symbol in libruby 2.5 - 3.2 which we can use to
7
- /// determine if the VM has been initialized, or shut down.
8
- ///
9
- /// # Notes
10
- ///
11
- /// Ruby 2.4 and below don't have a global VM pointer, so we can't check if it's
12
- /// null. Ruby 2.4 is EOL, and support will be dropped soon anyway.
13
- //
14
- /// In Ruby 3.3, the global VM pointer is no longer exported, so there's no
15
- /// simple way to check the global VM pointer, so instead we check if known
16
- /// static value is non-zero.
17
- ///
18
- /// On Ruby < 3.3, we also need to check if the global VM pointer is null to
19
- /// ensure the VM hasn't stopped, which makes the function name a bit of a
20
- /// misnomer... but in actuality this function can only guarantee that the
21
- /// VM is started, not that it's still running.
22
- #[allow(dead_code)]
23
- pub(crate) unsafe fn is_ruby_vm_started() -> bool {
24
- #[cfg(ruby_engine = "mri")]
25
- let ret = {
26
- #[cfg(all(ruby_gt_2_4, ruby_lte_3_2))]
27
- let ret = !crate::hidden::ruby_current_vm_ptr.is_null();
28
-
29
- #[cfg(any(ruby_lte_2_4, ruby_gt_3_2))]
30
- let ret = crate::rb_cBasicObject != 0;
31
-
32
- ret
33
- };
34
-
35
- #[cfg(ruby_engine = "truffleruby")]
36
- let ret = crate::rb_cBasicObject != 0;
37
-
38
- ret
39
- }
40
-
41
- /// Macro for conditionally asserting type checks in Ruby, only active when RUBY_DEBUG is enabled.
42
- /// This matches Ruby's behavior of only checking types in debug mode.
43
- #[macro_export]
44
- macro_rules! debug_ruby_assert_type {
45
- ($obj:expr, $type:expr, $message:expr) => {
46
- #[cfg(ruby_ruby_debug = "true")]
47
- {
48
- #[allow(clippy::macro_metavars_in_unsafe)]
49
- unsafe {
50
- assert!(
51
- !$crate::SPECIAL_CONST_P($obj) && $crate::RB_BUILTIN_TYPE($obj) == $type,
52
- $message
53
- );
54
- }
55
- }
56
- #[cfg(not(ruby_ruby_debug = "true"))]
57
- {
58
- let _ = ($obj, $type, $message); // Prevent unused variable warnings
59
- }
60
- };
61
- }
62
-
63
- #[cfg(test)]
64
- mod tests {
65
- use super::*;
66
- use rusty_fork::rusty_fork_test;
67
-
68
- rusty_fork_test! {
69
- #[test]
70
- fn test_is_ruby_vm_started() {
71
- assert!(!unsafe { is_ruby_vm_started() });
72
-
73
- #[cfg(windows)]
74
- {
75
- let mut argc = 0;
76
- let mut argv: [*mut std::os::raw::c_char; 0] = [];
77
- let mut argv = argv.as_mut_ptr();
78
- unsafe { rb_sys::rb_w32_sysinit(&mut argc, &mut argv) };
79
- }
80
-
81
- match unsafe { crate::ruby_setup() } {
82
- 0 => {}
83
- code => panic!("Failed to setup Ruby (error code: {})", code),
84
- };
85
-
86
- assert!(unsafe { is_ruby_vm_started() });
87
- }
88
- }
89
- }
@@ -1,7 +0,0 @@
1
- #![allow(rustdoc::broken_intra_doc_links)]
2
- //! Definitions for Ruby's special constants.
3
- //!
4
- //! Makes it easier to reference important Ruby constants, without havign to dig
5
- //! around in bindgen's output.
6
-
7
- pub use crate::ruby_value_type::*;