yeptris 0.6.33.1 → 0.6.33.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.adoc +9 -0
- data/ext/yeptris_native/json_ruby.c +43 -11
- data/lib/yeptris/ffi.rb +5 -0
- data/lib/yeptris/json.rb +48 -2
- data/lib/yeptris.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c8387634db975646ba93194c5b420eaee60e63b2c5d1e7e1792820f4466fe63
|
|
4
|
+
data.tar.gz: e57d53e6242a6cd3ba4f176785800a4ac5864cb93bdd79ff838f23f926068531
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 84b3b33511828a97084d720e53dda58d4a8aa64b51993bc48aa76cca773844ce86758d0f41d053abf2849c8e5c77c22a5f9ba06f6f797b96783c966233d699a9
|
|
7
|
+
data.tar.gz: 5499a1cb92292591025abe0a89406fb6ba4a427876cc08d171ad7a554da3cfdebf0d0ba79762f05d6a9e01853082348376c2d5d6125445ceed74218f279181fa
|
data/README.adoc
CHANGED
|
@@ -5,6 +5,15 @@ https://github.com/leptris/yeptris[libyeptris] — the YAML counterpart
|
|
|
5
5
|
of libleptris. Psych-compatible semantics, one shared library, zero
|
|
6
6
|
compilation at install.
|
|
7
7
|
|
|
8
|
+
Part of the yeptris program: *the best (multiple dimensions)
|
|
9
|
+
YAML/JSON parser/builder ever* — conformance, performance,
|
|
10
|
+
safety/hardening, API surfaces, transport correctness, and trust,
|
|
11
|
+
held simultaneously, in C, Ruby, Rust, and JS. This binding is the
|
|
12
|
+
most complete surface: the Psych drop-in namespace, JSON.parse
|
|
13
|
+
parity with the strict duplicate-key contract, CBOR, and ValueML,
|
|
14
|
+
tracking every libyeptris release in lockstep. The achievement
|
|
15
|
+
program lives in the engine's PLAN.md ("The best-ever program").
|
|
16
|
+
|
|
8
17
|
== Install (development)
|
|
9
18
|
|
|
10
19
|
The gem loads a shared `libyeptris` — from `YEPTRIS_LIB_PATH`, a
|
|
@@ -173,9 +173,19 @@ static VALUE jr_object(jr* j) {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
static VALUE jr_object_body(jr* j, VALUE h_pre) {
|
|
176
|
+
/* The pairs staging buffer MUST live in GC-scanned memory: pairs
|
|
177
|
+
* beyond the current one exist only there once the key/val locals
|
|
178
|
+
* are reused, so a malloc'd buffer makes them invisible to the
|
|
179
|
+
* collector — it can free them mid-parse and recycle their slots,
|
|
180
|
+
* and rb_hash_bulk_insert then inserts garbage (yeptris-ruby#279:
|
|
181
|
+
* the arm64-darwin SIGSEGV whose fault address was document text).
|
|
182
|
+
* The stack array IS scanned, so the bulk fast path is bounded at
|
|
183
|
+
* 31 pairs; beyond that the buffered pairs flush with one
|
|
184
|
+
* bulk_insert and the rest of the object rides rb_hash_aset. */
|
|
176
185
|
VALUE pairs[64];
|
|
177
186
|
VALUE* pv = pairs;
|
|
178
187
|
size_t pcap = 64, pn = 0, heap_cap = 0;
|
|
188
|
+
int aset_rest = 0;
|
|
179
189
|
for (;;) {
|
|
180
190
|
jr_ws(j);
|
|
181
191
|
if (j->i >= j->len || j->p[j->i] != '"') { j->err = -2; goto out; }
|
|
@@ -186,7 +196,7 @@ static VALUE jr_object_body(jr* j, VALUE h_pre) {
|
|
|
186
196
|
j->i++;
|
|
187
197
|
VALUE val = jr_value(j);
|
|
188
198
|
if (j->err) goto out;
|
|
189
|
-
if (yep_ins_mode == YEP_INS_ASET || j->strict_dup) {
|
|
199
|
+
if (yep_ins_mode == YEP_INS_ASET || j->strict_dup || aset_rest) {
|
|
190
200
|
VALUE h = h_pre == Qundef ? (h_pre = HASH_NEW_CAPA(8)) : h_pre;
|
|
191
201
|
if (j->strict_dup && !NIL_P(rb_hash_aref(h, key))) {
|
|
192
202
|
j->err = -3;
|
|
@@ -196,15 +206,21 @@ static VALUE jr_object_body(jr* j, VALUE h_pre) {
|
|
|
196
206
|
rb_hash_aset(h, key, val);
|
|
197
207
|
} else {
|
|
198
208
|
if (pn + 2 > pcap) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
209
|
+
/* buffer full: flush what is staged (no heap staging —
|
|
210
|
+
* see the #279 note above); THIS pair and the rest of
|
|
211
|
+
* the object ride aset — no continue here, the
|
|
212
|
+
* delimiter scan below must still run */
|
|
213
|
+
VALUE h = (h_pre == Qundef) ? (h_pre = HASH_NEW_CAPA((long)(pn / 2) + 8)) : h_pre;
|
|
214
|
+
rb_hash_bulk_insert((long)pn, (const VALUE*)pv, h);
|
|
215
|
+
pn = 0;
|
|
216
|
+
aset_rest = 1;
|
|
217
|
+
}
|
|
218
|
+
if (aset_rest) {
|
|
219
|
+
rb_hash_aset(h_pre, key, val);
|
|
220
|
+
} else {
|
|
221
|
+
pv[pn++] = key;
|
|
222
|
+
pv[pn++] = val;
|
|
205
223
|
}
|
|
206
|
-
pv[pn++] = key;
|
|
207
|
-
pv[pn++] = val;
|
|
208
224
|
}
|
|
209
225
|
jr_ws(j);
|
|
210
226
|
if (j->i >= j->len) { j->err = -2; goto out; }
|
|
@@ -351,7 +367,17 @@ double yep_rb_scan_time(const char* p, size_t len, int n) {
|
|
|
351
367
|
VALUE yep_rb_parse_json(const char* p, size_t len, int strict_dup) {
|
|
352
368
|
jr j;
|
|
353
369
|
memset(&j, 0, sizeof(j));
|
|
354
|
-
|
|
370
|
+
/* The parse holds j.p across unbounded allocations, and the GC
|
|
371
|
+
* strategy knobs leave collection ENABLED during the window
|
|
372
|
+
* (arm64's default is none). A compaction moving the source
|
|
373
|
+
* string would dangle every j->p read after the move
|
|
374
|
+
* (yeptris-ruby#279's heap-layout-dependent SIGSEGV class), so
|
|
375
|
+
* the parse runs on a private copy: one memcpy of the input,
|
|
376
|
+
* then no Ruby object backs the cursor. */
|
|
377
|
+
char* own = malloc(len ? len : 1);
|
|
378
|
+
if (own == NULL) rb_raise(rb_eNoMemError, "yeptris native json");
|
|
379
|
+
memcpy(own, p, len);
|
|
380
|
+
j.p = own; j.len = len; j.enc = rb_utf8_encoding();
|
|
355
381
|
j.strict_dup = strict_dup;
|
|
356
382
|
VALUE already = Qtrue;
|
|
357
383
|
if (yep_gc_mode != YEP_GC_NONE) already = rb_gc_disable();
|
|
@@ -359,6 +385,7 @@ VALUE yep_rb_parse_json(const char* p, size_t len, int strict_dup) {
|
|
|
359
385
|
jr_ws(&j);
|
|
360
386
|
if (j.i != len && j.err == 0) j.err = -2;
|
|
361
387
|
free(j.scratch);
|
|
388
|
+
free(own);
|
|
362
389
|
if (already == Qfalse) rb_gc_enable();
|
|
363
390
|
if (yep_gc_mode == YEP_GC_START && j.err == 0) rb_gc_start();
|
|
364
391
|
if (j.err == -1) rb_raise(rb_eNoMemError, "yeptris native json");
|
|
@@ -366,6 +393,11 @@ VALUE yep_rb_parse_json(const char* p, size_t len, int strict_dup) {
|
|
|
366
393
|
rb_raise(rb_path2class("Yeptris::ParseError"), "duplicate key \"%s\" in JSON object",
|
|
367
394
|
RSTRING_PTR(j.dup_key));
|
|
368
395
|
}
|
|
369
|
-
if (j.err != 0)
|
|
396
|
+
if (j.err != 0) {
|
|
397
|
+
/* the tape engine's wording ("not strict JSON at byte N") so
|
|
398
|
+
* consumers can pin one error shape across both routes
|
|
399
|
+
* (yeptris-ruby#279's adjacent note) */
|
|
400
|
+
rb_raise(rb_path2class("Yeptris::ParseError"), "not strict JSON at byte %zu", j.i);
|
|
401
|
+
}
|
|
370
402
|
return v;
|
|
371
403
|
}
|
data/lib/yeptris/ffi.rb
CHANGED
|
@@ -228,12 +228,17 @@ module Yeptris
|
|
|
228
228
|
%i[pointer size_t int int pointer pointer], :int
|
|
229
229
|
attach_function :yeptris_marshal_node,
|
|
230
230
|
%i[yeptris_node pointer pointer], :int
|
|
231
|
+
attach_function :yeptris_marshal_node_ex,
|
|
232
|
+
%i[yeptris_node uint32 pointer pointer], :int
|
|
231
233
|
attach_function :yeptris_marshal_free, [:pointer], :void
|
|
232
234
|
# The bulk child drain (#168's quadratic): O(n) iteration for
|
|
233
235
|
# #each/#each_pair. Engines without it fall back to the per-index
|
|
234
236
|
# walk (correct, quadratic).
|
|
235
237
|
CHILDREN_DRAIN = !(@missing ||= []).include?(:yeptris_node_children)
|
|
236
238
|
MARSHAL = !(@missing ||= []).include?(:yeptris_marshal_node)
|
|
239
|
+
# the strict-dup marshal entry (engine 0.6.34+, yeptris-ruby#278):
|
|
240
|
+
# gates the JSON fallback's C route in STRICT mode
|
|
241
|
+
MARSHAL_STRICT_DUP = !(@missing ||= []).include?(:yeptris_marshal_node_ex)
|
|
237
242
|
|
|
238
243
|
# bulk build (TODO.impl/15 phase D): one call raises a document
|
|
239
244
|
BUILD_SCALAR = 1
|
data/lib/yeptris/json.rb
CHANGED
|
@@ -9,10 +9,13 @@ module Yeptris
|
|
|
9
9
|
# keeps the Psych contract for every input (JSON-shaped included),
|
|
10
10
|
# so the two never drift into each other's semantics.
|
|
11
11
|
#
|
|
12
|
-
# Engines, fastest first (
|
|
12
|
+
# Engines, fastest first (all exact — the parity spec runs against
|
|
13
13
|
# whichever is loaded):
|
|
14
14
|
# 1. the native materializer (fused C scan → VALUE; opt-in build)
|
|
15
|
-
# 2. the
|
|
15
|
+
# 2. the marshal engine (#278): strict-JSON parse + Marshal 4.8
|
|
16
|
+
# emission + ONE core Marshal.load — all C, no per-value Ruby
|
|
17
|
+
# (engine 0.6.34+; the strict flag follows the resolved json gem)
|
|
18
|
+
# 3. the record drain + strict conversion walk (always available)
|
|
16
19
|
module JSON
|
|
17
20
|
class Error < ::Yeptris::Error; end
|
|
18
21
|
class ParseError < Error; end
|
|
@@ -39,9 +42,46 @@ module Yeptris
|
|
|
39
42
|
raise ParseError, e.message
|
|
40
43
|
end
|
|
41
44
|
end
|
|
45
|
+
# yeptris-ruby#278: with no Ruby-version-matched native build the
|
|
46
|
+
# pure-Ruby walk measured 0.11x vs JSON.parse on real documents —
|
|
47
|
+
# the marshal engine keeps the fallback C-side end to end.
|
|
48
|
+
return marshal_engine(source, 0) if ::Yeptris::FFI::MARSHAL_STRICT_DUP
|
|
42
49
|
tape_engine(source)
|
|
43
50
|
end
|
|
44
51
|
|
|
52
|
+
# The marshal engine (#278): yeptris_parse_json gates the strict
|
|
53
|
+
# grammar, yeptris_marshal_node_ex writes the Ruby Marshal 4.8
|
|
54
|
+
# stream (STRICT_DUP_KEYS raising on json 3's default contract),
|
|
55
|
+
# and ONE core Marshal.load materializes the graph. Returns nil
|
|
56
|
+
# when the engine cannot serve the route (caller keeps walking);
|
|
57
|
+
# every parse/dup failure raises ParseError.
|
|
58
|
+
def marshal_engine(source, flags)
|
|
59
|
+
begin
|
|
60
|
+
gate = ::Yeptris::Document.parse_json(source)
|
|
61
|
+
rescue ::Yeptris::ParseError => e
|
|
62
|
+
raise ParseError, e.message
|
|
63
|
+
end
|
|
64
|
+
begin
|
|
65
|
+
out_p = ::FFI::MemoryPointer.new(:pointer)
|
|
66
|
+
olen_p = ::FFI::MemoryPointer.new(:size_t)
|
|
67
|
+
st = ::Yeptris::FFI.yeptris_marshal_node_ex(
|
|
68
|
+
::Yeptris::FFI.yeptris_document_root(gate.c_ptr, 0), flags, out_p, olen_p
|
|
69
|
+
)
|
|
70
|
+
if st != ::Yeptris::FFI::OK
|
|
71
|
+
raise ParseError, ::Yeptris::FFI.last_error_message if st == ::Yeptris::FFI::ERROR_PARSE
|
|
72
|
+
|
|
73
|
+
return nil # UNSUPPORTED: merge keys et al. cannot occur in JSON
|
|
74
|
+
end
|
|
75
|
+
buf = out_p.read_pointer
|
|
76
|
+
data = buf.read_bytes(::Yeptris::FFI.read_c_size_t(olen_p))
|
|
77
|
+
data.force_encoding(Encoding::ASCII_8BIT)
|
|
78
|
+
::Yeptris::FFI.yeptris_marshal_free(buf)
|
|
79
|
+
Marshal.load(data)
|
|
80
|
+
ensure
|
|
81
|
+
gate.free
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
45
85
|
# The tape engine (issue #81): ONE call validates and materializes
|
|
46
86
|
# the record stream; the walk reads four bulk columns and slices
|
|
47
87
|
# strings straight out of the caller's source — no gate document,
|
|
@@ -212,6 +252,12 @@ module Yeptris
|
|
|
212
252
|
raise ParseError, e.message
|
|
213
253
|
end
|
|
214
254
|
begin
|
|
255
|
+
if ::Yeptris::FFI::MARSHAL_STRICT_DUP
|
|
256
|
+
routed = marshal_engine(
|
|
257
|
+
source, STRICT_DUPLICATE_KEYS ? ::Yeptris::FFI::MARSHAL_STRICT_DUP_KEYS : 0
|
|
258
|
+
)
|
|
259
|
+
return routed unless routed.nil?
|
|
260
|
+
end
|
|
215
261
|
cols = ::Yeptris::FFI::ValueColumns.new
|
|
216
262
|
st = ::Yeptris::FFI.yeptris_value_drain_columns(
|
|
217
263
|
source, source.bytesize, ::Yeptris::FFI::SCHEMA_12_CORE, cols
|
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.33.
|
|
6
|
+
VERSION = "0.6.33.2".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
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yeptris
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.33.
|
|
4
|
+
version: 0.6.33.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ffi
|