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
//! C ABI versioning — LIBXML2_VERSION, LIBXSLT_VERSION, runtime version APIs (§83, §84).
//!
//! This module implements the public C ABI version functions:
//! - `xmlLibxmlVersion()` — returns LIBXML2_VERSION as integer
//! - `xmlLibxmlVersionString()` — returns LIBXML2_VERSION string pointer
//! - `xmlParserVersion()` — alias for xmlLibxmlVersionString
//! - `xmlCheckVersion()` — runtime version compatibility check
//! - `xsltLibxsltVersion()` — returns LIBXSLT_VERSION as integer
//! - `xsltLibxsltVersionString()` — returns LIBXSLT_VERSION string pointer
//! - `xsltCheckVersion()` — runtime XSLT version compatibility check
//!
//! # Phase 1 status
//!
//! Complete — all version APIs are implemented.
//!
//! # Compatibility profile
//!
//! Currently targeting libxml2 2.12.0 / libxslt 1.1.39 compatibility.
//! These versions are selected as the first modern stable release after
//! the major 2.11 → 2.12 API transition.
//!
//! # UPSTREAM-PARITY
//!
//! Upstream version format: major * 10000 + minor * 100 + micro
//! Example: 2.12.0 → 21200
use c_char;
use ptr;
use AtomicBool;
use Ordering;
use c_int;
use crate*;
// ═══════════════════════════════════════════════════════════════════════════════
// Target Version Constants
// ═══════════════════════════════════════════════════════════════════════════════
/// The target libxml2 version we aim to be compatible with.
const TARGET_LIBXML2_MAJOR: c_int = 2;
const TARGET_LIBXML2_MINOR: c_int = 12;
const TARGET_LIBXML2_MICRO: c_int = 0;
/// The target libxslt version we aim to be compatible with.
const TARGET_LIBXSLT_MAJOR: c_int = 1;
const TARGET_LIBXSLT_MINOR: c_int = 1;
const TARGET_LIBXSLT_MICRO: c_int = 39;
/// The version string for libxml2 compatibility.
const LIBXML2_VERSION_STRING: & = b"2.12.0\0";
/// The version string for libxslt compatibility.
const LIBXSLT_VERSION_STRING: & = b"1.1.39\0";
// ═══════════════════════════════════════════════════════════════════════════════
// Version Macros (also defined in types.rs for compile-time use)
// ═══════════════════════════════════════════════════════════════════════════════
/// Compute the numeric version from major/minor/micro components.
pub const
/// libxml2 version as a number: 2 * 10000 + 12 * 100 + 0 = 21200
pub const LIBXML2_VERSION_NUM: c_int = version_number;
/// libxslt version as a number: 1 * 10000 + 1 * 100 + 39 = 10139
pub const LIBXSLT_VERSION_NUM: c_int = version_number;
// ═══════════════════════════════════════════════════════════════════════════════
// Initialization Tracking
// ═══════════════════════════════════════════════════════════════════════════════
/// Whether the library has been initialized.
static INITIALIZED: AtomicBool = new;
/// Mark the library as initialized.
/// Check whether the library has been initialized.
// ═══════════════════════════════════════════════════════════════════════════════
// libxml2 Version Functions
// ═══════════════════════════════════════════════════════════════════════════════
/// Return the libxml2 version as an integer.
///
/// Returns `major * 10000 + minor * 100 + micro`.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlLibxmlVersion(void);
/// ```
///
/// Oracle behavior (2.12.0): returns 21200.
/// Return the libxml2 version as a static C string.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// const char *xmlLibxmlVersionString(void);
/// ```
///
/// Oracle behavior (2.12.0): returns pointer to "2.12.0".
/// Return the parser version string (alias for `xmlLibxmlVersionString`).
///
/// # UPSTREAM-PARITY
///
/// ```c
/// const char *xmlParserVersion(void);
/// ```
/// Check that the library version is at least `version`.
///
/// # Returns
///
/// - 0 if the library version is >= `version`
/// - -1 if the library version is < `version`
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xmlCheckVersion(int version);
/// ```
///
/// Oracle behavior: compares LIBXML2_VERSION (compiled-in) against `version`.
/// Returns 0 if compatible, -1 if not.
// ═══════════════════════════════════════════════════════════════════════════════
// libxslt Version Functions
// ═══════════════════════════════════════════════════════════════════════════════
/// Return the libxslt version as an integer.
///
/// Returns `major * 10000 + minor * 100 + micro`.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltLibxsltVersion(void);
/// ```
/// Return the libxslt version as a static C string.
///
/// # UPSTREAM-PARITY
///
/// ```c
/// const char *xsltLibxsltVersionString(void);
/// ```
/// Convert a C string pointer to a byte slice (NULL-safe).
///
/// # SAFETY
///
/// - `ptr` must be a valid null-terminated C string or NULL.
pub unsafe
/// Check that the XSLT library version is at least `version`.
///
/// # Returns
///
/// - 0 if the library version is >= `version`
/// - -1 if the library version is < `version`
///
/// # UPSTREAM-PARITY
///
/// ```c
/// int xsltCheckVersion(int version);
/// ```
// ═══════════════════════════════════════════════════════════════════════════════
// Feature Detection
// ═══════════════════════════════════════════════════════════════════════════════
// ═══════════════════════════════════════════════════════════════════════════════
// Compile-time Version Macros (for Rust consumers)
// ═══════════════════════════════════════════════════════════════════════════════
/// The libxml2 version as a number (compile-time constant).
pub const LIBXML2_VERSION: c_int = LIBXML2_VERSION_NUM;
/// The libxml2 version major number.
pub const LIBXML2_VERSION_MAJOR: c_int = TARGET_LIBXML2_MAJOR;
/// The libxml2 version minor number.
pub const LIBXML2_VERSION_MINOR: c_int = TARGET_LIBXML2_MINOR;
/// The libxml2 version micro number.
pub const LIBXML2_VERSION_MICRO: c_int = TARGET_LIBXML2_MICRO;
/// The libxml2 version as a number (alternate name).
pub const LIBXML2_VERSION_NUMBER: c_int = LIBXML2_VERSION_NUM;
/// Extra version suffix (empty string for release versions).
pub const LIBXML2_VERSION_EXTRA: & = b"\0";
/// The libxslt version as a number (compile-time constant).
pub const LIBXSLT_VERSION: c_int = LIBXSLT_VERSION_NUM;
/// The libxslt version major number.
pub const LIBXSLT_VERSION_MAJOR: c_int = TARGET_LIBXSLT_MAJOR;
/// The libxslt version minor number.
pub const LIBXSLT_VERSION_MINOR: c_int = TARGET_LIBXSLT_MINOR;
/// The libxslt version micro number.
pub const LIBXSLT_VERSION_MICRO: c_int = TARGET_LIBXSLT_MICRO;
/// The libxslt version as a number (alternate name).
pub const LIBXSLT_VERSION_NUMBER: c_int = LIBXSLT_VERSION_NUM;
/// Extra version suffix for libxslt (empty string for release versions).
pub const LIBXSLT_VERSION_EXTRA: & = b"\0";
// ═══════════════════════════════════════════════════════════════════════════════
// Tests