yeptris 0.6.18.2-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 +7 -0
- data/README.adoc +141 -0
- data/ext/build_windows_native.rb +41 -0
- data/ext/libyeptris/extconf.rb +57 -0
- data/ext/yeptris_native/cbor_ruby.c +193 -0
- data/ext/yeptris_native/extconf.rb +47 -0
- data/ext/yeptris_native/json_ruby.c +354 -0
- data/ext/yeptris_native/yeptris_native.c +497 -0
- data/lib/yeptris/cbor.rb +130 -0
- data/lib/yeptris/document.rb +255 -0
- data/lib/yeptris/ffi.rb +426 -0
- data/lib/yeptris/json/descriptor.rb +266 -0
- data/lib/yeptris/json.rb +394 -0
- data/lib/yeptris/materializer.rb +354 -0
- data/lib/yeptris/native-3.4.so +0 -0
- data/lib/yeptris/node.rb +453 -0
- data/lib/yeptris/psych/class_loader.rb +24 -0
- data/lib/yeptris/psych/coder_shim.rb +55 -0
- data/lib/yeptris/psych/drop_in.rb +63 -0
- data/lib/yeptris/psych/encodable.rb +14 -0
- data/lib/yeptris/psych/handler.rb +90 -0
- data/lib/yeptris/psych/parser.rb +105 -0
- data/lib/yeptris/psych/scalar_scanner.rb +149 -0
- data/lib/yeptris/psych/visitors.rb +545 -0
- data/lib/yeptris/psych.rb +622 -0
- data/lib/yeptris/schema.rb +253 -0
- data/lib/yeptris/valueml.rb +455 -0
- data/lib/yeptris/yaml/descriptor.rb +56 -0
- data/lib/yeptris/yaml.rb +422 -0
- data/lib/yeptris.rb +113 -0
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +254 -0
- data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
- data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
- data/vendor/libyeptris/src/CMakeLists.txt +167 -0
- data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
- data/vendor/libyeptris/src/include/yeptris/cbor.h +101 -0
- data/vendor/libyeptris/src/include/yeptris/dom.h +190 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +81 -0
- data/vendor/libyeptris/src/include/yeptris/error.h +41 -0
- data/vendor/libyeptris/src/include/yeptris/events.h +157 -0
- data/vendor/libyeptris/src/include/yeptris/json.h +45 -0
- data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
- data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
- data/vendor/libyeptris/src/include/yeptris/marshal.h +52 -0
- data/vendor/libyeptris/src/include/yeptris/parse.h +48 -0
- data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +71 -0
- data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +123 -0
- data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
- data/vendor/libyeptris/src/include/yeptris/values.h +102 -0
- data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
- data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
- data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
- data/vendor/libyeptris/src/include/yeptris.h +23 -0
- data/vendor/libyeptris/src/yeptris/build.c +376 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +25 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +981 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +835 -0
- data/vendor/libyeptris/src/yeptris/cbor/sink.h +58 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
- data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
- data/vendor/libyeptris/src/yeptris/common/error.h +79 -0
- data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
- data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.h +295 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +534 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +662 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +298 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
- data/vendor/libyeptris/src/yeptris/doc.h +56 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +1192 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +312 -0
- data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
- data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +434 -0
- data/vendor/libyeptris/src/yeptris/emit/float/api.h +38 -0
- data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
- data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
- data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
- data/vendor/libyeptris/src/yeptris/emit/style.c +81 -0
- data/vendor/libyeptris/src/yeptris/emit/style.h +24 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.c +816 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +76 -0
- data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
- data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
- data/vendor/libyeptris/src/yeptris/encoding/transcode.c +148 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
- data/vendor/libyeptris/src/yeptris/events/capture.c +150 -0
- data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
- data/vendor/libyeptris/src/yeptris/events/iterparse.c +208 -0
- data/vendor/libyeptris/src/yeptris/events/pull.c +97 -0
- data/vendor/libyeptris/src/yeptris/events/push.c +104 -0
- data/vendor/libyeptris/src/yeptris/events/recorder.c +107 -0
- data/vendor/libyeptris/src/yeptris/events/values.c +527 -0
- data/vendor/libyeptris/src/yeptris/events/values_priv.h +51 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
- data/vendor/libyeptris/src/yeptris/marshal.c +782 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.c +134 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.c +122 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +3698 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.h +65 -0
- data/vendor/libyeptris/src/yeptris/parse/events.h +124 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.c +349 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.c +416 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.h +75 -0
- data/vendor/libyeptris/src/yeptris/parse.c +737 -0
- data/vendor/libyeptris/src/yeptris/plan.c +824 -0
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +334 -0
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +143 -0
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +56 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +58 -0
- data/vendor/libyeptris/src/yeptris/scan/json.c +792 -0
- data/vendor/libyeptris/src/yeptris/scan/json.h +109 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +463 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +150 -0
- data/vendor/libyeptris/src/yeptris/schema.c +308 -0
- data/vendor/libyeptris/src/yeptris/tape.c +1308 -0
- data/vendor/libyeptris/src/yeptris/tape_in.h +19 -0
- data/vendor/libyeptris/src/yeptris/version.c +7 -0
- data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
- data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
- data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
- metadata +199 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/* emit.c — public serialization API (TODO.impl/13).
|
|
2
|
+
*
|
|
3
|
+
* Two passes of the ONE writer: dry (exact size), wet (linear writes
|
|
4
|
+
* into the caller's buffer — zero reallocations by construction). */
|
|
5
|
+
|
|
6
|
+
#include <stddef.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#include "../../include/yeptris/emit.h"
|
|
11
|
+
#include "../doc.h"
|
|
12
|
+
#include "writer.h"
|
|
13
|
+
|
|
14
|
+
static int opts_canonical(const yeptris_emit_options* opts) {
|
|
15
|
+
return opts != NULL && opts->size >= sizeof(*opts) && opts->canonical;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static int opts_width(const yeptris_emit_options* opts) {
|
|
19
|
+
if (opts == NULL || opts->size < sizeof(*opts) || opts->best_width <= 0) {
|
|
20
|
+
return 80; /* libyaml best_width parity */
|
|
21
|
+
}
|
|
22
|
+
return opts->best_width;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static int opts_doc_marker(const yeptris_emit_options* opts) {
|
|
26
|
+
/* size-versioned: callers compiled against the older struct keep
|
|
27
|
+
* the implicit single-document behavior */
|
|
28
|
+
if (opts == NULL ||
|
|
29
|
+
opts->size < (uint32_t)(offsetof(yeptris_emit_options, explicit_doc_start) + sizeof(int))) {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
return opts->explicit_doc_start != 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
YEPTRIS_API size_t yeptris_serialize_into_ex(YeptrisDocument handle,
|
|
36
|
+
const yeptris_emit_options* opts, char* buf,
|
|
37
|
+
size_t cap) {
|
|
38
|
+
if (handle == NULL) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
yep_emitter em;
|
|
42
|
+
em.w.sc_dec = NULL;
|
|
43
|
+
em.w.sc_i = 0;
|
|
44
|
+
em.w.cap = 0;
|
|
45
|
+
em.w.grow = 0;
|
|
46
|
+
em.w.oom = 0;
|
|
47
|
+
em.doc = (const yeptris_document*)handle;
|
|
48
|
+
if (yep_doc_dom((yeptris_document*)handle) == NULL) { /* #342 lazy */
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
em.w.p = NULL;
|
|
52
|
+
em.w.last = 0;
|
|
53
|
+
em.w.force_flow = 0;
|
|
54
|
+
em.w.canonical = opts_canonical(opts);
|
|
55
|
+
em.w.explicit_doc_start = opts_doc_marker(opts);
|
|
56
|
+
em.w.json = 0;
|
|
57
|
+
em.w.json_compact = 0;
|
|
58
|
+
em.w.json_pretty = 0;
|
|
59
|
+
em.w.pretty_depth = 0;
|
|
60
|
+
em.w.best_width = opts_width(opts);
|
|
61
|
+
em.w.col = 0;
|
|
62
|
+
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
63
|
+
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
64
|
+
em.w.sink = NULL;
|
|
65
|
+
em.w.watermark = 0;
|
|
66
|
+
em.w.sink_aborted = 0;
|
|
67
|
+
em.w.flushed = 0;
|
|
68
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
em.w.sc_dec = (uint8_t*)malloc(em.doc->dom->ncount > 0 ? em.doc->dom->ncount : 1);
|
|
72
|
+
if (em.w.sc_dec == NULL) {
|
|
73
|
+
yep_nametab_free(&em.canon_names);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
size_t need = yep_emit_run(&em, 1);
|
|
77
|
+
if (buf == NULL || cap < need + 1) {
|
|
78
|
+
free(em.w.sc_dec);
|
|
79
|
+
yep_nametab_free(&em.canon_names);
|
|
80
|
+
return need;
|
|
81
|
+
}
|
|
82
|
+
em.w.p = buf;
|
|
83
|
+
size_t wrote = yep_emit_run(&em, 0);
|
|
84
|
+
free(em.w.sc_dec);
|
|
85
|
+
yep_nametab_free(&em.canon_names);
|
|
86
|
+
buf[wrote] = '\0';
|
|
87
|
+
return wrote;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
YEPTRIS_API void yeptris_free(void* p) {
|
|
91
|
+
free(p);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
YEPTRIS_API char* yeptris_serialize_ex(YeptrisDocument handle, const yeptris_emit_options* opts,
|
|
95
|
+
size_t* len) {
|
|
96
|
+
if (handle == NULL) {
|
|
97
|
+
return NULL;
|
|
98
|
+
}
|
|
99
|
+
yep_emitter em;
|
|
100
|
+
em.w.sc_dec = NULL;
|
|
101
|
+
em.w.sc_i = 0;
|
|
102
|
+
em.w.cap = 0;
|
|
103
|
+
em.w.grow = 0;
|
|
104
|
+
em.w.oom = 0;
|
|
105
|
+
em.doc = (const yeptris_document*)handle;
|
|
106
|
+
if (yep_doc_dom((yeptris_document*)handle) == NULL) { /* #342 lazy */
|
|
107
|
+
return NULL;
|
|
108
|
+
}
|
|
109
|
+
em.w.p = NULL;
|
|
110
|
+
em.w.last = 0;
|
|
111
|
+
em.w.force_flow = 0;
|
|
112
|
+
em.w.canonical = opts_canonical(opts);
|
|
113
|
+
em.w.explicit_doc_start = opts_doc_marker(opts);
|
|
114
|
+
em.w.json = 0;
|
|
115
|
+
em.w.json_compact = 0;
|
|
116
|
+
em.w.json_pretty = 0;
|
|
117
|
+
em.w.pretty_depth = 0;
|
|
118
|
+
em.w.best_width = opts_width(opts);
|
|
119
|
+
em.w.col = 0;
|
|
120
|
+
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
121
|
+
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
122
|
+
em.w.sink = NULL;
|
|
123
|
+
em.w.watermark = 0;
|
|
124
|
+
em.w.sink_aborted = 0;
|
|
125
|
+
em.w.flushed = 0;
|
|
126
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
127
|
+
return NULL;
|
|
128
|
+
}
|
|
129
|
+
/* #352 slice 2: ONE wet pass into a growable buffer — the dry
|
|
130
|
+
* exact-sizing pass measured 0.54-0.73x of this route on CI-fresh
|
|
131
|
+
* runners (the emit-split table's 2p/1p column). The estimate
|
|
132
|
+
* starts at the input size (+64) and doubles on demand; a final
|
|
133
|
+
* shrink-to-fit keeps the returned allocation tight. No dry pass,
|
|
134
|
+
* so no decisions table. */
|
|
135
|
+
size_t est = em.doc->dom->input_len + 64;
|
|
136
|
+
if (est < 256) {
|
|
137
|
+
est = 256;
|
|
138
|
+
}
|
|
139
|
+
char* out = (char*)malloc(est);
|
|
140
|
+
if (out == NULL) {
|
|
141
|
+
yep_nametab_free(&em.canon_names);
|
|
142
|
+
return NULL;
|
|
143
|
+
}
|
|
144
|
+
em.w.p = out;
|
|
145
|
+
em.w.cap = est;
|
|
146
|
+
em.w.grow = 1;
|
|
147
|
+
size_t wrote = yep_emit_run(&em, 0);
|
|
148
|
+
em.w.grow = 0;
|
|
149
|
+
/* wr_grow reallocs through w->p — the local `out` is stale after
|
|
150
|
+
* any growth; every post-run touch goes through the writer's
|
|
151
|
+
* pointer (the first round's abort was exactly this aliasing) */
|
|
152
|
+
out = em.w.p;
|
|
153
|
+
if (em.w.oom) {
|
|
154
|
+
free(out);
|
|
155
|
+
yep_nametab_free(&em.canon_names);
|
|
156
|
+
return NULL;
|
|
157
|
+
}
|
|
158
|
+
if (wrote + 1 < em.w.cap) {
|
|
159
|
+
char* tight = (char*)realloc(out, wrote + 1);
|
|
160
|
+
if (tight != NULL) {
|
|
161
|
+
out = tight;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
yep_nametab_free(&em.canon_names);
|
|
165
|
+
out[wrote] = '\0';
|
|
166
|
+
if (len != NULL) {
|
|
167
|
+
*len = wrote;
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
YEPTRIS_API char* yeptris_serialize_json(YeptrisDocument handle, size_t* len) {
|
|
173
|
+
if (handle == NULL) {
|
|
174
|
+
return NULL;
|
|
175
|
+
}
|
|
176
|
+
yep_emitter em;
|
|
177
|
+
em.w.sc_dec = NULL;
|
|
178
|
+
em.w.sc_i = 0;
|
|
179
|
+
em.w.cap = 0;
|
|
180
|
+
em.w.grow = 0;
|
|
181
|
+
em.w.oom = 0;
|
|
182
|
+
em.doc = (const yeptris_document*)handle;
|
|
183
|
+
if (yep_doc_dom((yeptris_document*)handle) == NULL) { /* #342 lazy */
|
|
184
|
+
return NULL;
|
|
185
|
+
}
|
|
186
|
+
em.w.p = NULL;
|
|
187
|
+
em.w.last = 0;
|
|
188
|
+
em.w.force_flow = 0;
|
|
189
|
+
em.w.canonical = 0;
|
|
190
|
+
em.w.explicit_doc_start = 0; /* JSON output carries no --- */
|
|
191
|
+
em.w.json = 1;
|
|
192
|
+
em.w.json_compact = 0;
|
|
193
|
+
em.w.json_pretty = 0;
|
|
194
|
+
em.w.pretty_depth = 0;
|
|
195
|
+
em.w.best_width = 0; /* JSON: no folding (single-line output) */
|
|
196
|
+
em.w.col = 0;
|
|
197
|
+
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
198
|
+
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
199
|
+
em.w.sink = NULL;
|
|
200
|
+
em.w.watermark = 0;
|
|
201
|
+
em.w.sink_aborted = 0;
|
|
202
|
+
em.w.flushed = 0;
|
|
203
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
204
|
+
return NULL;
|
|
205
|
+
}
|
|
206
|
+
size_t need = yep_emit_run(&em, 1);
|
|
207
|
+
char* out = malloc(need + 1);
|
|
208
|
+
if (out == NULL) {
|
|
209
|
+
yep_nametab_free(&em.canon_names);
|
|
210
|
+
return NULL;
|
|
211
|
+
}
|
|
212
|
+
em.w.p = out;
|
|
213
|
+
size_t wrote = yep_emit_run(&em, 0);
|
|
214
|
+
yep_nametab_free(&em.canon_names);
|
|
215
|
+
out[wrote] = '\0';
|
|
216
|
+
if (len != NULL) {
|
|
217
|
+
*len = wrote;
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
YEPTRIS_API char* yeptris_serialize_json_ex(YeptrisDocument handle, size_t* len, int compact) {
|
|
223
|
+
if (handle == NULL) {
|
|
224
|
+
return NULL;
|
|
225
|
+
}
|
|
226
|
+
if (handle == NULL) {
|
|
227
|
+
return NULL;
|
|
228
|
+
}
|
|
229
|
+
yep_emitter em;
|
|
230
|
+
em.w.sc_dec = NULL;
|
|
231
|
+
em.w.sc_i = 0;
|
|
232
|
+
em.w.cap = 0;
|
|
233
|
+
em.w.grow = 0;
|
|
234
|
+
em.w.oom = 0;
|
|
235
|
+
em.doc = (const yeptris_document*)handle;
|
|
236
|
+
if (yep_doc_dom((yeptris_document*)handle) == NULL) { /* #342 lazy */
|
|
237
|
+
return NULL;
|
|
238
|
+
}
|
|
239
|
+
em.w.p = NULL;
|
|
240
|
+
em.w.last = 0;
|
|
241
|
+
em.w.force_flow = 0;
|
|
242
|
+
em.w.canonical = 0;
|
|
243
|
+
em.w.explicit_doc_start = 0; /* JSON output carries no --- */
|
|
244
|
+
em.w.json = 1;
|
|
245
|
+
em.w.json_compact = compact ? 1 : 0;
|
|
246
|
+
em.w.json_pretty = 0;
|
|
247
|
+
em.w.pretty_depth = 0;
|
|
248
|
+
em.w.best_width = 0; /* JSON: no folding (single-line output) */
|
|
249
|
+
em.w.col = 0;
|
|
250
|
+
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
251
|
+
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
252
|
+
em.w.sink = NULL;
|
|
253
|
+
em.w.watermark = 0;
|
|
254
|
+
em.w.sink_aborted = 0;
|
|
255
|
+
em.w.flushed = 0;
|
|
256
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
257
|
+
return NULL;
|
|
258
|
+
}
|
|
259
|
+
size_t need = yep_emit_run(&em, 1);
|
|
260
|
+
char* out = malloc(need + 1);
|
|
261
|
+
if (out == NULL) {
|
|
262
|
+
yep_nametab_free(&em.canon_names);
|
|
263
|
+
return NULL;
|
|
264
|
+
}
|
|
265
|
+
em.w.p = out;
|
|
266
|
+
size_t wrote = yep_emit_run(&em, 0);
|
|
267
|
+
yep_nametab_free(&em.canon_names);
|
|
268
|
+
out[wrote] = '\0';
|
|
269
|
+
if (len != NULL) {
|
|
270
|
+
*len = wrote;
|
|
271
|
+
}
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
char* yep_serialize_json_compact(const yeptris_document* doc, size_t* len) {
|
|
276
|
+
if (doc == NULL) {
|
|
277
|
+
return NULL;
|
|
278
|
+
}
|
|
279
|
+
yep_emitter em;
|
|
280
|
+
em.w.sc_dec = NULL;
|
|
281
|
+
em.w.sc_i = 0;
|
|
282
|
+
em.w.cap = 0;
|
|
283
|
+
em.w.grow = 0;
|
|
284
|
+
em.w.oom = 0;
|
|
285
|
+
em.doc = doc;
|
|
286
|
+
em.w.p = NULL;
|
|
287
|
+
em.w.last = 0;
|
|
288
|
+
em.w.force_flow = 0;
|
|
289
|
+
em.w.canonical = 0;
|
|
290
|
+
em.w.explicit_doc_start = 0; /* JSON output carries no --- */
|
|
291
|
+
em.w.json = 1;
|
|
292
|
+
em.w.json_compact = 1;
|
|
293
|
+
em.w.json_pretty = 0;
|
|
294
|
+
em.w.pretty_depth = 0;
|
|
295
|
+
em.w.best_width = 0;
|
|
296
|
+
em.w.col = 0;
|
|
297
|
+
em.w.sv_input = doc->dom->input_base;
|
|
298
|
+
em.w.sv_arena = doc->dom->str;
|
|
299
|
+
em.w.sink = NULL;
|
|
300
|
+
em.w.watermark = 0;
|
|
301
|
+
em.w.sink_aborted = 0;
|
|
302
|
+
em.w.flushed = 0;
|
|
303
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
304
|
+
return NULL;
|
|
305
|
+
}
|
|
306
|
+
size_t need = yep_emit_run(&em, 1);
|
|
307
|
+
char* out = malloc(need + 1);
|
|
308
|
+
if (out == NULL) {
|
|
309
|
+
yep_nametab_free(&em.canon_names);
|
|
310
|
+
return NULL;
|
|
311
|
+
}
|
|
312
|
+
em.w.p = out;
|
|
313
|
+
size_t wrote = yep_emit_run(&em, 0);
|
|
314
|
+
yep_nametab_free(&em.canon_names);
|
|
315
|
+
out[wrote] = '\0';
|
|
316
|
+
if (len != NULL) {
|
|
317
|
+
*len = wrote;
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
char* yep_serialize_json_pretty(const yeptris_document* doc, size_t* len) {
|
|
323
|
+
if (doc == NULL) {
|
|
324
|
+
return NULL;
|
|
325
|
+
}
|
|
326
|
+
yep_emitter em;
|
|
327
|
+
em.w.sc_dec = NULL;
|
|
328
|
+
em.w.sc_i = 0;
|
|
329
|
+
em.w.cap = 0;
|
|
330
|
+
em.w.grow = 0;
|
|
331
|
+
em.w.oom = 0;
|
|
332
|
+
em.doc = doc;
|
|
333
|
+
em.w.p = NULL;
|
|
334
|
+
em.w.last = 0;
|
|
335
|
+
em.w.force_flow = 0;
|
|
336
|
+
em.w.canonical = 0;
|
|
337
|
+
em.w.explicit_doc_start = 0; /* JSON output carries no --- */
|
|
338
|
+
em.w.json = 1;
|
|
339
|
+
em.w.json_compact = 0;
|
|
340
|
+
em.w.json_pretty = 1;
|
|
341
|
+
em.w.pretty_depth = 0;
|
|
342
|
+
em.w.best_width = 0;
|
|
343
|
+
em.w.col = 0;
|
|
344
|
+
em.w.sv_input = doc->dom->input_base;
|
|
345
|
+
em.w.sv_arena = doc->dom->str;
|
|
346
|
+
em.w.sink = NULL;
|
|
347
|
+
em.w.watermark = 0;
|
|
348
|
+
em.w.sink_aborted = 0;
|
|
349
|
+
em.w.flushed = 0;
|
|
350
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
351
|
+
return NULL;
|
|
352
|
+
}
|
|
353
|
+
size_t need = yep_emit_run(&em, 1);
|
|
354
|
+
char* out = malloc(need + 1);
|
|
355
|
+
if (out == NULL) {
|
|
356
|
+
yep_nametab_free(&em.canon_names);
|
|
357
|
+
return NULL;
|
|
358
|
+
}
|
|
359
|
+
em.w.p = out;
|
|
360
|
+
size_t wrote = yep_emit_run(&em, 0);
|
|
361
|
+
yep_nametab_free(&em.canon_names);
|
|
362
|
+
out[wrote] = '\0';
|
|
363
|
+
if (len != NULL) {
|
|
364
|
+
*len = wrote;
|
|
365
|
+
}
|
|
366
|
+
return out;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
YEPTRIS_API size_t yeptris_serialize_into(YeptrisDocument handle, char* buf, size_t cap) {
|
|
370
|
+
return yeptris_serialize_into_ex(handle, NULL, buf, cap);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
YEPTRIS_API char* yeptris_serialize(YeptrisDocument handle, size_t* len) {
|
|
374
|
+
return yeptris_serialize_ex(handle, NULL, len);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/* Streaming writer (13C): the writer appends linearly (nothing is
|
|
378
|
+
* back-patched), so flushing at a high-water mark is always safe —
|
|
379
|
+
* memory stays bounded by the mark, never the document. */
|
|
380
|
+
YEPTRIS_API size_t yeptris_serialize_stream(YeptrisDocument handle,
|
|
381
|
+
const yeptris_emit_options* opts,
|
|
382
|
+
yeptris_emit_sink sink, void* ctx) {
|
|
383
|
+
if (handle == NULL || sink == NULL) {
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
yep_emitter em;
|
|
387
|
+
em.w.sc_dec = NULL;
|
|
388
|
+
em.w.sc_i = 0;
|
|
389
|
+
em.w.cap = 0;
|
|
390
|
+
em.w.grow = 0;
|
|
391
|
+
em.w.oom = 0;
|
|
392
|
+
em.doc = (const yeptris_document*)handle;
|
|
393
|
+
if (yep_doc_dom((yeptris_document*)handle) == NULL) { /* #342 lazy */
|
|
394
|
+
return 0;
|
|
395
|
+
}
|
|
396
|
+
em.w.p = NULL;
|
|
397
|
+
em.w.last = 0;
|
|
398
|
+
em.w.force_flow = 0;
|
|
399
|
+
em.w.canonical = opts_canonical(opts);
|
|
400
|
+
em.w.explicit_doc_start = opts_doc_marker(opts);
|
|
401
|
+
em.w.json = 0;
|
|
402
|
+
em.w.json_compact = 0;
|
|
403
|
+
em.w.json_pretty = 0;
|
|
404
|
+
em.w.pretty_depth = 0;
|
|
405
|
+
em.w.best_width = opts_width(opts);
|
|
406
|
+
em.w.col = 0;
|
|
407
|
+
em.w.sv_input = handle ? ((const yeptris_document*)handle)->dom->input_base : NULL;
|
|
408
|
+
em.w.sv_arena = handle ? ((const yeptris_document*)handle)->dom->str : NULL;
|
|
409
|
+
em.w.sink = sink;
|
|
410
|
+
em.w.sink_ctx = ctx;
|
|
411
|
+
em.w.watermark = YEP_EMIT_WATERMARK;
|
|
412
|
+
if (!yep_nametab_init(&em.canon_names, yep_system_allocator())) {
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
/* one scratch window; the writer flushes it when it fills */
|
|
416
|
+
char* window = malloc(YEP_EMIT_WATERMARK * 2);
|
|
417
|
+
if (window == NULL) {
|
|
418
|
+
yep_nametab_free(&em.canon_names);
|
|
419
|
+
return 0;
|
|
420
|
+
}
|
|
421
|
+
em.w.p = window;
|
|
422
|
+
em.w.sink_aborted = 0;
|
|
423
|
+
size_t total = yep_emit_run(&em, 0);
|
|
424
|
+
if (em.w.len > 0 && !em.w.sink_aborted) {
|
|
425
|
+
if (sink(ctx, window, em.w.len) != 0) {
|
|
426
|
+
em.w.sink_aborted = 1;
|
|
427
|
+
} else {
|
|
428
|
+
/* total already counted by the flush hooks */
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
free(window);
|
|
432
|
+
yep_nametab_free(&em.canon_names);
|
|
433
|
+
return em.w.sink_aborted ? 0 : total;
|
|
434
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* api.h — the emitter-facing float printer boundary (TODO.impl/14).
|
|
2
|
+
*
|
|
3
|
+
* Thin adaptation over the clean-room float printer TUs
|
|
4
|
+
* (TODO.impl/14 — no third-party code). Non-finite
|
|
5
|
+
* values print as the YAML core-schema words (.inf/-.inf/.nan), never
|
|
6
|
+
* ryu's "Infinity"/"NaN" — the resolver and the printer agree.
|
|
7
|
+
*
|
|
8
|
+
* Buffer contracts (caller provides; asserted by tests):
|
|
9
|
+
* shortest: 32 bytes; fixed: 2 + 309 + 1 + precision.
|
|
10
|
+
*/
|
|
11
|
+
#ifndef YEP_FLOAT_API_H
|
|
12
|
+
#define YEP_FLOAT_API_H
|
|
13
|
+
|
|
14
|
+
#include <stddef.h>
|
|
15
|
+
#include <stdint.h>
|
|
16
|
+
|
|
17
|
+
#ifdef __cplusplus
|
|
18
|
+
extern "C" {
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
/* Shortest round-trip decimal for a double. Returns the length written. */
|
|
22
|
+
int yep_d2s_shortest(double d, char* buf);
|
|
23
|
+
|
|
24
|
+
/* Shortest round-trip decimal for a float. Returns the length written. */
|
|
25
|
+
int yep_f2s_shortest(float f, char* buf);
|
|
26
|
+
|
|
27
|
+
/* Fixed-notation output with exactly `precision` fraction digits
|
|
28
|
+
* (Psych Float#to_s / explicit-precision emission). Returns length. */
|
|
29
|
+
int yep_d2fixed(double d, uint32_t precision, char* buf);
|
|
30
|
+
|
|
31
|
+
/* YAML words for non-finite values (finite input returns 0). */
|
|
32
|
+
int yep_d2s_nonfinite(double d, char* buf);
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif /* YEP_FLOAT_API_H */
|