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
//! Raw FFI bindings to the LibreDWG C sources (a vendored subset of the
//! real upstream project at `lib/libredwg`, GPLv3+, carrying five local
//! patches marked `uncad local patch`; see `NOTICE.md` in this crate and
//! docs/THIRD_PARTY_NOTICES.md).
//! Generated by `build.rs` via `bindgen` against the public
//! `dwg.h`/`dwg_api.h` headers plus this crate's own `uncad_*` C shims
//! (see `shim/uncad_shim.h`).
//!
//! This crate is intentionally low-level and `unsafe`-heavy -- it exists to
//! be wrapped by the `uncad` crate, not used directly.
//!
//! # Not thread-safe -- callers must serialize every call themselves
//!
//! The underlying LibreDWG C library has non-reentrant global state (e.g.
//! the `loglevel` global read/written throughout `decode.c`/`bits.c`, and
//! likely more that hasn't been individually catalogued). Calling into any
//! function in this crate concurrently from multiple threads -- even two
//! calls that never touch the same `Dwg_Data`/`Dwg_Object` -- has
//! reproducibly caused `STATUS_HEAP_CORRUPTION` once both threads' work
//! overlapped enough for the shared C-side state to race. **This crate does
//! nothing to prevent that**; every FFI entry point here is exactly as
//! unsynchronized as the C library it binds.
//!
//! The `uncad` crate's own public API (`uncad::parse()` and friends) is
//! safe to call from multiple threads because it serializes every call
//! through a single process-wide `Mutex` before reaching this crate --
//! see `uncad`'s top-level doc comment / `docs/ARCHITECTURE.md`'s "Thread
//! safety" section. Any other consumer of `libredwg-sys` directly must
//! implement that same serialization itself (a single global lock around
//! every call into this crate, held for the call's entire duration) or
//! risk memory corruption under concurrent use.
// bindgen emits `mem::transmute(x)` for every bitfield accessor regardless
// of whether the source and target types happen to coincide (they do for
// every current `BITCODE_B`/`_BS`-backed bitfield in dwg.h) -- harmless,
// and not something editing generated code (re-generated fresh on every
// build) could fix. See docs/CAVEATS.md's "Clippy" note.
// Same rationale, for bindgen's generated `BindgenUninitializedField` helper
// (`as_slice`/`as_mut_slice`/`as_ref`/`as_mut`) -- its `unsafe fn`s have no
// `# Safety` doc section because bindgen doesn't emit one, not because this
// crate's own unsafe code is undocumented (see `dynapi.rs` in `uncad` for
// this project's own actual safety-doc convention).
// Same rationale again: bindgen's generated helper methods call other
// unsafe functions (`slice::from_raw_parts`, `mem::transmute`) without
// wrapping each one in its own `unsafe { }` block, relying on the whole
// `unsafe fn` body being implicitly unsafe (2021 edition default) --
// harmless and, again, not this crate's own code to restyle.
// bindgen 0.72 changed the bitfield accessors it emits to compute a byte
// offset as `usize` and then cast it to `isize` for `.offset()`. clippy asks
// for `.add()` instead, which is the right advice for hand-written code and
// unactionable here: these bodies are regenerated from dwg.h on every build.
// Same rationale as the three allows above.
// bindgen 0.73 emits `(bits + 7) / 8` in the same bitfield accessors, which
// clippy asks to write as `.div_ceil(8)`. Right for hand-written code, and
// unactionable here for the same reason as the allows above: this file is
// regenerated from dwg.h on every build.
include!;
// --- Hand-written struct mirrors ---------------------------------------
//
// bindgen cannot generate real field access for the types below, and this
// crate needs it (see build.rs's blocklist_type calls for the failure mode).
// Each one mirrors dwg.h's field order and types exactly; #[repr(C)] then
// reproduces C's alignment and padding rules, and the compile-time size
// assertions at the end of this section check the result against clang's own
// sizeof() -- a safety net against a transcription mistake here.
/// `_dwg_HATCH_ControlPoint` (dwg.h) -- a SPLINE-type boundary edge's
/// control point.
/// `_dwg_HATCH_PathSeg` (dwg.h) -- one edge of a non-polyline HATCH boundary
/// path. Not a real C union despite dwg.h's "could be a union" comment: every
/// field is present regardless of `curve_type`, and only the ones relevant to
/// that curve type are meaningfully populated.
/// `_dwg_HATCH_Path` (dwg.h) -- one HATCH boundary path, either a
/// polyline (`polyline_paths`, when `flag & 0x02`) or a list of curved/
/// straight edges (`segs`).
// _dwg_HATCH_PolylinePath is still bindgen-generated and refers to the raw tag
// name in its `parent` field, so the alias has to exist even though nothing
// else here uses it.
pub type _dwg_HATCH_Path = Dwg_HATCH_Path;
/// `_dwg_HATCH_DefLine` (dwg.h) -- one pattern-fill "definition line": a family
/// of parallel lines (`angle`/`pt0`/`offset`) plus an optional dash pattern
/// (`dashes`: positive = dash length, negative = gap, empty = continuous). One
/// of `Dwg_Entity_HATCH.deflines`.
///
/// `pt0`/`offset` are declared `BITCODE_2BD` in dwg.h but typed `BITCODE_2RD`
/// here: both are two `double`s with no padding, and `BITCODE_2RD` is already
/// bound elsewhere in this crate, so reusing it avoids pulling in a type
/// bindgen would otherwise never generate.
pub type _dwg_HATCH_DefLine = Dwg_HATCH_DefLine;
/// `_dwg_HATCH_Color` (dwg.h) -- one gradient-fill color stop: `shift_value`
/// (0.0-1.0, its position along the gradient) plus a plain `Dwg_Color`. One of
/// `Dwg_Entity_HATCH.colors`.
pub type _dwg_HATCH_Color = Dwg_HATCH_Color;
/// `_dwg_MLINE_vertex` (dwg.h). Its `vertex`/`vertex_direction`/
/// `miter_direction` fields are declared `BITCODE_3BD`, which bindgen never
/// generates on its own; `dwg_point_3d` stands in, being the same three
/// `double`s with no padding. `lines` (the per-vertex parallel-line array) is
/// left as an untyped `*mut c_void` because nothing dereferences it, which
/// saves hand-writing `Dwg_MLINE_line` as well.
/// `_dwg_MLINESTYLE_line` (dwg.h) -- one parallel-line definition in an
/// MLINESTYLE object: `offset` (distance from the MLINE centerline, combined
/// with each vertex's `miter_direction` to get that line's actual point) plus
/// `color`/`lt_index`/`lt_ltype`, none of which this workspace renders.
/// `lt_ltype` is typed properly rather than left opaque, `Dwg_Object_Ref`
/// already being a bound type here.
pub type _dwg_MLINESTYLE_line = Dwg_MLINESTYLE_line;
const _: = ;