yeptris 0.6.61.1-s390x-linux → 0.6.62.2-s390x-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: 323758eb40d052be96f9c7693004051f500ceea27cb24421132b24da32e22193
4
- data.tar.gz: 4166d331a2a7be5df21ddd99cbf7463931f9ed316e60c2ef06e5df96d4fe0e85
3
+ metadata.gz: 27f3416b226da11052e90c71abf1044a8702a7256c95cdae0f7d77c0ec95114f
4
+ data.tar.gz: 50997e3cb181f58b7f34eb9408cbf3367f4677e785cda86df5511f213269d11f
5
5
  SHA512:
6
- metadata.gz: 125c33b26f00fda5b6aee442ba002b43d282d754da827742081bf014c2f1e853c38285a27d26fe74631fda3dda0d0cca19f45e75405aac195097ca3c250d10a8
7
- data.tar.gz: eff64f8c0a2c53e7c5e6fa343fb8067971d838cdd63cb6c78e5f70e4cb2bd0beabb247ff7fe1501a40f978a3c7aaabd0dc15084c326688671cdf534bdd7b21df
6
+ metadata.gz: a5a726ef7db13f8ffa34d8a5f7c9e32842a169d87a59ad5ce176f905ffc7be1d9ce67e97070055136d06aebcc541bf046766d3962fd0d1bc31de8b21d227f79a
7
+ data.tar.gz: 7ed2b037a9def150d0f6c02607052d5c24b5500133e11d5ef3a1fb7471eda50db883e0b9de1c0906919b9bacf9beeb235952647e5ac8dcc6bba7b608e458166f
@@ -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 61
15
- #define YEPTRIS_VERSION_STRING "0.6.61"
14
+ #define YEPTRIS_VERSION_PATCH 62
15
+ #define YEPTRIS_VERSION_STRING "0.6.62"
16
16
 
17
17
  #ifdef __cplusplus
18
18
  extern "C" {
Binary file
@@ -190,8 +190,11 @@ class Yeptris::Document
190
190
  def serialize(canonical: false, best_width: 0, explicit_doc_start: false)
191
191
  ensure_alive!
192
192
  len = ::FFI::MemoryPointer.new(:size_t)
193
+ # any non-zero width builds the opts — negative rides the engine's
194
+ # #1257 clamp (psych's line_width: -1 unwrap), 0/absent rides the
195
+ # engine default (80, folding)
193
196
  ptr =
194
- if canonical || best_width.positive? || explicit_doc_start
197
+ if canonical || !best_width.zero? || explicit_doc_start
195
198
  opts = Yeptris::FFI::EmitOptions.new
196
199
  opts[:size] = Yeptris::FFI::EmitOptions.size
197
200
  opts[:canonical] = canonical ? 1 : 0
data/lib/yeptris/psych.rb CHANGED
@@ -424,12 +424,15 @@ module Yeptris
424
424
 
425
425
  # Arbitrary object graphs through the YAMLTree visitor
426
426
  # (anchors, !ruby/ tags); plain data rides the fast builder.
427
- # options reach the engine's emitter: :line_width folds flow
428
- # collections past the width (the engine default is 80),
429
- # :canonical switches the fixed form; :indentation is accepted
430
- # for Psych parity (the engine's YAML emitter has no indentation
431
- # knob). The audit round-2 finding — width accepted and
432
- # discarded — is closed here and in YAMLTree.create.
427
+ # options reach the engine's emitter: :line_width is psych's
428
+ # fold-column knob — 0/nil rides the engine default (80; with the
429
+ # engine's #1257 flip, block plain/single-quoted scalars fold
430
+ # there too, matching stdlib Psych's stored-file bytes), a
431
+ # negative value is the unwrap (the engine clamps it to
432
+ # never-fold), :canonical switches the fixed form; :indentation
433
+ # is accepted for Psych parity (the engine's YAML emitter has no
434
+ # indentation knob). The audit round-2 finding — width accepted
435
+ # and discarded — is closed here and in YAMLTree.create.
433
436
  def dump(obj, io = nil, options = {})
434
437
  # stdlib's Object#to_yaml calls Psych.dump(self, options) —
435
438
  # the options hash lands in the io slot positionally; treat a
data/lib/yeptris/yaml.rb CHANGED
@@ -294,9 +294,11 @@ module Yeptris
294
294
  # (TODO.impl/11 phase 3). Strings are emitted plain only when the
295
295
  # resolver round-trips them as strings — everything else takes a
296
296
  # quoted style, so dump(load(x)) == x for the scalar types.
297
- # width: the emitter's best_width (the engine wraps flow
298
- # collections after a value when the line exceeds it; 0/nil rides
299
- # the engine default of 80 — emit.h 13B).
297
+ # width: the emitter's best_width. 0/nil rides the engine default
298
+ # (80, folding — flow collections after a value past the width, and
299
+ # with the #1257 flip also block plain/single-quoted scalars, the
300
+ # psych/libyaml stored-file behavior); a negative width is psych's
301
+ # line_width: -1 unwrap (the engine clamps it to never-fold).
300
302
  def dump(obj, canonical: false, header: false, width: nil)
301
303
  BulkBuilder.dump(obj, canonical: canonical, header: header, width: width)
302
304
  end
@@ -412,7 +414,14 @@ module Yeptris
412
414
  blob << "!!str"
413
415
  off[0] += 5
414
416
  elsif k.is_a?(String)
415
- place(k, emit, blob, off, seen)
417
+ # keys ride the explicit-!!str semantics: the 1.1
418
+ # reshape words (y/n/yes/no...) stay BARE like stdlib's
419
+ # key path (leptris/yeptris#1264 — the visitor face has
420
+ # always emitted them bare), so the RESHAPES_SET gate
421
+ # does not apply; the SAFE_WORD fast lane is the
422
+ # positional-safety check alone
423
+ style = k.match?(SAFE_WORD) && !k.end_with?(" ") ? STYLE_PLAIN : STYLE_BY_NAME[string_style(k)]
424
+ scalar(k, style, emit, blob, off)
416
425
  else
417
426
  scalar(k.to_s, STYLE_PLAIN, emit, blob, off)
418
427
  end
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.61.1".freeze
6
+ VERSION = "0.6.62.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
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.61
6
+ VERSION 0.6.62
7
7
  DESCRIPTION "Ultra-fast YAML 1.2 parser, emitter and streamer in C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -37,11 +37,16 @@ typedef struct yeptris_emit_options {
37
37
  int canonical; /* fixed form: flow collections, quoted strings,
38
38
  * typed words, shortest floats; a parse of the
39
39
  * output re-serializes byte-identically */
40
- int best_width; /* 0 = library default (80): flow collections
41
- * wrap after a value when the current line
42
- * exceeds the width (13B); with block_fold
43
- * it is also the fold column for block
44
- * scalars (#903) */
40
+ int best_width; /* (#1257) the fold/wrap column, clamped the
41
+ * way libyaml's emitter init does:
42
+ * `best_width < 0` NEVER wraps (Psych's
43
+ * `line_width: -1` unwrap); `0 <= width <=
44
+ * best_indent*2` snaps to 80; 0 or absent =
45
+ * the library default 80. Drives the flow
46
+ * wrap (13B) and — with folding on (the
47
+ * default, #1257) — the block scalar fold
48
+ * column (#903). Only read when the
49
+ * caller's struct is large enough. */
45
50
  int explicit_doc_start; /* nonzero: every document carries the
46
51
  * leading --- marker (Psych/libyaml's
47
52
  * implicit=false parity). Default 0: a
@@ -54,19 +59,20 @@ typedef struct yeptris_emit_options {
54
59
  * (< 2 or > 9, libyaml's clamp) or 0 = the
55
60
  * library default 2. Only read when the
56
61
  * caller's struct is large enough. */
57
- int block_fold; /* (#903) nonzero: plain and single-quoted
58
- * scalars in block context fold at
59
- * best_width the way libyaml/Psych/PyYAML
60
- * do — at an interior single space past the
61
- * width the break replaces the space and
62
- * the continuation re-indents to
63
- * parent_col + best_indent. Default 0:
64
- * block output is width-invariant (byte-
65
- * identical with releases before the
66
- * option). Keys and flow members never
67
- * fold; canonical/JSON keep their fixed
68
- * forms. Only read when the caller's
69
- * struct is large enough. */
62
+ int block_fold; /* (#903, the #1257 default flip) nonzero:
63
+ * plain and single-quoted scalars in block
64
+ * context fold at best_width the way
65
+ * libyaml/Psych/PyYAML do — at an interior
66
+ * single space past the width the break
67
+ * replaces the space and the continuation
68
+ * re-indents to parent_col + best_indent.
69
+ * DEFAULT ON (a fold default matches
70
+ * Psych's stored-file bytes; an explicit 0
71
+ * unwraps, as does best_width < 0). Keys
72
+ * and flow members never fold;
73
+ * canonical/JSON keep their fixed forms.
74
+ * Only read when the caller's struct is
75
+ * large enough. */
70
76
  } yeptris_emit_options;
71
77
 
72
78
  /* Options-aware entries; opts == NULL selects the fidelity mode
@@ -76,12 +76,25 @@ static inline void yep_stopset_init(yep_stopset* ss, const unsigned char bitmap[
76
76
  * end is the first \n/\r at/after pos (or len); indent the first
77
77
  * byte != ' ' (spaces only — tabs are the caller's rule, as in
78
78
  * yep_scan_line); stop the first block-plain stop byte at/after the
79
- * indent and strictly before end, stop_set=0 when none exists. */
79
+ * indent and strictly before end, stop_set=0 when none exists.
80
+ * stop2 is the SECOND block-plain stop byte at/after indent (same
81
+ * class as stop: \n \r # :), stop2_set=0 when none exists — the
82
+ * value-side side output (TODO.max-perf/03): the pair arm's plain
83
+ * value starts past stop, so its first stop byte is stop2, computed
84
+ * over the same sweep instead of a second pass. flags bit0 mirrors
85
+ * stop2_set (uint32-packed so the struct stays sweep-width); bit1
86
+ * has_high marks any byte >= 0x80 in [pos, end) — the multibyte
87
+ * break-lead law needs the lead probe, so a facts consumer may take
88
+ * a zero-probe fast path only when the span is pure ASCII. */
89
+ #define YEP_FACTS_STOP2 0x1u
90
+ #define YEP_FACTS_HIGH 0x2u
80
91
  typedef struct yep_line_facts {
81
92
  uint32_t end;
82
93
  uint32_t indent;
83
94
  uint32_t stop;
84
95
  uint32_t stop_set;
96
+ uint32_t stop2;
97
+ uint32_t flags;
85
98
  } yep_line_facts;
86
99
 
87
100
  /* The flow-kernel chunk classifier's output (one <=32-byte chunk):
@@ -353,8 +353,8 @@ static void yep_avx2_line_facts(const char* s, size_t len, size_t pos, yep_line_
353
353
  ksp = _mm256_set1_epi8(' '), kco = _mm256_set1_epi8(':'),
354
354
  khash = _mm256_set1_epi8('#');
355
355
  size_t i = pos;
356
- int have_end = 0, have_indent = 0, have_stop = 0;
357
- uint32_t end = 0, indent = 0, stop = 0;
356
+ int have_end = 0, have_indent = 0, have_stop = 0, have_stop2 = 0, has_high = 0;
357
+ uint32_t end = 0, indent = 0, stop = 0, stop2 = 0;
358
358
  for (; i + 32 <= len; i += 32) {
359
359
  if (have_end) {
360
360
  break; /* indent <= end, stop < end: settled or absent */
@@ -374,6 +374,26 @@ static void yep_avx2_line_facts(const char* s, size_t len, size_t pos, yep_line_
374
374
  end = (uint32_t)(i + (size_t)yep_ctz32(br));
375
375
  have_end = 1;
376
376
  }
377
+ if (!has_high) {
378
+ /* any multibyte lead below the break (canon of the
379
+ * facts-consumer fast path: the lead probe rides only on
380
+ * non-ASCII lines). Full chunks test via movemask of the
381
+ * sign bits (the high bit IS the sign); the break chunk's
382
+ * tail (>= end) must not count. */
383
+ if (!have_end) {
384
+ if (_mm256_movemask_epi8(v)) {
385
+ has_high = 1;
386
+ }
387
+ } else {
388
+ uint32_t hlim = (uint32_t)(end - i);
389
+ for (uint32_t k = 0; k < hlim; k++) {
390
+ if ((uint8_t)s[i + k] & 0x80) {
391
+ has_high = 1;
392
+ break;
393
+ }
394
+ }
395
+ }
396
+ }
377
397
  if (!have_stop && have_indent) {
378
398
  uint32_t st = br;
379
399
  st |= (uint32_t)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, kco));
@@ -387,6 +407,27 @@ static void yep_avx2_line_facts(const char* s, size_t len, size_t pos, yep_line_
387
407
  if (at >= from && (!have_end || (uint32_t)(i + at) < end)) {
388
408
  stop = (uint32_t)(i + at);
389
409
  have_stop = 1;
410
+ /* the value-side stop (TODO.max-perf/03): the next
411
+ * stop lane in the same chunk */
412
+ uint32_t rest = st & (st - 1);
413
+ if (rest) {
414
+ uint32_t at2 = (uint32_t)yep_ctz32(rest);
415
+ if (!have_end || (uint32_t)(i + at2) < end) {
416
+ stop2 = (uint32_t)(i + at2);
417
+ have_stop2 = 1;
418
+ }
419
+ }
420
+ }
421
+ }
422
+ } else if (have_stop && !have_stop2 && have_indent) {
423
+ uint32_t st = br;
424
+ st |= (uint32_t)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, kco));
425
+ st |= (uint32_t)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v, khash));
426
+ if (st) {
427
+ uint32_t at = (uint32_t)yep_ctz32(st);
428
+ if (!have_end || (uint32_t)(i + at) < end) {
429
+ stop2 = (uint32_t)(i + at);
430
+ have_stop2 = 1;
390
431
  }
391
432
  }
392
433
  }
@@ -410,11 +451,23 @@ static void yep_avx2_line_facts(const char* s, size_t len, size_t pos, yep_line_
410
451
  stop_set = t.stop_set;
411
452
  }
412
453
  }
454
+ if (!have_stop2) {
455
+ if (!have_end && (t.flags & YEP_FACTS_STOP2)) {
456
+ stop2 = t.stop2;
457
+ have_stop2 = 1;
458
+ }
459
+ }
460
+ has_high |= (t.flags & YEP_FACTS_HIGH) != 0;
461
+ }
462
+ if (!have_stop2) {
463
+ stop2 = end; /* no second stop before the break */
413
464
  }
414
465
  out->end = end;
415
466
  out->indent = indent;
416
467
  out->stop = stop;
417
468
  out->stop_set = have_stop ? 1u : stop_set;
469
+ out->stop2 = stop2;
470
+ out->flags = (uint32_t)((have_stop2 ? YEP_FACTS_STOP2 : 0) | (has_high ? YEP_FACTS_HIGH : 0));
418
471
  }
419
472
 
420
473
  /* The flow-kernel chunk classifier: one 256-bit lane pass -> four
@@ -461,8 +461,8 @@ static void yep_neon_line_facts(const char* s, size_t len, size_t pos, yep_line_
461
461
  const uint8x16_t ksp = vdupq_n_u8(' '), knl = vdupq_n_u8('\n'), kcr = vdupq_n_u8('\r'),
462
462
  kco = vdupq_n_u8(':'), khash = vdupq_n_u8('#');
463
463
  size_t i = pos;
464
- int have_end = 0, have_indent = 0, have_stop = 0;
465
- uint32_t end = 0, indent = 0, stop = 0;
464
+ int have_end = 0, have_indent = 0, have_stop = 0, have_stop2 = 0, has_high = 0;
465
+ uint32_t end = 0, indent = 0, stop = 0, stop2 = 0;
466
466
  for (; i + 16 <= len; i += 16) {
467
467
  if (have_end) {
468
468
  break; /* indent <= end, stop < end: settled or absent */
@@ -490,6 +490,25 @@ static void yep_neon_line_facts(const char* s, size_t len, size_t pos, yep_line_
490
490
  }
491
491
  }
492
492
  }
493
+ if (!has_high) {
494
+ /* any multibyte lead below the break (canon of the
495
+ * facts-consumer fast path: the lead probe rides only on
496
+ * non-ASCII lines). Full chunks test in-vector; the break
497
+ * chunk's tail (>= end) must not count. */
498
+ if (!have_end) {
499
+ if (vmaxvq_u8(vandq_u8(v, vdupq_n_u8(0x80))) != 0) {
500
+ has_high = 1;
501
+ }
502
+ } else {
503
+ size_t hlim = (size_t)(end - i);
504
+ for (size_t k = 0; k < hlim; k++) {
505
+ if ((uint8_t)s[i + k] & 0x80) {
506
+ has_high = 1;
507
+ break;
508
+ }
509
+ }
510
+ }
511
+ }
493
512
  if (!have_stop && have_indent) {
494
513
  uint8x16_t st = vorrq_u8(br, vorrq_u8(vceqq_u8(v, kco), vceqq_u8(v, khash)));
495
514
  if (vmaxvq_u8(st) != 0) {
@@ -503,6 +522,32 @@ static void yep_neon_line_facts(const char* s, size_t len, size_t pos, yep_line_
503
522
  if (c == '\n' || c == '\r' || c == '#' || c == ':') {
504
523
  stop = (uint32_t)(i + k);
505
524
  have_stop = 1;
525
+ /* the value-side stop (TODO.max-perf/03): the
526
+ * next stop byte in the same chunk */
527
+ for (size_t k2 = k + 1; k2 < lim; k2++) {
528
+ char c2 = s[i + k2];
529
+ if (c2 == '\n' || c2 == '\r' || c2 == '#' || c2 == ':') {
530
+ stop2 = (uint32_t)(i + k2);
531
+ have_stop2 = 1;
532
+ break;
533
+ }
534
+ }
535
+ break;
536
+ }
537
+ }
538
+ }
539
+ } else if (have_stop && !have_stop2 && have_indent) {
540
+ uint8x16_t st = vorrq_u8(br, vorrq_u8(vceqq_u8(v, kco), vceqq_u8(v, khash)));
541
+ if (vmaxvq_u8(st) != 0) {
542
+ size_t lim = 16;
543
+ if (have_end && end < (uint32_t)(i + 16)) {
544
+ lim = (size_t)(end - i); /* stop is strictly before end */
545
+ }
546
+ for (size_t k = 0; k < lim; k++) {
547
+ char c = s[i + k];
548
+ if (c == '\n' || c == '\r' || c == '#' || c == ':') {
549
+ stop2 = (uint32_t)(i + k);
550
+ have_stop2 = 1;
506
551
  break;
507
552
  }
508
553
  }
@@ -532,11 +577,23 @@ static void yep_neon_line_facts(const char* s, size_t len, size_t pos, yep_line_
532
577
  stop_set = t.stop_set;
533
578
  }
534
579
  }
580
+ if (!have_stop2) {
581
+ if (!have_end && (t.flags & YEP_FACTS_STOP2)) {
582
+ stop2 = t.stop2;
583
+ have_stop2 = 1;
584
+ }
585
+ }
586
+ has_high |= (t.flags & YEP_FACTS_HIGH) != 0;
587
+ }
588
+ if (!have_stop2) {
589
+ stop2 = end; /* no second stop before the break */
535
590
  }
536
591
  out->end = end;
537
592
  out->indent = indent;
538
593
  out->stop = stop;
539
594
  out->stop_set = have_stop ? 1u : stop_set;
595
+ out->stop2 = stop2;
596
+ out->flags = (uint32_t)((have_stop2 ? YEP_FACTS_STOP2 : 0) | (has_high ? YEP_FACTS_HIGH : 0));
540
597
  }
541
598
 
542
599
  /* The flow-kernel chunk classifier: two 16-byte halves -> four
@@ -202,8 +202,8 @@ int yep_text_line_facts_capped(const char* s, size_t len, size_t pos, size_t cap
202
202
  k_ha = 0x2323232323232323ull;
203
203
  size_t whole = len - pos;
204
204
  size_t n = whole < cap ? whole : cap;
205
- size_t end = n, indent = n, stop = n;
206
- int have_indent = 0, stop_set = 0, have_end = 0;
205
+ size_t end = n, indent = n, stop = n, stop2 = n;
206
+ int have_indent = 0, stop_set = 0, have_end = 0, stop2_set = 0, has_high = 0;
207
207
  size_t i = 0;
208
208
  while (i < n) {
209
209
  size_t avail = n - i < 8 ? n - i : 8;
@@ -227,6 +227,9 @@ int yep_text_line_facts_capped(const char* s, size_t len, size_t pos, size_t cap
227
227
  have_indent = 1;
228
228
  }
229
229
  }
230
+ if (room & x & 0x8080808080808080ull) {
231
+ has_high = 1; /* a multibyte lead rides below the break */
232
+ }
230
233
  if (have_indent && !stop_set) {
231
234
  uint64_t stm = (yep_swar_eq8(x, k_co) | yep_swar_eq8(x, k_ha)) & room;
232
235
  if (stm) {
@@ -234,8 +237,22 @@ int yep_text_line_facts_capped(const char* s, size_t len, size_t pos, size_t cap
234
237
  if (cand >= indent) { /* a stop byte cannot precede the first non-space */
235
238
  stop = cand;
236
239
  stop_set = 1;
240
+ /* the value-side stop (TODO.max-perf/03): the next
241
+ * stop byte in the same chunk, over the same load */
242
+ uint64_t bit = (uint64_t)1 << ((cand - i) * 8);
243
+ uint64_t rest = stm & ~(bit | (bit - 1));
244
+ if (rest) {
245
+ stop2 = i + (size_t)(yep_ctz64(rest) >> 3);
246
+ stop2_set = 1;
247
+ }
237
248
  }
238
249
  }
250
+ } else if (have_indent && stop_set && !stop2_set) {
251
+ uint64_t stm = (yep_swar_eq8(x, k_co) | yep_swar_eq8(x, k_ha)) & room;
252
+ if (stm) {
253
+ stop2 = i + (size_t)(yep_ctz64(stm) >> 3);
254
+ stop2_set = 1;
255
+ }
239
256
  }
240
257
  if (br) {
241
258
  end = i + (size_t)(yep_ctz64(br) >> 3);
@@ -253,10 +270,15 @@ int yep_text_line_facts_capped(const char* s, size_t len, size_t pos, size_t cap
253
270
  if (!stop_set) {
254
271
  stop = end;
255
272
  }
273
+ if (!stop2_set) {
274
+ stop2 = end;
275
+ }
256
276
  out->end = (uint32_t)(pos + end);
257
277
  out->indent = (uint32_t)(pos + indent);
258
278
  out->stop = (uint32_t)(pos + stop);
259
279
  out->stop_set = stop_set;
280
+ out->stop2 = (uint32_t)(pos + stop2);
281
+ out->flags = (uint32_t)((stop2_set ? YEP_FACTS_STOP2 : 0) | (has_high ? YEP_FACTS_HIGH : 0));
260
282
  return 1;
261
283
  }
262
284
 
@@ -3,6 +3,7 @@
3
3
  * Two passes of the ONE writer: dry (exact size), wet (linear writes
4
4
  * into the caller's buffer — zero reallocations by construction). */
5
5
 
6
+ #include <limits.h>
6
7
  #include <stddef.h>
7
8
  #include <stdlib.h>
8
9
  #include <string.h>
@@ -23,12 +24,40 @@ static int opts_canonical(const yeptris_emit_options* opts) {
23
24
  opts->canonical;
24
25
  }
25
26
 
27
+ static int opts_indent(const yeptris_emit_options* opts) {
28
+ /* size-versioned (#903); out of range rides the default (libyaml
29
+ * clamps 2..9 the same way) */
30
+ int ind = 2;
31
+ if (opts != NULL &&
32
+ opts->size >= (uint32_t)(offsetof(yeptris_emit_options, best_indent) + sizeof(int))) {
33
+ ind = opts->best_indent;
34
+ }
35
+ if (ind < 2 || ind > 9) {
36
+ ind = 2;
37
+ }
38
+ return ind;
39
+ }
40
+
26
41
  static int opts_width(const yeptris_emit_options* opts) {
42
+ /* libyaml's emitter-init clamp, spelled per the caller's declared
43
+ * width (#1257): `best_width < 0` means NEVER fold — Psych's
44
+ * `line_width: -1` unwrap, applied to the flow wrap and the block
45
+ * fold alike; `0 <= best_width <= best_indent*2` snaps to 80
46
+ * (libyaml's too-narrow clamp); absent or 0 rides the default 80. */
47
+ if (opts != NULL &&
48
+ opts->size >= (uint32_t)(offsetof(yeptris_emit_options, best_width) + sizeof(int)) &&
49
+ opts->best_width < 0) {
50
+ return INT_MAX;
51
+ }
52
+ int ind = opts_indent(opts);
27
53
  if (opts == NULL ||
28
54
  opts->size < (uint32_t)(offsetof(yeptris_emit_options, best_width) + sizeof(int)) ||
29
- opts->best_width <= 0) {
55
+ opts->best_width == 0) {
30
56
  return 80; /* libyaml best_width parity */
31
57
  }
58
+ if (opts->best_width <= ind * 2) {
59
+ return 80; /* the too-narrow clamp (libyaml: w <= best_indent*2) */
60
+ }
32
61
  return opts->best_width;
33
62
  }
34
63
 
@@ -42,26 +71,15 @@ static int opts_doc_marker(const yeptris_emit_options* opts) {
42
71
  return opts->explicit_doc_start != 0;
43
72
  }
44
73
 
45
- static int opts_indent(const yeptris_emit_options* opts) {
46
- /* size-versioned (#903); out of range rides the default (libyaml
47
- * clamps 2..9 the same way) */
48
- int ind = 2;
49
- if (opts != NULL &&
50
- opts->size >= (uint32_t)(offsetof(yeptris_emit_options, best_indent) + sizeof(int))) {
51
- ind = opts->best_indent;
52
- }
53
- if (ind < 2 || ind > 9) {
54
- ind = 2;
55
- }
56
- return ind;
57
- }
58
-
59
74
  static int opts_block_fold(const yeptris_emit_options* opts) {
60
- /* size-versioned (#903): default off — block output stays
61
- * width-invariant (byte-identical with the pre-option releases) */
75
+ /* size-versioned (#903, the #1257 flip): DEFAULT ON — block output
76
+ * folds at best_width like Psych/libyaml, so a host flipping
77
+ * engines never changes stored bytes by accident. An explicit
78
+ * block_fold = 0 (a caller passing the full struct) still
79
+ * unwraps, as does best_width < 0 (the width clamp). */
62
80
  if (opts == NULL ||
63
81
  opts->size < (uint32_t)(offsetof(yeptris_emit_options, block_fold) + sizeof(int))) {
64
- return 0;
82
+ return 1;
65
83
  }
66
84
  return opts->block_fold != 0;
67
85
  }
@@ -20,6 +20,7 @@
20
20
 
21
21
  #include "../scan/scan.h"
22
22
 
23
+ #include <limits.h>
23
24
  #include <string.h>
24
25
 
25
26
  #include "style.h"
@@ -1332,20 +1333,35 @@ static void emit_block_map(yep_emitter* em, uint32_t id, int content_col) {
1332
1333
  * the exact predicates sc_route consults (no memo touch, so
1333
1334
  * the dry/wet sc_i streams stay aligned). Anything else falls
1334
1335
  * through untouched — parity by construction. block_fold
1335
- * (#903) declines the arm wholesale: the fused write's
1336
- * arithmetic column model has no fold walk, and the general
1337
- * body emits the identical bytes with folding. */
1336
+ * (#903) declines only the members folding can actually
1337
+ * touch (#1257): the fold walk breaks exclusively at an
1338
+ * interior space whose column passes best_width, so a member
1339
+ * is fold-inert — the fused write stays byte-identical —
1340
+ * when folding is off, the width is the unwrap INT_MAX, the
1341
+ * value carries no space at all, or the member line ends
1342
+ * within the width. Fold-possible members fall through to
1343
+ * the general body, which folds. */
1338
1344
  const yep_dnode* kn0 = yep_dom_node(d, child);
1339
1345
  const yep_dnode* vn0 = yep_dom_node(d, kn0->next_sibling);
1340
- if (!w->canonical && !w->json && !w->force_flow && !w->block_fold && vn0 != NULL &&
1341
- kn0->kind == 0 && kn0->style == 1 && kn0->anchor.len == 0 && kn0->tag.len == 0 &&
1342
- kn0->count == 0 && vn0->kind == 0 && vn0->style == 1 && vn0->anchor.len == 0 &&
1343
- vn0->tag.len == 0 && vn0->count == 0) {
1346
+ if (!w->canonical && !w->json && !w->force_flow && vn0 != NULL && kn0->kind == 0 &&
1347
+ kn0->style == 1 && kn0->anchor.len == 0 && kn0->tag.len == 0 && kn0->count == 0 &&
1348
+ vn0->kind == 0 && vn0->style == 1 && vn0->anchor.len == 0 && vn0->tag.len == 0 &&
1349
+ vn0->count == 0) {
1344
1350
  yep_view kv = wv(w, kn0->value);
1345
1351
  yep_view vv = wv(w, vn0->value);
1352
+ /* the member's start column: after a written newline the
1353
+ * cursor rides the indent (content_col); otherwise the
1354
+ * live column (the first member: the caller placed the
1355
+ * cursor at content_col) */
1356
+ int m_start = (pair == 0 || w->last == '\n') ? content_col : w->col;
1357
+ /* the empty value's view is {NULL, 0} (wv) — memchr's
1358
+ * nonnull contract forbids the probe even at len 0 */
1359
+ int fold_inert = !w->block_fold || w->best_width == INT_MAX || vv.p == NULL ||
1360
+ memchr(vv.p, ' ', vv.len) == NULL ||
1361
+ m_start + (int)kv.len + (int)vv.len + 2 <= w->best_width;
1346
1362
  uint32_t f_ind = 0, f_nl = 0, f_total = 0;
1347
- int fused = kv.len > 0 && !key_written_over_limit(w, kn0) && kn0->plain_ok &&
1348
- (vv.len == 0 || vn0->plain_ok);
1363
+ int fused = fold_inert && kv.len > 0 && !key_written_over_limit(w, kn0) &&
1364
+ kn0->plain_ok && (vv.len == 0 || vn0->plain_ok);
1349
1365
  if (fused) {
1350
1366
  /* fused member write: plain-safe spans carry no breaks,
1351
1367
  * so the col scan is arithmetic and one reservation
@@ -486,8 +486,68 @@ static int shape_val_bail(unsigned char c, const char* p, size_t len, size_t at)
486
486
  }
487
487
  }
488
488
 
489
+ /* The plain value span straight from the fused facts — the value-side
490
+ * mirror of shape_key_span (TODO.max-perf/03): the pair's value starts
491
+ * past the key's stop, so its first stop byte is facts stop2 (or the
492
+ * break when no second stop exists), already classified by the same
493
+ * sweep. The terminating law is re-checked exactly as the walking
494
+ * scan would apply it; a non-terminating stop or a high byte (the
495
+ * multibyte lead probe's territory) hands the span to the walk. The
496
+ * LineShape spec pins the two together. */
497
+ static yep_span shape_value_span(const char* p, size_t len, size_t vt, const yep_line_facts* f) {
498
+ yep_span v;
499
+ v.start = (uint32_t)vt;
500
+ v.term = YEP_TERM_EOF;
501
+ /* Long spans only: the walking scan's own tiny gate keeps a short
502
+ * value's scalar byte loop (cheaper than any facts read); below
503
+ * the threshold the fast path fired on shapes whose walk was
504
+ * already optimal and paid the kernel additions on every line
505
+ * (the anchor-heavy ABBA loss). 64 matches the walk's tiny gate. */
506
+ if (!(f->stop_set && f->stop < vt && !(f->flags & YEP_FACTS_HIGH) &&
507
+ (size_t)(f->end - vt) >= 64)) {
508
+ return yep_scan_plain(p, len, vt, 0);
509
+ }
510
+ size_t cand = 0;
511
+ int have = 0;
512
+ if (f->flags & YEP_FACTS_STOP2) {
513
+ if (f->stop2 >= vt) {
514
+ cand = f->stop2;
515
+ have = 1;
516
+ }
517
+ } else if (f->end >= vt) {
518
+ /* no second stop before the break: the first stop byte at or
519
+ * after the value start is the break itself */
520
+ cand = f->end;
521
+ have = 1;
522
+ }
523
+ if (have && cand <= len) {
524
+ if (cand == len) {
525
+ v.end = (uint32_t)len;
526
+ } else {
527
+ unsigned char c = (unsigned char)p[cand];
528
+ if (c == '\n' || c == '\r') {
529
+ v.end = (uint32_t)cand;
530
+ v.term = YEP_TERM_EOL;
531
+ } else if (c == ':' && yep_colon_terminates(p, len, cand, 0)) {
532
+ v.end = (uint32_t)cand;
533
+ v.term = YEP_TERM_COLON;
534
+ } else if (c == '#' && (cand == vt || p[cand - 1] == ' ' || p[cand - 1] == '\t')) {
535
+ v.end = (uint32_t)cand;
536
+ v.term = YEP_TERM_COMMENT;
537
+ } else {
538
+ return yep_scan_plain(p, len, vt, 0); /* non-terminating: walk */
539
+ }
540
+ }
541
+ while (v.end > v.start && (p[v.end - 1] == ' ' || p[v.end - 1] == '\t')) {
542
+ v.end--;
543
+ }
544
+ return v;
545
+ }
546
+ return yep_scan_plain(p, len, vt, 0);
547
+ }
548
+
489
549
  static void shape_value(const char* p, size_t len, const yep_line_info* li, size_t vt,
490
- yep_line_shape* s) {
550
+ const yep_line_facts* f, yep_line_shape* s) {
491
551
  s->val_start = (uint32_t)vt;
492
552
  if (vt >= li->end || p[vt] == '#') { /* '#' here follows a blank by construction */
493
553
  s->val = YEP_LVAL_EMPTY;
@@ -514,7 +574,7 @@ static void shape_value(const char* p, size_t len, const yep_line_info* li, size
514
574
  }
515
575
  if (t < li->end && p[t] != '#' && !shape_val_bail((unsigned char)p[t], p, len, t) &&
516
576
  yep_plain_first_ok((unsigned char)p[t])) {
517
- yep_span v = yep_scan_plain(p, len, t, 0);
577
+ yep_span v = shape_value_span(p, len, t, f);
518
578
  if (v.term != YEP_TERM_COLON && v.end > v.start) {
519
579
  s->val = YEP_LVAL_ANCHOR_PLAIN;
520
580
  s->anchor_end = (uint32_t)a_end;
@@ -527,7 +587,7 @@ static void shape_value(const char* p, size_t len, const yep_line_info* li, size
527
587
  if (shape_val_bail(c, p, len, vt) || !yep_plain_first_ok(c)) {
528
588
  return;
529
589
  }
530
- yep_span v = yep_scan_plain(p, len, vt, 0);
590
+ yep_span v = shape_value_span(p, len, vt, f);
531
591
  if (v.term == YEP_TERM_COLON) {
532
592
  return; /* a second terminating ':' is compact/error territory */
533
593
  }
@@ -591,7 +651,7 @@ void yep_scan_shape_f(const char* p, size_t len, const yep_line_info* li, const
591
651
  }
592
652
  s->kind = YEP_LSHAPE_DASH;
593
653
  s->dash = (uint32_t)t;
594
- shape_value(p, len, li, vt, s);
654
+ shape_value(p, len, li, vt, f, s);
595
655
  return;
596
656
  }
597
657
 
@@ -617,7 +677,7 @@ void yep_scan_shape_f(const char* p, size_t len, const yep_line_info* li, const
617
677
  s->key_start = k.start;
618
678
  s->key_end = k.end;
619
679
  s->colon = (uint32_t)colon;
620
- shape_value(p, len, li, vt, s);
680
+ shape_value(p, len, li, vt, f, s);
621
681
  }
622
682
  }
623
683
  }
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.61.1
4
+ version: 0.6.62.2
5
5
  platform: s390x-linux
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-10 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi