yeptris 0.6.59.1-arm-linux-eabihf → 0.6.60.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.
- checksums.yaml +4 -4
- data/ext/yeptris_native/version.h +2 -2
- data/lib/yeptris/3.4/native.so +0 -0
- data/lib/yeptris/ffi.rb +19 -0
- data/lib/yeptris/yaml.rb +61 -0
- data/lib/yeptris.rb +1 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/CMakeLists.txt +7 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +30 -2
- data/vendor/libyeptris/src/include/yeptris/parse.h +52 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +8 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +222 -21
- data/vendor/libyeptris/src/include/yeptris/values.h +8 -2
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +10 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +5 -7
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +9 -9
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +1 -1
- data/vendor/libyeptris/src/yeptris/common/error.h +2 -0
- data/vendor/libyeptris/src/yeptris/doc.h +20 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +85 -13
- data/vendor/libyeptris/src/yeptris/emit/writer.c +158 -642
- data/vendor/libyeptris/src/yeptris/emit/writer.h +15 -1
- data/vendor/libyeptris/src/yeptris/events/push.c +28 -3
- data/vendor/libyeptris/src/yeptris/events/values.c +24 -0
- data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +121 -40
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +326 -0
- data/vendor/libyeptris/src/yeptris/parse.c +173 -43
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +1 -1
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +11 -3
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +12 -6
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +20 -0
- data/vendor/libyeptris/src/yeptris/validate/compile.c +39 -3
- data/vendor/libyeptris/src/yeptris/validate/internal.h +223 -7
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +645 -115
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +623 -157
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +288 -145
- metadata +8 -1
|
@@ -50,11 +50,6 @@ typedef struct {
|
|
|
50
50
|
uint8_t is_map;
|
|
51
51
|
} yep_cframe;
|
|
52
52
|
|
|
53
|
-
#define YEP_CBOR_TAGBUF \
|
|
54
|
-
512 /* a semantic-tag chain over ~23 links is \
|
|
55
|
-
* pathological; the arena form had no cap, \
|
|
56
|
-
* the stack form does (documented) */
|
|
57
|
-
|
|
58
53
|
typedef struct {
|
|
59
54
|
yep_dom* d; /* the DOM sink's ctx (NULL for pure sinks) */
|
|
60
55
|
const unsigned char* p;
|
|
@@ -66,6 +61,7 @@ typedef struct {
|
|
|
66
61
|
* first — the next item's writer consumes it) */
|
|
67
62
|
char tagbuf[YEP_CBOR_TAGBUF];
|
|
68
63
|
uint32_t taglen;
|
|
64
|
+
uint32_t taglinks; /* the chain's link count (the shared cap) */
|
|
69
65
|
/* indefinite-string accumulation (chunk framing is the grammar's;
|
|
70
66
|
* the finished span goes to one str/bytes callback) */
|
|
71
67
|
unsigned char* ibuf;
|
|
@@ -190,6 +186,7 @@ static const char* cbor_take_tag(yep_cdec* c, uint32_t* len) {
|
|
|
190
186
|
}
|
|
191
187
|
*len = c->taglen;
|
|
192
188
|
c->taglen = 0;
|
|
189
|
+
c->taglinks = 0;
|
|
193
190
|
return c->tagbuf;
|
|
194
191
|
}
|
|
195
192
|
|
|
@@ -239,9 +236,9 @@ static int cbor_open(yep_cdec* c, int is_map, uint64_t cap) {
|
|
|
239
236
|
}
|
|
240
237
|
|
|
241
238
|
static int cbor_note_tag(yep_cdec* c, uint64_t tag) {
|
|
242
|
-
if (c->taglen + 1 + 20 > sizeof c->tagbuf) {
|
|
239
|
+
if (c->taglinks >= YEP_CBOR_TAG_MAX_LINKS || c->taglen + 1 + 20 > sizeof c->tagbuf) {
|
|
243
240
|
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, c->i,
|
|
244
|
-
"semantic-tag chain exceeds %u
|
|
241
|
+
"semantic-tag chain exceeds %u links at byte %zu", YEP_CBOR_TAG_MAX_LINKS,
|
|
245
242
|
c->i);
|
|
246
243
|
c->status = YEPTRIS_ERROR_PARSE;
|
|
247
244
|
return 0;
|
|
@@ -250,6 +247,7 @@ static int cbor_note_tag(yep_cdec* c, uint64_t tag) {
|
|
|
250
247
|
c->tagbuf[c->taglen++] = ' '; /* separator between chain links */
|
|
251
248
|
}
|
|
252
249
|
c->taglen += cbor_u64dec(tag, c->tagbuf + c->taglen);
|
|
250
|
+
c->taglinks++;
|
|
253
251
|
return 1;
|
|
254
252
|
}
|
|
255
253
|
|
|
@@ -326,14 +326,14 @@ typedef struct {
|
|
|
326
326
|
/* Encodes one KEY item (tags + scalar) into exactly-sized scratch. */
|
|
327
327
|
static uint8_t* cbor_encode_key(const yep_dom* d, const yep_dnode* key, size_t* out_len) {
|
|
328
328
|
yep_view v = yep_dom_view(d, key->value);
|
|
329
|
-
size_t cap =
|
|
329
|
+
size_t cap = (size_t)YEP_CBOR_TAG_MAX_LINKS * 9 + 9 + v.len; /* tags + head + text */
|
|
330
330
|
uint8_t* buf = malloc(cap);
|
|
331
331
|
if (buf == NULL) {
|
|
332
332
|
return NULL;
|
|
333
333
|
}
|
|
334
334
|
size_t pos = 0;
|
|
335
|
-
uint64_t tags[
|
|
336
|
-
int ntags = cbor_tag_chain(d, key, tags,
|
|
335
|
+
uint64_t tags[YEP_CBOR_TAG_MAX_LINKS];
|
|
336
|
+
int ntags = cbor_tag_chain(d, key, tags, YEP_CBOR_TAG_MAX_LINKS);
|
|
337
337
|
if (ntags < 0) {
|
|
338
338
|
goto bad;
|
|
339
339
|
}
|
|
@@ -491,8 +491,8 @@ static size_t cbor_size_item(cenc* e, uint32_t id);
|
|
|
491
491
|
static size_t cbor_size_scalar(cenc* e, const yep_dnode* n) {
|
|
492
492
|
const yep_dom* d = e->d;
|
|
493
493
|
size_t sz = 0;
|
|
494
|
-
uint64_t tags[
|
|
495
|
-
int ntags = cbor_tag_chain(d, n, tags,
|
|
494
|
+
uint64_t tags[YEP_CBOR_TAG_MAX_LINKS];
|
|
495
|
+
int ntags = cbor_tag_chain(d, n, tags, YEP_CBOR_TAG_MAX_LINKS);
|
|
496
496
|
if (ntags < 0) {
|
|
497
497
|
e->failed = 1;
|
|
498
498
|
e->status = YEPTRIS_ERROR_UNSUPPORTED;
|
|
@@ -534,8 +534,8 @@ static size_t cbor_size_item(cenc* e, uint32_t id) {
|
|
|
534
534
|
return cbor_size_scalar(e, n); /* includes the node's own tags */
|
|
535
535
|
}
|
|
536
536
|
size_t sz = 0;
|
|
537
|
-
uint64_t tags[
|
|
538
|
-
int ntags = cbor_tag_chain(d, n, tags,
|
|
537
|
+
uint64_t tags[YEP_CBOR_TAG_MAX_LINKS];
|
|
538
|
+
int ntags = cbor_tag_chain(d, n, tags, YEP_CBOR_TAG_MAX_LINKS);
|
|
539
539
|
if (ntags < 0) {
|
|
540
540
|
e->failed = 1;
|
|
541
541
|
e->status = YEPTRIS_ERROR_UNSUPPORTED;
|
|
@@ -653,8 +653,8 @@ static void cbor_write_scalar(cenc* e, const yep_dnode* n, uint8_t* out, size_t*
|
|
|
653
653
|
static void cbor_write_item(cenc* e, uint32_t id, uint8_t* out, size_t* pos) {
|
|
654
654
|
const yep_dom* d = e->d;
|
|
655
655
|
const yep_dnode* n = &d->nodes[id];
|
|
656
|
-
uint64_t tags[
|
|
657
|
-
int ntags = cbor_tag_chain(d, n, tags,
|
|
656
|
+
uint64_t tags[YEP_CBOR_TAG_MAX_LINKS];
|
|
657
|
+
int ntags = cbor_tag_chain(d, n, tags, YEP_CBOR_TAG_MAX_LINKS);
|
|
658
658
|
for (int t = 0; t < ntags; t++) {
|
|
659
659
|
yep_cbor_put_head(out, pos, 6, tags[t]);
|
|
660
660
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* from_marshal.c — Ruby Marshal.dump bytes to ONE CBOR data item
|
|
2
2
|
* (yeptris-ruby#322's CBOR half: the binding's dump face).
|
|
3
3
|
*
|
|
4
|
-
* The twin of
|
|
4
|
+
* The twin of marshal/to_json.c's JSON reader (yeptris_json_from_marshal):
|
|
5
5
|
* the Marshal stream is walked once, in C, and the CBOR item is
|
|
6
6
|
* appended straight to the output — no per-node Ruby crossings, no
|
|
7
7
|
* Document, no YAMLTree. The format facts mirror marshal.c's emission
|
|
@@ -25,6 +25,7 @@ extern "C" {
|
|
|
25
25
|
#define YEP_ERROR_X(X) \
|
|
26
26
|
X(YEP_ERR_NONE, "no error") \
|
|
27
27
|
X(YEP_ERR_UNEXPECTED, "unexpected parser state") \
|
|
28
|
+
X(YEP_ERR_DOC_BOUNDARY, "invalid content at a document boundary") \
|
|
28
29
|
X(YEP_ERR_MEMORY, "out of memory") \
|
|
29
30
|
X(YEP_ERR_DEPTH, "nesting depth exceeds the limit") \
|
|
30
31
|
X(YEP_ERR_ENCODING, "ill-formed or unsupported character encoding") \
|
|
@@ -33,6 +34,7 @@ extern "C" {
|
|
|
33
34
|
X(YEP_ERR_BAD_INDENT, "inconsistent indentation") \
|
|
34
35
|
X(YEP_ERR_KEY_TOO_LONG, "simple key exceeds 1024 characters") \
|
|
35
36
|
X(YEP_ERR_UNDEFINED_ALIAS, "alias references an undefined anchor") \
|
|
37
|
+
X(YEP_ERR_ABORTED, "parse aborted by the event callback") \
|
|
36
38
|
X(YEP_ERR_INVALID_ESCAPE, "invalid escape sequence in double-quoted scalar") \
|
|
37
39
|
X(YEP_ERR_BAD_DIRECTIVE, "invalid or unsupported directive") \
|
|
38
40
|
X(YEP_ERR_INTERNAL, "internal invariant violation") \
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
#include "dom/dom.h"
|
|
12
12
|
#include "memory/allocator.h"
|
|
13
13
|
|
|
14
|
+
#include <yeptris/error.h>
|
|
15
|
+
#include <yeptris/resolve.h> /* YeptrisSchema */
|
|
16
|
+
|
|
14
17
|
typedef struct yeptris_document {
|
|
15
18
|
yep_dom* dom;
|
|
16
19
|
const yep_allocator* sys;
|
|
@@ -59,8 +62,25 @@ extern "C" {
|
|
|
59
62
|
yep_dom* yep_doc_dom(yeptris_document* doc);
|
|
60
63
|
yeptris_node* yep_handle_new(yeptris_document* doc, uint32_t id);
|
|
61
64
|
|
|
65
|
+
/* parse.c's sink-entry seam (#902): the DOM route's exact front-end and
|
|
66
|
+
* engine run into a caller sink — no DOM, no tape. Statuses are the
|
|
67
|
+
* parse route's (OK, or PARSE / DEPTH / ENCODING / MEMORY; the sink's
|
|
68
|
+
* own failure rides MEMORY like the DOM builder's). on_input (may be
|
|
69
|
+
* NULL) receives the run's input view — the DOM route's input_base law
|
|
70
|
+
* (the transcoded copy, or the caller's bytes) and its post-BOM length
|
|
71
|
+
* — immediately before the engine runs, because the events' borrowed
|
|
72
|
+
* views subtract from it. The bytes live only for the run. */
|
|
73
|
+
typedef void (*yep_input_fn)(void* ctx, const char* base, size_t len);
|
|
74
|
+
YeptrisStatus yep_parse_events(const char* buf, size_t len, YeptrisSchema schema,
|
|
75
|
+
const yep_sink* sink, yep_input_fn on_input, void* on_ctx);
|
|
76
|
+
|
|
62
77
|
#ifdef __cplusplus
|
|
63
78
|
}
|
|
64
79
|
#endif
|
|
65
80
|
|
|
81
|
+
/* The typing SSOT's one switch (parse.c owns it; the stream iterator
|
|
82
|
+
* and any future bytes->document route select through it too). */
|
|
83
|
+
struct yep_resolver; /* resolve/resolver.h's fwd — doc.h stays leaf */
|
|
84
|
+
const struct yep_resolver* resolver_for_schema(YeptrisSchema schema);
|
|
85
|
+
|
|
66
86
|
#endif /* YEP_DOC_H */
|
|
@@ -11,12 +11,22 @@
|
|
|
11
11
|
#include "../doc.h"
|
|
12
12
|
#include "writer.h"
|
|
13
13
|
|
|
14
|
+
/* Every field reads behind ITS OWN offsetof gate — never the whole
|
|
15
|
+
* struct's sizeof. The #909/#903 append grew sizeof(*opts) to 24, and
|
|
16
|
+
* a `size >= sizeof(*opts)` gate silently orphaned the ORIGINAL
|
|
17
|
+
* fields for callers compiled against the 16-byte struct (the Ruby
|
|
18
|
+
* binding): best_width fell back to 80 and canonical fell off. The
|
|
19
|
+
* versioning contract is per field: declared-present or default. */
|
|
14
20
|
static int opts_canonical(const yeptris_emit_options* opts) {
|
|
15
|
-
return opts != NULL &&
|
|
21
|
+
return opts != NULL &&
|
|
22
|
+
opts->size >= (uint32_t)(offsetof(yeptris_emit_options, canonical) + sizeof(int)) &&
|
|
23
|
+
opts->canonical;
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
static int opts_width(const yeptris_emit_options* opts) {
|
|
19
|
-
if (opts == NULL ||
|
|
27
|
+
if (opts == NULL ||
|
|
28
|
+
opts->size < (uint32_t)(offsetof(yeptris_emit_options, best_width) + sizeof(int)) ||
|
|
29
|
+
opts->best_width <= 0) {
|
|
20
30
|
return 80; /* libyaml best_width parity */
|
|
21
31
|
}
|
|
22
32
|
return opts->best_width;
|
|
@@ -32,6 +42,41 @@ static int opts_doc_marker(const yeptris_emit_options* opts) {
|
|
|
32
42
|
return opts->explicit_doc_start != 0;
|
|
33
43
|
}
|
|
34
44
|
|
|
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
|
+
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) */
|
|
62
|
+
if (opts == NULL ||
|
|
63
|
+
opts->size < (uint32_t)(offsetof(yeptris_emit_options, block_fold) + sizeof(int))) {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
return opts->block_fold != 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* The emitter's SCRATCH rides the document's allocator (#904 item 3):
|
|
70
|
+
* sc_dec and the streaming window are emitter-internal (never leak
|
|
71
|
+
* into caller hands), so the fail-injection harness — a counting
|
|
72
|
+
* allocator passed at the document's build — now reaches them. The
|
|
73
|
+
* CALLER-RETURNED output buffers stay system-malloc on purpose: their
|
|
74
|
+
* release contract is free() (emit.h "malloc'd buffer, caller frees"),
|
|
75
|
+
* and a failing allocator's pointer cannot be freed by the host. */
|
|
76
|
+
static const yep_allocator* emit_sys(const yeptris_document* doc) {
|
|
77
|
+
return doc->sys != NULL ? doc->sys : yep_system_allocator();
|
|
78
|
+
}
|
|
79
|
+
|
|
35
80
|
YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
|
|
36
81
|
const yeptris_emit_options* opts, char* buf,
|
|
37
82
|
size_t cap) {
|
|
@@ -62,6 +107,8 @@ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
|
|
|
62
107
|
em.w.json_pretty = 0;
|
|
63
108
|
em.w.pretty_depth = 0;
|
|
64
109
|
em.w.best_width = opts_width(opts);
|
|
110
|
+
em.w.indent = opts_indent(opts);
|
|
111
|
+
em.w.block_fold = opts_block_fold(opts);
|
|
65
112
|
em.w.col = 0;
|
|
66
113
|
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
67
114
|
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
@@ -70,10 +117,11 @@ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
|
|
|
70
117
|
em.w.sink_aborted = 0;
|
|
71
118
|
em.w.flushed = 0;
|
|
72
119
|
memset(&em.canon_names, 0, sizeof(em.canon_names));
|
|
73
|
-
if (em.w.canonical && !yep_nametab_init(&em.canon_names,
|
|
120
|
+
if (em.w.canonical && !yep_nametab_init(&em.canon_names, emit_sys(em.doc))) {
|
|
74
121
|
return 0;
|
|
75
122
|
}
|
|
76
|
-
em.w.sc_dec =
|
|
123
|
+
em.w.sc_dec =
|
|
124
|
+
(uint8_t*)yep_alloc(emit_sys(em.doc), em.doc->dom->ncount > 0 ? em.doc->dom->ncount : 1);
|
|
77
125
|
if (em.w.sc_dec == NULL) {
|
|
78
126
|
if (em.canon_names.sys != NULL) {
|
|
79
127
|
yep_nametab_free(&em.canon_names);
|
|
@@ -82,7 +130,7 @@ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
|
|
|
82
130
|
}
|
|
83
131
|
size_t need = yep_emit_run(&em, 1);
|
|
84
132
|
if (buf == NULL || cap < need + 1) {
|
|
85
|
-
|
|
133
|
+
yep_free(emit_sys(em.doc), em.w.sc_dec);
|
|
86
134
|
if (em.canon_names.sys != NULL) {
|
|
87
135
|
yep_nametab_free(&em.canon_names);
|
|
88
136
|
}
|
|
@@ -90,7 +138,7 @@ YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
|
|
|
90
138
|
}
|
|
91
139
|
em.w.p = buf;
|
|
92
140
|
size_t wrote = yep_emit_run(&em, 0);
|
|
93
|
-
|
|
141
|
+
yep_free(emit_sys(em.doc), em.w.sc_dec);
|
|
94
142
|
if (em.canon_names.sys != NULL) {
|
|
95
143
|
yep_nametab_free(&em.canon_names);
|
|
96
144
|
}
|
|
@@ -128,6 +176,8 @@ YEPTRIS_API size_t yeptris_serialize_into_trusted(YeptrisDocument handle,
|
|
|
128
176
|
em.w.json_pretty = 0;
|
|
129
177
|
em.w.pretty_depth = 0;
|
|
130
178
|
em.w.best_width = opts_width(opts);
|
|
179
|
+
em.w.indent = opts_indent(opts);
|
|
180
|
+
em.w.block_fold = opts_block_fold(opts);
|
|
131
181
|
em.w.col = 0;
|
|
132
182
|
em.w.sv_input = ((const yeptris_document*)handle)->dom->input_base;
|
|
133
183
|
em.w.sv_arena = ((const yeptris_document*)handle)->dom->str;
|
|
@@ -136,7 +186,7 @@ YEPTRIS_API size_t yeptris_serialize_into_trusted(YeptrisDocument handle,
|
|
|
136
186
|
em.w.sink_aborted = 0;
|
|
137
187
|
em.w.flushed = 0;
|
|
138
188
|
memset(&em.canon_names, 0, sizeof(em.canon_names));
|
|
139
|
-
if (em.w.canonical && !yep_nametab_init(&em.canon_names,
|
|
189
|
+
if (em.w.canonical && !yep_nametab_init(&em.canon_names, emit_sys(em.doc))) {
|
|
140
190
|
return 0;
|
|
141
191
|
}
|
|
142
192
|
/* #352: ONE bounded wet pass — no memo, no dry run (the emit-split
|
|
@@ -194,6 +244,8 @@ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument handle, const yeptris_emi
|
|
|
194
244
|
em.w.json_pretty = 0;
|
|
195
245
|
em.w.pretty_depth = 0;
|
|
196
246
|
em.w.best_width = opts_width(opts);
|
|
247
|
+
em.w.indent = opts_indent(opts);
|
|
248
|
+
em.w.block_fold = opts_block_fold(opts);
|
|
197
249
|
em.w.col = 0;
|
|
198
250
|
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
199
251
|
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
@@ -202,7 +254,7 @@ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument handle, const yeptris_emi
|
|
|
202
254
|
em.w.sink_aborted = 0;
|
|
203
255
|
em.w.flushed = 0;
|
|
204
256
|
memset(&em.canon_names, 0, sizeof(em.canon_names));
|
|
205
|
-
if (em.w.canonical && !yep_nametab_init(&em.canon_names,
|
|
257
|
+
if (em.w.canonical && !yep_nametab_init(&em.canon_names, emit_sys(em.doc))) {
|
|
206
258
|
return NULL;
|
|
207
259
|
}
|
|
208
260
|
/* #352 slice 2: ONE wet pass into a growable buffer — the dry
|
|
@@ -211,6 +263,9 @@ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument handle, const yeptris_emi
|
|
|
211
263
|
* starts at the input size (+64) and doubles on demand; a final
|
|
212
264
|
* shrink-to-fit keeps the returned allocation tight. No dry pass,
|
|
213
265
|
* so no decisions table. */
|
|
266
|
+
/* raw malloc ON PURPOSE (#904 item 3): this buffer is RETURNED —
|
|
267
|
+
* the release contract is the host's free() (emit.h), so it must
|
|
268
|
+
* come from the system allocator, not the document's */
|
|
214
269
|
size_t est = em.doc->dom->input_len + 64;
|
|
215
270
|
if (est < 256) {
|
|
216
271
|
est = 256;
|
|
@@ -260,6 +315,8 @@ YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument handle, const yeptris_emi
|
|
|
260
315
|
* (+64) and doubles on demand; shrink-to-fit at the end. Owns the
|
|
261
316
|
* emitter's canon_names cleanup. */
|
|
262
317
|
static char* yep_json_run_growable(yep_emitter* em, size_t* len) {
|
|
318
|
+
/* raw malloc ON PURPOSE (#904 item 3): the buffer is RETURNED —
|
|
319
|
+
* the host's free() owns it (emit.h), system allocator only */
|
|
263
320
|
size_t est = em->doc->dom->input_len + 64;
|
|
264
321
|
if (est < 256) {
|
|
265
322
|
est = 256;
|
|
@@ -328,6 +385,8 @@ YEPTRIS_API char* yeptris_serialize_json(YeptrisDocument handle, size_t* len) {
|
|
|
328
385
|
em.w.json_pretty = 0;
|
|
329
386
|
em.w.pretty_depth = 0;
|
|
330
387
|
em.w.best_width = 0; /* JSON: no folding (single-line output) */
|
|
388
|
+
em.w.indent = 2;
|
|
389
|
+
em.w.block_fold = 0;
|
|
331
390
|
em.w.col = 0;
|
|
332
391
|
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
333
392
|
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
@@ -370,6 +429,8 @@ YEPTRIS_API char* yeptris_serialize_json_ex(YeptrisDocument handle, size_t* len,
|
|
|
370
429
|
em.w.json_pretty = 0;
|
|
371
430
|
em.w.pretty_depth = 0;
|
|
372
431
|
em.w.best_width = 0; /* JSON: no folding (single-line output) */
|
|
432
|
+
em.w.indent = 2;
|
|
433
|
+
em.w.block_fold = 0;
|
|
373
434
|
em.w.col = 0;
|
|
374
435
|
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
375
436
|
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
@@ -414,6 +475,8 @@ char* yep_serialize_json_compact(const yeptris_document* doc, size_t* len) {
|
|
|
414
475
|
em.w.json_pretty = 0;
|
|
415
476
|
em.w.pretty_depth = 0;
|
|
416
477
|
em.w.best_width = 0;
|
|
478
|
+
em.w.indent = 2;
|
|
479
|
+
em.w.block_fold = 0;
|
|
417
480
|
em.w.col = 0;
|
|
418
481
|
em.w.sv_input = doc->dom->input_base;
|
|
419
482
|
em.w.sv_arena = doc->dom->str;
|
|
@@ -460,6 +523,8 @@ char* yep_serialize_json_pretty_ex(const yeptris_document* doc, size_t* len, con
|
|
|
460
523
|
em.w.json_indent = indent;
|
|
461
524
|
em.w.json_indent_len = indent == NULL ? 2 : (int)indent_len;
|
|
462
525
|
em.w.best_width = 0;
|
|
526
|
+
em.w.indent = 2;
|
|
527
|
+
em.w.block_fold = 0;
|
|
463
528
|
em.w.col = 0;
|
|
464
529
|
em.w.sv_input = doc->dom->input_base;
|
|
465
530
|
em.w.sv_arena = doc->dom->str;
|
|
@@ -468,9 +533,11 @@ char* yep_serialize_json_pretty_ex(const yeptris_document* doc, size_t* len, con
|
|
|
468
533
|
em.w.sink_aborted = 0;
|
|
469
534
|
em.w.flushed = 0;
|
|
470
535
|
memset(&em.canon_names, 0, sizeof(em.canon_names));
|
|
471
|
-
if (em.w.canonical && !yep_nametab_init(&em.canon_names,
|
|
536
|
+
if (em.w.canonical && !yep_nametab_init(&em.canon_names, emit_sys(doc))) {
|
|
472
537
|
return NULL;
|
|
473
538
|
}
|
|
539
|
+
/* raw malloc ON PURPOSE (#904 item 3): the dry-wet pair's exact-
|
|
540
|
+
* sized output is RETURNED — the host's free() owns it */
|
|
474
541
|
size_t need = yep_emit_run(&em, 1);
|
|
475
542
|
char* out = malloc(need + 1);
|
|
476
543
|
if (out == NULL) {
|
|
@@ -532,6 +599,8 @@ YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument handle,
|
|
|
532
599
|
em.w.json_pretty = 0;
|
|
533
600
|
em.w.pretty_depth = 0;
|
|
534
601
|
em.w.best_width = opts_width(opts);
|
|
602
|
+
em.w.indent = opts_indent(opts);
|
|
603
|
+
em.w.block_fold = opts_block_fold(opts);
|
|
535
604
|
em.w.col = 0;
|
|
536
605
|
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
537
606
|
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
@@ -539,11 +608,14 @@ YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument handle,
|
|
|
539
608
|
em.w.sink_ctx = ctx;
|
|
540
609
|
em.w.watermark = YEP_EMIT_WATERMARK;
|
|
541
610
|
memset(&em.canon_names, 0, sizeof(em.canon_names));
|
|
542
|
-
if (em.w.canonical && !yep_nametab_init(&em.canon_names,
|
|
611
|
+
if (em.w.canonical && !yep_nametab_init(&em.canon_names, emit_sys(em.doc))) {
|
|
543
612
|
return 0;
|
|
544
613
|
}
|
|
545
|
-
/* one scratch window; the writer flushes it when it fills
|
|
546
|
-
|
|
614
|
+
/* one scratch window; the writer flushes it when it fills.
|
|
615
|
+
* Document allocator (#904 item 3): emitter-internal scratch —
|
|
616
|
+
* flushed out through the sink, never returned — so the
|
|
617
|
+
* fail-injection harness reaches it. */
|
|
618
|
+
char* window = yep_alloc(emit_sys(em.doc), YEP_EMIT_WATERMARK * 2);
|
|
547
619
|
if (window == NULL) {
|
|
548
620
|
if (em.canon_names.sys != NULL) {
|
|
549
621
|
yep_nametab_free(&em.canon_names);
|
|
@@ -564,7 +636,7 @@ YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument handle,
|
|
|
564
636
|
/* total already counted by the flush hooks */
|
|
565
637
|
}
|
|
566
638
|
}
|
|
567
|
-
|
|
639
|
+
yep_free(emit_sys(em.doc), window);
|
|
568
640
|
if (em.canon_names.sys != NULL) {
|
|
569
641
|
yep_nametab_free(&em.canon_names);
|
|
570
642
|
}
|