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
//! exports_xlink — XLink detection module C ABI exports (11.1-X R-000165
//! closure).
//!
//! Ported from `archaeology/libxml2-git/xlink.c` (libxml2 2.15.3). The
//! default handler/detect slots are static globals exactly like upstream;
//! `xlinkIsLink` implements the (deprecated, never-finished) detection
//! rules for XML XLinks.
//!
//! These five symbols are part of the 11.1-W parity obligations (5 xlink
//! obligations) and are declared by the drop-in `include/libxml/xlink.h`.
//!
//! # Upstream contract
//!
//! Parity target is upstream `xlink.c` (libxml2 2.15.3,
//! SRC-LIBXML2-2.15.0-XLINK-C) with the `xlink.h` signatures; the five symbols
//! are part of the 11.1-W parity obligations (R-000165 closed the xlink
//! surface in 11.1-O/X).
//!
//! # Conceptual behavior
//!
//! This module implements the XLink detection module ABI: the default
//! handler/detect slots (`xlinkGet/SetDefaultHandler`, `xlinkGet/SetDefaultDetect`)
//! and `xlinkIsLink`, which implements the deprecated, never-finished
//! detection rules for XML XLinks. The slots are static globals exactly like
//! upstream.
//!
//! # Ownership & safety invariants
//!
//! The handler/detect slots store caller-provided function pointers and return
//! them verbatim; the caller keeps any associated context alive (callback
//! user-data contract, OWNERSHIP_ATLAS section 6). `xlinkIsLink` returns an
//! enum value (0 none / 1 simple / 2 extended / 3 extended set) and never
//! takes ownership of the node.
//!
//! # Historical quirks & epochs
//!
//! The XLink module has been effectively frozen since the early 2000s — the
//! detection rules were never completed upstream (the header comment above
//! records this); the ABI is still exported in 2.15.3 and the candidate
//! mirrors it. R-000165 (11.1-O) added the missing xlink symbols
//! (xlinkGetDefaultDetect/xlinkIsLink family) to the census.
//!
//! # Deliberate oddities
//!
//! The oddities are the module itself: the 1999 XLink namespace string with
//! its trailing slash (`http://www.w3.org/1999/xlink/namespace/`), the
//! never-finished detection rules, and the handler blocks stored as opaque
//! pointers never dereferenced — all deliberate parity with upstreams
//! deprecated API.
//!
//! # Proving courts
//!
//! The DSO-LOADER court resolves all five symbols from the built DSO; the
//! HEADER-COMPILE court compiles `include/libxml/xlink.h` against it; the
//! callback-family probe exercises the default-slot round-trip.
//!
//! # Tempting simplifications that would break parity
//!
//! A tempting simplification is to drop the xlink surface entirely because the
//! detection rules are unfinished — the symbols are still oracle-DSO exports
//! and downstream code calls `xlinkIsLink` on documents with XLink attributes;
//! removing them would fail symbol resolution. Another shortcut, correcting
//! the namespace string to the modern one, would break consumers matching the
//! historical 1999 URI.
use c_void;
use ptr;
use c_int;
use crate;
use cratexmlChar;
/// `xlinkType` (xlink.h): NONE 0, SIMPLE 1, EXTENDED 2, EXTENDED_SET 3.
const XLINK_TYPE_NONE: c_int = 0;
const XLINK_TYPE_SIMPLE: c_int = 1;
const XLINK_TYPE_EXTENDED: c_int = 2;
const XLINK_TYPE_EXTENDED_SET: c_int = 3;
/// Upstream XLINK_NAMESPACE (note: the 1999 namespace with trailing slash).
const XLINK_NS: & = b"http://www.w3.org/1999/xlink/namespace/\0";
/// Upstream XHTML_NAMESPACE.
const XHTML_NS: & = b"http://www.w3.org/1999/xhtml/\0";
/// `xlinkNodeDetectFunc` — node detection callback.
pub type xlinkNodeDetectFunc = unsafe extern "C" fn;
/// `xlinkHandler` — opaque handler block (never dereferenced by the
/// candidate; stored as an opaque pointer exactly like upstream's
/// deprecated API).
/// Default handler slot (upstream `xlinkDefaultHandler`).
static mut XLINK_DEFAULT_HANDLER: *mut _xlinkHandler = null_mut;
/// Default detection routine slot (upstream `xlinkDefaultDetect`).
static mut XLINK_DEFAULT_DETECT: = None;
/// Get the default xlink handler.
///
/// # 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 unsafe extern "C"
/// Set the default xlink handler.
///
/// # SAFETY
///
/// - `handler` must be valid pointers (or NULL
/// where the upstream C contract allows), obtained from the
/// matching constructor/owner and not yet freed; the callee may
/// take or keep ownership exactly as the C API specifies.
///
/// The caller must not race this call with concurrent mutation of the
/// same objects from other threads (per-object state is not internally
/// synchronized). Violating any of the above is undefined behavior.
///
/// Exercised by the C-API differential courts
/// (courts/suites/data-abi/*-family-probe.c) and the CLI differential
/// courts; those pass byte-for-byte against the upstream oracle.
pub unsafe extern "C"
/// Get the default xlink detection routine.
///
/// # 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 unsafe extern "C"
/// Set the default xlink detection routine.
///
/// # SAFETY
///
///
/// - `func` must be a valid callback (or None);
/// the callback is invoked with the documented context pointer and
/// must itself uphold the same pointer invariants.
///
/// The caller must not race this call with concurrent mutation of the
/// same objects from other threads (per-object state is not internally
/// synchronized). Violating any of the above is undefined behavior.
///
/// Exercised by the C-API differential courts
/// (courts/suites/data-abi/*-family-probe.c) and the CLI differential
/// courts; those pass byte-for-byte against the upstream oracle.
pub unsafe extern "C"
/// Check whether the given node carries the attributes needed to be a link
/// element (upstream xlink.c `xlinkIsLink`).
///
/// Returns the xlinkType of the node (XLINK_TYPE_NONE if no link is
/// detected).
///
/// # SAFETY
///
/// - `node` must be NULL or a valid `_xmlNode`.
/// - `doc` must be NULL or a valid `_xmlDoc`.
pub unsafe extern "C"