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
@@ -5,6 +5,8 @@
5
5
  *
6
6
  * - LEPTRIS_CTZ(mask) — count trailing zeros (GCC: __builtin_ctz,
7
7
  * MSVC: _BitScanForward).
8
+ * - LEPTRIS_CTZ64(mask) — the 64-bit form (GCC: __builtin_ctzll,
9
+ * MSVC: two _BitScanForward halves).
8
10
  * - strdup/strndup shims for MSVC's CRT (which only ships _strdup
9
11
  * and lacks strndup entirely).
10
12
  *
@@ -48,6 +50,66 @@ static __inline int leptris_port_ctz(uint32_t mask) {
48
50
  # define LEPTRIS_CTZ(mask) leptris_port_ctz((uint32_t)(mask))
49
51
  #endif
50
52
 
53
+ /* ---- Count trailing zeros, 64-bit -------------------------------------- */
54
+
55
+ #if defined(__GNUC__) || defined(__clang__)
56
+ # define LEPTRIS_CTZ64(mask) __builtin_ctzll(mask)
57
+ #elif defined(_MSC_VER)
58
+ static __inline int leptris_msvc_ctz64(uint64_t mask) {
59
+ unsigned long pos;
60
+ if (_BitScanForward(&pos, (uint32_t)mask)) return (int)pos;
61
+ if (_BitScanForward(&pos, (uint32_t)(mask >> 32))) return (int)pos + 32;
62
+ return 64;
63
+ }
64
+ # define LEPTRIS_CTZ64(mask) leptris_msvc_ctz64(mask)
65
+ #else
66
+ /* Fallback: O(n) loop. */
67
+ static __inline int leptris_port_ctz64(uint64_t mask) {
68
+ if (mask == 0) return 64;
69
+ int n = 0;
70
+ while ((mask & 1u) == 0) { mask >>= 1; n++; }
71
+ return n;
72
+ }
73
+ # define LEPTRIS_CTZ64(mask) leptris_port_ctz64(mask)
74
+ #endif
75
+
76
+ /* ---- Byte swap, 64-bit -------------------------------------------------- */
77
+ /* LEPTRIS_BSWAP64 reverses the byte order of a 64-bit word. The word <->
78
+ * string conversions (dom/element.h: leptris_word8_*) carry a LOGICAL
79
+ * layout — string byte i occupies bits [8i, 8i+8) — whose MEMORY image
80
+ * is the host's own, so every copy between the two converts at the
81
+ * boundary. The conversion is selected at compile time (see
82
+ * LEPTRIS_HOST_BIG_ENDIAN below): on little-endian hosts it folds away
83
+ * and no swap is emitted. */
84
+ #if defined(__GNUC__) || defined(__clang__)
85
+ # define LEPTRIS_BSWAP64(w) __builtin_bswap64((uint64_t)(w))
86
+ #elif defined(_MSC_VER)
87
+ # define LEPTRIS_BSWAP64(w) _byteswap_uint64((uint64_t)(w))
88
+ #else
89
+ static __inline uint64_t leptris_port_bswap64(uint64_t w) {
90
+ return ((w & UINT64_C(0x00000000000000FF)) << 56) |
91
+ ((w & UINT64_C(0x000000000000FF00)) << 40) |
92
+ ((w & UINT64_C(0x0000000000FF0000)) << 24) |
93
+ ((w & UINT64_C(0x00000000FF000000)) << 8) |
94
+ ((w & UINT64_C(0x000000FF00000000)) >> 8) |
95
+ ((w & UINT64_C(0x0000FF0000000000)) >> 24) |
96
+ ((w & UINT64_C(0x00FF000000000000)) >> 40) |
97
+ ((w & UINT64_C(0xFF00000000000000)) >> 56);
98
+ }
99
+ # define LEPTRIS_BSWAP64(w) leptris_port_bswap64((uint64_t)(w))
100
+ #endif
101
+
102
+ /* Host byte order as a 0/1 compile-time constant: 1 on big-endian.
103
+ * The explicit defined() guards matter — a bare `__BYTE_ORDER__ ==
104
+ * __ORDER_BIG_ENDIAN__` evaluates 0 == 0 on a compiler that defines
105
+ * neither and silently selects the big-endian path. */
106
+ #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
107
+ (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
108
+ # define LEPTRIS_HOST_BIG_ENDIAN 1
109
+ #else
110
+ # define LEPTRIS_HOST_BIG_ENDIAN 0
111
+ #endif
112
+
51
113
  /* ---- Inline / noinline hints ------------------------------------------ */
52
114
  /* LEPTRIS_NOINLINE keeps cold paths (DOCTYPE, entity expansion, error
53
115
  * recovery) out of the hot path's i-cache working set. The hot parse
@@ -0,0 +1,284 @@
1
+ /* common/uri_base.c — RFC 3986 base-URI algebra (#2278). See the
2
+ * header for the contract. The merge is the XInclude implementation
3
+ * (TODO.assemble 03) lifted to its own module so the XPath function
4
+ * library resolves against the same algebra; behavior is unchanged
5
+ * for every caller that already rode it. */
6
+
7
+ #include "uri_base.h"
8
+
9
+ #include <ctype.h>
10
+ #include <stdio.h>
11
+ #include <string.h>
12
+
13
+ #ifdef _WIN32
14
+ #include <direct.h>
15
+ #else
16
+ #include <unistd.h>
17
+ #endif
18
+
19
+ int leptris_uri_is_absolute(const char* s) {
20
+ if (!s) return 0;
21
+ for (const char* p = s; *p; p++) {
22
+ if (*p == ':') return p != s;
23
+ if (*p == '/' || *p == '?' || *p == '#') return 0;
24
+ }
25
+ return 0;
26
+ }
27
+
28
+ void leptris_uri_dir_of(char* out, size_t out_size, const char* uri) {
29
+ if (!out || out_size == 0) return;
30
+ out[0] = 0;
31
+ if (!uri) return;
32
+ const char* slash = strrchr(uri, '/');
33
+ if (!slash) return;
34
+ if (slash == uri) {
35
+ /* the root directory: "/x" lives in "/" */
36
+ if (out_size > 1) {
37
+ out[0] = '/';
38
+ out[1] = 0;
39
+ }
40
+ return;
41
+ }
42
+ size_t bl = (size_t)(slash - uri);
43
+ if (bl >= out_size) bl = out_size - 1;
44
+ memcpy(out, uri, bl);
45
+ out[bl] = 0;
46
+ }
47
+
48
+ /* Rebuild the path segment by segment, dropping "." segments and
49
+ * popping ".." against the last emitted one (RFC 3986 §5.2.4 for the
50
+ * path-only form — no query/fragment here). */
51
+ static void remove_dot_segments(char* path) {
52
+ char tmp[8192];
53
+ size_t tl = strlen(path);
54
+ if (tl >= sizeof(tmp)) return; /* oversized: leave as-is */
55
+ memcpy(tmp, path, tl + 1);
56
+
57
+ char* out = path;
58
+ size_t out_len = 0;
59
+ const char* r = tmp;
60
+ int absolute = (*r == '/');
61
+ if (absolute) r++;
62
+
63
+ while (*r) {
64
+ const char* seg = r;
65
+ while (*r && *r != '/') r++;
66
+ size_t sl = (size_t)(r - seg);
67
+ int had_slash = (*r == '/');
68
+ if (had_slash) r++;
69
+
70
+ if (sl == 1 && seg[0] == '.') continue;
71
+ if (sl == 2 && seg[0] == '.' && seg[1] == '.') {
72
+ if (out_len > 0) {
73
+ while (out_len > 0 && out[out_len - 1] != '/') out_len--;
74
+ if (out_len > 0) out_len--; /* the separator itself */
75
+ }
76
+ out[out_len] = 0;
77
+ continue;
78
+ }
79
+ if (out_len == 0) {
80
+ if (absolute) out[out_len++] = '/';
81
+ } else if (out[out_len - 1] != '/') {
82
+ out[out_len++] = '/';
83
+ }
84
+ memcpy(out + out_len, seg, sl);
85
+ out_len += sl;
86
+ out[out_len] = 0;
87
+ }
88
+ if (tl > 0 && tmp[tl - 1] == '/' &&
89
+ !(out_len > 0 && out[out_len - 1] == '/')) {
90
+ if (out_len == 0) {
91
+ if (absolute) out[out_len++] = '/';
92
+ } else if (out[out_len - 1] != '/') {
93
+ out[out_len++] = '/';
94
+ }
95
+ out[out_len] = 0;
96
+ }
97
+ }
98
+
99
+ int leptris_uri_merge(const char* base, const char* ref, char* out,
100
+ size_t out_size) {
101
+ if (!out || out_size == 0) return 1;
102
+ if (!ref || !ref[0]) {
103
+ snprintf(out, out_size, "%s", base ? base : "");
104
+ return 0;
105
+ }
106
+ if (!base || !base[0] || leptris_uri_is_absolute(ref)) {
107
+ snprintf(out, out_size, "%s", ref);
108
+ return 0;
109
+ }
110
+ /* Filesystem-absolute reference: used as-is (the processor's
111
+ * base is a plain directory prefix, not a URI with authority). */
112
+ if (ref[0] == '/') {
113
+ snprintf(out, out_size, "%s", ref);
114
+ return 0;
115
+ }
116
+ if (strncmp(ref, "//", 2) == 0) {
117
+ /* scheme-relative: reuse the base's scheme */
118
+ const char* colon = strchr(base, ':');
119
+ if (colon) {
120
+ int n = snprintf(out, out_size, "%.*s:%s",
121
+ (int)(colon - base), base, ref);
122
+ return (n < 0 || (size_t)n >= out_size);
123
+ }
124
+ snprintf(out, out_size, "%s", ref);
125
+ return 0;
126
+ }
127
+ /* The directory merge runs on the base's PATH only: a scheme
128
+ * and authority ("http://host", "C:") stay outside it so the
129
+ * dot-segment rebuild never folds the authority's "//" (the
130
+ * xinclude-era merge collapsed "http://h/d" + "x" into
131
+ * "http:/h/d/x"). Query/fragment are stripped first. */
132
+ const char* bpath = base;
133
+ size_t plen = 0;
134
+ const char* colon = strchr(base, ':');
135
+ if (colon && leptris_uri_is_absolute(base)) {
136
+ const char* p = colon + 1;
137
+ if (p[0] == '/' && p[1] == '/') {
138
+ const char* ps = strchr(p + 2, '/');
139
+ p = ps ? ps : p + strlen(p);
140
+ }
141
+ plen = (size_t)(p - base);
142
+ bpath = p;
143
+ }
144
+ char base_path[4096];
145
+ snprintf(base_path, sizeof(base_path), "%s", bpath);
146
+ char* cut = strpbrk(base_path, "?#");
147
+ if (cut) *cut = 0;
148
+ char dir[4096];
149
+ leptris_uri_dir_of(dir, sizeof(dir), base_path);
150
+ size_t dl = strlen(dir);
151
+ char joined[8192];
152
+ if (dl == 0)
153
+ snprintf(joined, sizeof(joined), "%s", ref);
154
+ else if (dir[dl - 1] == '/')
155
+ snprintf(joined, sizeof(joined), "%s%s", dir, ref);
156
+ else
157
+ snprintf(joined, sizeof(joined), "%s/%s", dir, ref);
158
+ remove_dot_segments(joined);
159
+ int n = snprintf(out, out_size, "%.*s%s", (int)plen, base, joined);
160
+ return (n < 0 || (size_t)n >= out_size);
161
+ }
162
+
163
+ #ifdef _WIN32
164
+ /* '\' is a path separator on Windows and folds to '/'; on POSIX it
165
+ * is an ordinary name character and stays. */
166
+ static int is_sep(char c) { return c == '/' || c == '\\'; }
167
+ #else
168
+ static int is_sep(char c) { return c == '/'; }
169
+ #endif
170
+
171
+ void leptris_uri_normalize_path(const char* in, char* out,
172
+ size_t out_size) {
173
+ if (!out || out_size == 0) return;
174
+ out[0] = 0;
175
+ if (!in) return;
176
+ const char* r = in;
177
+ size_t o = 0;
178
+ /* The root prefix: a Windows drive root ("C:/"), a UNC lead
179
+ * ("//") or a plain "/". Pops never cut into it. */
180
+ size_t prefix_len = 0;
181
+ #ifdef _WIN32
182
+ if (isalpha((unsigned char)r[0]) && r[1] == ':') {
183
+ if (o + 2 < out_size) {
184
+ out[o++] = r[0];
185
+ out[o++] = ':';
186
+ }
187
+ r += 2;
188
+ if (!is_sep(r[0])) {
189
+ /* Drive-relative ("C:foo") or bare ("C:"): the drive's
190
+ * own working directory is not knowable portably — the
191
+ * name as given, separators folded. */
192
+ for (; *r && o + 1 < out_size; r++)
193
+ out[o++] = is_sep(*r) ? '/' : *r;
194
+ out[o] = 0;
195
+ return;
196
+ }
197
+ if (o + 1 < out_size) out[o++] = '/';
198
+ prefix_len = o;
199
+ } else
200
+ #endif
201
+ if (is_sep(r[0]) && is_sep(r[1]) && r[2] && !is_sep(r[2])) {
202
+ /* UNC: "//server/share" keeps its double lead */
203
+ if (o + 2 < out_size) {
204
+ out[o++] = '/';
205
+ out[o++] = '/';
206
+ }
207
+ r += 2;
208
+ prefix_len = o;
209
+ } else if (is_sep(r[0])) {
210
+ if (o + 1 < out_size) out[o++] = '/';
211
+ r += 1;
212
+ prefix_len = o;
213
+ }
214
+ /* Segments push onto out; ".." truncates back to the previous
215
+ * separator (never past the prefix), "." drops out. */
216
+ while (*r) {
217
+ while (is_sep(*r)) r++;
218
+ if (!*r) break;
219
+ const char* start = r;
220
+ while (*r && !is_sep(*r)) r++;
221
+ size_t sl = (size_t)(r - start);
222
+ if (sl == 1 && start[0] == '.') continue;
223
+ if (sl == 2 && start[0] == '.' && start[1] == '.') {
224
+ /* pop the last emitted segment: past any trailing
225
+ * separator (so consecutive pops keep going), back to
226
+ * the separator before it — never into the prefix */
227
+ size_t p = o;
228
+ while (p > prefix_len && out[p - 1] == '/') p--;
229
+ while (p > prefix_len && out[p - 1] != '/') p--;
230
+ o = p;
231
+ /* the popped segment's separator goes with it; the
232
+ * root prefix keeps its own */
233
+ if (o > prefix_len && out[o - 1] == '/') o--;
234
+ continue;
235
+ }
236
+ if (o > 0 && out[o - 1] != '/') {
237
+ if (o + 1 >= out_size) break;
238
+ out[o++] = '/';
239
+ }
240
+ if (o + sl >= out_size) break;
241
+ memcpy(out + o, start, sl);
242
+ o += sl;
243
+ }
244
+ if (o == 0 && out_size > 1) out[o++] = '.';
245
+ out[o] = 0;
246
+ }
247
+
248
+ #ifdef _WIN32
249
+ static int current_dir(char* buf, size_t size) {
250
+ return _getcwd(buf, (int)size) != NULL;
251
+ }
252
+ #else
253
+ static int current_dir(char* buf, size_t size) {
254
+ return getcwd(buf, size) != NULL;
255
+ }
256
+ #endif
257
+
258
+ int leptris_uri_from_path(const char* path, char* out, size_t out_size) {
259
+ if (!out || out_size == 0) return 1;
260
+ out[0] = 0;
261
+ if (!path || !*path) return 0;
262
+ #ifdef _WIN32
263
+ int abs = is_sep(path[0]) ||
264
+ (isalpha((unsigned char)path[0]) && path[1] == ':' &&
265
+ is_sep(path[2]));
266
+ #else
267
+ int abs = path[0] == '/';
268
+ #endif
269
+ if (abs) {
270
+ leptris_uri_normalize_path(path, out, out_size);
271
+ return 0;
272
+ }
273
+ char cwd[4096];
274
+ if (!current_dir(cwd, sizeof(cwd))) {
275
+ /* no working directory to ride: the path as given */
276
+ leptris_uri_normalize_path(path, out, out_size);
277
+ return 0;
278
+ }
279
+ char joined[8192];
280
+ int n = snprintf(joined, sizeof(joined), "%s/%s", cwd, path);
281
+ if (n < 0 || (size_t)n >= sizeof(joined)) return 1;
282
+ leptris_uri_normalize_path(joined, out, out_size);
283
+ return 0;
284
+ }
@@ -0,0 +1,62 @@
1
+ /* common/uri_base.h — RFC 3986 base-URI algebra (#2278).
2
+ *
3
+ * ONE implementation of the URI merge every base-URI consumer
4
+ * needs: XInclude's xml:base chase (xinclude.c), fn:base-uri()'s
5
+ * xml:base ladder, and fn:doc()'s relative-reference resolution
6
+ * against the static base URI (functions_ext31.c). Before this
7
+ * module the merge lived as statics inside xinclude.c and the
8
+ * function library had nothing to resolve against at all.
9
+ *
10
+ * Plain-path form throughout: the engine's href consumers
11
+ * (fn:doc, document(), xi:include, xs:include/import) all hand
12
+ * filesystem paths to fopen(), so a document URI is the resolved
13
+ * path, never a file: URL — introducing the scheme here would
14
+ * break every one of those concatenating consumers. */
15
+ #ifndef LEPTRIS_COMMON_URI_BASE_H
16
+ #define LEPTRIS_COMMON_URI_BASE_H
17
+
18
+ #include <stddef.h>
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
23
+
24
+ /* Does s carry a URI scheme (RFC 3986: ALPHA *( ALPHA / DIGIT /
25
+ * "+" / "-" / "." ) ":")? A ':' past a '/', '?' or '#' is a path
26
+ * character, not a scheme separator. */
27
+ int leptris_uri_is_absolute(const char* s);
28
+
29
+ /* The directory prefix of uri — everything before the last '/';
30
+ * "" when the URI carries none. */
31
+ void leptris_uri_dir_of(char* out, size_t out_size, const char* uri);
32
+
33
+ /* RFC 3986 §5.2: merge ref over base. An absolute ref replaces the
34
+ * base; a root-relative ref ("/x") is used as-is (the processor's
35
+ * bases are plain paths without an authority component); otherwise
36
+ * the reference rides the base's path directory with its
37
+ * dot-segments removed (§5.2.4). An empty ref answers the base
38
+ * itself. Returns 0, or non-zero when the result does not fit. */
39
+ int leptris_uri_merge(const char* base, const char* ref, char* out,
40
+ size_t out_size);
41
+
42
+ /* Lexical path normalization (no filesystem probe): separators
43
+ * folded to '/', "." segments dropped, ".." popped against the
44
+ * preceding segment (a pop past the root is dropped — the root is
45
+ * the floor). A Windows drive prefix ("C:") and a UNC leading "//"
46
+ * are preserved. */
47
+ void leptris_uri_normalize_path(const char* in, char* out,
48
+ size_t out_size);
49
+
50
+ /* A filesystem path as the DOCUMENT URI: absolute (a relative path
51
+ * rides the current working directory) and lexically normalized.
52
+ * No symlink resolution and no existence probe — the URI is the
53
+ * name the document was loaded under. Returns 0, or non-zero when
54
+ * the working-directory join does not fit (a result longer than
55
+ * out_size is truncated to fit). */
56
+ int leptris_uri_from_path(const char* path, char* out, size_t out_size);
57
+
58
+ #ifdef __cplusplus
59
+ }
60
+ #endif
61
+
62
+ #endif /* LEPTRIS_COMMON_URI_BASE_H */
@@ -21,7 +21,7 @@
21
21
  * reaches here via target_compile_definitions in src/CMakeLists.txt.
22
22
  * Fallback keeps hand-built compilers honest. */
23
23
  #ifndef LEPTRIS_VERSION
24
- #define LEPTRIS_VERSION "1.9.458"
24
+ #define LEPTRIS_VERSION "1.9.460"
25
25
  #endif
26
26
  #ifndef LEPTRIS_VERSION_MAJOR
27
27
  #define LEPTRIS_VERSION_MAJOR 1
@@ -30,7 +30,7 @@
30
30
  #define LEPTRIS_VERSION_MINOR 9
31
31
  #endif
32
32
  #ifndef LEPTRIS_VERSION_PATCH
33
- #define LEPTRIS_VERSION_PATCH 458
33
+ #define LEPTRIS_VERSION_PATCH 460
34
34
  #endif
35
35
 
36
36
  /* Thread-local allocator hooks (TODO 27/74).
@@ -238,6 +238,37 @@ LEPTRIS_API LeptrisStatus leptris_document_set_standalone(
238
238
  return LEPTRIS_OK;
239
239
  }
240
240
 
241
+ /* ---- #2278: the document URI ------------------------------------------
242
+ * leptris_parse_file stamps the resolved path; an in-memory parse
243
+ * carries none until the caller supplies one (the xmlReadMemory url
244
+ * / Nokogiri Document.parse(string, url) shape). The string is the
245
+ * root of every base-uri()/document-uri() answer — see
246
+ * common/uri_base.c and dom/leptris_node_base_uri. */
247
+ LEPTRIS_API const char* leptris_document_uri(LeptrisDocument doc) {
248
+ return doc ? doc->doc_uri : NULL;
249
+ }
250
+
251
+ /* document_free releases doc_uri with LEPTRIS_FREE (malloc), so the
252
+ * setter malloc-copies and releases any prior value. NULL or an
253
+ * empty string CLEARS the URI (the document goes back to
254
+ * URI-less, as a string parse starts). */
255
+ LEPTRIS_API LeptrisStatus leptris_document_set_uri(
256
+ LeptrisDocument doc, const char* uri) {
257
+ if (!doc) return LEPTRIS_ERROR_NULL_ARG;
258
+ if (!uri || !*uri) {
259
+ if (doc->doc_uri) {
260
+ leptris_free(doc->doc_uri);
261
+ doc->doc_uri = NULL;
262
+ }
263
+ return LEPTRIS_OK;
264
+ }
265
+ char* copy = leptris_strdup(uri);
266
+ if (!copy) return LEPTRIS_ERROR_MEMORY;
267
+ if (doc->doc_uri) leptris_free(doc->doc_uri);
268
+ doc->doc_uri = copy;
269
+ return LEPTRIS_OK;
270
+ }
271
+
241
272
  /* #1229: the remove-half — back to as-if-the-input-had-none. The
242
273
  * setters' malloc'd strings are released here (document_free checks
243
274
  * for NULL), and the standalone marker returns to unset. */
@@ -157,6 +157,25 @@ static inline int32_t leptris_compact_int32_encode_inline(
157
157
  return (int32_t)d;
158
158
  }
159
159
 
160
+ /* #2255 parse-family: inline fast path for the DOC-TAGGED encode —
161
+ * the parse loop stamps owner_doc_off per carved text/comment/PI
162
+ * node and every stamp paid the out-of-line compact.c call (a plain
163
+ * subtraction + range check). Semantics identical to
164
+ * leptris_compact_int32_encode_doc: the boundary uses `>` (not
165
+ * `>=` — INT32_MAX is legal raw here, unlike the _inline form where
166
+ * it collides with the EMPTY sentinel) and out-of-range deltas fall
167
+ * back to the shared doc-tagged overflow registration. */
168
+ static inline int32_t leptris_compact_int32_encode_doc_inline(
169
+ void* base, void* target, const int32_t* field_addr,
170
+ struct leptris_document* doc) {
171
+ if (!target) return 0;
172
+ ptrdiff_t d = (char*)target - (char*)base;
173
+ if (d < INT32_MIN || d > INT32_MAX)
174
+ return leptris_compact_int32_encode_doc(base, target, field_addr,
175
+ doc);
176
+ return (int32_t)d;
177
+ }
178
+
160
179
  static inline void* leptris_compact_int32_decode_inline(
161
180
  void* base, int32_t off, const int32_t* field_addr) {
162
181
  if (off == 0) return NULL;
@@ -209,6 +228,38 @@ void* leptris_compact_ptr16_decode(const void* base, int16_t off,
209
228
  }
210
229
  #endif
211
230
 
231
+ /* #2274 set-attr: inline fast paths for the cp16 pair — the int32
232
+ * pair's #2255 lever applied to the attribute list. Every attribute
233
+ * link (leptris_attr_set_next) and every chain step (leptris_attr_next)
234
+ * paid the out-of-line compact.c call for what is a shift and a range
235
+ * check. Semantics are identical to the compact.c definitions: only
236
+ * NULL, the overflow sentinel, misaligned and out-of-range deltas reach
237
+ * the shared functions (which own the overflow-table semantics). */
238
+ static inline int16_t leptris_compact_ptr16_encode_inline(
239
+ const void* base, const void* target, int align_log2,
240
+ const int16_t* field_addr) {
241
+ if (!target) return 0;
242
+ ptrdiff_t d = (const char*)target - (const char*)base;
243
+ if (d & (((ptrdiff_t)1 << align_log2) - 1))
244
+ return leptris_compact_ptr16_encode(base, target, align_log2,
245
+ field_addr);
246
+ ptrdiff_t scaled = d >> align_log2;
247
+ if (scaled <= INT16_MIN || scaled > INT16_MAX)
248
+ return leptris_compact_ptr16_encode(base, target, align_log2,
249
+ field_addr);
250
+ return (int16_t)scaled;
251
+ }
252
+
253
+ static inline void* leptris_compact_ptr16_decode_inline(
254
+ const void* base, int16_t off, int align_log2,
255
+ const int16_t* field_addr) {
256
+ if (off == 0) return NULL;
257
+ if (off == LEPTRIS_COMPACT_PTR16_OVERFLOW)
258
+ return leptris_compact_ptr16_decode(base, off, align_log2,
259
+ field_addr);
260
+ return (char*)base + ((ptrdiff_t)off << align_log2);
261
+ }
262
+
212
263
  /* ============================================================================
213
264
  * Overflow Hash Table Functions
214
265
  * ============================================================================ */
@@ -476,6 +476,8 @@ void leptris_element_set_namespace_uri_view(LeptrisElement elem, LeptrisStringVi
476
476
  struct leptris_document* d = leptris_element_get_document(elem);
477
477
  if (d) d->has_namespaces = 1;
478
478
  }
479
+ /* #2294: a real namespace supersedes an explicit detach. */
480
+ leptris_elem_set_ns_cleared(elem, 0);
479
481
  LeptrisMemoryPool* pool = leptris_element_get_pool(elem);
480
482
  if (pool) {
481
483
  char* storage = (char*)leptris_pool_alloc(pool, uri_view.length + 1);
@@ -500,6 +502,13 @@ const char* leptris_element_get_namespace_uri(LeptrisElement elem) {
500
502
  char* cached = leptris_elem_ns_uri(elem);
501
503
  if (cached) return cached;
502
504
 
505
+ /* #2294: an explicit detach (leptris_element_set_namespace(""))
506
+ * is a persistent "no namespace" request — a later attachment
507
+ * under a default-namespaced parent must not capture the
508
+ * element. The serializer reads the same flag to emit the
509
+ * xmlns="" reset. */
510
+ if (leptris_elem_ns_cleared(elem)) return NULL;
511
+
503
512
  /* LAZY NAMESPACE RESOLUTION: resolve via ancestors. An
504
513
  * xmlns="" UNDECLARATION resolves to the empty string — the
505
514
  * element deliberately has NO namespace (the #817 detach and
@@ -552,6 +561,8 @@ void leptris_element_set_namespace_uri(LeptrisElement elem, const char* uri) {
552
561
  ? (pool ? leptris_pool_strdup(pool, uri)
553
562
  : leptris_strdup(uri))
554
563
  : NULL;
564
+ /* #2294: a real namespace supersedes an explicit detach. */
565
+ if (copy) leptris_elem_set_ns_cleared(elem, 0);
555
566
  leptris_elem_set_ns_uri(elem, copy, pool);
556
567
  }
557
568
 
@@ -723,6 +734,13 @@ const char* leptris_element_lookup_namespace(LeptrisElement elem,
723
734
  return NULL;
724
735
  }
725
736
 
737
+ /* #2294: an explicit detach is an in-scope UNDECLARATION for the
738
+ * element and its descendants — the wire form carries xmlns=""
739
+ * there, so the default-namespace lookup must answer empty (the
740
+ * parent's default cannot capture them). */
741
+ if ((!prefix || !*prefix) && leptris_elem_ns_cleared(elem))
742
+ return "";
743
+
726
744
  /* Search namespaces linked list on current element */
727
745
  struct leptris_namespace* ns = leptris_elem_namespaces(elem);
728
746
  while (ns) {