ddigraph-core 0.6.0__tar.gz

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.
@@ -0,0 +1,399 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "arrayvec"
7
+ version = "0.7.8"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
10
+
11
+ [[package]]
12
+ name = "autocfg"
13
+ version = "1.5.1"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
16
+
17
+ [[package]]
18
+ name = "blake3"
19
+ version = "1.8.8"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "64c0e36294adc8db531500e3f2b8ec75c4af9177271e9c6d33f93609d56e57cd"
22
+ dependencies = [
23
+ "arrayvec",
24
+ "cc",
25
+ "cfg-if",
26
+ "constant_time_eq",
27
+ "cpufeatures",
28
+ ]
29
+
30
+ [[package]]
31
+ name = "cc"
32
+ version = "1.11.1"
33
+ source = "registry+https://github.com/rust-lang/crates.io-index"
34
+ checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155"
35
+ dependencies = [
36
+ "find-msvc-tools",
37
+ "shlex",
38
+ ]
39
+
40
+ [[package]]
41
+ name = "cfg-if"
42
+ version = "1.0.5"
43
+ source = "registry+https://github.com/rust-lang/crates.io-index"
44
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
45
+
46
+ [[package]]
47
+ name = "constant_time_eq"
48
+ version = "0.6.2"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+ checksum = "144e7f1de087984240b7816d47f698b414979faa6f40839c5b86d6bd47db57b7"
51
+ dependencies = [
52
+ "rustversion",
53
+ ]
54
+
55
+ [[package]]
56
+ name = "core_detect"
57
+ version = "1.0.0"
58
+ source = "registry+https://github.com/rust-lang/crates.io-index"
59
+ checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
60
+
61
+ [[package]]
62
+ name = "cpufeatures"
63
+ version = "0.3.1"
64
+ source = "registry+https://github.com/rust-lang/crates.io-index"
65
+ checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
66
+ dependencies = [
67
+ "libc",
68
+ ]
69
+
70
+ [[package]]
71
+ name = "ddigraph-core"
72
+ version = "0.6.0"
73
+ dependencies = [
74
+ "blake3",
75
+ "encoding_rs",
76
+ "quick-xml",
77
+ "rmp-serde",
78
+ "serde",
79
+ "serde_json",
80
+ "thiserror",
81
+ ]
82
+
83
+ [[package]]
84
+ name = "ddigraph-core-py"
85
+ version = "0.6.0"
86
+ dependencies = [
87
+ "ddigraph-core",
88
+ "pyo3",
89
+ ]
90
+
91
+ [[package]]
92
+ name = "ddigraph-sandbox"
93
+ version = "0.6.0"
94
+ dependencies = [
95
+ "ddigraph-core",
96
+ "rmp-serde",
97
+ "serde",
98
+ "serde_bytes",
99
+ ]
100
+
101
+ [[package]]
102
+ name = "encoding_rs"
103
+ version = "0.8.44"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "89253175e704ab869b04f9db224d38630e0211a53841a79181deae0889e169f5"
106
+ dependencies = [
107
+ "cfg-if",
108
+ "core_detect",
109
+ "multiversion_no_op",
110
+ "rustversion",
111
+ "scopeguard",
112
+ "simdutf8",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "find-msvc-tools"
117
+ version = "0.1.15"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
120
+
121
+ [[package]]
122
+ name = "heck"
123
+ version = "0.5.0"
124
+ source = "registry+https://github.com/rust-lang/crates.io-index"
125
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
126
+
127
+ [[package]]
128
+ name = "itoa"
129
+ version = "1.0.18"
130
+ source = "registry+https://github.com/rust-lang/crates.io-index"
131
+ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
132
+
133
+ [[package]]
134
+ name = "libc"
135
+ version = "0.2.191"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
138
+
139
+ [[package]]
140
+ name = "memchr"
141
+ version = "2.8.3"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
144
+
145
+ [[package]]
146
+ name = "multiversion_no_op"
147
+ version = "1.0.0"
148
+ source = "registry+https://github.com/rust-lang/crates.io-index"
149
+ checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"
150
+
151
+ [[package]]
152
+ name = "num-traits"
153
+ version = "0.2.19"
154
+ source = "registry+https://github.com/rust-lang/crates.io-index"
155
+ checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
156
+ dependencies = [
157
+ "autocfg",
158
+ ]
159
+
160
+ [[package]]
161
+ name = "once_cell"
162
+ version = "1.21.4"
163
+ source = "registry+https://github.com/rust-lang/crates.io-index"
164
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
165
+
166
+ [[package]]
167
+ name = "portable-atomic"
168
+ version = "1.15.0"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
171
+
172
+ [[package]]
173
+ name = "proc-macro2"
174
+ version = "1.0.107"
175
+ source = "registry+https://github.com/rust-lang/crates.io-index"
176
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
177
+ dependencies = [
178
+ "unicode-ident",
179
+ ]
180
+
181
+ [[package]]
182
+ name = "pyo3"
183
+ version = "0.30.1"
184
+ source = "registry+https://github.com/rust-lang/crates.io-index"
185
+ checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
186
+ dependencies = [
187
+ "libc",
188
+ "once_cell",
189
+ "portable-atomic",
190
+ "pyo3-build-config",
191
+ "pyo3-ffi",
192
+ "pyo3-macros",
193
+ ]
194
+
195
+ [[package]]
196
+ name = "pyo3-build-config"
197
+ version = "0.30.1"
198
+ source = "registry+https://github.com/rust-lang/crates.io-index"
199
+ checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
200
+ dependencies = [
201
+ "target-lexicon",
202
+ ]
203
+
204
+ [[package]]
205
+ name = "pyo3-ffi"
206
+ version = "0.30.1"
207
+ source = "registry+https://github.com/rust-lang/crates.io-index"
208
+ checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
209
+ dependencies = [
210
+ "libc",
211
+ "pyo3-build-config",
212
+ ]
213
+
214
+ [[package]]
215
+ name = "pyo3-macros"
216
+ version = "0.30.1"
217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
218
+ checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
219
+ dependencies = [
220
+ "proc-macro2",
221
+ "pyo3-macros-backend",
222
+ "quote",
223
+ "syn",
224
+ ]
225
+
226
+ [[package]]
227
+ name = "pyo3-macros-backend"
228
+ version = "0.30.1"
229
+ source = "registry+https://github.com/rust-lang/crates.io-index"
230
+ checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
231
+ dependencies = [
232
+ "heck",
233
+ "proc-macro2",
234
+ "quote",
235
+ "syn",
236
+ ]
237
+
238
+ [[package]]
239
+ name = "quick-xml"
240
+ version = "0.42.0"
241
+ source = "registry+https://github.com/rust-lang/crates.io-index"
242
+ checksum = "41b1177fdf999d2321d3fb46ff47159d9c1fb9ad66a4879f8c50a0b504615e9b"
243
+ dependencies = [
244
+ "memchr",
245
+ ]
246
+
247
+ [[package]]
248
+ name = "quote"
249
+ version = "1.0.47"
250
+ source = "registry+https://github.com/rust-lang/crates.io-index"
251
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
252
+ dependencies = [
253
+ "proc-macro2",
254
+ ]
255
+
256
+ [[package]]
257
+ name = "rmp"
258
+ version = "0.8.15"
259
+ source = "registry+https://github.com/rust-lang/crates.io-index"
260
+ checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c"
261
+ dependencies = [
262
+ "num-traits",
263
+ ]
264
+
265
+ [[package]]
266
+ name = "rmp-serde"
267
+ version = "1.3.1"
268
+ source = "registry+https://github.com/rust-lang/crates.io-index"
269
+ checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155"
270
+ dependencies = [
271
+ "rmp",
272
+ "serde",
273
+ ]
274
+
275
+ [[package]]
276
+ name = "rustversion"
277
+ version = "1.0.23"
278
+ source = "registry+https://github.com/rust-lang/crates.io-index"
279
+ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
280
+
281
+ [[package]]
282
+ name = "scopeguard"
283
+ version = "1.2.0"
284
+ source = "registry+https://github.com/rust-lang/crates.io-index"
285
+ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
286
+
287
+ [[package]]
288
+ name = "serde"
289
+ version = "1.0.229"
290
+ source = "registry+https://github.com/rust-lang/crates.io-index"
291
+ checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
292
+ dependencies = [
293
+ "serde_core",
294
+ "serde_derive",
295
+ ]
296
+
297
+ [[package]]
298
+ name = "serde_bytes"
299
+ version = "0.11.19"
300
+ source = "registry+https://github.com/rust-lang/crates.io-index"
301
+ checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8"
302
+ dependencies = [
303
+ "serde",
304
+ "serde_core",
305
+ ]
306
+
307
+ [[package]]
308
+ name = "serde_core"
309
+ version = "1.0.229"
310
+ source = "registry+https://github.com/rust-lang/crates.io-index"
311
+ checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
312
+ dependencies = [
313
+ "serde_derive",
314
+ ]
315
+
316
+ [[package]]
317
+ name = "serde_derive"
318
+ version = "1.0.229"
319
+ source = "registry+https://github.com/rust-lang/crates.io-index"
320
+ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
321
+ dependencies = [
322
+ "proc-macro2",
323
+ "quote",
324
+ "syn",
325
+ ]
326
+
327
+ [[package]]
328
+ name = "serde_json"
329
+ version = "1.0.154"
330
+ source = "registry+https://github.com/rust-lang/crates.io-index"
331
+ checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
332
+ dependencies = [
333
+ "itoa",
334
+ "memchr",
335
+ "serde",
336
+ "serde_core",
337
+ "zmij",
338
+ ]
339
+
340
+ [[package]]
341
+ name = "shlex"
342
+ version = "2.0.1"
343
+ source = "registry+https://github.com/rust-lang/crates.io-index"
344
+ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
345
+
346
+ [[package]]
347
+ name = "simdutf8"
348
+ version = "0.1.5"
349
+ source = "registry+https://github.com/rust-lang/crates.io-index"
350
+ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
351
+
352
+ [[package]]
353
+ name = "syn"
354
+ version = "3.0.9"
355
+ source = "registry+https://github.com/rust-lang/crates.io-index"
356
+ checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
357
+ dependencies = [
358
+ "proc-macro2",
359
+ "quote",
360
+ "unicode-ident",
361
+ ]
362
+
363
+ [[package]]
364
+ name = "target-lexicon"
365
+ version = "0.13.5"
366
+ source = "registry+https://github.com/rust-lang/crates.io-index"
367
+ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
368
+
369
+ [[package]]
370
+ name = "thiserror"
371
+ version = "2.0.21"
372
+ source = "registry+https://github.com/rust-lang/crates.io-index"
373
+ checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
374
+ dependencies = [
375
+ "thiserror-impl",
376
+ ]
377
+
378
+ [[package]]
379
+ name = "thiserror-impl"
380
+ version = "2.0.21"
381
+ source = "registry+https://github.com/rust-lang/crates.io-index"
382
+ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
383
+ dependencies = [
384
+ "proc-macro2",
385
+ "quote",
386
+ "syn",
387
+ ]
388
+
389
+ [[package]]
390
+ name = "unicode-ident"
391
+ version = "1.0.27"
392
+ source = "registry+https://github.com/rust-lang/crates.io-index"
393
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
394
+
395
+ [[package]]
396
+ name = "zmij"
397
+ version = "1.0.23"
398
+ source = "registry+https://github.com/rust-lang/crates.io-index"
399
+ checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
@@ -0,0 +1,12 @@
1
+ [workspace]
2
+ members = ["crates/ddigraph-core", "crates/ddigraph-core-py"]
3
+ # The cargo-fuzz targets are a workspace of their own, built with nightly
4
+ # only when asked for (see README.md); CI never builds them.
5
+ exclude = ["fuzz"]
6
+ resolver = "3"
7
+
8
+ [workspace.package]
9
+ version = "0.6.0"
10
+ edition = "2024"
11
+ license = "MIT"
12
+ rust-version = "1.85"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Philippe Bisson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: ddigraph-core
3
+ Version: 0.6.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Operating System :: MacOS
7
+ Classifier: Operating System :: Microsoft :: Windows
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Programming Language :: Rust
17
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
18
+ Classifier: Topic :: Text Processing :: Markup :: XML
19
+ License-File: LICENSE
20
+ Summary: The optional Rust engine of ddigraph: reads DDI XML files into ddigraph's graph IR
21
+ Keywords: ddi,ddi-cdi,knowledge-graph,xml,metadata,rust
22
+ Author-email: Philippe Bisson <pbisson44@gmail.com>
23
+ Maintainer: Philippe Bisson
24
+ License-Expression: MIT
25
+ Requires-Python: >=3.12
26
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
27
+ Project-URL: Changelog, https://github.com/pbisson44/ddigraph/blob/main/CHANGELOG.md
28
+ Project-URL: Documentation, https://pbisson44.github.io/ddigraph/advanced/rust-engine/
29
+ Project-URL: Homepage, https://github.com/pbisson44/ddigraph
30
+ Project-URL: Issues, https://github.com/pbisson44/ddigraph/issues
31
+ Project-URL: Repository, https://github.com/pbisson44/ddigraph
32
+
33
+ # ddigraph-core
34
+
35
+ The Rust engine of [ddigraph](https://github.com/pbisson44/ddigraph). It
36
+ reads a DDI XML file into the same graph IR as ddigraph's own lxml engine: the
37
+ same chunks, in the same order, with the same parse report. ddigraph depends
38
+ on it at its own version and, by default (`engine="auto"`), reads a file with
39
+ it where it is installed and the file fits the memory limit.
40
+
41
+ ## Install
42
+
43
+ `pip install ddigraph` installs it. pip takes a wheel where one fits: Linux
44
+ (x86_64, aarch64), macOS (x86_64, arm64) or Windows (x64), an abi3 wheel for
45
+ Python 3.12 to 3.14, and an abi3t wheel (PEP 803) for Python 3.15 and later,
46
+ with or without the GIL. Elsewhere it takes a pure-Python stand-in of the same
47
+ name and version (`fallback/`), whose import raises `ModuleNotFoundError`, and
48
+ ddigraph reads every file with lxml. So installing ddigraph never compiles
49
+ Rust.
50
+
51
+ The engine runs without the GIL, but ddigraph itself cannot be installed on a
52
+ free-threaded Python yet (orjson does not build there), and lxml 6.1 turns the
53
+ GIL back on when it is imported.
54
+
55
+ To build it from a ddigraph checkout, which needs a Rust toolchain:
56
+
57
+ ```bash
58
+ pip install --force-reinstall ./rust
59
+ ```
60
+
61
+ In a checkout, `uv sync` installs the stand-in (`[tool.uv.sources]`); build the
62
+ engine over it with `uv pip install --reinstall-package ddigraph-core ./rust`
63
+ and run with `uv run --no-sync`.
64
+
65
+ ## Use
66
+
67
+ ```bash
68
+ ddigraph load survey.xml --engine rust
69
+ DDIGRAPH_ENGINE=lxml ddigraph export survey.xml -o survey.ttl
70
+ ```
71
+
72
+ ```python
73
+ from ddigraph import ir
74
+
75
+ chunks = ir.parse("survey.xml", engine="rust")
76
+ ```
77
+
78
+ It reads every flavor ddigraph reads: DDI Codebook 2.x (`codebook`), DDI-CDI
79
+ 1.0 (`cdi`), the experimental DDI-CDI 1.1 (`cdi11`), DDI-Lifecycle 3.1 to 3.3
80
+ FragmentInstance files (`lifecycle`) and the experimental DDI-Lifecycle 4.0
81
+ (`lifecycle4`). `ddigraph_core.UnsupportedFlavorError`, a `ValueError`, means
82
+ a flavor name it does not know; `ddigraph.ir.parse` refuses such a name first.
83
+
84
+ It differs from the lxml engine in three main ways, and in the rare cases
85
+ below:
86
+
87
+ - It reads well-formed XML only. Where lxml would recover from a syntax error,
88
+ it raises a `ValueError`. So it also refuses what lxml reads past unless
89
+ it parses strictly: a colon in the target of a processing instruction or in
90
+ an entity's name, a namespace name that is no URI, and an entity whose text
91
+ is not well-formed where it is used (a character reference to no
92
+ character, a stray `&`, or `]]>` in element content).
93
+ - It holds the whole parse in memory: it accepts `memory_limit`
94
+ (`DDIGRAPH_MEMORY_LIMIT_MB`) and does not apply it.
95
+ - It decodes UTF-8, UTF-16, US-ASCII, ISO-8859-1 to ISO-8859-16, windows-874,
96
+ windows-1250 to windows-1254, windows-1256, windows-1257, KOI8-R and IBM866
97
+ only, by the names libxml2 knows them by (`latin2`, `IBM819`, ...). A file in
98
+ another encoding, UTF-32 too, raises a `ValueError` (`Unsupported encoding`).
99
+
100
+ It keeps lxml's safety limits: no DTD fetch, no external entity, no entity
101
+ declaration with markup, the text, depth and name limits that `huge_tree`
102
+ lifts, entity bombs, and the 10 MB limit of libxml2's input buffer, for any
103
+ piece of markup, as lxml feeds it a file 32 KB at a time. Where a limit comes
104
+ soon after another error, it raises the one the lxml engine raises by default:
105
+ lxml searches the 32 KB it has read for a limit at the root of a DDI-L file and
106
+ at every 1,000th element event. With strict parsing (`recover=False`) lxml
107
+ skips the search at the root, so it may raise the other error first.
108
+
109
+ libxml2 checks its buffer at the end of each 32 KB read, once it has parsed the
110
+ whole read, so the engine reads that read's elements first: an error in one of
111
+ them comes before the buffer's limit. libxml2 logs some limits and reads on: a
112
+ name over 50,000 bytes in an attribute, an entity reference or a processing
113
+ instruction, a CDATA section over 10 MB, an entity's text or an attribute's
114
+ default over 10 MB, and entities nested too deep in an attribute value. The
115
+ engine raises the first of them where lxml does: at its next search, at the end
116
+ of the file, or in place of a later limit. An attribute value over 10 MB that
117
+ libxml2 keeps as it is, lxml refuses at its element's first event, and so does
118
+ the engine, with the line lxml gives.
119
+
120
+ Line numbers past 65,535 are lxml's too: the engine hands text over in parts at
121
+ the end of each 32 KB read, as libxml2 does. These rare cases differ:
122
+
123
+ - the line in the error for an empty top-level element (a `TopLevelReference`
124
+ or a 4.0 item);
125
+ - the line of an item that holds a nested `Fragment` and no text before its
126
+ first child, which lxml may take from a node after the `Fragment`;
127
+ - past line 65,535, the line in the error for an attribute value over 10 MB,
128
+ where lxml takes it from a sibling the frontend's tree never holds: an empty
129
+ top-level DDI-L element, an empty DDI-CDI object, a DDI-CDI container
130
+ (`Wrapper`, `DDICDIModels`), or a DDI-L root that starts past that line;
131
+ - an attribute name over 50,000 bytes: libxml2 drops the attribute and mends
132
+ the start tag, which may change what follows;
133
+ - a comment over 10 MB in element content: lxml may read its end as text, and
134
+ name the limit of a text;
135
+ - a processing instruction of nearly 10 MB or more at the very start of the
136
+ file: libxml2 may give it up just short of its buffer's limit, and lxml then
137
+ reads the file as empty;
138
+ - a namespace declaration that the DTD types other than CDATA, with spaces in
139
+ the text of an entity it refers to: libxml2 collapses them, the engine does
140
+ not;
141
+ - a limit met in the text of an entity that element text refers to (an entity
142
+ bomb, entities nested too deep, an entity that refers to itself): lxml gives
143
+ a line in the entity's text, the engine the line of the reference;
144
+ - a well-formed file in which libxml2 logs 100 errors and reads on, such as an
145
+ `xml:id` used twice: lxml stops with an `XMLLimitError`, the engine reads it.
146
+
147
+ `python -m ddigraph.conform run --corpus DIR --engine rust` compares what the
148
+ two engines give for each file. See
149
+ [The Rust engine](https://pbisson44.github.io/ddigraph/advanced/rust-engine/).
150
+
151
+ ## Layout
152
+
153
+ - `crates/ddigraph-core`: the engine, a Rust library.
154
+ - `crates/ddigraph-core-py`: its Python module, `ddigraph_core` (PyO3). A
155
+ default build gives an abi3 wheel for Python 3.12 and later.
156
+ `maturin build --features abi3t`, with Python 3.15 or later, free-threaded
157
+ or not, gives an abi3t wheel (PEP 803) for Python 3.15 and later.
158
+ - `crates/ddigraph-sandbox`: the engine as a WebAssembly guest
159
+ (`wasm32-wasip1`), which `ddigraph.sandbox` runs. Build it with
160
+ `cargo build --release --target wasm32-wasip1 -p ddigraph-sandbox`.
161
+ - `fuzz`: the cargo-fuzz targets, a workspace of their own (see Fuzzing).
162
+
163
+ Check it from this folder:
164
+
165
+ ```bash
166
+ cargo fmt --all --check
167
+ cargo clippy --all-targets -- -D warnings
168
+ cargo test
169
+ ```
170
+
171
+ ## Fuzzing
172
+
173
+ `fuzz/` holds cargo-fuzz targets for the engine. It is a cargo workspace of
174
+ its own: the engine's workspace excludes it, and CI never builds it. It needs
175
+ the nightly toolchain and cargo-fuzz. Each target reads the fuzzer's bytes as
176
+ a DDI file, under each resolve mode, at one node per chunk, with the default
177
+ safety limits:
178
+
179
+ - `cdi`: as DDI-CDI 1.0 and 1.1 (`cdi`, `cdi11`);
180
+ - `lifecycle`: as DDI-Lifecycle 3 and 4.0 (`lifecycle`, `lifecycle4`);
181
+ - `every_flavor`: as each of the five flavors.
182
+
183
+ A result or an error is fine. A panic, a hang or a run out of memory is a
184
+ bug. Run a target for ten minutes, from this folder:
185
+
186
+ ```bash
187
+ rustup toolchain install nightly
188
+ cargo install cargo-fuzz
189
+ mkdir -p fuzz/corpus/cdi fuzz/seeds
190
+ find ../tests/fixtures -name '*.xml' -exec cp {} fuzz/seeds/ \;
191
+ cargo +nightly fuzz run cdi fuzz/corpus/cdi fuzz/seeds -- -dict=fuzz/xml.dict -max_total_time=600 -timeout=10
192
+ ```
193
+
194
+ The fuzzer saves an input that fails under `fuzz/artifacts/cdi/`. Replay it,
195
+ then shrink it to a smaller input that fails the same way:
196
+
197
+ ```bash
198
+ cargo +nightly fuzz run cdi fuzz/artifacts/cdi/crash-...
199
+ cargo +nightly fuzz tmin cdi fuzz/artifacts/cdi/crash-...
200
+ ```
201
+