yeptris 0.6.107.2 → 0.6.107.3
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/lib/yeptris/document.rb +20 -9
- data/lib/yeptris/ffi.rb +76 -4
- data/lib/yeptris/json/tape.rb +45 -15
- data/lib/yeptris/json.rb +28 -13
- data/lib/yeptris/plan.rb +4 -2
- data/lib/yeptris/validation.rb +4 -2
- data/lib/yeptris/valueml.rb +24 -9
- data/lib/yeptris/yaml.rb +5 -2
- data/lib/yeptris.rb +30 -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: 0dc5bf7cfe9ef4393c91c84763d1a339cf692db60b372a576f443652b833465b
|
|
4
|
+
data.tar.gz: ee33283a7f004b96cbd8b04d63ce7b85d72bf7d8687510d36af1e331c53fadd4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea9dfd2ff11859861e61e8dfc44dc1f770a3a42671b812693361f0bdf507c024a57279c55d4604f62b651c897bc33f8c57e3ed7f9a46e0e782a753e40f2253e6
|
|
7
|
+
data.tar.gz: a4c2dcca2eefdea4b3e223600146afcf265f22bd4ce01ca3fbc4dee93a4352b15db1df44856aff9c9ce8d9c81865e8ab07c0444187e1af31e70a4b69dbc2bb07
|
data/lib/yeptris/document.rb
CHANGED
|
@@ -42,7 +42,10 @@ class Yeptris::Document
|
|
|
42
42
|
# always yields the same Ruby object (identity for aliases/eql?),
|
|
43
43
|
# cleared at free — no stale entries, no GC-race weak maps.
|
|
44
44
|
@wrapper_cache = {}
|
|
45
|
-
|
|
45
|
+
# #460: the backstop is main-Ractor-only (MRI's finalizer table
|
|
46
|
+
# desyncs under parallel-Ractor define/undefine); a document
|
|
47
|
+
# created inside a Ractor is caller-owned and must be #free'd.
|
|
48
|
+
Yeptris.define_gc_finalizer(self, self.class.finalize(c_ptr)) unless c_ptr.null?
|
|
46
49
|
end
|
|
47
50
|
|
|
48
51
|
def self.parse(yaml, schema: :core_12, max_depth: 0)
|
|
@@ -54,8 +57,12 @@ class Yeptris::Document
|
|
|
54
57
|
Yeptris::FFI.yeptris_parse(yaml, yaml.bytesize, status)
|
|
55
58
|
else
|
|
56
59
|
opts = Yeptris::FFI::ParseOptions.new
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
# Ractor boundary (#460): write by frozen offset, never
|
|
61
|
+
# Struct#[]= (the cache-writing call the #456 law bans).
|
|
62
|
+
poff = Yeptris::FFI::PARSE_OPTIONS_OFFSET
|
|
63
|
+
omp = opts.to_ptr
|
|
64
|
+
omp.put_int32(poff[:schema], schema == :compat_11 ? Yeptris::FFI::SCHEMA_11_COMPAT : Yeptris::FFI::SCHEMA_12_CORE)
|
|
65
|
+
omp.put_int32(poff[:max_depth], max_depth)
|
|
59
66
|
Yeptris::FFI.yeptris_parse_ex(yaml, yaml.bytesize, opts, status)
|
|
60
67
|
end
|
|
61
68
|
if doc.null?
|
|
@@ -118,7 +125,7 @@ class Yeptris::Document
|
|
|
118
125
|
# WITHOUT a finalizer; the wrapper's lifetime follows the owner.
|
|
119
126
|
def self.without_finalizer(c_ptr, source = nil)
|
|
120
127
|
doc = new(c_ptr, Freed.new(:alive), :core_12, source)
|
|
121
|
-
|
|
128
|
+
Yeptris.undefine_gc_finalizer(doc)
|
|
122
129
|
doc
|
|
123
130
|
end
|
|
124
131
|
|
|
@@ -132,7 +139,7 @@ class Yeptris::Document
|
|
|
132
139
|
@freed.state = :freed
|
|
133
140
|
# stop the GC finalizer BEFORE the C free — it captures the same
|
|
134
141
|
# pointer, and its firing after this free is the double free
|
|
135
|
-
|
|
142
|
+
Yeptris.undefine_gc_finalizer(self)
|
|
136
143
|
@wrapper_cache.clear
|
|
137
144
|
Yeptris::FFI.yeptris_document_free(@c_ptr)
|
|
138
145
|
end
|
|
@@ -216,10 +223,14 @@ class Yeptris::Document
|
|
|
216
223
|
ptr =
|
|
217
224
|
if canonical || !best_width.zero? || explicit_doc_start
|
|
218
225
|
opts = Yeptris::FFI::EmitOptions.new
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
# Ractor boundary (#460): write by frozen offset, never
|
|
227
|
+
# Struct#[]= (the cache-writing call the #456 law bans).
|
|
228
|
+
eoff = Yeptris::FFI::EMIT_OPTIONS_OFFSET
|
|
229
|
+
omp = opts.to_ptr
|
|
230
|
+
omp.put_uint32(eoff[:size], Yeptris::FFI::EmitOptions.size)
|
|
231
|
+
omp.put_int32(eoff[:canonical], canonical ? 1 : 0)
|
|
232
|
+
omp.put_int32(eoff[:best_width], best_width)
|
|
233
|
+
omp.put_int32(eoff[:explicit_doc_start], explicit_doc_start ? 1 : 0)
|
|
223
234
|
Yeptris::FFI.yeptris_serialize_ex(@c_ptr, opts, len)
|
|
224
235
|
else
|
|
225
236
|
Yeptris::FFI.yeptris_serialize(@c_ptr, len)
|
data/lib/yeptris/ffi.rb
CHANGED
|
@@ -124,6 +124,23 @@ module Yeptris
|
|
|
124
124
|
:explicit_doc_start, :int
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
# Option structs, Ractor boundary (yeptris-ruby#460, the #456 law):
|
|
128
|
+
# ffi's Struct#[]/#[]= ride a per-layout field cache written
|
|
129
|
+
# UNSYNCHRONIZED (ext/ffi_c/Struct.c struct_field: fieldName store,
|
|
130
|
+
# then field store; slots (symbol bits >> 8) & 0xff). Parallel
|
|
131
|
+
# Ractors that build ParseOptions/EmitOptions share the class-level
|
|
132
|
+
# layouts, so every field access here is a cache write. These
|
|
133
|
+
# offsets freeze once at require (main Ractor; StructLayout#[]
|
|
134
|
+
# is a plain hash lookup and never writes the cache) and the
|
|
135
|
+
# builders write through them with put_int32/put_uint32 — the
|
|
136
|
+
# load/serialize lanes never touch the cache.
|
|
137
|
+
PARSE_OPTIONS_OFFSET = ParseOptions.members.to_h do |member|
|
|
138
|
+
[member, ParseOptions.offset_of(member)]
|
|
139
|
+
end.freeze
|
|
140
|
+
EMIT_OPTIONS_OFFSET = EmitOptions.members.to_h do |member|
|
|
141
|
+
[member, EmitOptions.offset_of(member)]
|
|
142
|
+
end.freeze
|
|
143
|
+
|
|
127
144
|
attach_function :yeptris_version, [], :string
|
|
128
145
|
|
|
129
146
|
attach_function :yeptris_last_error, [:pointer, :pointer], :string
|
|
@@ -175,6 +192,25 @@ module Yeptris
|
|
|
175
192
|
:_long_key_known, :uchar, :_long_key, :uchar
|
|
176
193
|
end
|
|
177
194
|
|
|
195
|
+
# Tape face, Ractor boundary (yeptris-ruby#460): the same law as
|
|
196
|
+
# VALUE_COLUMNS_OFFSET below. JSON::Tape and JSON::Tape::Columns
|
|
197
|
+
# read this struct from whatever Ractor parses (the tape handle is
|
|
198
|
+
# per-Ractor; the class-level layout is shared), and JSON's
|
|
199
|
+
# tape_engine walk reads it too. ffi's per-layout field cache tears
|
|
200
|
+
# under parallel Ractors — a boot where two used field names share
|
|
201
|
+
# a slot (observed: kinds/offs/lens/int_min together on a ruby
|
|
202
|
+
# 3.3.12 process image) hands a :pointer query another field's
|
|
203
|
+
# StructField, and the face reads a non-Pointer: the #456 family's
|
|
204
|
+
# read_bytes-on-Integer, byteslice-nil / force_encoding-nil and
|
|
205
|
+
# wrong-column family. These offsets freeze once here (main
|
|
206
|
+
# Ractor) and every read goes by explicit offset; get_pointer
|
|
207
|
+
# wraps a fresh FFI::Pointer per read, and the size_t count/int64
|
|
208
|
+
# int_min come from the same memory-op shapes the struct cache
|
|
209
|
+
# dispatched to.
|
|
210
|
+
JSON_TAPE_OFFSET = JsonTape.members.to_h do |member|
|
|
211
|
+
[member, JsonTape.offset_of(member)]
|
|
212
|
+
end.freeze
|
|
213
|
+
|
|
178
214
|
attach_function :yeptris_parse_json_tape, %i[pointer size_t pointer], :int
|
|
179
215
|
attach_function :yeptris_parse_json_tape_lenient, %i[pointer size_t pointer], :int
|
|
180
216
|
# the columns-lazy law (tape.h): when the interleaved records are
|
|
@@ -293,6 +329,31 @@ module Yeptris
|
|
|
293
329
|
:bools, :pointer, :arena, :pointer
|
|
294
330
|
end
|
|
295
331
|
|
|
332
|
+
# Columnar drain, Ractor boundary (yeptris-ruby#456): ffi's Struct#[]
|
|
333
|
+
# rides a per-layout field cache — a 256-row slot table ON the layout
|
|
334
|
+
# object, written UNSYNCHRONIZED on every lookup (ext/ffi_c/Struct.c
|
|
335
|
+
# struct_field: fieldName store, then field store). Slots are indexed
|
|
336
|
+
# by (symbol bits >> 8) & 0xff, so a layout's field names collide per
|
|
337
|
+
# process (birthday over 256 rows; which pair collides depends on the
|
|
338
|
+
# process's symbol-interning order), and parallel Ractors sharing the
|
|
339
|
+
# class-level layout tear a colliding slot: a reader that matches the
|
|
340
|
+
# torn fieldName receives the OTHER field's StructField — on
|
|
341
|
+
# ValueColumns a :pointer query can receive :count's size_t field,
|
|
342
|
+
# the read_bytes-on-Integer NoMethodError of #456 (seen once: run
|
|
343
|
+
# 47607340219, job Spec on macos-15-intel). The law: NO
|
|
344
|
+
# Struct#[]/#[]= in Ractor-reachable faces. These offsets freeze once
|
|
345
|
+
# here (main Ractor, plain rb_hash_aref lookups — StructLayout#[]
|
|
346
|
+
# never touches the cache), and ValueML.load_all_columns reads every
|
|
347
|
+
# field by explicit offset: get_pointer(offset) wraps the raw address
|
|
348
|
+
# in a fresh FFI::Pointer on EVERY read (a NULL column routes to the
|
|
349
|
+
# NULL singleton, as before), so nothing mutable is shared and no
|
|
350
|
+
# bare Integer can reach read_bytes. Same shape per read as
|
|
351
|
+
# Struct#[] (which also allocates its Pointer per read); the bulk
|
|
352
|
+
# one-call-per-column reads the benchmarks price are untouched.
|
|
353
|
+
VALUE_COLUMNS_OFFSET = ValueColumns.members.to_h do |member|
|
|
354
|
+
[member, ValueColumns.offset_of(member)]
|
|
355
|
+
end.freeze
|
|
356
|
+
|
|
296
357
|
# Marshal 4.8 emission (TODO.restructure/21): the C side converts
|
|
297
358
|
# value records directly into Ruby's wire format; the binding
|
|
298
359
|
# materializes the whole graph with one core-C Marshal.load call
|
|
@@ -339,10 +400,20 @@ module Yeptris
|
|
|
339
400
|
BUILD_TAG = 5
|
|
340
401
|
|
|
341
402
|
# the ABI-pinned shape; the bulk builder packs these bytes
|
|
342
|
-
# directly (12 per entry)
|
|
403
|
+
# directly (12 per entry). Ractor boundary (yeptris-ruby#460): the
|
|
404
|
+
# dump lane never constructs or dereferences this struct — it
|
|
405
|
+
# packs 12-byte entries into ONE String and hands that to
|
|
406
|
+
# yeptris_document_build by reference, so no field-cache lookup
|
|
407
|
+
# exists on the lane. The offsets freeze once at require under the
|
|
408
|
+
# same #456 law anyway, so any future entry-struct consumer reads
|
|
409
|
+
# by explicit offset, never Struct#[] (the layout IS armed: op/len
|
|
410
|
+
# share a cache slot on some ruby builds).
|
|
343
411
|
class BuildEntry < ::FFI::Struct
|
|
344
412
|
layout op: :uint8, style: :uint8, reserved: :uint16, off: :uint32, len: :uint32
|
|
345
413
|
end
|
|
414
|
+
BUILD_ENTRY_OFFSET = BuildEntry.members.to_h do |member|
|
|
415
|
+
[member, BuildEntry.offset_of(member)]
|
|
416
|
+
end.freeze
|
|
346
417
|
attach_function :yeptris_document_build,
|
|
347
418
|
%i[yeptris_document pointer size_t pointer size_t], :int
|
|
348
419
|
# the bulk build's probe (the MARSHAL/MARSHAL_JSON pattern, engine
|
|
@@ -419,11 +490,12 @@ module Yeptris
|
|
|
419
490
|
# except ILP32 armv7, where it is 4). The ffi gem (1.17.4) has no
|
|
420
491
|
# read_size_t, so dispatch on the measured type size: read_uint64
|
|
421
492
|
# on a 4-byte :size_t buffer ran out of bounds on arm-linux (the
|
|
422
|
-
# 0.6.18.1 armv7 smoke, valueml.rb:118).
|
|
493
|
+
# 0.6.18.1 armv7 smoke, valueml.rb:118). `off` reaches INTO a
|
|
494
|
+
# struct (the #456 boundary reads use it for ValueColumns members).
|
|
423
495
|
SIZE_T_WIDTH = ::FFI.type_size(:size_t)
|
|
424
496
|
|
|
425
|
-
def self.read_c_size_t(ptr)
|
|
426
|
-
SIZE_T_WIDTH == 8 ? ptr.
|
|
497
|
+
def self.read_c_size_t(ptr, off = 0)
|
|
498
|
+
SIZE_T_WIDTH == 8 ? ptr.get_uint64(off) : ptr.get_uint32(off)
|
|
427
499
|
end
|
|
428
500
|
|
|
429
501
|
module Owned
|
data/lib/yeptris/json/tape.rb
CHANGED
|
@@ -71,7 +71,23 @@ module Yeptris
|
|
|
71
71
|
@tape = tape
|
|
72
72
|
@c_ptr = tape
|
|
73
73
|
@freed = freed
|
|
74
|
-
|
|
74
|
+
# Ractor boundary (#460): the tape struct's field reads go by
|
|
75
|
+
# the FROZEN layout offsets (FFI::JSON_TAPE_OFFSET), never
|
|
76
|
+
# Struct#[] — ffi's per-layout field cache is written
|
|
77
|
+
# unsynchronized by every Ractor sharing the class-level
|
|
78
|
+
# layout; a boot whose tape-field symbols collide hands a
|
|
79
|
+
# :pointer query another field's StructField (read_bytes on an
|
|
80
|
+
# Integer, force_encoding on nil, wrong-column bytes). The
|
|
81
|
+
# memory pointer and the frozen hash are immutable; nothing
|
|
82
|
+
# mutable crosses a Ractor boundary.
|
|
83
|
+
@mem = tape.to_ptr
|
|
84
|
+
@off = ::Yeptris::FFI::JSON_TAPE_OFFSET
|
|
85
|
+
# #460: main-Ractor-only backstop (MRI's finalizer table
|
|
86
|
+
# desyncs under parallel-Ractor define/undefine: the tape pin
|
|
87
|
+
# aborted ruby 3.4.13 with "FL_FINALIZE flag is set, but
|
|
88
|
+
# finalizers are not found"). A tape created inside a Ractor
|
|
89
|
+
# is caller-owned — #free is required.
|
|
90
|
+
Yeptris.define_gc_finalizer(self, self.class.finalize(tape.to_ptr, freed))
|
|
75
91
|
end
|
|
76
92
|
|
|
77
93
|
def self.finalize(ptr, freed)
|
|
@@ -87,15 +103,15 @@ module Yeptris
|
|
|
87
103
|
# record leads).
|
|
88
104
|
def count
|
|
89
105
|
ensure_alive!
|
|
90
|
-
@
|
|
106
|
+
::Yeptris::FFI.read_c_size_t(@mem, @off[:count])
|
|
91
107
|
end
|
|
92
108
|
alias size count
|
|
93
109
|
|
|
94
110
|
# Every record's kind, as symbols (tape.h's record kinds).
|
|
95
111
|
def kinds
|
|
96
112
|
ensure_alive!
|
|
97
|
-
@kinds ||= @
|
|
98
|
-
|
|
113
|
+
@kinds ||= @mem.get_pointer(@off[:kinds]).read_bytes(count).unpack("C*")
|
|
114
|
+
.map { |k| RECORD_KINDS.fetch(k, k) }
|
|
99
115
|
end
|
|
100
116
|
|
|
101
117
|
# The record's source span as [offset, length] into the parsed
|
|
@@ -139,7 +155,7 @@ module Yeptris
|
|
|
139
155
|
return if @freed.flag
|
|
140
156
|
|
|
141
157
|
@freed.flag = true
|
|
142
|
-
|
|
158
|
+
Yeptris.undefine_gc_finalizer(self)
|
|
143
159
|
::Yeptris::FFI.yeptris_tape_free(@tape.to_ptr)
|
|
144
160
|
nil
|
|
145
161
|
end
|
|
@@ -197,6 +213,10 @@ module Yeptris
|
|
|
197
213
|
def initialize(tape)
|
|
198
214
|
@tape = tape
|
|
199
215
|
@c = tape.c_ptr
|
|
216
|
+
# Ractor boundary (#460): frozen-offset reads only — see
|
|
217
|
+
# Tape#initialize; @count comes from the same contract.
|
|
218
|
+
@mem = @c.to_ptr
|
|
219
|
+
@off = ::Yeptris::FFI::JSON_TAPE_OFFSET
|
|
200
220
|
@source = tape.source
|
|
201
221
|
@count = tape.count
|
|
202
222
|
end
|
|
@@ -212,19 +232,19 @@ module Yeptris
|
|
|
212
232
|
# zero-copy: a BINARY String of +count+ bytes.
|
|
213
233
|
def kinds_bytes
|
|
214
234
|
ensure_alive!
|
|
215
|
-
@kinds_bytes ||= @
|
|
235
|
+
@kinds_bytes ||= @mem.get_pointer(@off[:kinds]).read_bytes(@count)
|
|
216
236
|
end
|
|
217
237
|
|
|
218
238
|
# The offsets column's bytes — ONE bulk read: +count+ little-endian u32.
|
|
219
239
|
def offs_bytes
|
|
220
240
|
ensure_alive!
|
|
221
|
-
@offs_bytes ||= @
|
|
241
|
+
@offs_bytes ||= @mem.get_pointer(@off[:offs]).read_bytes(@count * 4)
|
|
222
242
|
end
|
|
223
243
|
|
|
224
244
|
# The lengths column's bytes — ONE bulk read: +count+ little-endian u32.
|
|
225
245
|
def lens_bytes
|
|
226
246
|
ensure_alive!
|
|
227
|
-
@lens_bytes ||= @
|
|
247
|
+
@lens_bytes ||= @mem.get_pointer(@off[:lens]).read_bytes(@count * 4)
|
|
228
248
|
end
|
|
229
249
|
|
|
230
250
|
# The kinds column as the record kind codes (Integer; 0 = :doc
|
|
@@ -248,7 +268,7 @@ module Yeptris
|
|
|
248
268
|
def ints
|
|
249
269
|
@ints ||= begin
|
|
250
270
|
ensure_alive!
|
|
251
|
-
if
|
|
271
|
+
if native_fast_path?
|
|
252
272
|
::Yeptris::Native.tape_ints(@c.to_ptr.address)
|
|
253
273
|
else
|
|
254
274
|
ruby_numbers
|
|
@@ -261,7 +281,7 @@ module Yeptris
|
|
|
261
281
|
def floats
|
|
262
282
|
@floats ||= begin
|
|
263
283
|
ensure_alive!
|
|
264
|
-
if
|
|
284
|
+
if native_fast_path?
|
|
265
285
|
::Yeptris::Native.tape_floats(@c.to_ptr.address)
|
|
266
286
|
else
|
|
267
287
|
ruby_numbers
|
|
@@ -276,7 +296,7 @@ module Yeptris
|
|
|
276
296
|
def strs
|
|
277
297
|
@strs ||= begin
|
|
278
298
|
ensure_alive!
|
|
279
|
-
if
|
|
299
|
+
if native_fast_path?
|
|
280
300
|
::Yeptris::Native.tape_strings(@c.to_ptr.address)
|
|
281
301
|
else
|
|
282
302
|
decode = ::Yeptris::JSON.method(:decode_span)
|
|
@@ -292,6 +312,16 @@ module Yeptris
|
|
|
292
312
|
|
|
293
313
|
private
|
|
294
314
|
|
|
315
|
+
# The native materializer is a C extension that has NOT
|
|
316
|
+
# declared itself Ractor-safe (rb_ext_ractor_safe; its mode
|
|
317
|
+
# globals are process-wide), so calling it from a non-main
|
|
318
|
+
# Ractor raises Ractor::UnsafeError. Inside a Ractor the
|
|
319
|
+
# pure-FFI reads serve instead — the same frozen-offset
|
|
320
|
+
# contract, same results, just slower.
|
|
321
|
+
def native_fast_path?
|
|
322
|
+
NATIVE && ::Yeptris.main_ractor?
|
|
323
|
+
end
|
|
324
|
+
|
|
295
325
|
def ensure_alive!
|
|
296
326
|
return unless @tape.freed?
|
|
297
327
|
|
|
@@ -307,7 +337,7 @@ module Yeptris
|
|
|
307
337
|
::Yeptris::FFI.yeptris_tape_convert(@c, 0, n, ivp, dvp)
|
|
308
338
|
iv = ivp.read_bytes(n * 8).unpack("q<*")
|
|
309
339
|
fv = dvp.read_bytes(n * 8).unpack("E*")
|
|
310
|
-
exact = !@
|
|
340
|
+
exact = !@mem.get_int64(@off[:int_min]).zero?
|
|
311
341
|
ints = []
|
|
312
342
|
floats = []
|
|
313
343
|
kinds.each_with_index do |k, i|
|
|
@@ -333,11 +363,11 @@ module Yeptris
|
|
|
333
363
|
end
|
|
334
364
|
|
|
335
365
|
def offs
|
|
336
|
-
@offs ||= @
|
|
366
|
+
@offs ||= @mem.get_pointer(@off[:offs]).read_bytes(count * 4).unpack("V*")
|
|
337
367
|
end
|
|
338
368
|
|
|
339
369
|
def lens
|
|
340
|
-
@lens ||= @
|
|
370
|
+
@lens ||= @mem.get_pointer(@off[:lens]).read_bytes(count * 4).unpack("V*")
|
|
341
371
|
end
|
|
342
372
|
|
|
343
373
|
# One bulk convert pass over the number spans (the engine's
|
|
@@ -362,7 +392,7 @@ module Yeptris
|
|
|
362
392
|
# any integer text beyond int64: exact Bignum rebuilds from
|
|
363
393
|
# the spans (the JSON.load parity contract, int_min is the
|
|
364
394
|
# engine's materialize-time discovery)
|
|
365
|
-
@exact_ints = @
|
|
395
|
+
@exact_ints = @mem.get_int64(@off[:int_min]) != 0
|
|
366
396
|
end
|
|
367
397
|
|
|
368
398
|
def number(i)
|
data/lib/yeptris/json.rb
CHANGED
|
@@ -179,10 +179,17 @@ module Yeptris
|
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
def walk_tape(src, tape, strict_dup)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
# Ractor boundary (#460): frozen-offset reads only — never
|
|
183
|
+
# Struct#[], whose per-layout field cache tears under parallel
|
|
184
|
+
# Ractors (see FFI::JSON_TAPE_OFFSET). get_pointer wraps a fresh
|
|
185
|
+
# FFI::Pointer per read; the count/int_min memory-op shapes are
|
|
186
|
+
# the ones Struct#[] dispatched to.
|
|
187
|
+
mem = tape.to_ptr
|
|
188
|
+
off = ::Yeptris::FFI::JSON_TAPE_OFFSET
|
|
189
|
+
n = ::Yeptris::FFI.read_c_size_t(mem, off[:count])
|
|
190
|
+
kinds = mem.get_pointer(off[:kinds]).read_bytes(n).unpack("C*")
|
|
191
|
+
offs = mem.get_pointer(off[:offs]).read_bytes(n * 4).unpack("V*")
|
|
192
|
+
lens = mem.get_pointer(off[:lens]).read_bytes(n * 4).unpack("V*")
|
|
186
193
|
# v2: parse records number spans only — ONE bulk convert call
|
|
187
194
|
# materializes them (per-number FFI calls would sink the ladder)
|
|
188
195
|
ivp = ::FFI::MemoryPointer.new(:int64, n, true)
|
|
@@ -193,7 +200,7 @@ module Yeptris
|
|
|
193
200
|
# any integer text beyond int64: every INT rebuilds from its span
|
|
194
201
|
# (exact Bignum; JSON.parse parity) — int_min is set by the
|
|
195
202
|
# convert call above
|
|
196
|
-
exact_ints = !
|
|
203
|
+
exact_ints = !mem.get_int64(off[:int_min]).zero?
|
|
197
204
|
utf8 = src.encoding == Encoding::UTF_8
|
|
198
205
|
|
|
199
206
|
docs = [nil] # record 0 (DOC) pre-consumed — the root's slot
|
|
@@ -297,15 +304,23 @@ module Yeptris
|
|
|
297
304
|
# is the strict-JSON one (no ':sym' scan, no y/n quirk, no
|
|
298
305
|
# dot-required floats). Anchors/aliases/timestamps cannot occur
|
|
299
306
|
# in strict JSON — reaching them is an internal error.
|
|
307
|
+
#
|
|
308
|
+
# Ractor boundary (#460): ValueColumns reads go by the FROZEN
|
|
309
|
+
# layout offsets (FFI::VALUE_COLUMNS_OFFSET), never Struct#[] —
|
|
310
|
+
# this is the same lane #456 fixed in ValueML.load_all_columns;
|
|
311
|
+
# its JSON twin carried the identical racy calls.
|
|
300
312
|
def walk_strict(cols, strict_dup = STRICT_DUPLICATE_KEYS)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
313
|
+
mem = cols.to_ptr
|
|
314
|
+
col_off = ::Yeptris::FFI::VALUE_COLUMNS_OFFSET
|
|
315
|
+
n = ::Yeptris::FFI.read_c_size_t(mem, col_off[:count])
|
|
316
|
+
kinds = mem.get_pointer(col_off[:kinds]).read_bytes(n).unpack("C*")
|
|
317
|
+
ikeys = mem.get_pointer(col_off[:is_keys]).read_bytes(n).unpack("C*")
|
|
318
|
+
bools = mem.get_pointer(col_off[:bools]).read_bytes(n).unpack("C*")
|
|
319
|
+
offs = mem.get_pointer(col_off[:offs]).read_bytes(n * 4).unpack("V*")
|
|
320
|
+
lens = mem.get_pointer(col_off[:lens]).read_bytes(n * 4).unpack("V*")
|
|
321
|
+
pays = mem.get_pointer(col_off[:payloads]).read_bytes(n * 8).unpack("q<*")
|
|
322
|
+
arena_len = ::Yeptris::FFI.read_c_size_t(mem, col_off[:arena_len])
|
|
323
|
+
arena = arena_len.zero? ? +"" : mem.get_pointer(col_off[:arena]).read_bytes(arena_len)
|
|
309
324
|
arena.force_encoding(Encoding::UTF_8)
|
|
310
325
|
|
|
311
326
|
docs = []
|
data/lib/yeptris/plan.rb
CHANGED
|
@@ -87,7 +87,9 @@ module Yeptris
|
|
|
87
87
|
@doc = doc
|
|
88
88
|
@freed = Freed.new(false)
|
|
89
89
|
@cache = {}
|
|
90
|
-
|
|
90
|
+
# #460: main-Ractor-only backstop (MRI's finalizer table
|
|
91
|
+
# desyncs under parallel-Ractor define/undefine).
|
|
92
|
+
Yeptris.define_gc_finalizer(self, self.class.finalize(c_ptr, @freed))
|
|
91
93
|
# the eager str pass (the DOM borrow law): read every str
|
|
92
94
|
# column NOW, while the document is certainly alive
|
|
93
95
|
return unless @doc && plan
|
|
@@ -151,7 +153,7 @@ module Yeptris
|
|
|
151
153
|
return if @freed.flag
|
|
152
154
|
|
|
153
155
|
@freed.flag = true
|
|
154
|
-
|
|
156
|
+
Yeptris.undefine_gc_finalizer(self)
|
|
155
157
|
::Yeptris::FFI.yeptris_plan_result_free(@c_ptr)
|
|
156
158
|
nil
|
|
157
159
|
end
|
data/lib/yeptris/validation.rb
CHANGED
|
@@ -176,7 +176,9 @@ module Yeptris
|
|
|
176
176
|
|
|
177
177
|
@c_ptr = c_ptr
|
|
178
178
|
@freed = Freed.new(:alive)
|
|
179
|
-
|
|
179
|
+
# #460: main-Ractor-only backstop (MRI's finalizer table
|
|
180
|
+
# desyncs under parallel-Ractor define/undefine).
|
|
181
|
+
Yeptris.define_gc_finalizer(self, self.class.finalize(c_ptr)) unless c_ptr.null?
|
|
180
182
|
end
|
|
181
183
|
|
|
182
184
|
# Validates one instance stream against the retained model.
|
|
@@ -201,7 +203,7 @@ module Yeptris
|
|
|
201
203
|
return if @freed.state == :freed
|
|
202
204
|
|
|
203
205
|
@freed.state = :freed
|
|
204
|
-
|
|
206
|
+
Yeptris.undefine_gc_finalizer(self)
|
|
205
207
|
FFI.yeptris_schema_free(@c_ptr)
|
|
206
208
|
end
|
|
207
209
|
|
data/lib/yeptris/valueml.rb
CHANGED
|
@@ -99,6 +99,17 @@ module Yeptris
|
|
|
99
99
|
# call each, and the walk indexes tight arrays (no 7-slot stride).
|
|
100
100
|
# Semantics are IDENTICAL to the record walk — the two bodies are
|
|
101
101
|
# maintained in lockstep; field-access shape is the only difference.
|
|
102
|
+
#
|
|
103
|
+
# Ractor boundary (#456): the reads go by the FROZEN layout offsets
|
|
104
|
+
# (FFI::VALUE_COLUMNS_OFFSET), never Struct#[] — ffi's per-layout
|
|
105
|
+
# field cache is written unsynchronized by every Ractor sharing the
|
|
106
|
+
# class-level layout, and a torn slot handed a :pointer query the
|
|
107
|
+
# :count size_t field (read_bytes on an Integer, run 47607340219).
|
|
108
|
+
# get_pointer(offset) wraps a fresh FFI::Pointer per read, so the
|
|
109
|
+
# read_bytes receiver is structurally a Pointer (a NULL column — the
|
|
110
|
+
# zero-entry drain — routes to the NULL singleton, as before). No
|
|
111
|
+
# mutable state crosses a Ractor boundary here: the only shared
|
|
112
|
+
# objects are the immutable layout and the frozen offsets hash.
|
|
102
113
|
def load_all_columns(yaml, schema: :compat_11)
|
|
103
114
|
yaml = Yeptris.read_input(yaml)
|
|
104
115
|
yaml = yaml.to_s
|
|
@@ -111,15 +122,19 @@ module Yeptris
|
|
|
111
122
|
raise ParseError, FFI.last_error_message if st != FFI::OK
|
|
112
123
|
|
|
113
124
|
begin
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
mem = cols.to_ptr
|
|
126
|
+
col_off = FFI::VALUE_COLUMNS_OFFSET
|
|
127
|
+
n = FFI.read_c_size_t(mem)
|
|
128
|
+
kinds = mem.get_pointer(col_off[:kinds]).read_bytes(n).unpack("C*")
|
|
129
|
+
tags = mem.get_pointer(col_off[:tags]).read_bytes(n).unpack("C*")
|
|
130
|
+
ikeys = mem.get_pointer(col_off[:is_keys]).read_bytes(n).unpack("C*")
|
|
131
|
+
bools = mem.get_pointer(col_off[:bools]).read_bytes(n).unpack("C*")
|
|
132
|
+
offs = mem.get_pointer(col_off[:offs]).read_bytes(n * 4).unpack("V*")
|
|
133
|
+
lens = mem.get_pointer(col_off[:lens]).read_bytes(n * 4).unpack("V*")
|
|
134
|
+
pays = mem.get_pointer(col_off[:payloads]).read_bytes(n * 8).unpack("q<*")
|
|
135
|
+
arena_bytes = mem.get_pointer(col_off[:arena]).read_bytes(
|
|
136
|
+
FFI.read_c_size_t(mem, col_off[:arena_len])
|
|
137
|
+
)
|
|
123
138
|
arena_bytes.force_encoding(Encoding::UTF_8)
|
|
124
139
|
walk_columns(kinds, tags, ikeys, bools, offs, lens, pays, arena_bytes,
|
|
125
140
|
schema == :compat_11)
|
data/lib/yeptris/yaml.rb
CHANGED
|
@@ -221,8 +221,11 @@ module Yeptris
|
|
|
221
221
|
yaml = Yeptris.read_input(yaml)
|
|
222
222
|
yaml = yaml.to_s
|
|
223
223
|
opts = FFI::ParseOptions.new
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
# Ractor boundary (#460): frozen-offset writes, never Struct#[]=.
|
|
225
|
+
poff = FFI::PARSE_OPTIONS_OFFSET
|
|
226
|
+
omp = opts.to_ptr
|
|
227
|
+
omp.put_int32(poff[:schema], schema == :compat_11 ? FFI::SCHEMA_11_COMPAT : FFI::SCHEMA_12_CORE)
|
|
228
|
+
omp.put_int32(poff[:max_depth], max_depth)
|
|
226
229
|
it = FFI.yeptris_stream_iter_new(yaml, yaml.bytesize, opts)
|
|
227
230
|
doc_p = ::FFI::MemoryPointer.new(:pointer)
|
|
228
231
|
idx_p = ::FFI::MemoryPointer.new(:size_t)
|
data/lib/yeptris.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Yeptris
|
|
4
4
|
# The gem's version lives in the parent namespace's file — the last
|
|
5
5
|
# internal require (yeptris/version) retired with it.
|
|
6
|
-
VERSION = "0.6.107.
|
|
6
|
+
VERSION = "0.6.107.3".freeze
|
|
7
7
|
|
|
8
8
|
# Informational notices are OPT-IN (yeptris-ruby#217): consumers
|
|
9
9
|
# embed yeptris inside CLIs that assert clean stderr, and a
|
|
@@ -56,6 +56,35 @@ module Yeptris
|
|
|
56
56
|
NativeLayout.bundle_feature
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
# Whether the caller runs on the main Ractor. The one predicate for
|
|
60
|
+
# every Ractor-boundary policy (GC finalizers, the native fast
|
|
61
|
+
# paths), so no face re-derives it.
|
|
62
|
+
# @api private
|
|
63
|
+
def self.main_ractor?
|
|
64
|
+
!defined?(::Ractor) || ::Ractor.current.equal?(::Ractor.main)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The GC-backstop finalizer registry (yeptris-ruby#460). MRI's
|
|
68
|
+
# PROCESS-WIDE ObjectSpace finalizer table desynchronizes when
|
|
69
|
+
# define_finalizer/undefine_finalizer run concurrently from
|
|
70
|
+
# non-main Ractors: a later GC aborts with "FL_FINALIZE flag is
|
|
71
|
+
# set, but finalizers are not found" (ruby 3.4.13 CI abort on the
|
|
72
|
+
# #460 tape/build Ractor pins; reproduced by parallel Ractors
|
|
73
|
+
# churning handle create/free). Every C handle below therefore
|
|
74
|
+
# registers and retires its backstop ONLY on the main Ractor. A
|
|
75
|
+
# handle created inside a Ractor is caller-owned: #free is required
|
|
76
|
+
# (the class docs already say so); without it the C block leaks
|
|
77
|
+
# instead of taking the VM down.
|
|
78
|
+
# @api private
|
|
79
|
+
def self.define_gc_finalizer(obj, finalizer)
|
|
80
|
+
ObjectSpace.define_finalizer(obj, finalizer) if main_ractor?
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @api private
|
|
84
|
+
def self.undefine_gc_finalizer(obj)
|
|
85
|
+
ObjectSpace.undefine_finalizer(obj) if main_ractor?
|
|
86
|
+
end
|
|
87
|
+
|
|
59
88
|
autoload :Document, "yeptris/document"
|
|
60
89
|
autoload :Node, "yeptris/node"
|
|
61
90
|
autoload :YAML, "yeptris/yaml"
|