yeptris 0.6.31.2-arm-linux-eabihf → 0.6.33.1-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.
@@ -55,6 +55,13 @@ typedef struct yep_writer {
55
55
  size_t cap;
56
56
  int grow;
57
57
  int oom;
58
+ int in_flow; /* scalars inside flow collections: plain must drop
59
+ ',', '[', ']', '{', '}' — flow terminators */
60
+ int flow_item; /* the NEXT scalar is a flow-SEQ item: a null must
61
+ emit '~' (a bare nothing reads as "[, x]") */
62
+ int unserializable; /* an anchor name that cannot ride raw in flow
63
+ context: the document has no safe spelling —
64
+ serialize fails rather than corrupt */
58
65
  } yep_writer;
59
66
 
60
67
  typedef struct yep_emitter {
@@ -19,6 +19,7 @@
19
19
  #include "../../include/yeptris/values.h"
20
20
  #include "../common/simd_text.h"
21
21
  #include "../dom/dom.h"
22
+ #include "../encoding/encoding.h"
22
23
  #include "../memory/allocator.h"
23
24
  #include "../parse/engine.h"
24
25
  #include "../parse/numbers.h"
@@ -377,54 +378,92 @@ static int drain_json_route(const char* yaml, size_t len, yep_value_ctx** out) {
377
378
  * record array + arena, ownership moves to the caller. */
378
379
  int yep_values_from_input(const char* yaml, size_t len, int schema_compat, yep_value_ctx** out) {
379
380
  *out = NULL;
380
- if (looks_strict_json(yaml, len)) {
381
- int jrc = drain_json_route(yaml, len, out);
382
- if (jrc <= 0) {
383
- return jrc == 0 ? 0 : -1;
381
+ /* The encoding gate the parse entry owns (parse.c): the marshal/
382
+ * visit / value drains must not feed raw UTF-16/32 bytes to the
383
+ * engine while yeptris_parse accepts them — the nightly's marshal
384
+ * crasher (a UTF-16BE doc whose raw bytes contain "-s"). */
385
+ yep_encoding enc = YEP_ENC_UNKNOWN;
386
+ size_t bom = yep_bom_sniff((const unsigned char*)yaml, len, &enc);
387
+ const char* data = yaml + bom;
388
+ size_t data_len = len - bom;
389
+ unsigned char* transcoded = NULL;
390
+ const yep_allocator* sys = yep_system_allocator();
391
+ if (enc == YEP_ENC_UTF16LE || enc == YEP_ENC_UTF16BE || enc == YEP_ENC_UTF32LE ||
392
+ enc == YEP_ENC_UTF32BE) {
393
+ size_t tlen = 0;
394
+ size_t terr = 0;
395
+ int rc = yep_transcode_to_utf8(sys, enc, (const unsigned char*)data, data_len, &transcoded,
396
+ &tlen, &terr);
397
+ if (rc != 0) {
398
+ return -2;
399
+ }
400
+ size_t pverr = 0;
401
+ if (!yep_printable_validate(transcoded, tlen, &pverr)) {
402
+ yep_free(sys, transcoded);
403
+ return -2;
404
+ }
405
+ data = (const char*)transcoded;
406
+ data_len = tlen;
407
+ }
408
+ int prc_final = -2;
409
+ do {
410
+ if (looks_strict_json(data, data_len)) {
411
+ int jrc = drain_json_route(data, data_len, out);
412
+ if (jrc <= 0) {
413
+ prc_final = (jrc == 0) ? 0 : -1;
414
+ break;
415
+ }
416
+ /* fall through: engine */
417
+ }
418
+ yep_engine* eng = yep_engine_create(yep_system_allocator());
419
+ if (eng == NULL) {
420
+ return -1;
421
+ }
422
+ yep_engine_set_resolver(eng,
423
+ schema_compat ? yep_resolver_compat11() : yep_resolver_core12());
424
+ if (schema_compat) {
425
+ yep_engine_set_compat_grammar(eng, 1); /* libyaml grammar parity
426
+ * (the value drains ride the
427
+ * same compat contract) */
384
428
  }
385
- /* fall through: engine */
386
- }
387
- yep_engine* eng = yep_engine_create(yep_system_allocator());
388
- if (eng == NULL) {
389
- return -1;
390
- }
391
- yep_engine_set_resolver(eng, schema_compat ? yep_resolver_compat11() : yep_resolver_core12());
392
- if (schema_compat) {
393
- yep_engine_set_compat_grammar(eng, 1); /* libyaml grammar parity
394
- * (the value drains ride the
395
- * same compat contract) */
396
- }
397
429
 
398
- yep_value_ctx* c = ctx_create();
399
- if (c == NULL) {
400
- yep_engine_destroy(eng);
401
- return -1;
402
- }
403
- yep_rec_store store;
404
- yep_rec_init(&store);
430
+ yep_value_ctx* c = ctx_create();
431
+ if (c == NULL) {
432
+ yep_engine_destroy(eng);
433
+ return -1;
434
+ }
435
+ yep_rec_store store;
436
+ yep_rec_init(&store);
405
437
 
406
- int prc = -2;
407
- yep_sink sink = {.on_event = yep_rec_on_event,
408
- .ctx = &store,
409
- .on_flow_build = NULL,
410
- .on_flow_commit = NULL,
411
- .on_flow_rollback = NULL,
412
- .on_block_pair = NULL,
413
- .on_block_open = NULL,
414
- .on_block_item = NULL};
415
- /* strict JSON carries no anchors: no nametab reserve needed */
416
- if (yep_engine_run(eng, yaml, len, &sink) == 0 && transform(c, &store) == 0) {
417
- prc = 0;
418
- } else if (c->oom) {
419
- prc = -1;
420
- }
421
- yep_engine_destroy(eng);
422
- yep_rec_free(&store);
423
- if (prc != 0) {
424
- yep_value_ctx_free(c);
425
- return prc == -1 ? -1 : -2;
438
+ int prc = -2;
439
+ yep_sink sink = {.on_event = yep_rec_on_event,
440
+ .ctx = &store,
441
+ .on_flow_build = NULL,
442
+ .on_flow_commit = NULL,
443
+ .on_flow_rollback = NULL,
444
+ .on_block_pair = NULL,
445
+ .on_block_open = NULL,
446
+ .on_block_item = NULL};
447
+ /* strict JSON carries no anchors: no nametab reserve needed */
448
+ yep_engine_front_done(eng);
449
+ if (yep_engine_run(eng, data, data_len, &sink) == 0 && transform(c, &store) == 0) {
450
+ prc = 0;
451
+ } else if (c->oom) {
452
+ prc = -1;
453
+ }
454
+ yep_engine_destroy(eng);
455
+ yep_rec_free(&store);
456
+ if (prc != 0) {
457
+ yep_value_ctx_free(c);
458
+ break;
459
+ }
460
+ prc_final = ctx_finalize(c, out) == 0 ? 0 : -1;
461
+ } while (0);
462
+ yep_free(sys, transcoded);
463
+ if (prc_final != 0 && prc_final != -1) {
464
+ return -2;
426
465
  }
427
- return ctx_finalize(c, out) == 0 ? 0 : -1;
466
+ return prc_final;
428
467
  }
429
468
 
430
469
  static YeptrisStatus map_status(int rc) {