yeptris 0.6.65.0-arm-linux-eabihf → 0.6.66.0-arm-linux-eabihf
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/ext/yeptris_native/version.h +2 -2
- data/lib/yeptris/ffi.rb +4 -0
- data/lib/yeptris/materializer.rb +29 -7
- data/lib/yeptris/node.rb +1 -1
- data/lib/yeptris/psych/visitors.rb +71 -5
- data/lib/yeptris/psych.rb +177 -88
- data/lib/yeptris/yaml.rb +62 -18
- data/lib/yeptris.rb +1 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +43 -7
- data/vendor/libyeptris/src/yeptris/dom/dom.c +18 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +24 -16
- data/vendor/libyeptris/src/yeptris/emit/writer.c +375 -29
- data/vendor/libyeptris/src/yeptris/emit/writer.h +6 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +362 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +36 -40
- data/vendor/libyeptris/src/yeptris/scan/scan.c +10 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +7 -0
- data/vendor/libyeptris/src/yeptris/tape.c +21 -13
- 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: dd7a22353e3793afe0325d21945a8ca57f363c119ab7ee3b2ea7b87bc9e598b5
|
|
4
|
+
data.tar.gz: 21910ea72c51aa69dfdab20c91b0df947a363cdf73a98645d4348b8274c451b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 446d4615afd15df2819b49b7c0934e4838fc2531958db6c2f10157ffd1dc8d434bac70b032a2a0603fa5bb8a98cc66a9539b69afd5a9c855922e4cd5cdb93ac4
|
|
7
|
+
data.tar.gz: c42411600719f05a3974e965df6154eacc9ca17568977dbfdf7e8b4fc72db080060289ad0a3e69bdb8f49ff95eff18df2982f57359a375e0dde89a411e4e9281
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
#define YEPTRIS_VERSION_MAJOR 0
|
|
13
13
|
#define YEPTRIS_VERSION_MINOR 6
|
|
14
|
-
#define YEPTRIS_VERSION_PATCH
|
|
15
|
-
#define YEPTRIS_VERSION_STRING "0.6.
|
|
14
|
+
#define YEPTRIS_VERSION_PATCH 66
|
|
15
|
+
#define YEPTRIS_VERSION_STRING "0.6.66"
|
|
16
16
|
|
|
17
17
|
#ifdef __cplusplus
|
|
18
18
|
extern "C" {
|
data/lib/yeptris/ffi.rb
CHANGED
|
@@ -288,6 +288,10 @@ module Yeptris
|
|
|
288
288
|
end
|
|
289
289
|
attach_function :yeptris_document_build,
|
|
290
290
|
%i[yeptris_document pointer size_t pointer size_t], :int
|
|
291
|
+
# the bulk build's probe (the MARSHAL/MARSHAL_JSON pattern, engine
|
|
292
|
+
# 0.6.45+): YAMLTree's node-free dump lane (#857) gates on it — an
|
|
293
|
+
# engine older than the bulk build keeps the per-node walk
|
|
294
|
+
BULK_BUILD = !(@missing ||= []).include?(:yeptris_document_build)
|
|
291
295
|
|
|
292
296
|
attach_function :yeptris_serialize, %i[yeptris_document pointer], :pointer
|
|
293
297
|
attach_function :yeptris_serialize_ex,
|
data/lib/yeptris/materializer.rb
CHANGED
|
@@ -249,6 +249,14 @@ module Yeptris
|
|
|
249
249
|
walk(flat, arena)
|
|
250
250
|
end
|
|
251
251
|
|
|
252
|
+
# The compositional seam for hosts that need the records BEFORE the
|
|
253
|
+
# build (the #862 facade gate: one drain feeds the permission check
|
|
254
|
+
# AND the materialization — no per-node FFI, no second parse).
|
|
255
|
+
# Arguments are exactly what Materializer.drain returns.
|
|
256
|
+
def materialize_records(flat, arena)
|
|
257
|
+
walk(flat, arena)
|
|
258
|
+
end
|
|
259
|
+
|
|
252
260
|
private
|
|
253
261
|
|
|
254
262
|
# The stack machine: containers on a stack, a pending-key slot per
|
|
@@ -257,9 +265,10 @@ module Yeptris
|
|
|
257
265
|
# (<<) resolve inline: existing keys win, sequences merge in
|
|
258
266
|
# order — Psych load-time semantics.
|
|
259
267
|
#
|
|
260
|
-
# flat: one Integer per unpack field,
|
|
261
|
-
# 0 type, 1 style, 2 flags, 3 tag_id, 4 line, 5 col,
|
|
262
|
-
# 7
|
|
268
|
+
# flat: one Integer per unpack field, 14 per record (RECORD_UNPACK
|
|
269
|
+
# = C4V10): 0 type, 1 style, 2 flags, 3 tag_id, 4 line, 5 col,
|
|
270
|
+
# 6 end_line, 7 end_col (#179), 8 value_off, 9 value_len,
|
|
271
|
+
# 10 anchor_off, 11 anchor_len, 12 tag_off, 13 tag_len.
|
|
263
272
|
def walk(flat, arena)
|
|
264
273
|
docs = []
|
|
265
274
|
stack = []
|
|
@@ -289,6 +298,14 @@ module Yeptris
|
|
|
289
298
|
v = Materializer.scan_by_tag(
|
|
290
299
|
arena[flat[i + 8], flat[i + 9]], tag_id, (flat[i + 2] & EF_IMPLICIT) != 0
|
|
291
300
|
)
|
|
301
|
+
# !ruby/symbol (#258): the tag TEXT (not the resolver tag_id)
|
|
302
|
+
# decides — psych deserializes the scalar to a Symbol, the
|
|
303
|
+
# same arm the DOM walk carries (Node#scalar_to_ruby)
|
|
304
|
+
tl = flat[i + 13]
|
|
305
|
+
if tl != 0
|
|
306
|
+
t = arena[flat[i + 12], tl]
|
|
307
|
+
v = v.to_sym if t == "!ruby/symbol" || t == "tag:ruby.yaml.org,2002:symbol"
|
|
308
|
+
end
|
|
292
309
|
l = flat[i + 11]
|
|
293
310
|
anchors[arena[flat[i + 10], l]] = v if l != 0
|
|
294
311
|
# place(): the scalar fast path inlined — the overwhelming
|
|
@@ -304,7 +321,7 @@ module Yeptris
|
|
|
304
321
|
else
|
|
305
322
|
pending_key[-1] = nil
|
|
306
323
|
if pending_key_merge[-1]
|
|
307
|
-
merge_into(parent, v)
|
|
324
|
+
Materializer.merge_into(parent, v)
|
|
308
325
|
else
|
|
309
326
|
parent[key] = v
|
|
310
327
|
end
|
|
@@ -331,7 +348,12 @@ module Yeptris
|
|
|
331
348
|
pending_key_merge.push(nil)
|
|
332
349
|
when ALIAS
|
|
333
350
|
name = arena[flat[i + 8], flat[i + 9]]
|
|
334
|
-
|
|
351
|
+
# the engine DOM parse's spelling, with the record's own
|
|
352
|
+
# location — the ONE undefined-anchor phrase every face
|
|
353
|
+
# raises (the facade's AnchorNotDefined lift matches on it)
|
|
354
|
+
raise Yeptris::ParseError,
|
|
355
|
+
"alias references an undefined anchor at line #{flat[i + 4]}, " \
|
|
356
|
+
"column #{flat[i + 5]}: #{name.inspect}" unless anchors.key?(name)
|
|
335
357
|
|
|
336
358
|
place(docs, stack, pending_key, pending_key_merge, anchors[name])
|
|
337
359
|
when MAPPING_END, SEQUENCE_END
|
|
@@ -339,7 +361,7 @@ module Yeptris
|
|
|
339
361
|
pending_key.pop
|
|
340
362
|
pending_key_merge.pop
|
|
341
363
|
target = merge_target.pop
|
|
342
|
-
merge_into(target, done) if target
|
|
364
|
+
Materializer.merge_into(target, done) if target
|
|
343
365
|
when DOCUMENT_START
|
|
344
366
|
# anchors are per-document (the engine memo law; PyYAML's
|
|
345
367
|
# composer resets per document): a later document's alias
|
|
@@ -373,7 +395,7 @@ module Yeptris
|
|
|
373
395
|
key = pending_key.last
|
|
374
396
|
pending_key[-1] = nil
|
|
375
397
|
if pending_key_merge[-1]
|
|
376
|
-
merge_into(parent, obj)
|
|
398
|
+
Materializer.merge_into(parent, obj)
|
|
377
399
|
parent
|
|
378
400
|
else
|
|
379
401
|
parent[key] = obj
|
data/lib/yeptris/node.rb
CHANGED
|
@@ -407,7 +407,7 @@ class Yeptris::Node
|
|
|
407
407
|
return symbolize if symbol? && tag_id == :str
|
|
408
408
|
|
|
409
409
|
# !ruby/symbol (#258): psych deserializes the scalar to a Symbol
|
|
410
|
-
# (both spellings; safety is
|
|
410
|
+
# (both spellings; safety is check_records's permitted_classes gate)
|
|
411
411
|
if tag == "!ruby/symbol" || tag == "tag:ruby.yaml.org,2002:symbol"
|
|
412
412
|
return value.to_s.to_sym
|
|
413
413
|
end
|
|
@@ -12,6 +12,12 @@ module Yeptris
|
|
|
12
12
|
# objects, aliases for repeats, the Encodable protocol, and the
|
|
13
13
|
# !ruby/... tags Psych's own emitter produces.
|
|
14
14
|
class YAMLTree
|
|
15
|
+
# The chevron KEY tag the bulk lane stores: the full core URI
|
|
16
|
+
# the engine's tag writer renders as !!str (the verbatim
|
|
17
|
+
# shorthand would emit as a LOCAL tag — writer.c's regression).
|
|
18
|
+
# One definition, in the writer of the tag bytes (BulkBuilder).
|
|
19
|
+
MERGE_KEY_TAG = ::Yeptris::YAML::BulkBuilder::MERGE_KEY_TAG
|
|
20
|
+
|
|
15
21
|
# stdlib's factory (relaton's db cache calls it): the options
|
|
16
22
|
# reach the engine's emitter — :line_width and :canonical ride
|
|
17
23
|
# yeptris_emit_options (13B), :indentation is accepted for
|
|
@@ -22,23 +28,42 @@ module Yeptris
|
|
|
22
28
|
new(options: options)
|
|
23
29
|
end
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
# force_node: the node walk's escape hatch — the A/B switch the
|
|
32
|
+
# byte-parity specs drive (#857). Hosts never pass it; stdlib's
|
|
33
|
+
# .create(options, emitter) signature is untouched.
|
|
34
|
+
def initialize(schema: nil, options: {}, force_node: false)
|
|
26
35
|
@options = options || {}
|
|
27
36
|
@tree = ::Yeptris::Document.create(schema: schema)
|
|
28
37
|
@names = {} # object_id -> anchor name
|
|
29
38
|
@counter = 0
|
|
39
|
+
@bulk_ok = ::Yeptris::FFI::BULK_BUILD && !force_node
|
|
40
|
+
@force_node = force_node
|
|
30
41
|
end
|
|
31
42
|
|
|
32
43
|
def push(obj)
|
|
33
44
|
@refs = Hash.new(0)
|
|
34
45
|
@refs[obj.object_id] += 1 # the root counts as a reference
|
|
46
|
+
# re-armed per push: the gate walk below clears it for any
|
|
47
|
+
# graph the bulk lane cannot express
|
|
48
|
+
@fast = @bulk_ok && !@force_node
|
|
35
49
|
count_refs(obj, {})
|
|
50
|
+
if @fast
|
|
51
|
+
build_bulk(obj) # the node-free lane (#857): one FFI call, no handles
|
|
52
|
+
return self
|
|
53
|
+
end
|
|
36
54
|
root = visit(obj)
|
|
37
55
|
@tree.set_root(root) if root
|
|
38
56
|
self
|
|
39
57
|
end
|
|
40
58
|
alias_method :<<, :push # stdlib's dump body pushes via <<
|
|
41
59
|
|
|
60
|
+
# Whether push took the node-free lane. False when the graph
|
|
61
|
+
# carries anchor candidates, tagged/object shapes, or the
|
|
62
|
+
# engine predates the bulk build (the capability probe).
|
|
63
|
+
def fast_lane?
|
|
64
|
+
@took_fast == true
|
|
65
|
+
end
|
|
66
|
+
|
|
42
67
|
# stdlib Psych.dump's tail: `visitor.tree.yaml io, options` —
|
|
43
68
|
# the tree wraps the built document; yaml serializes it
|
|
44
69
|
# (string return, or writes + returns the io)
|
|
@@ -139,21 +164,34 @@ module Yeptris
|
|
|
139
164
|
[:new, name]
|
|
140
165
|
end
|
|
141
166
|
|
|
167
|
+
# The reference-count walk doubles as the node-free lane's
|
|
168
|
+
# gate (#857): the graph rides the bulk build only when every
|
|
169
|
+
# value is a plain-data type AND no anchorable object repeats
|
|
170
|
+
# (anchors/aliases are inexpressible in the flat entry stream).
|
|
142
171
|
def count_refs(obj, seen)
|
|
143
172
|
return if seen.key?(obj.object_id)
|
|
144
173
|
|
|
145
174
|
seen[obj.object_id] = true
|
|
146
175
|
case obj
|
|
147
176
|
when Hash
|
|
148
|
-
obj.each_value { |v|
|
|
177
|
+
obj.each_value { |v| bump_ref(v); count_refs(v, seen) }
|
|
149
178
|
when Array
|
|
150
|
-
obj.each { |v|
|
|
179
|
+
obj.each { |v| bump_ref(v); count_refs(v, seen) }
|
|
151
180
|
when Struct
|
|
181
|
+
@fast = false # !ruby/struct tag
|
|
152
182
|
obj.each_pair { |_k, v| @refs[v.object_id] += 1; count_refs(v, seen) }
|
|
153
183
|
when Set
|
|
184
|
+
@fast = false # !ruby/set tag
|
|
154
185
|
obj.each { |v| @refs[v.object_id] += 1; count_refs(v, seen) }
|
|
155
|
-
when ::String, ::Integer, ::Float, ::Symbol, ::Date, ::Time, true, false, nil
|
|
156
|
-
# immutables
|
|
186
|
+
when ::String, ::Integer, ::Float, ::Symbol, ::Date, ::Time, true, false, nil
|
|
187
|
+
# bulk-lane immutables — except DateTime, which carries the
|
|
188
|
+
# !ruby/object:DateTime tag even when unshared (the visit
|
|
189
|
+
# dispatch's own DateTime arm)
|
|
190
|
+
@fast = false if obj.is_a?(::DateTime)
|
|
191
|
+
when ::Numeric
|
|
192
|
+
# BigDecimal & co: visit's refuse_dump owns the contract
|
|
193
|
+
# (and its message) — the node walk keeps it
|
|
194
|
+
@fast = false
|
|
157
195
|
else
|
|
158
196
|
unless obj.instance_of?(::Object)
|
|
159
197
|
refuse_dump(obj) unless obj.is_a?(Encodable)
|
|
@@ -170,9 +208,37 @@ module Yeptris
|
|
|
170
208
|
coder.each { |_k, v| @refs[v.object_id] += 1; count_refs(v, seen) }
|
|
171
209
|
end
|
|
172
210
|
end
|
|
211
|
+
@fast = false # bare Object and Encodable: the node walk owns them
|
|
173
212
|
end
|
|
174
213
|
end
|
|
175
214
|
|
|
215
|
+
# A SECOND occurrence forces the node walk when the object's
|
|
216
|
+
# visit arm anchors (Hash/Array and the timestamp family —
|
|
217
|
+
# anchored_scalar). Plain scalars never anchor (the stdlib
|
|
218
|
+
# law), so shared strings, numbers, bools and nils stay on the
|
|
219
|
+
# bulk lane.
|
|
220
|
+
def bump_ref(v)
|
|
221
|
+
@refs[v.object_id] += 1
|
|
222
|
+
return unless @refs[v.object_id] == 2
|
|
223
|
+
|
|
224
|
+
@fast = false unless v.is_a?(::String) || v.is_a?(::Symbol) ||
|
|
225
|
+
v.is_a?(::Integer) || v.is_a?(::Float) ||
|
|
226
|
+
v.equal?(true) || v.equal?(false) || v.nil?
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def build_bulk(obj)
|
|
230
|
+
# The node-free lane (#857): the SAME flat entry stream the
|
|
231
|
+
# neutral face's BulkBuilder feeds yeptris_document_build —
|
|
232
|
+
# one FFI call raises the document, zero node handles, zero
|
|
233
|
+
# anchor bookkeeping (a graph that needed any would have
|
|
234
|
+
# taken the node walk above). Merge keys carry the FULL core
|
|
235
|
+
# URI: the engine's tag writer spells !!str from it (the
|
|
236
|
+
# verbatim shorthand would emit as a LOCAL tag — the
|
|
237
|
+
# writer.c chevron-key regression).
|
|
238
|
+
::Yeptris::YAML::BulkBuilder.build_into(@tree, obj, MERGE_KEY_TAG)
|
|
239
|
+
@took_fast = true
|
|
240
|
+
end
|
|
241
|
+
|
|
176
242
|
def refuse_dump(obj)
|
|
177
243
|
raise ::Yeptris::DumpError,
|
|
178
244
|
"cannot dump #{obj.class}: include Yeptris::Psych::Encodable and implement encode_with(coder)"
|
data/lib/yeptris/psych.rb
CHANGED
|
@@ -209,23 +209,61 @@ module Yeptris
|
|
|
209
209
|
def safe_load(yaml, permitted_classes: [::Date, ::Time], aliases: false,
|
|
210
210
|
symbolize_names: false, **)
|
|
211
211
|
# ONE read at the boundary (read_input): IO-like input must be
|
|
212
|
-
# consumed once — the string rides
|
|
212
|
+
# consumed once — the string rides every lane below
|
|
213
213
|
source = ::Yeptris.read_input(yaml)
|
|
214
214
|
begin
|
|
215
|
-
|
|
216
|
-
return nil if doc.nil? # the legal empty stream
|
|
217
|
-
|
|
218
|
-
res = force_utf8_scalars(walk_safe(doc.root(0), permitted_classes, aliases, source))
|
|
215
|
+
res = safe_load_source(source, permitted_classes, aliases)
|
|
219
216
|
res = deep_symbolize_keys(res) if symbolize_names
|
|
220
217
|
res
|
|
221
218
|
rescue ::Yeptris::ParseError => e
|
|
222
|
-
doc&.free unless doc&.freed?
|
|
223
219
|
translate_parse_error(e)
|
|
224
|
-
ensure
|
|
225
|
-
doc&.free
|
|
226
220
|
end
|
|
227
221
|
end
|
|
228
222
|
|
|
223
|
+
# The drain-lane dispatcher (#862). The gate walk IS the facade's
|
|
224
|
+
# parse cost — per-node FFI reads paid twice (check + to_ruby).
|
|
225
|
+
# Two byte facts retire it for clean sources: the parser cannot
|
|
226
|
+
# build an alias without a `*` byte, cannot build an explicit tag
|
|
227
|
+
# without a `!` byte — and the marshal builder refuses timestamps
|
|
228
|
+
# and merge keys, so its SUCCESS proves the gate could not have
|
|
229
|
+
# raised: ONE C call materializes the whole graph (the same lane
|
|
230
|
+
# Yeptris::YAML rides). A refusal (timestamps, merge keys, quoted
|
|
231
|
+
# symbols) or a gate byte drops onto the records lane — one
|
|
232
|
+
# recorder drain feeds BOTH the permission check (over the flat
|
|
233
|
+
# record array, pure Ruby) and the build.
|
|
234
|
+
def safe_load_source(source, permitted, aliases_enabled)
|
|
235
|
+
res =
|
|
236
|
+
if ::Yeptris::FFI::MARSHAL && !source.include?("*") &&
|
|
237
|
+
!source.include?("!") && ValueML.marshal_lane_ok?(source)
|
|
238
|
+
docs = ValueML.load_all_marshal(source, schema: :compat_11, mode: :all)
|
|
239
|
+
# nil = the marshal lane refused (its refusal IS the gate
|
|
240
|
+
# probe): the records lane judges. An empty stream marshals
|
|
241
|
+
# as [nil] — the first document, exactly the legal-empty nil.
|
|
242
|
+
docs.nil? ? records_lane(source, permitted, aliases_enabled)
|
|
243
|
+
: (docs.empty? ? nil : docs.first)
|
|
244
|
+
else
|
|
245
|
+
records_lane(source, permitted, aliases_enabled)
|
|
246
|
+
end
|
|
247
|
+
# The Unicode re-tag (#135) provably does nothing for an
|
|
248
|
+
# ASCII-only source: no scalar can carry a non-ASCII byte, so
|
|
249
|
+
# no BINARY string can pass the valid-UTF-8 probe — the whole
|
|
250
|
+
# result-tree walk is skipped.
|
|
251
|
+
return res if res.nil? || source.ascii_only?
|
|
252
|
+
|
|
253
|
+
force_utf8_scalars(res)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# The gated lane: ONE recorder drain, the permission check over
|
|
257
|
+
# the flat record array (no per-node FFI), then the record stack
|
|
258
|
+
# machine builds the graph — the same Materializer the direct
|
|
259
|
+
# surface rides.
|
|
260
|
+
def records_lane(source, permitted, aliases_enabled)
|
|
261
|
+
flat, arena = ::Yeptris::Materializer.drain(source, schema: :compat_11)
|
|
262
|
+
check_records(flat, arena, permitted, aliases_enabled)
|
|
263
|
+
docs = ::Yeptris::Materializer.new.materialize_records(flat, arena)
|
|
264
|
+
docs.empty? ? nil : docs.first
|
|
265
|
+
end
|
|
266
|
+
|
|
229
267
|
# A YAML stream is a Unicode character stream: stdlib psych tags
|
|
230
268
|
# non-ASCII scalars UTF-8 even when the input String is BINARY
|
|
231
269
|
# (#135). ASCII-only values keep their (binary) encoding — a
|
|
@@ -374,9 +412,10 @@ module Yeptris
|
|
|
374
412
|
|
|
375
413
|
# The first document's node tree (no Ruby materialization).
|
|
376
414
|
def translate_parse_error(e)
|
|
377
|
-
# yeptris rejects *foo without &foo
|
|
378
|
-
#
|
|
379
|
-
#
|
|
415
|
+
# yeptris rejects *foo without &foo (the DOM parse at parse
|
|
416
|
+
# time; the record walk at resolution — the SAME "undefined
|
|
417
|
+
# anchor" phrase) — surface it as stdlib's class so consumers'
|
|
418
|
+
# rescues keep working
|
|
380
419
|
raise AnchorNotDefined, e.message if e.message.include?("undefined anchor")
|
|
381
420
|
|
|
382
421
|
raise SyntaxError.from_parse_error(e)
|
|
@@ -441,10 +480,12 @@ module Yeptris
|
|
|
441
480
|
options = io
|
|
442
481
|
io = nil
|
|
443
482
|
end
|
|
444
|
-
# scalars take the fast builder;
|
|
445
|
-
#
|
|
446
|
-
#
|
|
447
|
-
#
|
|
483
|
+
# scalars take the fast builder; plain-data containers take it
|
|
484
|
+
# too (the #862 dump cut: ONE bulk build + ONE serialize — the
|
|
485
|
+
# YAMLTree DOM build is per-node FFI and buried the engine's
|
|
486
|
+
# speed on document-tree workloads); EVERYTHING else (custom
|
|
487
|
+
# objects, Struct/Set, DateTime, shared containers) goes
|
|
488
|
+
# through the visitor
|
|
448
489
|
out =
|
|
449
490
|
case obj
|
|
450
491
|
# DateTime < Date in ruby's hierarchy — the fast scalar
|
|
@@ -455,6 +496,16 @@ module Yeptris
|
|
|
455
496
|
when nil, true, false, ::String, ::Integer, ::Float, ::Symbol, ::Date, ::Time
|
|
456
497
|
Yeptris::YAML.dump(obj, header: true, width: options[:line_width],
|
|
457
498
|
canonical: options[:canonical] ? true : false)
|
|
499
|
+
when ::Hash, ::Array
|
|
500
|
+
if plain_graph?(obj, {})
|
|
501
|
+
# merge_tag: the URI the engine's tag writer renders as
|
|
502
|
+
# !!str (the shorthand rides the bulk build's URI escaper)
|
|
503
|
+
Yeptris::YAML.dump(obj, header: true, width: options[:line_width],
|
|
504
|
+
canonical: options[:canonical] ? true : false,
|
|
505
|
+
merge_tag: Yeptris::YAML::BulkBuilder::MERGE_KEY_TAG)
|
|
506
|
+
else
|
|
507
|
+
Visitors::YAMLTree.new(options: options).push(obj).finish
|
|
508
|
+
end
|
|
458
509
|
else
|
|
459
510
|
Visitors::YAMLTree.new(options: options).push(obj).finish
|
|
460
511
|
end
|
|
@@ -466,36 +517,59 @@ module Yeptris
|
|
|
466
517
|
|
|
467
518
|
private
|
|
468
519
|
|
|
469
|
-
#
|
|
470
|
-
#
|
|
471
|
-
#
|
|
472
|
-
#
|
|
473
|
-
#
|
|
474
|
-
#
|
|
475
|
-
#
|
|
476
|
-
#
|
|
477
|
-
#
|
|
478
|
-
#
|
|
479
|
-
#
|
|
480
|
-
#
|
|
481
|
-
#
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
520
|
+
# The bulk lane's admission probe (#862): true when every node is
|
|
521
|
+
# plain data AND no anchorable object repeats — the visitor
|
|
522
|
+
# anchors a repeated Hash/Array (&1/*1, the stdlib law) and a
|
|
523
|
+
# repeated Time/Date alike (visit_Time/visit_Date route through
|
|
524
|
+
# anchored_scalar; test_alias_with_time), the bulk walk would
|
|
525
|
+
# duplicate them instead, so those graphs keep the visitor.
|
|
526
|
+
# Strings/symbols/numbers never anchor (immutable identity), so
|
|
527
|
+
# they are leaves. Keys ride both builders' identical key law
|
|
528
|
+
# (nil → `! ''`, "<<" → !!str, Strings → the visit_String rules,
|
|
529
|
+
# Symbols → :sym, everything else → to_s plain), so only VALUES
|
|
530
|
+
# are probed. Numeric beyond Integer/Float (BigDecimal) and
|
|
531
|
+
# DateTime keep the visitor, matching what the visitor does with
|
|
532
|
+
# them.
|
|
533
|
+
BULK_LEAF = [::String, ::Symbol, ::Integer, ::Float, ::TrueClass,
|
|
534
|
+
::FalseClass, ::NilClass].freeze
|
|
535
|
+
private_constant :BULK_LEAF
|
|
536
|
+
|
|
537
|
+
def plain_graph?(obj, seen)
|
|
538
|
+
case obj
|
|
539
|
+
when ::Hash
|
|
540
|
+
return false if seen.key?(obj.object_id)
|
|
541
|
+
|
|
542
|
+
seen[obj.object_id] = true
|
|
543
|
+
obj.each_value { |v| return false unless plain_graph?(v, seen) }
|
|
544
|
+
true
|
|
545
|
+
when ::Array
|
|
546
|
+
return false if seen.key?(obj.object_id)
|
|
547
|
+
|
|
548
|
+
seen[obj.object_id] = true
|
|
549
|
+
obj.each { |v| return false unless plain_graph?(v, seen) }
|
|
550
|
+
true
|
|
551
|
+
when ::Time, ::Date
|
|
552
|
+
# DateTime < Date: the visitor carries its !ruby/object:DateTime tag
|
|
553
|
+
return false if obj.is_a?(::DateTime)
|
|
554
|
+
# identity-anchored per object (unlike the immutables)
|
|
555
|
+
return false if seen.key?(obj.object_id)
|
|
556
|
+
|
|
557
|
+
seen[obj.object_id] = true
|
|
558
|
+
true
|
|
559
|
+
else
|
|
560
|
+
BULK_LEAF.any? { |k| obj.is_a?(k) }
|
|
494
561
|
end
|
|
495
|
-
check(root, permitted, aliases_enabled) if root
|
|
496
|
-
root.to_ruby
|
|
497
562
|
end
|
|
498
563
|
|
|
564
|
+
# yeptris materializes plain data only — there is nothing
|
|
565
|
+
# unsafe it COULD load. The safety enforcement lives on the
|
|
566
|
+
# drained records (check_records): aliases need opt-in, explicit
|
|
567
|
+
# non-core tags raise DisallowedClass, and a scalar whose
|
|
568
|
+
# RESOLVED typing yields a class outside the permitted set
|
|
569
|
+
# raises too (issue #69: a compat_11 date must not become a
|
|
570
|
+
# Date unless Date is permitted — Psych::DisallowedClass
|
|
571
|
+
# semantics).
|
|
572
|
+
|
|
499
573
|
PERMITTED_BY_DEFAULT = [TrueClass, FalseClass, NilClass, Integer, Float,
|
|
500
574
|
String, Array, Hash].freeze
|
|
501
575
|
|
|
@@ -535,56 +609,71 @@ module Yeptris
|
|
|
535
609
|
end
|
|
536
610
|
end
|
|
537
611
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
612
|
+
# The gate over drained records — the same law as the old
|
|
613
|
+
# per-node DOM walk, read off the flat record array instead of
|
|
614
|
+
# FFI handles: alias records need opt-in; an explicit tag
|
|
615
|
+
# (tag_len != 0, any node kind) follows the core/ruby rules; and
|
|
616
|
+
# a timestamp tag_id resolves through parse_timestamp and rides
|
|
617
|
+
# the permitted set. Records are 14 fields, type first
|
|
618
|
+
# (Materializer::FIELDS; the #179 layout puts end_line/end_col
|
|
619
|
+
# at 6/7, the value at 8/9, the anchor at 10/11 and the tag
|
|
620
|
+
# text at 12/13 — the walk() reads are the SSOT).
|
|
621
|
+
def check_records(flat, arena, permitted, aliases_enabled)
|
|
622
|
+
# The timestamp gate needs the RESOLVED class only when the
|
|
623
|
+
# permitted set cannot absorb both answers (the facade default
|
|
624
|
+
# permits Date AND Time — the resolution is skipped entirely).
|
|
625
|
+
gate_ts = !(permitted.include?(::Date) && permitted.include?(::Time))
|
|
626
|
+
m = ::Yeptris::Materializer
|
|
627
|
+
i = 0
|
|
628
|
+
n = flat.length
|
|
629
|
+
while i < n
|
|
630
|
+
type = flat[i]
|
|
631
|
+
if type == m::ALIAS
|
|
632
|
+
raise AliasesError, "Unknown alias" unless aliases_enabled
|
|
633
|
+
else
|
|
634
|
+
l = flat[i + 13]
|
|
635
|
+
if l != 0
|
|
636
|
+
tag = arena[flat[i + 12], l]
|
|
637
|
+
# the bare non-specific tag (`! ''` — the nil-key form,
|
|
638
|
+
# #300): the DOM face normalized it away (node.tag nil),
|
|
639
|
+
# the record keeps it verbatim — it names no class and is
|
|
640
|
+
# always plain data
|
|
641
|
+
unless tag == "!"
|
|
642
|
+
# both tag spellings pass: the URI form's last segment and
|
|
643
|
+
# the short "!binary" shorthand (#168's cassettes carry it)
|
|
644
|
+
name = tag.split(":").last.sub(/\A!/, "")
|
|
645
|
+
unless CORE_TAGS.include?(name)
|
|
646
|
+
# #258: !ruby/… tags follow psych's ClassLoader rules —
|
|
647
|
+
# the scalar primitives (string/integer/float) coerce
|
|
648
|
+
# through the scanner and are allowed as-is; !ruby/symbol
|
|
649
|
+
# passes exactly when Symbol is in permitted_classes;
|
|
650
|
+
# class-bearing forms (ruby/object:K, ruby/hash:K, …)
|
|
651
|
+
# pass when K is in permitted_classes
|
|
652
|
+
short = ruby_tag_short(tag)
|
|
653
|
+
unless RUBY_TAG_PRIMITIVES.include?(short)
|
|
654
|
+
klass = ruby_tag_class(short)
|
|
655
|
+
raise DisallowedClass, name if klass.nil?
|
|
656
|
+
raise DisallowedClass, name unless permitted.include?(klass)
|
|
657
|
+
end
|
|
658
|
+
end
|
|
560
659
|
end
|
|
561
660
|
end
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (klass == ::Date || klass == ::Time) && !permitted.include?(klass)
|
|
576
|
-
raise DisallowedClass, klass.name
|
|
577
|
-
end
|
|
578
|
-
end
|
|
579
|
-
case node.kind
|
|
580
|
-
when :mapping
|
|
581
|
-
node.each_pair do |k, v|
|
|
582
|
-
check(k, permitted, aliases_enabled)
|
|
583
|
-
check(v, permitted, aliases_enabled)
|
|
661
|
+
# psych's safe law for the timestamp family (#1305): the
|
|
662
|
+
# gate applies to the RESOLVED class, not the tag. A
|
|
663
|
+
# timestamp resolves like psych's scanner — date-only to
|
|
664
|
+
# Date, date+time to Time — via the ONE resolver the
|
|
665
|
+
# materializer itself uses; a malformed timestamp text
|
|
666
|
+
# resolves to String there and psych likewise yields a
|
|
667
|
+
# String (no gate — plain data).
|
|
668
|
+
if gate_ts && type == m::SCALAR && flat[i + 3] == m::TAG_TIMESTAMP
|
|
669
|
+
resolved = m.parse_timestamp(arena[flat[i + 8], flat[i + 9]])
|
|
670
|
+
klass = resolved.class
|
|
671
|
+
if (klass == ::Date || klass == ::Time) && !permitted.include?(klass)
|
|
672
|
+
raise DisallowedClass, klass.name
|
|
673
|
+
end
|
|
584
674
|
end
|
|
585
|
-
when :sequence
|
|
586
|
-
node.each { |e| check(e, permitted, aliases_enabled) }
|
|
587
675
|
end
|
|
676
|
+
i += m::FIELDS
|
|
588
677
|
end
|
|
589
678
|
end
|
|
590
679
|
end
|