1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
//! exports_relaxng — RELAX NG C ABI exports (family closure 11.1-I).
//!
//! This module implements the RELAX NG entry points from `relaxng.h` that are
//! not already exported by the internal engine in `src/xml/relaxng/mod.rs`
//! (which owns `xmlRelaxNGNewParserCtxt`, `xmlRelaxNGNewMemParserCtxt`,
//! `xmlRelaxNGParse`, `xmlRelaxNGFree`, `xmlRelaxNGFreeParserCtxt`,
//! `xmlRelaxNGNewValidCtxt`, `xmlRelaxNGFreeValidCtxt`, `xmlRelaxNGValidateDoc`
//! and `xmlRelaxNGValidateFullElement`).
//!
//! # Opaque-pointer convention
//!
//! `xmlRelaxNGPtr`, `xmlRelaxNGParserCtxtPtr` and `xmlRelaxNGValidCtxtPtr` are
//! opaque at the ABI boundary. The internal engine represents a parser context
//! as a `Box<RelaxNgSchema>` (parsed eagerly when the context is created) and a
//! validation context as a `Box<RelaxNgValidCtxt>`, both carried as `*mut
//! c_void`; this module follows that convention so pointers are interchangeable
//! between the two layers.
//!
//! # Error-callback state
//!
//! Upstream stores the error/warning/structured callbacks inside the context
//! structs. The internal engine's structs have no such fields, so the callbacks
//! registered via the `xmlRelaxNGSet*Errors` family are kept in side tables
//! keyed by context address. Entries live as long as the owning context; the
//! engine's own free functions are the only releasers, so entries are not
//! eagerly pruned (a fixed-size registry keyed by stable `Box` addresses).
//!
//! # Known divergences from upstream
//!
//! - Schema parsing is eager (done in the context constructors) rather than
//! lazy at `xmlRelaxNGParse` time; parse failures are recorded in
//! `schema.errors` and still produce a usable (empty) schema object.
//! - The engine reports validation errors through its internal error list
//! (`ctxt->errors` / return counts); per-context callbacks are consulted by
//! this module's streaming entry points (`xmlRelaxNGValidatePopElement`).
//! - `xmlRelaxNGDump` / `xmlRelaxNGDumpTree` render the parsed grammar in a
//! readable form; upstream's exact debug format is a libxml2-internal
//! artifact and is not replicated byte-for-byte.
//!
//! # Upstream contract
//!
//! Parity target is upstream `relaxng.c` (libxml2 2.15.3,
//! SRC-LIBXML2-2.15.0-RELAXNG-C) with the `relaxng.h` signatures; R-000165
//! (11.1-O) closed the relaxng export gaps (e.g. `xmlRelaxNGValidCtxtClearErrors`,
//! `xmlRelaxParserSetIncLImit`).
//!
//! # Conceptual behavior
//!
//! This module implements the RELAX NG entry points not already exported by
//! the internal engine in `src/xml/relaxng/mod.rs`: dump/tree rendering,
//! parser/validation error-callback registration and the streaming validation
//! entry points, using the opaque-pointer convention documented above.
//!
//! # Ownership & safety invariants
//!
//! `xmlRelaxNGPtr`/`xmlRelaxNGParserCtxtPtr`/`xmlRelaxNGValidCtxtPtr` are
//! caller-owned: schemas freed with `xmlRelaxNGFree`, contexts with
//! `xmlRelaxNGFreeParserCtxt`/`xmlRelaxNGFreeValidCtxt`. The error-callback
//! side tables are keyed by context address and live exactly as long as the
//! owning context (the engines own free functions are the only releasers).
//!
//! # Historical quirks & epochs
//!
//! RELAX NG matured in the 2.6 `validation_era` (HISTORY.md) and the ABI has
//! been stable since; R-000165 (11.1-O) added the missing relaxng symbols so
//! the oracle DSO export set is complete.
//!
//! # Deliberate oddities
//!
//! The eager schema parse in the context constructors (upstream parses lazily
//! at `xmlRelaxNGParse`) is a deliberate divergence documented in the header
//! above, as is `xmlRelaxNGDump`/`xmlRelaxNGDumpTree` not replicating
//! upstreams internal debug format byte-for-byte.
//!
//! # Proving courts
//!
//! The RELAXNG court family, the CLI-XMLLINT relaxng cases and the
//! DSO-LOADER/HEADER-COMPILE courts cover this module; the relaxng unit tests
//! run under cargo test.
//!
//! # Tempting simplifications that would break parity
//!
//! A tempting simplification is to make `xmlRelaxNGSetParserErrors` a stored
//! no-op because the engine reports internally — the error callbacks are the
//! observable contract for C consumers validating documents (the RELAXNG
//! courts drive them), so the side tables must stay. Another shortcut —
//! freeing schema objects eagerly when the parser context dies — would break
//! the callers valid-ctxt reuse of a parsed schema.
use c_void;
use ptr;
use Lazy;
use Mutex;
use HashMap;
use CString;
use ;
use cratexmlStructuredErrorFunc;
use crate;
use crate;
use crate;
// ═══════════════════════════════════════════════════════════════════════════════
// Callback types (relaxng.h)
// ═══════════════════════════════════════════════════════════════════════════════
/// `xmlRelaxNGValidityErrorFunc` — printf-style error callback (variadic at the
/// C call site; only the `msg` argument is representable in Rust).
pub type xmlRelaxNGValidityErrorFunc = unsafe extern "C" fn;
/// `xmlRelaxNGValidityWarningFunc` — printf-style warning callback (variadic at
/// the C call site; only the `msg` argument is representable in Rust).
pub type xmlRelaxNGValidityWarningFunc = unsafe extern "C" fn;
// ═══════════════════════════════════════════════════════════════════════════════
// Per-context callback/flag state (upstream keeps this inside the ctxt structs)
// ═══════════════════════════════════════════════════════════════════════════════
/// Wrapper around `*mut c_void` that implements `Send` + `Sync` so it can be
/// stored in a `Mutex`-protected global side table (same pattern as
/// `SendSyncPtr` in exports_xml2.rs). Pointers are only dereferenced while the
/// registry lock is held, so the wrapper is sound.
;
unsafe
unsafe
/// Error-callback state attached to a RELAX NG parser context.
/// Error-callback state attached to a RELAX NG validation context.
static PARSER_CTXT_STATE: =
new;
static VALID_CTXT_STATE: =
new;
// ═══════════════════════════════════════════════════════════════════════════════
// libc FILE* plumbing (the FILE* is opaque at the ABI boundary)
// ═══════════════════════════════════════════════════════════════════════════════
extern "C"
/// Write `text` to `output`; a NULL `output` falls back to stdout (the same
/// convention as `xmlBufferDump` and the debug dumpers in this crate).
///
/// # SAFETY
///
/// - `output` must be a valid `FILE*` or NULL.
unsafe
// ═══════════════════════════════════════════════════════════════════════════════
// Schema rendering for xmlRelaxNGDump / xmlRelaxNGDumpTree
// ═══════════════════════════════════════════════════════════════════════════════
/// RELAX NG pattern-kind names (the XML element names from the RELAX NG syntax).
const
/// Render a name class in a compact, readable form.
/// Render a pattern and its children as an indented tree.
/// Render a grammar: named defines, the start pattern, and included grammars.
/// Render the full schema.
// ═══════════════════════════════════════════════════════════════════════════════
// 1. Initialization / Cleanup
// ═══════════════════════════════════════════════════════════════════════════════
/// Initialize the datatype subsystem used by RELAX NG `<data>`/`<value>`
/// patterns.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxNGInitTypes(void);
/// ```
///
/// Returns 0 on success, -1 on error. The candidate's datatype checking is
/// compiled into the internal engine and needs no global initialization, so
/// this always succeeds.
///
/// # SAFETY
///
/// The function touches crate-global state only; it is safe
/// as long as the caller respects the library's global
/// initialization/cleanup ordering (xmlInitParser before use,
/// xmlCleanupParser only after all users are done).
///
/// Violating the global lifecycle ordering, or calling this after
/// teardown or from a signal handler, is undefined behavior.
pub const unsafe extern "C"
/// Tear down the datatype subsystem used by RELAX NG patterns.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGCleanupTypes(void);
/// ```
///
/// No-op: the candidate keeps no global datatype state.
///
/// # SAFETY
///
/// The function touches crate-global state only; it is safe
/// as long as the caller respects the library's global
/// initialization/cleanup ordering (xmlInitParser before use,
/// xmlCleanupParser only after all users are done).
///
/// Violating the global lifecycle ordering, or calling this after
/// teardown or from a signal handler, is undefined behavior.
pub const unsafe extern "C"
// ═══════════════════════════════════════════════════════════════════════════════
// 2. Dumping
// ═══════════════════════════════════════════════════════════════════════════════
/// Dump a RELAX NG schema to a file stream.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGDump(FILE *output, xmlRelaxNG *schema);
/// ```
///
/// `FILE*` is opaque at the ABI boundary and is passed as `*mut c_void`; a NULL
/// `output` falls back to stdout. Upstream's exact debug format is a
/// libxml2-internal artifact; the candidate renders the parsed grammar
/// (defines, start pattern, includes) in a readable, equivalent form.
///
/// # SAFETY
///
/// - `output` must be a valid `FILE*` or NULL.
/// - `schema` must be a valid `Box<RelaxNgSchema>` pointer or NULL.
pub unsafe extern "C"
/// Dump the pattern tree of a RELAX NG schema to a file stream.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGDumpTree(FILE *output, xmlRelaxNG *schema);
/// ```
///
/// Same opaque-pointer and format conventions as `xmlRelaxNGDump`; the output
/// is the same readable pattern-tree rendering (upstream's internal tree layout
/// is not replicated byte-for-byte).
///
/// # SAFETY
///
/// - `output` must be a valid `FILE*` or NULL.
/// - `schema` must be a valid `Box<RelaxNgSchema>` pointer or NULL.
pub unsafe extern "C"
/// Shared implementation for `xmlRelaxNGDump` and `xmlRelaxNGDumpTree`.
///
/// # SAFETY
///
/// - `output` must be a valid `FILE*` or NULL.
/// - `schema` must be a valid `Box<RelaxNgSchema>` pointer or NULL.
unsafe
// ═══════════════════════════════════════════════════════════════════════════════
// 3. Parser context construction
// ═══════════════════════════════════════════════════════════════════════════════
/// Create a RELAX NG parser context from an already-parsed XML document.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// xmlRelaxNGParserCtxt *xmlRelaxNGNewDocParserCtxt(xmlDoc *doc);
/// ```
///
/// Returns a parser context (`*mut c_void` pointing at a `Box<RelaxNgSchema>`,
/// matching the internal engine's convention) or NULL on allocation failure.
///
/// NOTE: upstream defers schema compilation to `xmlRelaxNGParse` and reports
/// parse errors through the parser error callbacks. The internal engine parses
/// eagerly in the context constructor, so a failed parse still yields a
/// (valid, empty) schema object with the failure recorded in its error list;
/// `xmlRelaxNGParse` then returns that object and validation reports the
/// recorded errors.
///
/// # SAFETY
///
/// - `doc` must be a valid pointer to an `_xmlDoc` or NULL.
pub unsafe extern "C"
// ═══════════════════════════════════════════════════════════════════════════════
// 4. Parser error handlers
// ═══════════════════════════════════════════════════════════════════════════════
/// Set the error and warning callbacks on a RELAX NG parser context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxt *ctxt,
/// xmlRelaxNGValidityErrorFunc err,
/// xmlRelaxNGValidityWarningFunc warn,
/// void *ctx);
/// ```
///
/// The callbacks are kept in a side table keyed by the context address (the
/// internal engine's context structs have no callback fields). Because schema
/// parsing in the candidate is eager, these callbacks are not invoked by the
/// parser; they are stored for ABI parity.
///
/// # SAFETY
///
/// - `ctxt` must be a valid parser context pointer or NULL.
pub unsafe extern "C"
/// Retrieve the error and warning callbacks from a RELAX NG parser context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxt *ctxt,
/// xmlRelaxNGValidityErrorFunc *err,
/// xmlRelaxNGValidityWarningFunc *warn,
/// void **ctx);
/// ```
///
/// Returns 0 on success, -1 if `ctxt` is NULL. Any of `err`, `warn`, `ctx` may
/// be NULL to skip that output.
///
/// # SAFETY
///
/// - `ctxt` must be a valid parser context pointer or NULL.
/// - `err`/`warn` must be valid out-parameters or NULL.
/// - `ctx` must be a valid `void **` out-parameter or NULL.
pub unsafe extern "C"
/// Set the structured error callback on a RELAX NG parser context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxt *ctxt,
/// xmlStructuredErrorFunc serror,
/// void *ctx);
/// ```
///
/// Stored for ABI parity; the candidate's eager parser reports errors through
/// the schema's internal error list rather than structured callbacks.
///
/// # SAFETY
///
/// - `ctxt` must be a valid parser context pointer or NULL.
pub unsafe extern "C"
// ═══════════════════════════════════════════════════════════════════════════════
// 5. Validation context error handlers
// ═══════════════════════════════════════════════════════════════════════════════
/// Set the error and warning callbacks on a RELAX NG validation context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxt *ctxt,
/// xmlRelaxNGValidityErrorFunc err,
/// xmlRelaxNGValidityWarningFunc warn,
/// void *ctx);
/// ```
///
/// The callbacks are consulted by this module's streaming entry points
/// (`xmlRelaxNGValidatePopElement`). Document validation
/// (`xmlRelaxNGValidateDoc`) is owned by the internal engine and reports
/// through its return value / `ctxt->errors` instead.
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer or NULL.
pub unsafe extern "C"
/// Retrieve the error and warning callbacks from a RELAX NG validation context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxt *ctxt,
/// xmlRelaxNGValidityErrorFunc *err,
/// xmlRelaxNGValidityWarningFunc *warn,
/// void **ctx);
/// ```
///
/// Returns 0 on success, -1 if `ctxt` is NULL. Any of `err`, `warn`, `ctx` may
/// be NULL to skip that output.
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer or NULL.
/// - `err`/`warn` must be valid out-parameters or NULL.
/// - `ctx` must be a valid `void **` out-parameter or NULL.
pub unsafe extern "C"
/// Set the structured error callback on a RELAX NG validation context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// void xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxt *ctxt,
/// xmlStructuredErrorFunc serror,
/// void *ctx);
/// ```
///
/// Consulted by `xmlRelaxNGValidatePopElement`, which delivers each released
/// validation error as a minimal `_xmlError` record (domain `XML_FROM_RELAXNGV`,
/// level `XML_ERR_ERROR`).
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer or NULL.
pub unsafe extern "C"
// ═══════════════════════════════════════════════════════════════════════════════
// 6. Streaming (push/pop) validation
// ═══════════════════════════════════════════════════════════════════════════════
/// Push an element start onto the streaming validation stack.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxt *ctxt,
/// xmlDoc *doc,
/// xmlNode *elem);
/// ```
///
/// Returns 0 if the element is valid, -1 on internal error, or a positive
/// number of validation errors.
///
/// Upstream's `xmlRelaxNGValidatePushElement` delegates to
/// `xmlRelaxNGValidateFullElement`; the internal engine validates the whole
/// element subtree (there is no start-tag-only mode), so a push validates the
/// element immediately and reports any errors in `ctxt->errors`. Nested
/// elements are validated again when their own push arrives, so per-push error
/// counts may double-count errors that belong to subtrees.
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer.
/// - `doc` must be a valid `_xmlDoc` pointer.
/// - `elem` must be a valid element node pointer.
pub unsafe extern "C"
/// Push character data onto the streaming validation stack.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxt *ctxt,
/// const xmlChar *data,
/// int len);
/// ```
///
/// Returns 0 if the character data is valid, -1 on internal error, or a
/// positive number of validation errors.
///
/// Character content is validated as part of element validation
/// (`text`/`data`/`value` patterns) by the internal engine; there is no
/// incremental text state to update here, so a well-formed call always
/// succeeds.
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer.
/// - `data` must be a valid buffer of `len` bytes (or NULL when `len` is 0).
pub const unsafe extern "C"
/// Deliver accumulated validation errors to the context's registered
/// callbacks (xmlRelaxNGSetValidErrors / xmlRelaxNGSetValidStructuredErrors).
/// The state is copied out so callbacks are never invoked while the lock is
/// held.
///
/// # SAFETY
///
/// - `ctxt_addr` must be the address of a `RelaxNgValidCtxt` that a caller
/// registered state for; otherwise this is a no-op.
/// - `node` may be NULL; it is stored in the structured error's `node`.
pub unsafe
/// Deliver accumulated schema-parse diagnostics to the parser context's
/// registered callbacks (xmlRelaxNGSetParserErrors /
/// xmlRelaxNGSetParserStructuredErrors). Upstream reports parse errors while
/// compiling in xmlRelaxNGParse; the internal engine parses eagerly at
/// context construction (before the callbacks are registered), so the
/// messages are queued on the parsed schema and flushed here.
///
/// # SAFETY
///
/// - `ctxt_addr` must be the address of a `RelaxNgParserCtxt` that a caller
/// registered state for; otherwise this is a no-op.
pub unsafe
/// Pop an element end off the streaming validation stack.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxNGValidatePopElement(xmlRelaxNGValidCtxt *ctxt,
/// xmlDoc *doc,
/// xmlNode *elem);
/// ```
///
/// Returns 0 if the element is valid, -1 on internal error, or a positive
/// number of validation errors.
///
/// Because the internal engine validated the element subtree eagerly at push
/// time, the pop step performs upstream's "release the accumulated errors"
/// step: the context's error list is drained and each message is delivered to
/// the callbacks registered with `xmlRelaxNGSetValidErrors` /
/// `xmlRelaxNGSetValidStructuredErrors` (the engine does not distinguish
/// warnings, so all messages are routed to the error callback). The return
/// value is 0 unless the arguments are invalid.
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer.
/// - `doc` must be a valid `_xmlDoc` pointer.
/// - `elem` must be a valid element node pointer.
pub unsafe extern "C"
// ═══════════════════════════════════════════════════════════════════════════════
// 7. Parser flags
// ═══════════════════════════════════════════════════════════════════════════════
/// Set parser flags on a RELAX NG parser context.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlRelaxParserSetFlag(xmlRelaxNGParserCtxt *ctxt, int flag);
/// ```
///
/// Returns 0 on success, -1 on error. `flag == 0` resets the flags
/// (`XML_RELAXNG_PARSE_FREE`). The flags are stored for ABI parity; the
/// candidate's parser compiles schemas eagerly and does not consult them.
///
/// # SAFETY
///
/// - `ctxt` must be a valid parser context pointer or NULL.
pub unsafe extern "C"
/// Set the incremental-compile limit on a RELAX NG parser context
/// (upstream relaxng.c `xmlRelaxParserSetIncLImit`).
///
/// # SAFETY
///
/// - `ctxt` must be a valid parser context pointer or NULL.
pub unsafe extern "C"
/// Install a custom resource loader on a RELAX NG parser context
/// (upstream relaxng.c `xmlRelaxNGSetResourceLoader`).
///
/// # SAFETY
///
/// - `ctxt` must be a valid parser context pointer or NULL.
pub unsafe extern "C"
/// Clear the error state of a RELAX NG validation context
/// (upstream relaxng.c `xmlRelaxNGValidCtxtClearErrors`).
///
/// # SAFETY
///
/// - `ctxt` must be a valid validation context pointer or NULL.
pub unsafe extern "C"