leptris 1.9.349.0-arm-linux → 1.9.351.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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/Rakefile +1 -1
  4. data/lib/leptris/version.rb +1 -1
  5. data/lib/libleptris.so +0 -0
  6. data/vendor-src/README.md +1 -1
  7. data/vendor-src/libleptris/CHANGELOG.md +80 -0
  8. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  9. data/vendor-src/libleptris/cli/commands/xquery.c +1 -1
  10. data/vendor-src/libleptris/src/leptris/common/simd_text.c +0 -12
  11. data/vendor-src/libleptris/src/leptris/common/simd_text.h +19 -0
  12. data/vendor-src/libleptris/src/leptris/common/simd_text_neon.c +0 -1
  13. data/vendor-src/libleptris/src/leptris/core.c +2 -5
  14. data/vendor-src/libleptris/src/leptris/dom/root_doc_map.h +3 -0
  15. data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +8 -33
  16. data/vendor-src/libleptris/src/leptris/flat/direct_parse.h +4 -0
  17. data/vendor-src/libleptris/src/leptris/html/html_parse.c +0 -2
  18. data/vendor-src/libleptris/src/leptris/leptris.c +6 -41
  19. data/vendor-src/libleptris/src/leptris/leptris_internal.h +14 -0
  20. data/vendor-src/libleptris/src/leptris/memory/pool.h +4 -0
  21. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +0 -2
  22. data/vendor-src/libleptris/src/leptris/xpath/evaluator_operators.c +2 -8
  23. data/vendor-src/libleptris/src/leptris/xpath/functions.c +1 -5
  24. data/vendor-src/libleptris/src/leptris/xpath/functions.h +29 -0
  25. data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +1 -19
  26. data/vendor-src/libleptris/src/leptris/xpath/xpath_carrier.h +32 -0
  27. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +1 -15
  28. data/vendor-src/libleptris/src/leptris/xquery/xquery.c +1 -2
  29. data/vendor-src/libleptris/src/leptris/xsd/compile.c +158 -3
  30. data/vendor-src/libleptris/src/leptris/xsd/validate.c +13 -9
  31. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +8 -0
  32. data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +0 -6
  33. data/vendor-src/libleptris/src/leptris/xslt/xslt_functions.c +0 -2
  34. data/vendor-src/libleptris/src/leptris/xslt/xslt_pattern.c +0 -1
  35. data/vendor-src/libleptris/src/leptris/xslt/xslt_public.c +1 -2
  36. data/vendor-src/libleptris/test/xquery/test_xquery.cpp +1 -1
  37. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/lib/base.xsd +23 -0
  38. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/lib/more.xsd +8 -0
  39. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/root.xsd +10 -0
  40. data/vendor-src/libleptris/test/xsd/libxml2-cases/fwd_ref_ext/sub/wrap.xsd +3 -0
  41. data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_simple_collision/m.xsd +14 -0
  42. data/vendor-src/libleptris/test/xsd/libxml2-cases/ns_simple_collision/w.xsd +14 -0
  43. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +70 -0
  44. data/vendor-src/libleptris/vcpkg.json +1 -1
  45. metadata +8 -1
@@ -126,7 +126,6 @@ void xpath_context_init(XPathContext* context,
126
126
  context->input = NULL;
127
127
  context->input_len = 0;
128
128
 
129
- extern XPathFunctionRegistry* leptris_xpath_build_custom_registry(struct leptris_document*);
130
129
  /* The borrow flag MUST be established on every init: the
131
130
  * context is stack storage and cleanup's registry-free is
132
131
  * gated on this flag — stale stack bytes read as borrowed=1
@@ -180,7 +179,6 @@ void xpath_context_cleanup(XPathContext* context) {
180
179
  * doc's custom XPath functions (TODO 148 Phase 5) is freed
181
180
  * here; a registry BORROWED from the document cache stays with
182
181
  * the document. */
183
- extern XPathFunctionRegistry* xpath_function_registry_get_standard(void);
184
182
  if (context->function_registry && !context->registry_borrowed &&
185
183
  context->function_registry != xpath_function_registry_get_standard()) {
186
184
  xpath_function_registry_free((XPathFunctionRegistry*)context->function_registry);
@@ -5,6 +5,8 @@
5
5
  */
6
6
 
7
7
  #include "evaluator_internal.h"
8
+ #include "functions.h"
9
+ #include "xpath_carrier.h"
8
10
  #include "../leptris_internal.h"
9
11
  #include "../dom/element.h" /* For LeptrisElement structure */
10
12
  #include "../dom/document_node.h" /* document-node handle + ->doc */
@@ -148,7 +150,6 @@ extern char* get_node_text(void* node);
148
150
  extern int xq_anchor_on_source(XPathContext* ctx,
149
151
  struct leptris_document* anchored);
150
152
  /* carrier-by-pointer decode (fold-left-009/016). */
151
- extern void* xpath_carrier_node_of(const char* s);
152
153
 
153
154
  /* #181: a materialized ctor node splices its MARKUP into a
154
155
  * parent's serialized content — get_node_text would yield only its
@@ -793,7 +794,6 @@ static int op_relational_cmp(XPathOperatorType op, double a, double b) {
793
794
  * `instance of` and XQuery typeswitch. */
794
795
  int xpath_result_matches_type(struct leptris_xpath_result* v,
795
796
  const char* base) {
796
- extern const char* leptris_element_get_name(LeptrisElement e);
797
797
  int is_string_ty = strcmp(base, "xs:string") == 0 ||
798
798
  strcmp(base, "xs:anyURI") == 0 ||
799
799
  strncmp(base, "xs:date", 7) == 0 ||
@@ -1817,8 +1817,6 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
1817
1817
  r->value.nodeset_value = out;
1818
1818
  return r;
1819
1819
  }
1820
- extern int xpath_array_members_of(const char* content, char*** out,
1821
- size_t* out_n);
1822
1820
  if (op == XPATH_OP_DYN_CALL) {
1823
1821
  struct leptris_xpath_result* callee =
1824
1822
  evaluate_expr(ctx, ast->children[0]);
@@ -1901,8 +1899,6 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
1901
1899
  * sequences ride the member carrier) — the
1902
1900
  * recursive declared folds pass $zero through
1903
1901
  * here (fold-left/right-103/104). */
1904
- extern char* xpath_item_arg_string(
1905
- struct leptris_xpath_result*);
1906
1902
  char* sv = ar ? xpath_item_arg_string(ar) : NULL;
1907
1903
  if (ar) xpath_result_free(ar);
1908
1904
  char** mem = NULL;
@@ -2261,8 +2257,6 @@ struct leptris_xpath_result* evaluate_operator(XPathContext* ctx,
2261
2257
  LeptrisDocument pdoc =
2262
2258
  blen ? leptris_parse_string(buf, blen, &pst) : NULL;
2263
2259
  if (pdoc && leptris_document_root(pdoc)) {
2264
- extern LeptrisNode* leptris_document_get_node(
2265
- struct leptris_document* doc);
2266
2260
  LeptrisNode* dn = leptris_document_get_node(pdoc);
2267
2261
  if (dn) {
2268
2262
  /* get_node's lazy creation registers the node
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  #include "functions.h"
9
+ #include "xpath_carrier.h"
9
10
  #include "collation.h"
10
11
  #include "evaluator.h"
11
12
  #include "evaluator_internal.h"
@@ -233,9 +234,7 @@ XPathFunctionDef* xpath_function_registry_get(
233
234
  /* Get text content from typed node (handles elements and attributes)
234
235
  * This is declared in evaluator_internal.h and implemented in evaluator_types.c
235
236
  */
236
- extern char* get_node_text(void* node);
237
237
  /* evaluator_operators.c — element markup discipline (#181). */
238
- extern char* ctor_member_markup(void* node);
239
238
  extern char* xpath_number_to_string(double number);
240
239
  extern char* xpath_int_to_string(long long v);
241
240
 
@@ -1126,8 +1125,6 @@ static size_t de_collect(struct leptris_xpath_result* r, DeItem* out,
1126
1125
  * strings (real elements collect as markup in
1127
1126
  * the element branch below); the markup compare
1128
1127
  * reparses into de_node_equal. */
1129
- extern void* xpath_carrier_node_of(const char*);
1130
- extern char* ctor_member_markup(void* node);
1131
1128
  void* cn = xpath_carrier_node_of(c);
1132
1129
  if (cn) {
1133
1130
  out[i].kind = 2;
@@ -3603,7 +3600,6 @@ void xpath_function_registry_init_standard(XPathFunctionRegistry* registry) {
3603
3600
 
3604
3601
  /* XPath 2.0/3.1 extension families (TODO.xslt-full 01/02/03):
3605
3602
  * sequences, math:, the regex trio. */
3606
- extern void xpath_register_fn31(XPathFunctionRegistry*);
3607
3603
  xpath_register_fn31(registry);
3608
3604
  xpath_function_registry_register(registry, "local-name", xpath_func_local_name, 0, 1);
3609
3605
  xpath_function_registry_register(registry, "namespace-uri", xpath_func_namespace_uri, 0, 1);
@@ -17,6 +17,35 @@
17
17
 
18
18
  typedef struct xpath_function_registry XPathFunctionRegistry;
19
19
 
20
+ /* Document-scoped custom function registry (TODO 148): built lazily
21
+ * per evaluation, freed with the document. */
22
+ XPathFunctionRegistry* leptris_xpath_build_custom_registry(
23
+ struct leptris_document* doc);
24
+ void leptris_xpath_free_custom_fns(struct leptris_document* doc);
25
+
26
+ /* XSLT/Schematron bridge registrations — defined in the xslt/sch
27
+ * TUs; the declaration lives here (the registry is an xpath type)
28
+ * so no TU needs a block-scope extern (leptris#1681). */
29
+ void xslt_register_bridge_static(XPathFunctionRegistry*, void*);
30
+ void xslt_register_ufn_handlers(XPathFunctionRegistry*, void*);
31
+ void xslt_register_bridge_handlers(XPathFunctionRegistry*, void*);
32
+ void leptris_sch_register_key_bridge(XPathFunctionRegistry*, void*);
33
+
34
+ /* EXSLT function pack (functions_exslt.c). */
35
+ void leptris_exslt_register(XPathFunctionRegistry* registry);
36
+
37
+ /* XPath 3.1 pack (functions_ext31.c) + helpers shared with the
38
+ * evaluator/xquery TUs. */
39
+ void xpath_register_fn31(XPathFunctionRegistry* registry);
40
+ char* ctor_member_markup(void* node);
41
+ char* xpath_seq_carrier_of(struct leptris_xpath_result* vr);
42
+ char* xpath_item_arg_string(struct leptris_xpath_result* vr);
43
+ int xpath_array_members_of(const char* content, char*** out,
44
+ size_t* out_n);
45
+ void* xpath_map_builder_new(void);
46
+ void xpath_map_builder_add(void* b, const char* k, const char* v);
47
+ struct leptris_xpath_result* xpath_map_builder_finish(void* b);
48
+
20
49
  /* ============================================================================
21
50
  * Function Handler Type
22
51
  * ============================================================================ */
@@ -12,6 +12,7 @@
12
12
  * FnMath / FnRegex).
13
13
  */
14
14
  #include "functions.h"
15
+ #include "xpath_carrier.h"
15
16
  #include "collation.h"
16
17
  #include "evaluator.h"
17
18
 
@@ -49,9 +50,7 @@ extern struct leptris_xpath_result* xpath_evaluate(XPathContext* context,
49
50
  XPathASTNode* ast);
50
51
  extern char* get_node_text(void* node);
51
52
  /* evaluator_operators.c — element members keep their markup (#181). */
52
- extern char* ctor_member_markup(void* node);
53
53
  /* carrier-by-pointer decode (fold-left-009/016); defined below. */
54
- void* xpath_carrier_node_of(const char* s);
55
54
 
56
55
  /* ---- sequence plumbing ---- */
57
56
 
@@ -135,7 +134,6 @@ static char* scalar_str(const struct leptris_xpath_result* r) {
135
134
  }
136
135
 
137
136
  static void free_items(char** items, size_t n);
138
- int xpath_array_members_of(const char* content, char*** out, size_t* out_n);
139
137
 
140
138
  /* Evaluate args[i] into a malloc'd array of malloc'd item strings.
141
139
  * Nodesets contribute one item per node; scalars one item.
@@ -4913,7 +4911,6 @@ static struct leptris_xpath_result* fn_json_to_xml(
4913
4911
 
4914
4912
  /* ---- registration (OCP: one call from the standard init) ---- */
4915
4913
 
4916
- void xpath_register_fn31(XPathFunctionRegistry* registry);
4917
4914
 
4918
4915
  /* xml-to-json (08): walk the canonical fn: vocabulary back into
4919
4916
  * the shared map representation — members add under @key; nested
@@ -5659,11 +5656,6 @@ char* xpath_seq_carrier_of(struct leptris_xpath_result* vr) {
5659
5656
  return NULL;
5660
5657
  XPathNodeSet* mns = vr->value.nodeset_value;
5661
5658
  void* b = NULL;
5662
- extern void* xpath_map_builder_new(void);
5663
- extern void xpath_map_builder_add(void* b, const char* k,
5664
- const char* v);
5665
- extern struct leptris_xpath_result* xpath_map_builder_finish(
5666
- void* b);
5667
5659
  b = xpath_map_builder_new();
5668
5660
  if (!b) return NULL;
5669
5661
  for (size_t j = 0; j < mns->count; j++) {
@@ -5713,16 +5705,6 @@ char* xpath_seq_carrier_of(struct leptris_xpath_result* vr) {
5713
5705
  return out;
5714
5706
  }
5715
5707
 
5716
- /* carrier-by-pointer decode (fold-left-009/016): a "\x03P" +
5717
- * 16-hex carrier resolves to its node, valid for the whole eval
5718
- * (ctor docs anchor on the source document, #691). NULL when the
5719
- * string is not a pointer carrier. */
5720
- void* xpath_carrier_node_of(const char* s) {
5721
- if (!s || s[0] != '\x03' || s[1] != 'P' || strlen(s) != 18)
5722
- return NULL;
5723
- return (void*)(uintptr_t)strtoull(s + 2, NULL, 16);
5724
- }
5725
-
5726
5708
  static struct leptris_xpath_result* fn_apply(XPathContext* ctx,
5727
5709
  XPathASTNode** args, size_t n) {
5728
5710
  (void)n;
@@ -0,0 +1,32 @@
1
+ /* Internal cross-TU carrier decode (fold-left-009/016, #691):
2
+ * a "\x03P" + 16-hex carrier resolves to its node pointer, valid
3
+ * for the whole eval (ctor docs anchor on the source document).
4
+ * NULL when the string is not a pointer carrier.
5
+ *
6
+ * leptris#1681: static inline — GCC LTO internalizes (hidden)
7
+ * out-of-line definitions and the block-scope extern references in
8
+ * functions.c / xpath_public.c / evaluator_operators.c / xquery.c
9
+ * resolve to nothing (ppc64le/s390x/truffleruby "undefined
10
+ * reference"); a header inline has no cross-TU symbol to drop. */
11
+ #ifndef LEPTRIS_XPATH_CARRIER_H
12
+ #define LEPTRIS_XPATH_CARRIER_H
13
+
14
+ #include <stdint.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ static inline void* xpath_carrier_node_of(const char* s) {
23
+ if (!s || s[0] != '\x03' || s[1] != 'P' || strlen(s) != 18)
24
+ return NULL;
25
+ return (void*)(uintptr_t)strtoull(s + 2, NULL, 16);
26
+ }
27
+
28
+ #ifdef __cplusplus
29
+ }
30
+ #endif
31
+
32
+ #endif /* LEPTRIS_XPATH_CARRIER_H */
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  #include "../dom/pi.h"
9
+ #include "xpath_carrier.h"
9
10
  #include "../include/leptris.h"
10
11
  #include "../leptris_internal.h"
11
12
  #include "parser.h"
@@ -507,7 +508,6 @@ LEPTRIS_API char* leptris_xpath_result_string(LeptrisXPathResult result) {
507
508
  * children before the root element's subtree. Shared
508
509
  * walker lives in evaluator_types.c. */
509
510
  if ((int)XPATH_NODE_TYPE(first) == LEPTRIS_NODE_TYPE_DOCUMENT) {
510
- extern char* get_node_text(void* node);
511
511
  char* dsv = get_node_text(first);
512
512
  return dsv ? dsv : leptris_strdup("");
513
513
  }
@@ -527,7 +527,6 @@ LEPTRIS_API char* leptris_xpath_result_string(LeptrisXPathResult result) {
527
527
  * string-value (the same contract as a real
528
528
  * element). */
529
529
  {
530
- extern void* xpath_carrier_node_of(const char* s);
531
530
  const char* raw =
532
531
  leptris_xpath_result_node_value(result, 0);
533
532
  if (raw && (unsigned char)raw[0] == 0x03 &&
@@ -802,8 +801,6 @@ static struct leptris_xpath_result* custom_xpath_thunk(
802
801
  (struct leptris_custom_fn_state*)context->current_fn_user_data;
803
802
  if (!state || !state->fn) return NULL;
804
803
 
805
- extern struct leptris_xpath_result* evaluate_expr(XPathContext*, XPathASTNode*);
806
-
807
804
  const char** str_args = NULL;
808
805
  char** owned = NULL;
809
806
  size_t owned_count = 0;
@@ -943,12 +940,8 @@ static const FnRegistryTemplate* fn_registry_template(int with_exslt) {
943
940
  }
944
941
  if (r->functions) {
945
942
  if (with_exslt) {
946
- extern void leptris_exslt_register(
947
- XPathFunctionRegistry*);
948
943
  leptris_exslt_register(r);
949
944
  }
950
- extern void xslt_register_bridge_static(
951
- XPathFunctionRegistry*, void*);
952
945
  xslt_register_bridge_static(r, FN_UD_SENTINEL);
953
946
  /* register()'s fresh-append path leaves user_data
954
947
  * unwritten (realloc memory) — normalize everything
@@ -1015,8 +1008,6 @@ XPathFunctionRegistry* leptris_xpath_build_custom_registry(struct leptris_docume
1015
1008
  reg->count = reg->capacity = t->count;
1016
1009
  for (size_t i = 0; i < t->n_ud_slots; i++)
1017
1010
  reg->functions[t->ud_slots[i]].user_data = doc->xslt_state;
1018
- extern void xslt_register_ufn_handlers(
1019
- XPathFunctionRegistry*, void*);
1020
1011
  xslt_register_ufn_handlers(reg, doc->xslt_state);
1021
1012
  doc->cached_fn_registry = reg;
1022
1013
  return reg;
@@ -1053,7 +1044,6 @@ XPathFunctionRegistry* leptris_xpath_build_custom_registry(struct leptris_docume
1053
1044
  /* EXSLT pack (TODO.concurrency/06): native handlers registered
1054
1045
  * alongside (and after) the standard library. */
1055
1046
  if (doc->exslt_enabled) {
1056
- extern void leptris_exslt_register(XPathFunctionRegistry*);
1057
1047
  leptris_exslt_register(reg);
1058
1048
  }
1059
1049
 
@@ -1066,8 +1056,6 @@ XPathFunctionRegistry* leptris_xpath_build_custom_registry(struct leptris_docume
1066
1056
  * stays with the eval context that built it (init → cleanup),
1067
1057
  * so no lifecycle juggling here. */
1068
1058
  if (doc->xslt_state) {
1069
- extern void xslt_register_bridge_handlers(XPathFunctionRegistry*,
1070
- void*);
1071
1059
  xslt_register_bridge_handlers(reg, doc->xslt_state);
1072
1060
  }
1073
1061
 
@@ -1076,8 +1064,6 @@ XPathFunctionRegistry* leptris_xpath_build_custom_registry(struct leptris_docume
1076
1064
  * xsl:key declarations. Same save/restore + invalidation
1077
1065
  * discipline as the XSLT bridge above. */
1078
1066
  if (doc->sch_state) {
1079
- extern void leptris_sch_register_key_bridge(
1080
- XPathFunctionRegistry*, void*);
1081
1067
  leptris_sch_register_key_bridge(reg, doc->sch_state);
1082
1068
  }
1083
1069
 
@@ -15,6 +15,7 @@
15
15
  #include "../../include/leptris.h"
16
16
  #include "../../include/leptris/xquery/xquery.h"
17
17
  #include "../leptris_internal.h"
18
+ #include "../xpath/xpath_carrier.h"
18
19
  #include "../xpath/evaluator.h"
19
20
  #include "../xpath/evaluator_internal.h"
20
21
  #include "../xpath/functions.h"
@@ -2019,8 +2020,6 @@ static struct leptris_xpath_result* xq_fn_thunk(XPathContext* ctx,
2019
2020
  v[2] = 0;
2020
2021
  }
2021
2022
  } else {
2022
- extern char* xpath_seq_carrier_of(
2023
- struct leptris_xpath_result*);
2024
2023
  v = xpath_seq_carrier_of(r);
2025
2024
  if (!v) {
2026
2025
  /* Single marked member: keep the RAW content —
@@ -10,6 +10,8 @@
10
10
  #include <string.h>
11
11
 
12
12
  #include "../../include/leptris.h"
13
+ #include "../common/port.h" /* strndup shim for MSVC's CRT */
14
+ #include "xsd_internal.h"
13
15
  #include "xsd_internal.h"
14
16
 
15
17
  #define XSD_NS "http://www.w3.org/2001/XMLSchema"
@@ -79,9 +81,13 @@ XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
79
81
  const char* type_name, const char* uri);
80
82
  extern XsdCm* xsd_find_complex(struct leptris_xsd_schema* s,
81
83
  const char* type_name);
84
+ extern const XsdTypeAttrs* xsd_find_type_attrs_ns(
85
+ struct leptris_xsd_schema* s, const char* type_name,
86
+ const char* uri);
82
87
  extern const XsdTypeAttrs* xsd_find_type_attrs(
83
88
  struct leptris_xsd_schema* s, const char* type_name);
84
89
  static XsdCm* xsd_cm_copy_list(const XsdCm* head);
90
+ static void xsd_resolve_extension_bases(struct leptris_xsd_schema* s);
85
91
  static void xsd_capture_root(struct leptris_xsd_schema* s,
86
92
  LeptrisElement root);
87
93
  static char* xsd_read_file(const char* path, size_t* out_len);
@@ -159,6 +165,7 @@ static void xsd_cm_free(XsdCm* cm) {
159
165
  free(cm->name);
160
166
  free(cm->type);
161
167
  free(cm->ns);
168
+ free(cm->ext_base);
162
169
  free(cm->any_ns);
163
170
  free(cm->text_type);
164
171
  free(cm);
@@ -199,6 +206,7 @@ static int xsd_capture_inline(struct leptris_xsd_schema* s,
199
206
  if (!captured) return 0;
200
207
  free(captured->name);
201
208
  captured->name = xsd_strdup(synth);
209
+ if (s->target_ns) captured->ns = xsd_strdup(s->target_ns);
202
210
  captured->next = s->simple_types;
203
211
  s->simple_types = captured;
204
212
  return 1;
@@ -453,6 +461,31 @@ static const XsdSimple* xsd_find_simple(struct leptris_xsd_schema* s,
453
461
  return NULL;
454
462
  }
455
463
 
464
+ /* leptris-ruby#440 shape B: prefer the (ns, name) exact match —
465
+ * imported namespaces carry same-name simpleTypes whose value
466
+ * spaces differ (shared-math ST_Jc has centerGroup, wml ST_Jc
467
+ * does not). A resolving namespace is in hand: a DIFFERENT
468
+ * namespace's same-name type must not win; but prefix-stripped
469
+ * type names legitimately cross namespaces (CT_TwipsMeasure in
470
+ * math types its val with sharedTypes' ST_TwipsMeasure), so the
471
+ * name-only match remains the last resort. */
472
+ const XsdSimple* xsd_find_simple_ns_pub(
473
+ struct leptris_xsd_schema* s, const char* name, const char* uri) {
474
+ if (!s || !name) return NULL;
475
+ if (uri && uri[0]) {
476
+ for (XsdSimple* t = s->simple_types; t; t = t->next)
477
+ if (t->ns && strcmp(t->name, name) == 0 &&
478
+ strcmp(t->ns, uri) == 0)
479
+ return t;
480
+ for (XsdSimple* t = s->simple_types; t; t = t->next)
481
+ if (!t->ns && strcmp(t->name, name) == 0)
482
+ return t;
483
+ /* cross-namespace reference: any spelling of the name */
484
+ return xsd_find_simple(s, name);
485
+ }
486
+ return xsd_find_simple(s, name);
487
+ }
488
+
456
489
  extern int xsd_builtin_valid(const char* type, const char* v);
457
490
  extern int rng_regex_matches(const char* pat, const char* text);
458
491
  static int xsd_valid_chain(struct leptris_xsd_schema* s,
@@ -695,6 +728,7 @@ static LeptrisXsdSchema xsd_compile_impl(const char* xsd_text,
695
728
  }
696
729
 
697
730
  xsd_capture_root(s, root);
731
+ xsd_resolve_extension_bases(s);
698
732
 
699
733
  leptris_document_free(doc);
700
734
  return s;
@@ -716,6 +750,78 @@ fail:
716
750
  * ".." segments (and duplicate separators) so the same file reached
717
751
  * through different relative spellings yields one dedup key.
718
752
  * Purely lexical: no filesystem access, portable. */
753
+ /* leptris-ruby#440 shape A: extensions whose base was not yet
754
+ * captured fold here, after every unit has merged into the tables
755
+ * — the correct place in XSD terms, since type references resolve
756
+ * against the WHOLE schema, not the preceding slice of it.
757
+ * Iterates to a fixpoint so extension chains resolve regardless of
758
+ * file order; unresolved leftovers keep their deferral marker. */
759
+ static void xsd_resolve_extension_bases(struct leptris_xsd_schema* s) {
760
+ int progressed = 1;
761
+ while (progressed) {
762
+ progressed = 0;
763
+ for (XsdCm* c = s->complex_types; c; c = c->next) {
764
+ if (!c->ext_base) continue;
765
+ XsdCm* base = xsd_find_complex_ns(s, c->ext_base, c->ns);
766
+ if (!base || base->ext_base) continue;
767
+ XsdCm* copied = xsd_cm_copy_list(base->first_child);
768
+ if (copied) {
769
+ XsdCm* tail = copied;
770
+ while (tail->next) tail = tail->next;
771
+ tail->next = c->first_child;
772
+ c->first_child = copied;
773
+ /* capture wraps a multi-particle splice under one
774
+ * sequence (the NFA consumes ONE root particle) —
775
+ * the deferred fold owes the same normalization */
776
+ if (c->first_child->next) {
777
+ XsdCm* seq = xsd_cm_new(XSD_CM_SEQ);
778
+ if (seq) {
779
+ seq->first_child = c->first_child;
780
+ c->first_child = seq;
781
+ }
782
+ }
783
+ }
784
+ const XsdTypeAttrs* bt =
785
+ xsd_find_type_attrs_ns(s, c->ext_base, c->ns);
786
+ if (bt) {
787
+ XsdTypeAttrs* mine = NULL;
788
+ for (XsdTypeAttrs* t = s->type_attrs; t; t = t->next)
789
+ if (strcmp(t->type_name, c->name) == 0 &&
790
+ ((!c->ns && !t->ns) ||
791
+ (c->ns && t->ns &&
792
+ strcmp(t->ns, c->ns) == 0))) {
793
+ mine = t;
794
+ break;
795
+ }
796
+ XsdAttrDecl* prepend =
797
+ xsd_copy_attr_rows(bt->attrs);
798
+ if (mine) {
799
+ XsdAttrDecl* tail_a = prepend;
800
+ while (tail_a && tail_a->next)
801
+ tail_a = tail_a->next;
802
+ if (tail_a) {
803
+ tail_a->next = mine->attrs;
804
+ mine->attrs = prepend;
805
+ }
806
+ } else if (prepend) {
807
+ XsdTypeAttrs* row =
808
+ (XsdTypeAttrs*)calloc(1, sizeof(*row));
809
+ if (row) {
810
+ row->type_name = xsd_strdup(c->name);
811
+ if (c->ns) row->ns = xsd_strdup(c->ns);
812
+ row->attrs = prepend;
813
+ row->next = s->type_attrs;
814
+ s->type_attrs = row;
815
+ }
816
+ }
817
+ }
818
+ free(c->ext_base);
819
+ c->ext_base = NULL;
820
+ progressed = 1;
821
+ }
822
+ }
823
+ }
824
+
719
825
  static void xsd_path_normalize(const char* in, char* out, size_t outsz) {
720
826
  struct {
721
827
  const char* p;
@@ -807,6 +913,20 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
807
913
  xsd_path_normalize(path, canon, sizeof(canon));
808
914
  if (xsd_visited_has(s, canon)) continue;
809
915
  xsd_visited_add(s, canon);
916
+ /* The SUBFILE's own schemaLocations resolve
917
+ * against ITS directory, not the compiled
918
+ * file's (#440 shape A): wml-2010 -> word12 ->
919
+ * ../iso/wml.xsd, and wml.xsd's same-dir
920
+ * shared-*.xsd siblings would resolve against
921
+ * microsoft/ and silently vanish — truncating
922
+ * every content model referencing them. */
923
+ char* saved_dir = s->base_dir;
924
+ char* sub_dir = NULL;
925
+ const char* lslash = strrchr(canon, '/');
926
+ if (lslash) {
927
+ sub_dir = strndup(canon, lslash - canon);
928
+ if (sub_dir) s->base_dir = sub_dir;
929
+ }
810
930
  size_t flen = 0;
811
931
  char* text = xsd_read_file(path, &flen);
812
932
  if (text) {
@@ -850,6 +970,15 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
850
970
  }
851
971
  free(text);
852
972
  }
973
+ /* base_dir is restored on EVERY exit path — an
974
+ * unreadable subfile must not leave the parent's
975
+ * base_dir lost (and its strdup leaked) while the
976
+ * later imports resolve against the subfile's
977
+ * directory. */
978
+ if (sub_dir) {
979
+ s->base_dir = saved_dir;
980
+ free(sub_dir);
981
+ }
853
982
  }
854
983
  continue;
855
984
  }
@@ -978,6 +1107,11 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
978
1107
  } else if (strcmp(local, "simpleType") == 0 && uri && !strcmp(uri, XSD_NS)) {
979
1108
  XsdSimple* captured = xsd_capture_simple((LeptrisElement)n);
980
1109
  if (captured) {
1110
+ /* leptris-ruby#440: stamp the declaring unit's
1111
+ * targetNamespace — same-name simpleTypes across
1112
+ * imported namespaces resolve by (ns, name)
1113
+ * (shared-math ST_Jc vs wml ST_Jc). */
1114
+ if (s->target_ns) captured->ns = xsd_strdup(s->target_ns);
981
1115
  captured->next = s->simple_types;
982
1116
  s->simple_types = captured;
983
1117
  }
@@ -988,6 +1122,7 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
988
1122
  static void xsd_free_simple_one(XsdSimple* t) {
989
1123
  if (!t) return;
990
1124
  free(t->name);
1125
+ free(t->ns);
991
1126
  free(t->base);
992
1127
  free(t->pattern);
993
1128
  XsdFacetValue* fv = t->enum_values;
@@ -1305,10 +1440,29 @@ static XsdCm* xsd_capture_complex_model(struct leptris_xsd_schema* s,
1305
1440
  (base && strncmp(base, "xs:", 3) != 0)
1306
1441
  ? xsd_find_complex_ns(s, base, s->target_ns)
1307
1442
  : NULL;
1443
+ /* leptris-ruby#440 shape A: a base that is not
1444
+ * captured YET (forward reference — CT_TcPr extends
1445
+ * CT_TcPrInner defined later in the same file) or
1446
+ * that is itself still deferred folds in the
1447
+ * post-capture resolver, not here: folding a
1448
+ * half-captured base silently truncates the model.
1449
+ * The visited memo means each file merges once, so
1450
+ * the double capture that used to mask this is
1451
+ * gone. */
1452
+ int defer_base =
1453
+ base_root
1454
+ ? base_root->ext_base != NULL
1455
+ : (base && strncmp(base, "xs:", 3) != 0);
1456
+ if (defer_base && base) {
1457
+ free(root->ext_base);
1458
+ root->ext_base = xsd_strdup(base);
1459
+ }
1308
1460
  if (strcmp(dl, "extension") == 0) {
1309
1461
  /* base content first, derived content after */
1310
1462
  root->first_child = xsd_cm_copy_list(
1311
- base_root ? base_root->first_child : NULL);
1463
+ (base_root && !defer_base)
1464
+ ? base_root->first_child
1465
+ : NULL);
1312
1466
  XsdCm* own_tail = root->first_child;
1313
1467
  while (own_tail && own_tail->next)
1314
1468
  own_tail = own_tail->next;
@@ -1317,7 +1471,7 @@ static XsdCm* xsd_capture_complex_model(struct leptris_xsd_schema* s,
1317
1471
  own_tail->next = own;
1318
1472
  else if (!root->first_child)
1319
1473
  root->first_child = own;
1320
- if (base_root) {
1474
+ if (base_root && !defer_base) {
1321
1475
  const XsdTypeAttrs* bt = xsd_find_type_attrs(
1322
1476
  s, base);
1323
1477
  attrs = xsd_copy_attr_rows(bt ? bt->attrs
@@ -1390,6 +1544,8 @@ static XsdCm* xsd_capture_complex_model(struct leptris_xsd_schema* s,
1390
1544
  "complex:%s", name);
1391
1545
  free(captured->name);
1392
1546
  captured->name = xsd_strdup(synth);
1547
+ if (s->target_ns)
1548
+ captured->ns = xsd_strdup(s->target_ns);
1393
1549
  captured->next = s->simple_types;
1394
1550
  s->simple_types = captured;
1395
1551
  root->text_type = xsd_strdup(synth);
@@ -1662,7 +1818,6 @@ static char* xsd_capture_any_attr_ns(LeptrisElement container) {
1662
1818
 
1663
1819
  LEPTRIS_API int leptris_xsd_builtin_valid(const char* builtin,
1664
1820
  const char* lexical) {
1665
- extern int xsd_builtin_valid(const char* type, const char* v);
1666
1821
  return xsd_builtin_valid(builtin, lexical);
1667
1822
  }
1668
1823
 
@@ -15,6 +15,7 @@
15
15
 
16
16
  #include "../../include/leptris.h"
17
17
  #include "xsd_internal.h"
18
+ #include "../dom/element.h"
18
19
 
19
20
  extern int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
20
21
  const char* target_ns,
@@ -40,6 +41,8 @@ extern const XsdElementDecl* xsd_find_element(
40
41
  extern XsdCm* xsd_find_complex_ns(struct leptris_xsd_schema* s,
41
42
  const char* type_name, const char* uri);
42
43
  XsdCm* xsd_find_complex(struct leptris_xsd_schema* s, const char* type_name);
44
+ extern const XsdSimple* xsd_find_simple_ns_pub(
45
+ struct leptris_xsd_schema* s, const char* name, const char* uri);
43
46
  extern const XsdSimple* xsd_find_simple_pub(
44
47
  struct leptris_xsd_schema* s, const char* name);
45
48
  extern const char* xsd_target_ns(struct leptris_xsd_schema* s);
@@ -130,15 +133,16 @@ static int simple_is_numeric(struct leptris_xsd_schema* s,
130
133
 
131
134
  static int text_valid(struct xsd_validator* v,
132
135
  struct leptris_xsd_schema* s, const char* type,
133
- const char* lexical, const char* what,
134
- const char* name, LeptrisElement elem) {
136
+ const char* lexical, const char* ns,
137
+ const char* what, const char* name,
138
+ LeptrisElement elem) {
135
139
  if (!type) return 1;
136
140
  int r;
137
141
  const XsdSimple* st = NULL;
138
142
  if (strncmp(type, "xs:", 3) == 0)
139
143
  r = xsd_builtin_valid(type, lexical);
140
144
  else {
141
- st = xsd_find_simple_pub(s, type);
145
+ st = xsd_find_simple_ns_pub(s, type, ns);
142
146
  if (!st) return 1; /* unresolved: accept */
143
147
  r = xsd_simple_valid_chain(s, st, lexical);
144
148
  }
@@ -430,7 +434,8 @@ static void validate_attributes(struct xsd_validator* v,
430
434
  "required but absent");
431
435
  continue;
432
436
  }
433
- text_valid(v, s, a->type, val, "attribute", a->name, elem);
437
+ text_valid(v, s, a->type, val, ta->ns, "attribute",
438
+ a->name, elem);
434
439
  if (a->fixed && strcmp(val, a->fixed) != 0)
435
440
  verrf_at(v, elem, "attribute", a->name,
436
441
  "value does not match the fixed value");
@@ -547,8 +552,8 @@ static void validate_local(struct xsd_validator* v,
547
552
  if (ct->text_type) {
548
553
  const char* text = leptris_element_text(elem);
549
554
  if (text && *text)
550
- text_valid(v, s, ct->text_type, text, "element",
551
- local, elem);
555
+ text_valid(v, s, ct->text_type, text, ct->ns,
556
+ "element", local, elem);
552
557
  }
553
558
  return;
554
559
  }
@@ -558,7 +563,8 @@ static void validate_local(struct xsd_validator* v,
558
563
  xsd_find_simple_pub(s, type)) {
559
564
  const char* text = leptris_element_text(elem);
560
565
  if (text && *text)
561
- text_valid(v, s, type, text, "element", local, elem);
566
+ text_valid(v, s, type, text, euri, "element", local,
567
+ elem);
562
568
  return;
563
569
  }
564
570
  /* neither complex nor simple nor builtin: the schema is
@@ -633,8 +639,6 @@ static void validate_ics(struct xsd_validator* v,
633
639
  (void)v;
634
640
  const XsdElementIcs* ics = xsd_find_element_ics(s, elem_name);
635
641
  if (!ics) return;
636
- extern struct leptris_document* leptris_element_get_document(
637
- LeptrisElement elem);
638
642
  LeptrisDocument doc = leptris_element_get_document(elem);
639
643
  for (XsdIc* ic = ics->constraints; ic; ic = ic->next) {
640
644
  int is_ref = ic->kind == 2;