leptris 1.9.458.0-arm-linux → 1.9.460.0-arm-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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/CONTEXT.md +9 -3
  4. data/README.adoc +28 -17
  5. data/Rakefile +1 -1
  6. data/lib/leptris/version.rb +1 -1
  7. data/lib/leptris/xml/document.rb +75 -48
  8. data/lib/leptris/xml/ffi.rb +8 -0
  9. data/lib/libleptris.so +0 -0
  10. data/vendor-src/README.md +1 -1
  11. data/vendor-src/libleptris/CHANGELOG.md +42 -0
  12. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  13. data/vendor-src/libleptris/README.adoc +19 -0
  14. data/vendor-src/libleptris/benchmarks/CMakeLists.txt +23 -2
  15. data/vendor-src/libleptris/benchmarks/README.adoc +15 -0
  16. data/vendor-src/libleptris/benchmarks/README.md +17 -4
  17. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_decomp.cpp +2 -1
  18. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_first_access.cpp +2 -1
  19. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_many_attrs.cpp +2 -1
  20. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_memory.cpp +2 -1
  21. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse.cpp +2 -2
  22. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse_ops.cpp +8 -4
  23. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_write.cpp +4 -2
  24. data/vendor-src/libleptris/benchmarks/dom/dom_benchmark_v2.cpp +8 -4
  25. data/vendor-src/libleptris/benchmarks/fixtures/serialbench_users_medium.xml +13004 -0
  26. data/vendor-src/libleptris/benchmarks/matrix/bench_matrix.cpp +21 -76
  27. data/vendor-src/libleptris/benchmarks/matrix/bench_matrix_fused.cpp +31 -0
  28. data/vendor-src/libleptris/benchmarks/matrix/bench_rows.h +94 -0
  29. data/vendor-src/libleptris/benchmarks/modification/bench_append_attr_pugixml.cpp +2 -1
  30. data/vendor-src/libleptris/benchmarks/parse/bench_parse_ab.cpp +2 -1
  31. data/vendor-src/libleptris/benchmarks/twins/generation_users.sh +49 -0
  32. data/vendor-src/libleptris/benchmarks/twins/generation_users_fixture.h +78 -0
  33. data/vendor-src/libleptris/benchmarks/twins/generation_users_leptris.c +122 -0
  34. data/vendor-src/libleptris/benchmarks/twins/generation_users_pugixml.cpp +231 -0
  35. data/vendor-src/libleptris/benchmarks/twins/parse_pugixml.cpp +1 -1
  36. data/vendor-src/libleptris/benchmarks/twins/parse_users_ab.cpp +158 -0
  37. data/vendor-src/libleptris/benchmarks/workflows/bench_pipeline_shapes.cpp +12 -4
  38. data/vendor-src/libleptris/benchmarks/xpath/bench_pugixml.cpp +2 -1
  39. data/vendor-src/libleptris/cli/CLI_ARCHITECTURE.md +9 -1
  40. data/vendor-src/libleptris/cli/commands/diff.c +26 -28
  41. data/vendor-src/libleptris/cli/commands/format.c +3 -1
  42. data/vendor-src/libleptris/cli/commands/parse.c +3 -1
  43. data/vendor-src/libleptris/cli/commands/validate.c +22 -24
  44. data/vendor-src/libleptris/cli/commands/xpath.c +9 -1
  45. data/vendor-src/libleptris/cli/commands/xquery.c +12 -3
  46. data/vendor-src/libleptris/cli/commands/xslt.c +24 -8
  47. data/vendor-src/libleptris/cli/error.c +91 -0
  48. data/vendor-src/libleptris/cli/error.h +84 -0
  49. data/vendor-src/libleptris/cli/man/leptris-parse.1.adoc +21 -10
  50. data/vendor-src/libleptris/cli/man/leptris.1.adoc +19 -0
  51. data/vendor-src/libleptris/cli/output.c +18 -9
  52. data/vendor-src/libleptris/cli/output.h +17 -0
  53. data/vendor-src/libleptris/src/CMakeLists.txt +3 -0
  54. data/vendor-src/libleptris/src/include/leptris/types.h +25 -1
  55. data/vendor-src/libleptris/src/include/leptris/xquery/xquery.h +9 -1
  56. data/vendor-src/libleptris/src/include/leptris.h +48 -3
  57. data/vendor-src/libleptris/src/leptris/common/entities.c +2 -2
  58. data/vendor-src/libleptris/src/leptris/common/entities.h +8 -2
  59. data/vendor-src/libleptris/src/leptris/common/port.h +62 -0
  60. data/vendor-src/libleptris/src/leptris/common/uri_base.c +284 -0
  61. data/vendor-src/libleptris/src/leptris/common/uri_base.h +62 -0
  62. data/vendor-src/libleptris/src/leptris/core.c +33 -2
  63. data/vendor-src/libleptris/src/leptris/dom/compact.h +51 -0
  64. data/vendor-src/libleptris/src/leptris/dom/element.c +18 -0
  65. data/vendor-src/libleptris/src/leptris/dom/element.h +201 -12
  66. data/vendor-src/libleptris/src/leptris/dom/element_modify.c +611 -210
  67. data/vendor-src/libleptris/src/leptris/dom/element_query.c +72 -1
  68. data/vendor-src/libleptris/src/leptris/dom/name_intern.c +3 -1
  69. data/vendor-src/libleptris/src/leptris/dtd/model.c +13 -0
  70. data/vendor-src/libleptris/src/leptris/dtd/model.h +95 -6
  71. data/vendor-src/libleptris/src/leptris/dtd/resolver.c +302 -215
  72. data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +801 -294
  73. data/vendor-src/libleptris/src/leptris/leptris.c +20 -5
  74. data/vendor-src/libleptris/src/leptris/leptris_internal.h +68 -22
  75. data/vendor-src/libleptris/src/leptris/serialize/serialize.c +289 -57
  76. data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +14 -125
  77. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +3 -0
  78. data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +11 -8
  79. data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +188 -24
  80. data/vendor-src/libleptris/src/leptris/xpath/vm.c +3 -1
  81. data/vendor-src/libleptris/src/leptris/xquery/xquery.c +5 -0
  82. data/vendor-src/libleptris/src/leptris/xsd/compile.c +59 -20
  83. data/vendor-src/libleptris/src/leptris/xsd/validate.c +291 -168
  84. data/vendor-src/libleptris/test/CMakeLists.txt +28 -0
  85. data/vendor-src/libleptris/test/abi/test_public_surface.cpp +37 -0
  86. data/vendor-src/libleptris/test/cli/test_cli.cpp +228 -0
  87. data/vendor-src/libleptris/test/common/hang_guard.h +179 -0
  88. data/vendor-src/libleptris/test/dom/test_compact.cpp +46 -0
  89. data/vendor-src/libleptris/test/dom/test_mut_append_contracts.cpp +173 -0
  90. data/vendor-src/libleptris/test/dom/test_mut_set_attr_contracts.cpp +771 -7
  91. data/vendor-src/libleptris/test/fixtures/entity_limits/good.xml +100 -0
  92. data/vendor-src/libleptris/test/fixtures/entity_limits/good_attr.xml +100 -0
  93. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_classic.xml +51 -0
  94. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_attr.xml +23 -0
  95. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_content.xml +23 -0
  96. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_long_name.xml +23 -0
  97. data/vendor-src/libleptris/test/memory/test_oom_injection.cpp +63 -0
  98. data/vendor-src/libleptris/test/parser/test_entity_limits.cpp +404 -0
  99. data/vendor-src/libleptris/test/parser/test_parser.cpp +126 -0
  100. data/vendor-src/libleptris/test/serializer/test_serialize.cpp +491 -0
  101. data/vendor-src/libleptris/test/xpath/test_base_uri.cpp +368 -0
  102. data/vendor-src/libleptris/test/xpath/test_xpath.cpp +86 -0
  103. data/vendor-src/libleptris/test/xsd/test_xsd11_base_uri.cpp +145 -0
  104. data/vendor-src/libleptris/test/xsd/test_xsd11_conformance.cpp +23 -5
  105. data/vendor-src/libleptris/test/xsd/test_xsd11_cta_context.cpp +385 -0
  106. data/vendor-src/libleptris/test/xsd/xsd11-all/all-restrict.xsd +3 -2
  107. data/vendor-src/libleptris/test/xsd/xsd11-all/all-wildcard.xsd +3 -2
  108. data/vendor-src/libleptris/test/xsd/xsd11-cases/MANIFEST.tsv +19 -2
  109. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.n01.xml +5 -0
  110. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.v01.xml +4 -0
  111. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.xsd +46 -0
  112. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.v01.xml +6 -0
  113. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.xsd +83 -0
  114. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.v01.xml +3 -0
  115. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.xsd +36 -0
  116. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.n01.xml +3 -0
  117. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.v01.xml +3 -0
  118. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.xsd +36 -0
  119. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0023.v01.xml +3 -0
  120. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0024.xsd +40 -0
  121. data/vendor-src/libleptris/test/xsd/xsd11-dispositions/README.md +67 -0
  122. data/vendor-src/libleptris/vcpkg.json +1 -1
  123. metadata +35 -2
@@ -0,0 +1,231 @@
1
+ /* generation_users_pugixml.cpp — the pugixml lane of serialbench's
2
+ * `generation` op on the canonical users fixture (leptris#2279), plus the
3
+ * paired driver (main). The leptris lane lives in generation_users_leptris.c;
4
+ * both include generation_users_fixture.h — one generator, one byte-identical
5
+ * document, both lanes in ONE process so the interleaved rounds see the
6
+ * same machine load.
7
+ *
8
+ * Op definition — serialbench-c src/bench_cpp.cpp, bench_cpp(), the
9
+ * g_cur_op = "generation" block over {size}.xml (pugi_opts is the
10
+ * lane's parse flag, fixed at the top of that block):
11
+ *
12
+ * const unsigned pugi_opts = pugi::parse_default | pugi::parse_ws_pcdata;
13
+ * pugi::xml_document doc; doc.load_buffer(data, len, pugi_opts);
14
+ * pugi_buf_writer w;
15
+ * doc.print(w);
16
+ *
17
+ * with, verbatim from that file:
18
+ * struct pugi_buf_writer : pugi::xml_writer {
19
+ * void write(const void* data, size_t size) override { n += size; (void)data; }
20
+ * size_t n = 0;
21
+ * };
22
+ *
23
+ * parse_ws_pcdata keeps whitespace-only text nodes — the same 29003-node
24
+ * tree the leptris lane carries (the same-tree law, leptris#1842). The
25
+ * writer COUNTS the bytes and never materializes them: the lane pays the
26
+ * walk and the escape scans, not an output buffer (load_buffer copies the
27
+ * input into pugixml's pages; print's default is indent="\t",
28
+ * format_default — on this document both reproduce the input bytes, see
29
+ * --check).
30
+ *
31
+ * Driver: min-of-N per phase, R interleaved rounds (leptris, then
32
+ * pugixml, per phase, per round), load average printed per round.
33
+ * --iters N iterations per phase per round (default 30)
34
+ * --rounds N interleaved rounds (default 3)
35
+ * --phases s comma list of gen,parse,ser,free (default all)
36
+ * --check output byte-identity against the pinned compact-default
37
+ * contract + element-count parity, no timing
38
+ * --dump write the generated fixture to stdout (shasum check)
39
+ * --dump-out write the leptris lane's GEN output to stdout (cmp the
40
+ * dumps of two builds: the lever's byte-identity witness)
41
+ */
42
+
43
+ #include <algorithm>
44
+ #include <cstdio>
45
+ #include <cstdlib>
46
+ #include <cstring>
47
+ #include <string>
48
+ #include <vector>
49
+
50
+ #include "../common/bench_time.h"
51
+ #include <pugixml.hpp>
52
+
53
+ #include "generation_users_fixture.h"
54
+
55
+ extern "C" double gu_leptris_min(const char* data, size_t len, int phase,
56
+ int iters);
57
+ extern "C" int gu_leptris_check(const char* data, size_t len, char* out,
58
+ size_t cap, size_t* out_len,
59
+ long* element_count);
60
+
61
+ struct pugi_buf_writer : pugi::xml_writer {
62
+ void write(const void* data, size_t size) override { n += size; (void)data; }
63
+ size_t n = 0;
64
+ };
65
+
66
+ static const unsigned pugi_opts = pugi::parse_default | pugi::parse_ws_pcdata;
67
+
68
+ /* One iteration of a phase; `held` is the document parsed outside the
69
+ * timer for SER. Returns the writer's byte count (SER/GEN). */
70
+ static size_t gu_pugixml_once(const char* data, size_t len, int phase,
71
+ pugi::xml_document* held) {
72
+ if (phase == GU_PHASE_FREE) {
73
+ delete held;
74
+ return 0;
75
+ }
76
+ if (phase == GU_PHASE_SER) {
77
+ pugi_buf_writer w;
78
+ held->print(w);
79
+ return w.n;
80
+ }
81
+ pugi::xml_document doc;
82
+ doc.load_buffer(data, len, pugi_opts);
83
+ if (phase == GU_PHASE_GEN) {
84
+ pugi_buf_writer w;
85
+ doc.print(w);
86
+ return w.n;
87
+ }
88
+ return 0;
89
+ }
90
+
91
+ double gu_pugixml_min(const char* data, size_t len, int phase, int iters) {
92
+ double best = 1e18;
93
+ pugi::xml_document* held = NULL;
94
+ if (phase == GU_PHASE_SER) {
95
+ held = new pugi::xml_document();
96
+ held->load_buffer(data, len, pugi_opts);
97
+ }
98
+ for (int i = 0; i < iters + 1; i++) { /* iteration 0 warms */
99
+ pugi::xml_document* d = held;
100
+ if (phase == GU_PHASE_FREE) {
101
+ d = new pugi::xml_document();
102
+ d->load_buffer(data, len, pugi_opts);
103
+ }
104
+ double t0 = bench_wall_us();
105
+ gu_pugixml_once(data, len, phase, d);
106
+ double dt = bench_wall_us() - t0;
107
+ if (i > 0 && dt < best) best = dt;
108
+ }
109
+ return best;
110
+ }
111
+
112
+ static double load_avg(void) {
113
+ #if defined(_WIN32)
114
+ return 0.0;
115
+ #else
116
+ double v[1] = {0.0};
117
+ if (getloadavg(v, 1) != 1) return 0.0;
118
+ return v[0];
119
+ #endif
120
+ }
121
+
122
+ static const char* phase_names[GU_PHASE_COUNT] = {"gen", "parse", "ser", "free"};
123
+
124
+ /* --check: the leptris lane's GEN output against the pinned contract
125
+ * (the fixture minus the newline after the declaration and the final
126
+ * newline), plus element-count parity with the pugixml lane. With
127
+ * `ref` set, the output goes to stdout instead (--dump-out: the before/
128
+ * after byte-identity witness for a lever — cmp the two dumps). */
129
+ static int run_check(const char* data, size_t len, int dump_out) {
130
+ static char out[GU_FIXTURE_CAP];
131
+ size_t out_len = 0;
132
+ long l_elems = -1;
133
+ int rc = gu_leptris_check(data, len, out, sizeof out, &out_len, &l_elems);
134
+ if (rc != 0) {
135
+ printf("CHECK leptris generation FAILED (rc=%d)\n", rc);
136
+ return 1;
137
+ }
138
+ if (dump_out) {
139
+ fwrite(out, 1, out_len, stdout);
140
+ return 0;
141
+ }
142
+ /* Expected: fixture without the byte after "?>" and without its last
143
+ * byte (both '\n' in the canonical fixture). */
144
+ static char expect[GU_FIXTURE_CAP];
145
+ size_t decl_nl = (size_t)-1;
146
+ for (size_t i = 0; i + 1 < len; i++) { /* the declaration is the first node */
147
+ if (data[i] == '?' && data[i + 1] == '>') { decl_nl = i + 2; break; }
148
+ }
149
+ size_t n = 0;
150
+ for (size_t i = 0; i < len; i++) {
151
+ if (i == decl_nl || i + 1 == len) continue;
152
+ expect[n++] = data[i];
153
+ }
154
+ size_t first_diff = (size_t)-1;
155
+ size_t common = out_len < n ? out_len : n;
156
+ for (size_t i = 0; i < common; i++)
157
+ if (out[i] != expect[i]) { first_diff = i; break; }
158
+ if (first_diff == (size_t)-1 && out_len != n) first_diff = common;
159
+ int same = first_diff == (size_t)-1;
160
+ printf("CHECK leptris generation: %zu bytes (contract %zu), elements=%ld, "
161
+ "byte-identical to the compact-default contract: %s",
162
+ out_len, n, l_elems, same ? "YES" : "NO");
163
+ if (!same) printf(" (first diff at %zu)", first_diff);
164
+ printf("\n");
165
+ pugi::xml_document doc;
166
+ pugi::xml_parse_result r = doc.load_buffer(data, len, pugi_opts);
167
+ long p_elems = r ? (long)doc.select_nodes("//*").size() : -1;
168
+ pugi_buf_writer w;
169
+ doc.print(w);
170
+ printf("CHECK pugixml generation: %zu bytes (counting writer), elements=%ld, "
171
+ "parse=%s\n",
172
+ w.n, p_elems, r ? "ok" : "FAILED");
173
+ int ok = same && r && p_elems == l_elems;
174
+ printf("CHECK %s\n", ok ? "ALL OK" : "FAILED");
175
+ return ok ? 0 : 1;
176
+ }
177
+
178
+ int main(int argc, char** argv) {
179
+ int iters = 30;
180
+ int rounds = 3;
181
+ int want[GU_PHASE_COUNT] = {1, 1, 1, 1};
182
+ int check = 0, dump = 0, dump_out = 0;
183
+ for (int i = 1; i < argc; i++) {
184
+ if (!strcmp(argv[i], "--iters") && i + 1 < argc) iters = atoi(argv[++i]);
185
+ else if (!strcmp(argv[i], "--rounds") && i + 1 < argc) rounds = atoi(argv[++i]);
186
+ else if (!strcmp(argv[i], "--check")) check = 1;
187
+ else if (!strcmp(argv[i], "--dump")) dump = 1;
188
+ else if (!strcmp(argv[i], "--dump-out")) { check = 1; dump_out = 1; }
189
+ else if (!strcmp(argv[i], "--phases") && i + 1 < argc) {
190
+ for (int p = 0; p < GU_PHASE_COUNT; p++) want[p] = 0;
191
+ const char* s = argv[++i];
192
+ for (int p = 0; p < GU_PHASE_COUNT; p++)
193
+ if (strstr(s, phase_names[p])) want[p] = 1;
194
+ }
195
+ }
196
+
197
+ static char data[GU_FIXTURE_CAP];
198
+ size_t len = gu_generate_users_xml(data);
199
+ if (dump) {
200
+ fwrite(data, 1, len, stdout);
201
+ return 0;
202
+ }
203
+ if (check) return run_check(data, len, dump_out);
204
+
205
+ double lmin[GU_PHASE_COUNT], pmin[GU_PHASE_COUNT];
206
+ for (int p = 0; p < GU_PHASE_COUNT; p++) { lmin[p] = 1e18; pmin[p] = 1e18; }
207
+ printf("serialbench generation op, users fixture: %zu bytes, min-of-%d, "
208
+ "%d interleaved rounds (leptris then pugixml per phase)\n",
209
+ len, iters, rounds);
210
+ for (int r = 0; r < rounds; r++) {
211
+ printf("round %d load %.1f\n", r, load_avg());
212
+ for (int p = 0; p < GU_PHASE_COUNT; p++) {
213
+ if (!want[p]) continue;
214
+ double l = gu_leptris_min(data, len, p, iters);
215
+ double q = gu_pugixml_min(data, len, p, iters);
216
+ lmin[p] = std::min(lmin[p], l);
217
+ pmin[p] = std::min(pmin[p], q);
218
+ printf(" %-5s leptris %8.1f us pugixml %8.1f us ratio %.3fx %s\n",
219
+ phase_names[p], l, q, l / q, l <= q ? "AHEAD" : "behind");
220
+ }
221
+ fflush(stdout);
222
+ }
223
+ for (int p = 0; p < GU_PHASE_COUNT; p++) {
224
+ if (!want[p]) continue;
225
+ printf("MIN %-5s leptris %8.1f us (%6.0f ips) pugixml %8.1f us (%6.0f ips) "
226
+ "ratio %.3fx %s\n",
227
+ phase_names[p], lmin[p], 1e6 / lmin[p], pmin[p], 1e6 / pmin[p],
228
+ lmin[p] / pmin[p], lmin[p] <= pmin[p] ? "AHEAD" : "BEHIND");
229
+ }
230
+ return 0;
231
+ }
@@ -21,7 +21,7 @@ static double bench(const char*xml,size_t n,int reps){
21
21
  for(int r=0;r<reps;r++){
22
22
  double t0=now_us();
23
23
  pugi::xml_document doc;
24
- doc.load_string(xml,pugi::parse_default|pugi::parse_ws_pcdata_single);
24
+ doc.load_string(xml,pugi::parse_default|pugi::parse_ws_pcdata);
25
25
  double t1=now_us();
26
26
  if(t1-t0<best)best=t1-t0;
27
27
  }
@@ -0,0 +1,158 @@
1
+ /* parse_users_ab.cpp — the serialbench `users` PARSE op, paired
2
+ * same-process A/B (leptris#2279).
3
+ *
4
+ * The canonical serialbench medium.xml: 1000 users x (3 text children +
5
+ * nested profile (2 text + nested preferences with 2 text)), one id
6
+ * attribute per user, pretty-printed whitespace between every element —
7
+ * 10,001 elements, ~13,000 whitespace-only text nodes, 306,805 bytes.
8
+ * Carried byte-identical (sha256 008777897407f88e...) as
9
+ * benchmarks/fixtures/serialbench_users_medium.xml; the referee's copy
10
+ * lives in the serialbench/fixtures repository. This is the
11
+ * element-heavy + whitespace-node shape, not the attr-heavy one.
12
+ *
13
+ * The same-tree law (benchmarks/README.md): pugixml parses with
14
+ * parse_default | parse_ws_pcdata so both engines build the same DOM.
15
+ *
16
+ * Protocol: min-of-N per round (default 30), leptris and pugixml
17
+ * interleaved L/P so drift hits both sides, R rounds (default 3); the
18
+ * verdict is the ratio on the cross-round minima. Prints the node count
19
+ * each engine built once, so a tree-shape mismatch cannot hide.
20
+ *
21
+ * bench_parse_users_ab [fixture-path]
22
+ * LEPTRIS_BENCH_ITERS=30 LEPTRIS_BENCH_ROUNDS=3 bench_parse_users_ab
23
+ */
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+ #include <algorithm>
28
+ #include <vector>
29
+ #include "../common/bench_time.h"
30
+ #include "leptris.h"
31
+ #include "leptris/xpath/xpath.h"
32
+ #ifdef HAVE_PUGIXML
33
+ #include "pugixml.hpp"
34
+ using namespace pugi;
35
+ #endif
36
+
37
+ #ifndef LEPTRIS_USERS_FIXTURE
38
+ #define LEPTRIS_USERS_FIXTURE "fixtures/serialbench_users_medium.xml"
39
+ #endif
40
+
41
+ static char* slurp(const char* path, size_t* len) {
42
+ FILE* f = fopen(path, "rb");
43
+ if (!f) {
44
+ fprintf(stderr, "cannot open %s\n", path);
45
+ return NULL;
46
+ }
47
+ fseek(f, 0, SEEK_END);
48
+ long n = ftell(f);
49
+ fseek(f, 0, SEEK_SET);
50
+ char* b = (char*)malloc((size_t)n + 1);
51
+ if (!b || fread(b, 1, (size_t)n, f) != (size_t)n) {
52
+ fprintf(stderr, "cannot read %s\n", path);
53
+ fclose(f);
54
+ free(b);
55
+ return NULL;
56
+ }
57
+ b[n] = 0;
58
+ fclose(f);
59
+ *len = (size_t)n;
60
+ return b;
61
+ }
62
+
63
+ static void run_leptris(const char* data, size_t len) {
64
+ LeptrisStatus st = LEPTRIS_OK;
65
+ LeptrisDocument d = leptris_parse_string(data, len, &st);
66
+ if (!d) { fprintf(stderr, "leptris: PARSE FAILED\n"); exit(2); }
67
+ leptris_document_free(d);
68
+ }
69
+
70
+ #ifdef HAVE_PUGIXML
71
+ static void run_pugixml(const char* data, size_t len) {
72
+ xml_document doc;
73
+ xml_parse_result r = doc.load_buffer(data, len,
74
+ parse_default | parse_ws_pcdata);
75
+ if (!r) { fprintf(stderr, "pugixml: PARSE FAILED\n"); exit(2); }
76
+ }
77
+
78
+ static size_t pugi_count_nodes(const xml_node& n) {
79
+ size_t c = 1;
80
+ for (xml_node cld = n.first_child(); cld; cld = cld.next_sibling())
81
+ c += pugi_count_nodes(cld);
82
+ return c;
83
+ }
84
+ #endif
85
+
86
+ static size_t leptris_count_nodes(const char* data, size_t len) {
87
+ LeptrisStatus st = LEPTRIS_OK;
88
+ LeptrisDocument d = leptris_parse_string(data, len, &st);
89
+ if (!d) return 0;
90
+ LeptrisXPathResult r = leptris_xpath_eval(d, NULL, "count(//node())");
91
+ size_t n = (size_t)leptris_xpath_result_number(r);
92
+ leptris_xpath_result_free(r);
93
+ leptris_document_free(d);
94
+ return n;
95
+ }
96
+
97
+ static double min_of(int iters, void (*fn)(const char*, size_t),
98
+ const char* data, size_t len) {
99
+ fn(data, len); /* warm */
100
+ std::vector<double> t;
101
+ t.reserve((size_t)iters);
102
+ for (int i = 0; i < iters; i++) {
103
+ double t0 = bench_wall_us();
104
+ fn(data, len);
105
+ t.push_back(bench_wall_us() - t0);
106
+ }
107
+ std::sort(t.begin(), t.end());
108
+ return t.front();
109
+ }
110
+
111
+ int main(int argc, char** argv) {
112
+ const char* path = argc > 1 ? argv[1] : LEPTRIS_USERS_FIXTURE;
113
+ const char* iters_env = getenv("LEPTRIS_BENCH_ITERS");
114
+ const char* rounds_env = getenv("LEPTRIS_BENCH_ROUNDS");
115
+ int iters = iters_env ? atoi(iters_env) : 30;
116
+ int rounds = rounds_env ? atoi(rounds_env) : 3;
117
+
118
+ size_t len = 0;
119
+ char* data = slurp(path, &len);
120
+ if (!data) return 2;
121
+
122
+ printf("users PARSE op (leptris#2279) — %s: %zu bytes, min-of-%d, "
123
+ "%d interleaved rounds; pugixml at ws_pcdata parity\n",
124
+ path, len, iters, rounds);
125
+ size_t ln = leptris_count_nodes(data, len);
126
+ #ifdef HAVE_PUGIXML
127
+ {
128
+ xml_document doc;
129
+ doc.load_buffer(data, len, parse_default | parse_ws_pcdata);
130
+ printf("tree check: leptris //node()=%zu pugixml nodes=%zu\n",
131
+ ln, pugi_count_nodes(doc) - 1); /* minus the document node */
132
+ }
133
+ #else
134
+ printf("tree check: leptris //node()=%zu (pugixml not built in)\n", ln);
135
+ #endif
136
+
137
+ double best_l = 1e18, best_p = 1e18;
138
+ for (int r = 0; r < rounds; r++) {
139
+ double l = min_of(iters, run_leptris, data, len);
140
+ #ifdef HAVE_PUGIXML
141
+ double p = min_of(iters, run_pugixml, data, len);
142
+ printf("round %d: leptris %8.1f us (%7.0f ips) pugixml %8.1f us "
143
+ "(%7.0f ips) ratio %.3fx\n",
144
+ r, l, 1e6 / l, p, 1e6 / p, l / p);
145
+ if (p < best_p) best_p = p;
146
+ #else
147
+ printf("round %d: leptris %8.1f us (%7.0f ips)\n", r, l, 1e6 / l);
148
+ #endif
149
+ if (l < best_l) best_l = l;
150
+ }
151
+ #ifdef HAVE_PUGIXML
152
+ printf("VERDICT (cross-round minima): leptris %.1f us / pugixml %.1f us "
153
+ "= %.3fx (%.0f vs %.0f ips)\n",
154
+ best_l, best_p, best_l / best_p, 1e6 / best_l, 1e6 / best_p);
155
+ #endif
156
+ free(data);
157
+ return 0;
158
+ }
@@ -438,7 +438,9 @@ int shape_extract_libxml2(const char* xml, size_t len) {
438
438
  #ifdef HAVE_PUGIXML
439
439
  int shape_metanorma_pugixml(const char* xml, size_t len) {
440
440
  pugi::xml_document doc;
441
- if (!doc.load_buffer(xml, len)) return 1;
441
+ if (!doc.load_buffer(xml, len,
442
+ pugi::parse_default | pugi::parse_ws_pcdata))
443
+ return 1;
442
444
  pugi::xpath_node_set terms =
443
445
  doc.select_nodes("//standard/clause/terms/term");
444
446
  if (terms.empty()) return 1;
@@ -465,7 +467,9 @@ int shape_metanorma_pugixml(const char* xml, size_t len) {
465
467
 
466
468
  int shape_config_pugixml(const char* xml, size_t len) {
467
469
  pugi::xml_document doc;
468
- if (!doc.load_buffer(xml, len)) return 1;
470
+ if (!doc.load_buffer(xml, len,
471
+ pugi::parse_default | pugi::parse_ws_pcdata))
472
+ return 1;
469
473
  static const char* ASSERTS[] = {
470
474
  "//service[@host]",
471
475
  "count(//service[not(@port)])",
@@ -497,7 +501,9 @@ int shape_config_pugixml(const char* xml, size_t len) {
497
501
 
498
502
  int shape_feed_pugixml(const char* xml, size_t len) {
499
503
  pugi::xml_document doc;
500
- if (!doc.load_buffer(xml, len)) return 1;
504
+ if (!doc.load_buffer(xml, len,
505
+ pugi::parse_default | pugi::parse_ws_pcdata))
506
+ return 1;
501
507
  pugi::xpath_node_set entries = doc.select_nodes("//feed/entry");
502
508
  if (entries.empty()) return 1;
503
509
  for (pugi::xpath_node en : entries) {
@@ -517,7 +523,9 @@ int shape_feed_pugixml(const char* xml, size_t len) {
517
523
 
518
524
  int shape_extract_pugixml(const char* xml, size_t len) {
519
525
  pugi::xml_document doc;
520
- if (!doc.load_buffer(xml, len)) return 1;
526
+ if (!doc.load_buffer(xml, len,
527
+ pugi::parse_default | pugi::parse_ws_pcdata))
528
+ return 1;
521
529
  pugi::xpath_node_set sel =
522
530
  doc.select_nodes("//records/record[@status='active']");
523
531
  if (sel.empty()) return 1;
@@ -59,7 +59,8 @@ typedef struct {
59
59
  static void pugi_xpath_eval(void* ctx) {
60
60
  pugi_xpath_ctx_t* c = (pugi_xpath_ctx_t*)ctx;
61
61
  pugi::xml_document doc;
62
- doc.load_buffer(c->xml, c->len);
62
+ doc.load_buffer(c->xml, c->len,
63
+ pugi::parse_default | pugi::parse_ws_pcdata);
63
64
 
64
65
  pugi::xpath_query q(c->query);
65
66
  if (!q) return;
@@ -579,7 +579,7 @@ suggestion: check element nesting
579
579
  cli_fatal("cannot allocate memory");
580
580
 
581
581
  // Regular error (continues)
582
- cli_error("failed to parse XML: %s", reason);
582
+ cli_error("cannot read file: %s: %s", path, strerror(errno));
583
583
 
584
584
  // Warning (continues)
585
585
  cli_warning("missing namespace declaration");
@@ -597,6 +597,14 @@ cli_debug("resolved option: indent=%d", indent);
597
597
  // Parse error
598
598
  cli_error_parse("file.xml", 10, 5, "unexpected end of element");
599
599
 
600
+ // Failed engine operation — the diagnostic comes from the PUBLIC error
601
+ // channel (leptris_last_error / leptris_last_error_position), never
602
+ // from a CLI-made-up message, and renders in the command's output
603
+ // format: `file:line:col: error: message` for xml/text, a structured
604
+ // {"error":{...}} object for json. The reason IS the error: it prints
605
+ // regardless of verbosity (#2291).
606
+ cli_error_engine(file, status, opts->format);
607
+
600
608
  // XPath error
601
609
  cli_error_xpath("//book[@id=1]", "invalid predicate syntax");
602
610
 
@@ -9,30 +9,21 @@
9
9
  #include <stdio.h>
10
10
  #include <string.h>
11
11
  #include <stdlib.h>
12
+ #include <errno.h>
12
13
 
13
- static LeptrisDocument read_doc(const char* path) {
14
- FILE* fp = strcmp(path, "-") == 0 ? stdin : fopen(path, "rb");
15
- if (!fp) return NULL;
16
- char* buf = NULL;
17
- size_t len = 0, cap = 0;
18
- int c;
19
- while ((c = fgetc(fp)) != EOF) {
20
- if (len + 1 >= cap) {
21
- cap = cap ? cap * 2 : 8192;
22
- char* nb = (char*)realloc(buf, cap);
23
- if (!nb) {
24
- free(buf);
25
- if (fp != stdin) fclose(fp);
26
- return NULL;
27
- }
28
- buf = nb;
29
- }
30
- buf[len++] = (char)c;
14
+ /* Load one diff input. NULL + LEPTRIS_ERROR_IO = the input could not be
15
+ * read (reported here, while errno still holds the open failure); NULL +
16
+ * any other status = a parse failure, whose engine diagnostic sits on
17
+ * the public error channel for the caller to report (#2291). */
18
+ static LeptrisDocument read_doc(const char* path, LeptrisStatus* status) {
19
+ size_t len = 0;
20
+ char* buf = cli_read_file(path, &len);
21
+ if (!buf) {
22
+ cli_error("cannot read file: %s: %s", path, strerror(errno));
23
+ *status = LEPTRIS_ERROR_IO;
24
+ return NULL;
31
25
  }
32
- if (fp != stdin) fclose(fp);
33
- LeptrisStatus st = LEPTRIS_OK;
34
- LeptrisDocument d =
35
- buf ? leptris_parse_string(buf, len, &st) : NULL;
26
+ LeptrisDocument d = leptris_parse_string(buf, len, status);
36
27
  free(buf);
37
28
  return d;
38
29
  }
@@ -110,19 +101,26 @@ static cli_result_t diff_execute(int argc, char** argv) {
110
101
  cli_error("diff requires two documents (paths or '-')");
111
102
  return CLI_ERROR_ARGS;
112
103
  }
113
- LeptrisDocument a = read_doc(paths[0]);
114
- LeptrisDocument b = read_doc(paths[1]);
104
+ /* Load and check A before B: the engine's diagnostic channel is
105
+ * thread-local, so a second parse would overwrite A's message
106
+ * before it is reported (#2291). */
107
+ LeptrisStatus st = LEPTRIS_OK;
108
+ LeptrisDocument a = read_doc(paths[0], &st);
115
109
  if (!a) {
116
- cli_error("cannot read or parse: %s", paths[0]);
117
- if (b) leptris_document_free(b);
110
+ if (st != LEPTRIS_ERROR_IO) {
111
+ cli_error_engine(paths[0], st, OUTPUT_FORMAT_TEXT);
112
+ }
118
113
  return CLI_ERROR_IO;
119
114
  }
115
+ st = LEPTRIS_OK;
116
+ LeptrisDocument b = read_doc(paths[1], &st);
120
117
  if (!b) {
121
- cli_error("cannot read or parse: %s", paths[1]);
118
+ if (st != LEPTRIS_ERROR_IO) {
119
+ cli_error_engine(paths[1], st, OUTPUT_FORMAT_TEXT);
120
+ }
122
121
  leptris_document_free(a);
123
122
  return CLI_ERROR_IO;
124
123
  }
125
- LeptrisStatus st = LEPTRIS_OK;
126
124
  LeptrisDiff d = leptris_diff(
127
125
  a, b, ignore_ws ? LEPTRIS_DIFF_IGNORE_WS_TEXT
128
126
  : LEPTRIS_DIFF_DEFAULT,
@@ -276,7 +276,9 @@ static cli_result_t format_execute(int argc, char** argv) {
276
276
  LeptrisStatus status;
277
277
  doc = leptris_parse_string(xml_content, xml_len, &status);
278
278
  if (!doc) {
279
- cli_error("failed to parse XML: %s", opts->input_file);
279
+ /* The engine's diagnostic (message + position) IS the error —
280
+ * printed in the output format, verbosity-independent (#2291). */
281
+ cli_error_engine(opts->input_file, status, opts->format);
280
282
  result = CLI_ERROR_PARSE;
281
283
  goto cleanup;
282
284
  }
@@ -255,7 +255,9 @@ static cli_result_t parse_execute(int argc, char** argv) {
255
255
  LeptrisStatus status;
256
256
  doc = leptris_parse_string_with_encoding(xml_content, xml_len, &status);
257
257
  if (!doc) {
258
- cli_error("failed to parse XML: %s", opts->input_file);
258
+ /* The engine's diagnostic (message + position) IS the error —
259
+ * printed in the output format, verbosity-independent (#2291). */
260
+ cli_error_engine(opts->input_file, status, opts->format);
259
261
  result = CLI_ERROR_PARSE;
260
262
  goto cleanup;
261
263
  }
@@ -10,30 +10,22 @@
10
10
  #include <stdio.h>
11
11
  #include <string.h>
12
12
  #include <stdlib.h>
13
+ #include <errno.h>
13
14
 
14
- static LeptrisDocument read_doc(const char* path) {
15
- FILE* fp = strcmp(path, "-") == 0 ? stdin : fopen(path, "rb");
16
- if (!fp) return NULL;
17
- char* buf = NULL;
18
- size_t len = 0, cap = 0;
19
- int c;
20
- while ((c = fgetc(fp)) != EOF) {
21
- if (len + 1 >= cap) {
22
- cap = cap ? cap * 2 : 8192;
23
- char* nb = (char*)realloc(buf, cap);
24
- if (!nb) {
25
- free(buf);
26
- if (fp != stdin) fclose(fp);
27
- return NULL;
28
- }
29
- buf = nb;
30
- }
31
- buf[len++] = (char)c;
15
+ /* Load the instance document. NULL + LEPTRIS_ERROR_IO = the input could
16
+ * not be read (reported here, while errno still holds the open
17
+ * failure); NULL + any other status = a parse failure, whose engine
18
+ * diagnostic sits on the public error channel for the caller to report
19
+ * (#2291). */
20
+ static LeptrisDocument read_doc(const char* path, LeptrisStatus* status) {
21
+ size_t len = 0;
22
+ char* buf = cli_read_file(path, &len);
23
+ if (!buf) {
24
+ cli_error("cannot read file: %s: %s", path, strerror(errno));
25
+ *status = LEPTRIS_ERROR_IO;
26
+ return NULL;
32
27
  }
33
- if (fp != stdin) fclose(fp);
34
- LeptrisStatus st = LEPTRIS_OK;
35
- LeptrisDocument d =
36
- buf ? leptris_parse_string(buf, len, &st) : NULL;
28
+ LeptrisDocument d = leptris_parse_string(buf, len, status);
37
29
  free(buf);
38
30
  return d;
39
31
  }
@@ -213,9 +205,15 @@ static cli_result_t validate_execute(int argc, char** argv) {
213
205
  cli_error("validate needs --dtd/--rng/--schematron/--xsd");
214
206
  return CLI_ERROR_ARGS;
215
207
  }
216
- LeptrisDocument doc = read_doc(xml_path);
208
+ LeptrisStatus doc_status = LEPTRIS_OK;
209
+ LeptrisDocument doc = read_doc(xml_path, &doc_status);
217
210
  if (!doc) {
218
- cli_error("cannot read or parse: %s", xml_path);
211
+ /* read_doc already reported an unreadable input; a parse
212
+ * failure carries the engine's diagnostic (#2291). Exit code
213
+ * unchanged: 3 for either, per the documented contract. */
214
+ if (doc_status != LEPTRIS_ERROR_IO) {
215
+ cli_error_engine(xml_path, doc_status, OUTPUT_FORMAT_TEXT);
216
+ }
219
217
  return CLI_ERROR_IO;
220
218
  }
221
219
  int invalid = 0;
@@ -268,10 +268,18 @@ static cli_result_t xpath_execute(int argc, char** argv) {
268
268
  LeptrisStatus status;
269
269
  doc = leptris_parse_string(xml_content, xml_len, &status);
270
270
  if (!doc) {
271
- cli_error("failed to parse XML: %s", opts->input_file);
271
+ /* The engine's diagnostic (message + position) IS the error —
272
+ * printed in the output format, verbosity-independent (#2291). */
273
+ cli_error_engine(opts->input_file, status, opts->format);
272
274
  result = CLI_ERROR_PARSE;
273
275
  goto cleanup;
274
276
  }
277
+ /* #2278: the command reads the file itself, so the document it
278
+ * parses from memory names its origin explicitly — base-uri()/
279
+ * document-uri()/static-base-uri() answer the loaded-from path
280
+ * (stdin carries none). Public API only; the URI is copied. */
281
+ if (strcmp(opts->input_file, "-") != 0)
282
+ leptris_document_set_uri(doc, opts->input_file);
275
283
 
276
284
  /* Evaluate XPath expression */
277
285
  xpath_result = leptris_xpath_eval(