yeptris 0.6.75.0-x86_64-linux → 0.6.77.0-x86_64-linux

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: 2400a55e5ad87c8bd9cb70432c7c012ae150f3d99c10b3a6a81327bdbae61cd7
4
- data.tar.gz: 7298076f5c37947cc63b8210cb85baad828ac34e65b387c4c44c60425cf5c4a6
3
+ metadata.gz: 6ce6eac589e325cb98ad20e70a880ab3416cf775f6738dd2bbc64673e948c2d7
4
+ data.tar.gz: 99fb624cd627877b30bfcdc457fdbc4b7cf9c928e955713c7e76997e9771e5b7
5
5
  SHA512:
6
- metadata.gz: e7390fd76be58b60fcf334dc23c0c1e8d08c93edd421ae879b6aefc28153080d5361fc397543972fd7870997cca17c2855dcd35844c94d604b58eed98303315c
7
- data.tar.gz: bd14877f66054158719adc8bd65ca7666be79bfaa331ff670b325aaeb6cdb31bab1ba4e272a24c9edc14ed1629cebfb5342ddb8f7e3cc07b9d994e9122004375
6
+ metadata.gz: 85533cb896e1fc504e9055bbcc2c1e1a19b3ba0a46db9b3d583e11d5a844b5151f5d2acca3ecd9fff0d2a6a39215a1905a5ad3f3c0c69ff8c02f4bec59f397b1
7
+ data.tar.gz: 307d74ace69b34186802d12973aab7d326df592bc39580157f4a25f4140751ae00772ac0ffdc4387509a44030fc890e2c7b5e9acd2309367314cffba0aadf00b
@@ -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 75
15
- #define YEPTRIS_VERSION_STRING "0.6.75"
14
+ #define YEPTRIS_VERSION_PATCH 77
15
+ #define YEPTRIS_VERSION_STRING "0.6.77"
16
16
 
17
17
  #ifdef __cplusplus
18
18
  extern "C" {
Binary file
Binary file
Binary file
@@ -27,9 +27,19 @@ Object.class_eval { remove_const(:Psych) } if defined?(::Psych) && !::Psych.equa
27
27
  # face reports the STDLIB version it replaces: ORIGINAL's when psych
28
28
  # was preloaded, else the default-gem spec's version (local lookup —
29
29
  # requiring stdlib psych post-rebind is censored by the header).
30
+ # ORIGINAL is guarded before the read: the ::Psych captured by the
31
+ # rebind can sit WITHOUT a VERSION constant — the windows CI children
32
+ # hit a boot that defines the name first with a bare module (the
33
+ # bundler-setup boot path on the runner), and the blind ORIGINAL
34
+ # read raised NameError at drop-in require time (run 44698420284,
35
+ # psych_compat_spec:111 + psych/version_spec:15). A VERSION-less
36
+ # ORIGINAL reports through the same default-gem spec lookup the
37
+ # not-preloaded path uses — the honest version for the psych the
38
+ # boot had half-formed.
30
39
  unless Yeptris::Psych.const_defined?(:VERSION, false)
31
40
  version =
32
- if Yeptris::Psych.const_defined?(:ORIGINAL, false)
41
+ if Yeptris::Psych.const_defined?(:ORIGINAL, false) &&
42
+ Yeptris::Psych::ORIGINAL.const_defined?(:VERSION)
33
43
  Yeptris::Psych::ORIGINAL::VERSION
34
44
  else
35
45
  spec = begin
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.75.0".freeze
6
+ VERSION = "0.6.77.0".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
data/libyeptris.so CHANGED
Binary file
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(yeptris
6
- VERSION 0.6.75
6
+ VERSION 0.6.77
7
7
  DESCRIPTION "Ultra-fast YAML 1.2 parser, emitter and streamer in C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -954,6 +954,7 @@ static YeptrisDocument cbor_wrap(yep_dom* dom, const void* buf, const yep_alloca
954
954
  d->finish_pool = NULL;
955
955
  d->lazy_tape = NULL; /* field-by-field ctor: no garbage for free */
956
956
  d->lazy_kind = 0;
957
+ d->lazy_input_ascii = 0; /* #1490: CBOR doms keep the gates armed */
957
958
  return (YeptrisDocument)d;
958
959
  }
959
960
 
@@ -1060,7 +1061,8 @@ YEPTRIS_API YeptrisDocument yeptris_cbor_decode(const void* buf, size_t len, uin
1060
1061
  doc->transcoded_len = 0;
1061
1062
  doc->input = (const char*)buf;
1062
1063
  doc->finish_pool = NULL;
1063
- doc->lazy_tape = NULL; /* field-by-field ctor: no garbage for free */
1064
+ doc->lazy_tape = NULL; /* field-by-field ctor: no garbage for free */
1065
+ doc->lazy_input_ascii = 0; /* #1490: CBOR doms keep the gates armed */
1064
1066
  if (status != NULL) {
1065
1067
  *status = YEPTRIS_OK;
1066
1068
  }
@@ -40,6 +40,11 @@ typedef struct yeptris_document {
40
40
  * wait (read-only sharing stays lock-free
41
41
  * once dom is set — every constructor must
42
42
  * yep_mutex_init it, the ctor trap) */
43
+ int lazy_input_ascii; /* #1490: the parse's column fact for the
44
+ * lazy tape, handed to the dom at
45
+ * materialization (parse.c's encoding gate).
46
+ * Every constructor must set it (0 =
47
+ * conservative, like the ctor trap above). */
43
48
  } yeptris_document;
44
49
 
45
50
  /* Node handle: a (document, node-id) pair so nodes stay usable even if
@@ -161,6 +161,15 @@ typedef struct yep_dom {
161
161
  int map_pending_key[YEP_DOM_MAX_DEPTH]; /* per-frame: key seen, value next */
162
162
  uint32_t pending_key_id[YEP_DOM_MAX_DEPTH];
163
163
  uint32_t pending_key;
164
+ /* #1490's emitter column fact, derived at parse: 1 = the encoding
165
+ * gate proved every input byte gate-safe (< 0x80) and no
166
+ * transcode/normalize copy ran, so input-region views are pure
167
+ * ASCII and the emitter's columns are byte counts. The arena region
168
+ * (decoded/copied strings) is NOT covered — the writer still scans
169
+ * it once per run. LAST FIELD ON PURPOSE: the hot fields above keep
170
+ * their layout. Defaults to 0 (conservative: per-span gates) via
171
+ * yep_dom_create's memset; builder/schema routes stay 0. */
172
+ int input_ascii;
164
173
  } yep_dom;
165
174
 
166
175
  /* Decodes to the pointer view callers use (defined after yep_dom).
@@ -130,6 +130,7 @@ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
130
130
  em.w.col = 0;
131
131
  em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
132
132
  em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
133
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
133
134
  em.w.resolver = handle ? ((const yeptris_document*)handle)->dom->resolver : NULL;
134
135
  em.w.sink = NULL;
135
136
  em.w.watermark = 0;
@@ -200,6 +201,7 @@ YEPTRIS_API size_t yeptris_serialize_into_trusted(YeptrisDocument handle,
200
201
  em.w.col = 0;
201
202
  em.w.sv_input = ((const yeptris_document*)handle)->dom->input_base;
202
203
  em.w.sv_arena = ((const yeptris_document*)handle)->dom->str;
204
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
203
205
  em.w.resolver = ((const yeptris_document*)handle)->dom->resolver;
204
206
  em.w.sink = NULL;
205
207
  em.w.watermark = 0;
@@ -269,6 +271,7 @@ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument handle, const yeptris_emi
269
271
  em.w.col = 0;
270
272
  em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
271
273
  em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
274
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
272
275
  em.w.resolver = handle ? ((const yeptris_document*)handle)->dom->resolver : NULL;
273
276
  em.w.sink = NULL;
274
277
  em.w.watermark = 0;
@@ -411,6 +414,7 @@ YEPTRIS_API char* yeptris_serialize_json(YeptrisDocument handle, size_t* len) {
411
414
  em.w.col = 0;
412
415
  em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
413
416
  em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
417
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
414
418
  em.w.resolver = handle ? ((const yeptris_document*)handle)->dom->resolver : NULL;
415
419
  em.w.sink = NULL;
416
420
  em.w.watermark = 0;
@@ -456,6 +460,7 @@ YEPTRIS_API char* yeptris_serialize_json_ex(YeptrisDocument handle, size_t* len,
456
460
  em.w.col = 0;
457
461
  em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
458
462
  em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
463
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
459
464
  em.w.resolver = handle ? ((const yeptris_document*)handle)->dom->resolver : NULL;
460
465
  em.w.sink = NULL;
461
466
  em.w.watermark = 0;
@@ -503,6 +508,7 @@ char* yep_serialize_json_compact(const yeptris_document* doc, size_t* len) {
503
508
  em.w.col = 0;
504
509
  em.w.sv_input = doc->dom->input_base;
505
510
  em.w.sv_arena = doc->dom->str;
511
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
506
512
  em.w.resolver = doc->dom->resolver;
507
513
  em.w.sink = NULL;
508
514
  em.w.watermark = 0;
@@ -552,6 +558,7 @@ char* yep_serialize_json_pretty_ex(const yeptris_document* doc, size_t* len, con
552
558
  em.w.col = 0;
553
559
  em.w.sv_input = doc->dom->input_base;
554
560
  em.w.sv_arena = doc->dom->str;
561
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
555
562
  em.w.resolver = doc->dom->resolver;
556
563
  em.w.sink = NULL;
557
564
  em.w.watermark = 0;
@@ -629,6 +636,7 @@ YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument handle,
629
636
  em.w.col = 0;
630
637
  em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
631
638
  em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
639
+ em.w.doc_ascii = -1; /* #1490: derived once in yep_emit_run */
632
640
  em.w.resolver = handle ? ((const yeptris_document*)handle)->dom->resolver : NULL;
633
641
  em.w.sink = sink;
634
642
  em.w.sink_ctx = ctx;
@@ -60,17 +60,65 @@ static void wr_maybe_flush(yep_writer* w) {
60
60
  /* the write primitives below are writer.h-visible: the marshal reader
61
61
  * (marshal/to_json.c) writes through the same engine (#904 item 5's
62
62
  * move kept ONE writer). */
63
+
64
+ /* The out-of-line gate on the #1490 helpers: inlined, the purity scans
65
+ * bloated every hot caller's frame (the auto-vectorizer spills). MSVC
66
+ * has no GNU attributes — __declspec(noinline) is the same switch
67
+ * (port.h's popcount/ctz branches are the idiom). */
68
+ #if defined(_MSC_VER) && !defined(__clang__)
69
+ #define WR_NOINLINE __declspec(noinline)
70
+ #elif defined(__GNUC__)
71
+ #define WR_NOINLINE __attribute__((noinline))
72
+ #else
73
+ #define WR_NOINLINE
74
+ #endif
75
+
76
+ /* The column is in CHARACTERS (code points) wherever a span carries
77
+ * multi-byte text (#1490: libyaml's emitter->column counts characters);
78
+ * a UTF-8 continuation byte (10xxxxxx) adds nothing. */
79
+ static inline int wr_char_cols(const char* p, uint32_t n) {
80
+ int cols = 0;
81
+ for (uint32_t i = 0; i < n; i++) {
82
+ cols += ((unsigned char)p[i] & 0xC0u) != 0x80u;
83
+ }
84
+ return cols;
85
+ }
86
+
87
+ static void WR_NOINLINE wr_col_update_mb(yep_writer* w, const char* p, uint32_t n);
88
+
63
89
  void wr_col_update(yep_writer* w, const char* p, uint32_t n) {
64
90
  if (w->skip_col) {
65
91
  return; /* the non-pretty JSON lanes never read col (#739) */
66
92
  }
93
+ if (w->doc_ascii == 1) { /* the run's purity fact: bytes are columns */
94
+ for (uint32_t i = n; i > 0; i--) { /* last newline wins */
95
+ if (p[i - 1] == '\n') {
96
+ w->col = (int)(n - i);
97
+ return;
98
+ }
99
+ }
100
+ w->col += (int)n;
101
+ return;
102
+ }
103
+ wr_col_update_mb(w, p, n);
104
+ }
105
+
106
+ /* The dirty-document twin: the same backward pass, OR-riding the
107
+ * bytes' high bits — purity falls out of the scan the newline search
108
+ * already is (no second pass). Out of line ON PURPOSE: inlined into
109
+ * wr_put, the dual loop re-bloated the hot frame and the walk lanes
110
+ * paid it per scalar (the #1490 restoration's measured lesson). */
111
+ static void WR_NOINLINE wr_col_update_mb(yep_writer* w, const char* p, uint32_t n) {
112
+ unsigned hi = 0;
67
113
  for (uint32_t i = n; i > 0; i--) { /* last newline wins */
68
- if (p[i - 1] == '\n') {
69
- w->col = (int)(n - i);
114
+ unsigned char c = (unsigned char)p[i - 1];
115
+ hi |= c;
116
+ if (c == '\n') {
117
+ w->col = (hi & 0x80u) ? wr_char_cols(p + i, n - i) : (int)(n - i);
70
118
  return;
71
119
  }
72
120
  }
73
- w->col += (int)n;
121
+ w->col += (hi & 0x80u) ? wr_char_cols(p, n) : (int)n;
74
122
  }
75
123
 
76
124
  void wr_reserve(yep_writer* w, size_t need);
@@ -199,8 +247,10 @@ void wr_byte(yep_writer* w, char c) {
199
247
  if (!w->skip_col) {
200
248
  if (c == '\n') {
201
249
  w->col = 0;
202
- } else {
250
+ } else if (w->doc_ascii == 1) {
203
251
  w->col++;
252
+ } else {
253
+ w->col += ((unsigned char)c >> 6) != 2u;
204
254
  }
205
255
  }
206
256
  if (w->dry) {
@@ -369,6 +419,57 @@ static void emit_sq(yep_writer* w, const char* p, uint32_t n) {
369
419
  wr_byte(w, '\'');
370
420
  }
371
421
 
422
+ /* 1 iff EVERY byte of [p, p+n) is ASCII (< 0x80): the per-span purity
423
+ * gate for dirty documents (the doc-level fact covers clean ones).
424
+ * SWAR: eight bytes OR'd per step, the high bits inspected once.
425
+ * OUT OF LINE ON PURPOSE: inlined, the auto-vectorizer turned this
426
+ * reduction into a NEON block that dragged ten callee-saved vector
427
+ * registers into every caller's prologue — the fold walks paid the
428
+ * spill/cleanup per scalar (the -6% the lanes caught). A real call per
429
+ * span on the dirty paths is cheaper than the prologue everywhere. */
430
+ static int WR_NOINLINE wr_span_ascii(const char* p, uint32_t n) {
431
+ uint32_t i = 0;
432
+ uint64_t acc = 0;
433
+ for (; i + 8 <= n; i += 8) {
434
+ uint64_t x;
435
+ memcpy(&x, p + i, 8);
436
+ acc |= x;
437
+ }
438
+ for (; i < n; i++) {
439
+ acc |= (unsigned char)p[i];
440
+ }
441
+ return (acc & YEP_SWAR_FLAGS) == 0;
442
+ }
443
+
444
+ /* Both span facts the dirty-document fused arm needs, in ONE pass:
445
+ * ascii (the column gate) and space (the #903 fold-candidate byte —
446
+ * the arm's inertness probe, standing in for its memchr so purity
447
+ * rides the scan the arm already paid for). */
448
+ typedef struct wr_span_scan {
449
+ int ascii;
450
+ int space;
451
+ } wr_span_scan;
452
+
453
+ static wr_span_scan WR_NOINLINE wr_span_facts(const char* p, uint32_t n) {
454
+ uint64_t hi = 0, sp = 0;
455
+ uint32_t i = 0;
456
+ for (; i + 8 <= n; i += 8) {
457
+ uint64_t x;
458
+ memcpy(&x, p + i, 8);
459
+ hi |= x;
460
+ sp |= yep_swar_eq8(x, 0x2020202020202020ull); /* ' ' splat */
461
+ }
462
+ for (; i < n; i++) {
463
+ unsigned char c = (unsigned char)p[i];
464
+ hi |= c;
465
+ sp |= (uint64_t)(c == ' ');
466
+ }
467
+ wr_span_scan f;
468
+ f.ascii = (hi & YEP_SWAR_FLAGS) == 0;
469
+ f.space = sp != 0;
470
+ return f;
471
+ }
472
+
372
473
  /* Block-side width folding (#903): libyaml's plain/single-quoted fold
373
474
  * walk. At an INTERIOR single space (not the value's first or last
374
475
  * byte, no adjacent spaces) with the column past best_width, the break
@@ -392,10 +493,17 @@ static void wr_fold_break(yep_writer* w, int fold_col) {
392
493
  wr_indent(w, fold_col);
393
494
  }
394
495
 
395
- /* The shared walk for a plain body (no doubling to apply). The fold
396
- * decision prices the PENDING run in (it flushes only at a fold): the
397
- * live column at the candidate space is w->col + run — exactly
398
- * libyaml's emitter->column at the same byte. */
496
+ /* The fold walks (#903, dispatched per scalar on the run's purity
497
+ * fact #1490): the fold decision prices the PENDING run in (it flushes
498
+ * only at a fold), so the live column at the candidate space is
499
+ * w->col + run — exactly libyaml's emitter->column at the same byte.
500
+ * An all-ASCII document folds byte-priced (columns ARE byte counts;
501
+ * the loop is the original verbatim); a dirty document rides the
502
+ * character-priced twin. The twins are separate functions ON PURPOSE:
503
+ * one gated body made every caller's frame pay for both loops and the
504
+ * auto-vectorizer's prologue spills (the -6% the lanes caught). On a
505
+ * pure span of a dirty document the dispatch still gates per span
506
+ * (wr_span_ascii) and keeps the byte walk. */
399
507
  static void emit_plain_folded(yep_writer* w, const char* p, uint32_t n, int fold_col) {
400
508
  uint32_t run = 0; /* pending flush span length */
401
509
  uint32_t i = 0;
@@ -418,6 +526,35 @@ static void emit_plain_folded(yep_writer* w, const char* p, uint32_t n, int fold
418
526
  }
419
527
  }
420
528
 
529
+ /* The character-priced twin (#1490): the same walk with the pending
530
+ * run priced in code points (run stays in bytes for the write). Only
531
+ * the dispatch below ever calls it — a document that carried a high
532
+ * byte somewhere. */
533
+ static void emit_plain_folded_mb(yep_writer* w, const char* p, uint32_t n, int fold_col) {
534
+ uint32_t run = 0; /* pending flush span length (bytes) */
535
+ int run_cols = 0; /* the same span in characters */
536
+ uint32_t i = 0;
537
+ while (i < n) {
538
+ if (p[i] == ' ' && i > 0 && i + 1 < n && w->col + run_cols > w->best_width &&
539
+ p[i - 1] != ' ' && p[i + 1] != ' ' && p[i - 1] != '\t' && p[i + 1] != '\t') {
540
+ if (run) {
541
+ wr_put(w, p + i - run, run);
542
+ run = 0;
543
+ run_cols = 0;
544
+ }
545
+ wr_fold_break(w, fold_col);
546
+ i++; /* the fold consumes the space (libyaml: MOVE without WRITE) */
547
+ continue;
548
+ }
549
+ run_cols += ((unsigned char)p[i] & 0xC0u) != 0x80u;
550
+ i++;
551
+ run++;
552
+ }
553
+ if (run) {
554
+ wr_put(w, p + n - run, run);
555
+ }
556
+ }
557
+
421
558
  /* libyaml's single_quoted_allowed predicate (emitter.c analyze):
422
559
  * disabled ONLY by special characters, a space immediately before a
423
560
  * break (space_break), or a break immediately followed by a space
@@ -506,6 +643,65 @@ static void emit_sq_folded(yep_writer* w, const char* p, uint32_t n, int fold_co
506
643
  wr_byte(w, '\'');
507
644
  }
508
645
 
646
+ /* The character-priced twin (#1490) of emit_sq_folded: same law, plus
647
+ * the run reset at every content break. */
648
+ static void emit_sq_folded_mb(yep_writer* w, const char* p, uint32_t n, int fold_col) {
649
+ wr_byte(w, '\'');
650
+ uint32_t run = 0;
651
+ int run_cols = 0;
652
+ uint32_t i = 0;
653
+ int breaks = 0;
654
+ while (i < n) {
655
+ if (p[i] == '\n' || p[i] == '\r') {
656
+ if (run) {
657
+ wr_put(w, p + i - run, run);
658
+ run = 0;
659
+ run_cols = 0;
660
+ }
661
+ if (!breaks && p[i] == '\n') {
662
+ wr_byte(w, '\n');
663
+ }
664
+ wr_byte(w, p[i]);
665
+ breaks = 1;
666
+ i++;
667
+ continue;
668
+ }
669
+ if (breaks) {
670
+ wr_indent(w, fold_col);
671
+ breaks = 0;
672
+ }
673
+ if (p[i] == '\'') {
674
+ if (run) {
675
+ wr_put(w, p + i - run, run);
676
+ run = 0;
677
+ run_cols = 0;
678
+ }
679
+ wr_put(w, "''", 2);
680
+ i++;
681
+ continue;
682
+ }
683
+ if (p[i] == ' ' && i > 0 && i + 1 < n && w->col + run_cols > w->best_width &&
684
+ p[i - 1] != ' ' && p[i + 1] != ' ' && p[i - 1] != '\t' && p[i + 1] != '\t') {
685
+ if (run) {
686
+ wr_put(w, p + i - run, run);
687
+ run = 0;
688
+ run_cols = 0;
689
+ }
690
+ wr_fold_break(w, fold_col);
691
+ i++;
692
+ continue;
693
+ }
694
+ run_cols += ((unsigned char)p[i] & 0xC0u) != 0x80u;
695
+ i++;
696
+ run++;
697
+ }
698
+ if (breaks) {
699
+ wr_indent(w, fold_col);
700
+ } else if (run) {
701
+ wr_put(w, p + n - run, run);
702
+ }
703
+ wr_byte(w, '\'');
704
+ }
509
705
  /* JSON string escapes: \" \\ \b \f \n \r \t and \uXXXX for other
510
706
  * controls; raw UTF-8 passes through (RFC 8259). */
511
707
  void emit_dq_json(yep_writer* w, const char* p, uint32_t n) {
@@ -559,7 +755,10 @@ static void emit_dq_json_raw(yep_writer* w, const char* p, uint32_t n) {
559
755
  size_t total = (size_t)n + 2;
560
756
  w->last = '"';
561
757
  if (!w->skip_col) {
562
- w->col += (int)total;
758
+ /* characters (#1490), gated: an ASCII span's columns are byte
759
+ * counts — the JSON fast path keeps its arithmetic unless a
760
+ * high byte rides */
761
+ w->col += (w->doc_ascii == 1 || wr_span_ascii(p, n)) ? (int)total : 2 + wr_char_cols(p, n);
563
762
  }
564
763
  if (w->dry) {
565
764
  w->len += total;
@@ -1014,6 +1213,25 @@ static void emit_scalar(yep_writer* w, const yep_dnode* n, int parent_col, int a
1014
1213
  wr_put(w, "~", 1);
1015
1214
  break;
1016
1215
  }
1216
+ /* the round-44 twin on the empty-inline spell: an anchor whose
1217
+ * name ends at ':' must never spell line-final — "k: &n:" + EOL
1218
+ * hands the scanner's riding-colon law to the NEXT line, and a
1219
+ * props/flow/block-led follower un-consumes the colon (the r358
1220
+ * artifact: "&4:- \"\": &4: " + "\n&1 ..." died at re-parse,
1221
+ * "mapping values are not allowed in this context" at the
1222
+ * stripped colon). A non-empty inline value already puts a
1223
+ * plain-led byte on the anchor's own line; the explicit-empty
1224
+ * quoted spell gives the empty twin the same follower
1225
+ * ("k: &n: ''"), and round 2 re-spells it byte-identically (the
1226
+ * quoted style is sticky). Non-scalar and block-style twins
1227
+ * keep the round-44 fail in anchor_name_unspellable. */
1228
+ if (n->anchor.len > 0) {
1229
+ yep_view av = wv(w, n->anchor);
1230
+ if (av.len > 0 && av.p[av.len - 1] == ':') {
1231
+ wr_put(w, "''", 2);
1232
+ break;
1233
+ }
1234
+ }
1017
1235
  break; /* an empty plain value emits as nothing (libyaml's null
1018
1236
  rendering, issue #290) */
1019
1237
  case YEP_SC_PLAIN:
@@ -1021,14 +1239,22 @@ static void emit_scalar(yep_writer* w, const yep_dnode* n, int parent_col, int a
1021
1239
  /* #903: block-context width folding; keys never fold
1022
1240
  * (libyaml: allow_breaks = !simple_key_context) and flow
1023
1241
  * members keep the flow walk */
1024
- emit_plain_folded(w, p, len, parent_col + w->indent);
1242
+ if (w->doc_ascii == 1 || wr_span_ascii(p, len)) {
1243
+ emit_plain_folded(w, p, len, parent_col + w->indent);
1244
+ } else {
1245
+ emit_plain_folded_mb(w, p, len, parent_col + w->indent);
1246
+ }
1025
1247
  } else {
1026
1248
  wr_put(w, p, len);
1027
1249
  }
1028
1250
  break;
1029
1251
  case YEP_SC_SQ:
1030
1252
  if (w->block_fold && !as_key && !w->in_flow && len > 0) {
1031
- emit_sq_folded(w, p, len, parent_col + w->indent);
1253
+ if (w->doc_ascii == 1 || wr_span_ascii(p, len)) {
1254
+ emit_sq_folded(w, p, len, parent_col + w->indent);
1255
+ } else {
1256
+ emit_sq_folded_mb(w, p, len, parent_col + w->indent);
1257
+ }
1032
1258
  } else {
1033
1259
  emit_sq(w, p, len);
1034
1260
  }
@@ -1486,6 +1712,27 @@ static void emit_flow(yep_emitter* em, uint32_t id) {
1486
1712
  w->in_flow = saved_flow;
1487
1713
  }
1488
1714
 
1715
+ /* The dirty-document column accounting for the fused member write
1716
+ * (#1490): one wr_char_cols walk per high-byte span, byte arithmetic
1717
+ * otherwise. Out of line so emit_block_map's hot loop keeps main's
1718
+ * exact frame on clean documents (the gated body in the loop cost the
1719
+ * wide lane -3%). */
1720
+ static void WR_NOINLINE wr_fused_cols_mb(yep_writer* w, yep_view kv, yep_view vv, uint32_t f_total,
1721
+ uint32_t f_nl) {
1722
+ int cols = (int)f_total;
1723
+ if (!wr_span_ascii(kv.p, kv.len)) {
1724
+ cols += wr_char_cols(kv.p, kv.len) - (int)kv.len;
1725
+ }
1726
+ if (vv.len > 0 && !wr_span_ascii(vv.p, vv.len)) {
1727
+ cols += wr_char_cols(vv.p, vv.len) - (int)vv.len;
1728
+ }
1729
+ if (f_nl) {
1730
+ w->col = cols - 1; /* the break resets, then the line */
1731
+ } else {
1732
+ w->col += cols;
1733
+ }
1734
+ }
1735
+
1489
1736
  /* Block map: first key at the cursor (the caller placed it at
1490
1737
  * content_col = parent_col+2); following keys on new lines there. */
1491
1738
  static void emit_block_map(yep_emitter* em, uint32_t id, int content_col) {
@@ -1494,6 +1741,9 @@ static void emit_block_map(yep_emitter* em, uint32_t id, int content_col) {
1494
1741
  const yep_dnode* n = yep_dom_node(d, id);
1495
1742
  uint32_t child = n->first_child;
1496
1743
  uint32_t pair = 0;
1744
+ /* #1490: the run's purity fact, cached for the loop (fixed for the
1745
+ * whole run by yep_emit_run; the fused arm only rides clean docs) */
1746
+ const int doc_clean = w->doc_ascii == 1;
1497
1747
  while (child != UINT32_MAX) {
1498
1748
  /* #352: the flat plain member specialist — tiny scalar pairs
1499
1749
  * pay dispatch and props checks, not byte work. Strictly
@@ -1523,10 +1773,14 @@ static void emit_block_map(yep_emitter* em, uint32_t id, int content_col) {
1523
1773
  * live column (the first member: the caller placed the
1524
1774
  * cursor at content_col) */
1525
1775
  int m_start = (pair == 0 || w->last == '\n') ? content_col : w->col;
1526
- /* the empty value's view is {NULL, 0} (wv) — memchr's
1527
- * nonnull contract forbids the probe even at len 0 */
1776
+ /* the empty value's view is {NULL, 0} (wv) — the probe's
1777
+ * nonnull contract forbids the check even at len 0. Clean
1778
+ * documents keep main's exact memchr probe; dirty ones scan
1779
+ * facts instead — the fold-candidate space AND the column
1780
+ * purity (#1490) ride one pass. */
1528
1781
  int fold_inert = !w->block_fold || w->best_width == INT_MAX || vv.p == NULL ||
1529
- memchr(vv.p, ' ', vv.len) == NULL ||
1782
+ (doc_clean ? memchr(vv.p, ' ', vv.len) == NULL
1783
+ : wr_span_facts(vv.p, vv.len).space == 0) ||
1530
1784
  m_start + (int)kv.len + (int)vv.len + 2 <= w->best_width;
1531
1785
  uint32_t f_ind = 0, f_nl = 0, f_total = 0;
1532
1786
  int fused = fold_inert && kv.len > 0 && !key_written_over_limit(w, kn0) &&
@@ -1552,10 +1806,18 @@ static void emit_block_map(yep_emitter* em, uint32_t id, int content_col) {
1552
1806
  }
1553
1807
  if (fused) {
1554
1808
  w->last = vv.len > 0 ? (char)vv.p[vv.len - 1] : ':';
1555
- if (f_nl) {
1556
- w->col = (int)(f_total - 1u); /* the break resets, then the line */
1809
+ /* the column in characters (#1490), gated on the run's
1810
+ * fact: a clean document's member is priced in bytes
1811
+ * (one reservation covers the whole member); a dirty one
1812
+ * walks only its high-byte spans, out of line */
1813
+ if (doc_clean) {
1814
+ if (f_nl) {
1815
+ w->col = (int)(f_total - 1u); /* the break resets, then the line */
1816
+ } else {
1817
+ w->col += (int)f_total;
1818
+ }
1557
1819
  } else {
1558
- w->col += (int)f_total;
1820
+ wr_fused_cols_mb(w, kv, vv, f_total, f_nl);
1559
1821
  }
1560
1822
  if (w->dry) {
1561
1823
  w->len += f_total;
@@ -1992,6 +2254,12 @@ static int emit_json_pair_fused(yep_writer* w, const yep_dnode* kn, const yep_dn
1992
2254
  /* the run-end law reads w->last for the root newline: spell the
1993
2255
  * byte that actually lands last (a digit tail for plain tokens) */
1994
2256
  w->last = (typed && !vquoted && vtl > 0) ? vt[vtl - 1] : '"';
2257
+ if (!w->skip_col && w->doc_ascii != 1) {
2258
+ /* #1490: the pair's col scan is arithmetic (bytes), so a dirty
2259
+ * document declines to the general pair path, whose wr_put
2260
+ * accounting prices characters exactly */
2261
+ return 0;
2262
+ }
1995
2263
  if (!w->skip_col) {
1996
2264
  w->col += (int)total;
1997
2265
  }
@@ -2212,6 +2480,18 @@ static void emit_json_node_p(yep_emitter* em, const yep_dnode* n) {
2212
2480
  size_t yep_emit_run(yep_emitter* em, int dry) {
2213
2481
  yep_writer* w = &em->w;
2214
2482
  const yep_dom* d = em->doc->dom;
2483
+ /* The doc-level purity fact (#1490's gate, hoisted): an all-ASCII
2484
+ * document keeps the byte arithmetic everywhere (the hot loops stay
2485
+ * byte-priced, no per-span scans); a multibyte document arms the
2486
+ * per-span gates. The INPUT half is the parse-side fact (parse.c's
2487
+ * encoding gate — no added pass); the arena half holds decoded and
2488
+ * copied strings, so it still earns one SWAR pass per run — small
2489
+ * by construction (zero-copy views ride the input region). Derived
2490
+ * once, shared by the dry and wet passes. */
2491
+ if (w->doc_ascii < 0) {
2492
+ w->doc_ascii = d->input_ascii &&
2493
+ (d->str == NULL || d->str_len == 0 || wr_span_ascii(d->str, d->str_len));
2494
+ }
2215
2495
  w->dry = dry;
2216
2496
  w->len = 0;
2217
2497
  w->reserve = 0;
@@ -85,6 +85,16 @@ typedef struct yep_writer {
85
85
  const struct yep_resolver* resolver; /* the document's implicit-typing
86
86
  family (NULL = core12): the INT arm's decode needs the family's
87
87
  own forms (leading-0 is octal in compat, decimal in core) */
88
+ int doc_ascii; /* #1490's span-purity gate, hoisted to the document.
89
+ LAST FIELD ON PURPOSE: the hot fields above keep
90
+ main's exact offsets and cache-line layout. 1 =
91
+ every byte of both DOM regions (input + arena) is
92
+ ASCII, so columns are byte counts everywhere and
93
+ every column site keeps the original arithmetic;
94
+ 0 = the document carried a high byte, so each site
95
+ gates per span (wr_span_ascii); -1 = not yet
96
+ computed (yep_emit_run derives it once, shared
97
+ dry/wet) */
88
98
  } yep_writer;
89
99
 
90
100
  typedef struct yep_emitter {
@@ -609,6 +609,9 @@ YEPTRIS_API YeptrisStatus yeptris_json_from_marshal(const char* m, size_t m_len,
609
609
  * block-indents, but the writer stays fully
610
610
  * initialized */
611
611
  w->block_fold = 0;
612
+ w->doc_ascii = 0; /* no DOM regions to derive the fact from: the
613
+ * per-span purity gates stay armed (the memset's
614
+ * 0 already means "dirty: gate per span") */
612
615
 
613
616
  mj_ctx c;
614
617
  memset(&c, 0, sizeof(c));
@@ -82,6 +82,7 @@ yep_dom* yep_doc_dom(yeptris_document* doc) {
82
82
  yep_dom* dom = yep_dom_create(doc->sys);
83
83
  if (dom != NULL) {
84
84
  dom->resolver = resolver_for_schema(doc->schema);
85
+ dom->input_ascii = doc->lazy_input_ascii; /* #1490 */
85
86
  }
86
87
  if (dom != NULL && dom_from_ytape(dom, t) == 0) {
87
88
  doc->dom = dom;
@@ -99,6 +100,9 @@ yep_dom* yep_doc_dom(yeptris_document* doc) {
99
100
  } else {
100
101
  yeptris_json_tape* t = (yeptris_json_tape*)doc->lazy_tape;
101
102
  yep_dom* dom = yep_dom_create(doc->sys);
103
+ if (dom != NULL) {
104
+ dom->input_ascii = doc->lazy_input_ascii; /* #1490 */
105
+ }
102
106
  if (dom != NULL && dom_from_tape(dom, t) == 0) {
103
107
  doc->dom = dom;
104
108
  yeptris_tape_free(t);
@@ -135,6 +139,7 @@ static YeptrisDocument yep_json_doc_wrap(yep_dom* dom, const char* buf, size_t l
135
139
  doc->sys = sys;
136
140
  doc->lazy_tape = NULL;
137
141
  doc->lazy_kind = 0;
142
+ doc->lazy_input_ascii = 0; /* #1490: the eager dom carries its own fact */
138
143
  doc->schema = YEPTRIS_SCHEMA_12_CORE; /* strict JSON is core by construction */
139
144
  doc->transcoded = NULL;
140
145
  doc->transcoded_len = 0;
@@ -185,6 +190,9 @@ YEPTRIS_API YeptrisDocument yeptris_parse_json(const char* buf, size_t len, Yept
185
190
  if (h != NULL) {
186
191
  ((yeptris_document*)h)->lazy_tape = t;
187
192
  ((yeptris_document*)h)->lazy_kind = 0;
193
+ ((yeptris_document*)h)->lazy_input_ascii =
194
+ 1; /* the fused walk is clean_only: a high byte
195
+ * or tab rejected to the strict route below */
188
196
  return h;
189
197
  }
190
198
  yeptris_tape_free(t); /* wrap failed (memory): below */
@@ -225,6 +233,7 @@ YEPTRIS_API YeptrisDocument yeptris_parse_json(const char* buf, size_t len, Yept
225
233
  }
226
234
  dom->input_base = buf; /* strict JSON is UTF-8 by definition */
227
235
  dom->input_len = len;
236
+ dom->input_ascii = !gated; /* #1490: the gate's clean answer is the fact */
228
237
  yep_dom_prepare_len(dom, len);
229
238
  int brc = yep_dom_build_json(dom, buf, len);
230
239
  if (brc == -1) {
@@ -255,7 +264,7 @@ jfail:
255
264
  static int parse_frontend(const char* buf, size_t len, const yep_allocator* sys, int json_mode,
256
265
  const char** data_out, size_t* data_len_out,
257
266
  unsigned char** transcoded_out, size_t* transcoded_len_out,
258
- int* norm_kept_raw_out, YeptrisStatus* st) {
267
+ int* norm_kept_raw_out, int* data_ascii_out, YeptrisStatus* st) {
259
268
  /* a NULL/0-byte stream is a valid empty input: parse it through a
260
269
  * non-null base so the BOM arithmetic never computes NULL+0
261
270
  * (clang's UBSan flags the zero-offset-null form; gcc's does not —
@@ -269,6 +278,11 @@ static int parse_frontend(const char* buf, size_t len, const yep_allocator* sys,
269
278
  int norm_kept_raw = 0; /* raw NEL/LS/PS survived the quote-aware
270
279
  * walk: the engine route owns the document
271
280
  * (the tape runner predates the cut) */
281
+ int data_ascii = 0; /* #1490: the emitter's column fact — the
282
+ * gate branch's clean answer proves every
283
+ * byte < 0x80 (the writer's byte-priced fast
284
+ * paths may ride); anything else keeps the
285
+ * per-span gates armed */
272
286
 
273
287
  if (json_mode) {
274
288
  /* JSON mode validated grammar and UTF-8 well-formedness at the
@@ -280,6 +294,9 @@ static int parse_frontend(const char* buf, size_t len, const yep_allocator* sys,
280
294
  *transcoded_out = NULL;
281
295
  *transcoded_len_out = 0;
282
296
  *norm_kept_raw_out = 0;
297
+ if (data_ascii_out != NULL) {
298
+ *data_ascii_out = yep_text_active()->gate_scan(data, data_len) == 0;
299
+ }
283
300
  return 0;
284
301
  }
285
302
 
@@ -324,6 +341,8 @@ static int parse_frontend(const char* buf, size_t len, const yep_allocator* sys,
324
341
  *st = YEPTRIS_ERROR_ENCODING;
325
342
  return -1;
326
343
  }
344
+ } else {
345
+ data_ascii = 1; /* every byte gate-safe: pure ASCII (#1490) */
327
346
  }
328
347
  }
329
348
 
@@ -347,11 +366,18 @@ static int parse_frontend(const char* buf, size_t len, const yep_allocator* sys,
347
366
  }
348
367
  }
349
368
 
369
+ if (transcoded != NULL) {
370
+ data_ascii = 0; /* a transcode or normalize copy rode: the
371
+ * copied bytes are not gate-proven */
372
+ }
350
373
  *data_out = data;
351
374
  *data_len_out = data_len;
352
375
  *transcoded_out = transcoded;
353
376
  *transcoded_len_out = transcoded_len;
354
377
  *norm_kept_raw_out = norm_kept_raw;
378
+ if (data_ascii_out != NULL) {
379
+ *data_ascii_out = data_ascii;
380
+ }
355
381
  return 0;
356
382
  }
357
383
 
@@ -378,7 +404,7 @@ YeptrisStatus yep_parse_events(const char* buf, size_t len, YeptrisSchema schema
378
404
  int norm_kept_raw = 0;
379
405
  YeptrisStatus st = YEPTRIS_OK;
380
406
  if (parse_frontend(buf, len, sys, 0, &data, &data_len, &transcoded, &transcoded_len,
381
- &norm_kept_raw, &st) != 0) {
407
+ &norm_kept_raw, NULL, &st) != 0) {
382
408
  return st;
383
409
  }
384
410
  yep_engine* eng = yep_engine_create(sys);
@@ -464,8 +490,9 @@ static YeptrisDocument parse_impl(const char* buf, size_t len, const YeptrisPars
464
490
  * finish pool and transcoded */
465
491
  size_t nblen = 0;
466
492
 
493
+ int data_ascii = 0;
467
494
  if (parse_frontend(buf, len, sys, json_mode, &data, &data_len, &transcoded, &transcoded_len,
468
- &norm_kept_raw, &st) != 0) {
495
+ &norm_kept_raw, &data_ascii, &st) != 0) {
469
496
  goto fail;
470
497
  }
471
498
 
@@ -512,6 +539,7 @@ static YeptrisDocument parse_impl(const char* buf, size_t len, const YeptrisPars
512
539
  * after, every scalar was arena-copied (found 2026-09-10). */
513
540
  dom->input_len = data_len;
514
541
  dom->input_base = transcoded ? (const char*)transcoded : buf;
542
+ dom->input_ascii = data_ascii; /* #1490: the emitter's column fact */
515
543
  yep_dom_prepare_len(dom, data_len);
516
544
  }
517
545
  if (!json_mode) {
@@ -648,6 +676,9 @@ static YeptrisDocument parse_impl(const char* buf, size_t len, const YeptrisPars
648
676
  st = YEPTRIS_ERROR_MEMORY;
649
677
  goto fail;
650
678
  }
679
+ doc->lazy_input_ascii = 0; /* field-by-field ctor (#1490): set below
680
+ * for the lazy tape (the eager dom carries
681
+ * its own fact) */
651
682
  yep_mutex_init(&doc->lazy_mu);
652
683
  doc->sys = sys;
653
684
  doc->schema = (opts != NULL && opts->schema != YEPTRIS_SCHEMA_12_CORE) ? opts->schema
@@ -704,6 +735,7 @@ static YeptrisDocument parse_impl(const char* buf, size_t len, const YeptrisPars
704
735
  doc->dom = NULL;
705
736
  doc->lazy_tape = heap_tape;
706
737
  doc->lazy_kind = 1;
738
+ doc->lazy_input_ascii = data_ascii; /* #1490: for the dom build */
707
739
  } else {
708
740
  doc->dom = dom;
709
741
  }
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.75.0
4
+ version: 0.6.77.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-18 00:00:00.000000000 Z
11
+ date: 2026-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi