Commit 9085327
committed
fix(generator): handle char vs uint8_t type distinction in CGO bindings
libclang on NixOS cannot locate stdint.h/inttypes.h, causing it to
resolve uint8_t typedefs to their canonical type "int". This creates
ambiguity when both 'char' and 'uint8_t' resolve to the same type,
resulting in incorrect CGO type casts.
Changes:
- Add CTypeName field to Field struct to preserve original C type
spelling before libclang canonicalization
- Capture original type name in parser before parseType() call
- Implement fieldCTypeOverrides map for known libclang misreports
(AVPixFmtDescriptor fields: nb_components, log2_chroma_w,
log2_chroma_h, flags)
- Enhance getCType() with special handling for 'char' type to prevent
incorrect uint8_t casting
- Add three-tier fallback for struct setter type resolution:
1. Use captured CTypeName if specific
2. Check fieldCTypeOverrides for known failures
3. Fall back to getCType() mapping
- Attempt to preserve typedef spellings in type parser for _t suffixed
types when libclang reports them correctly
This fixes compilation errors like:
cannot use _Ctype_uint8_t(separator) as _Ctype_char value
Successfully resolves:
- av_match_list() char separator parameter (char → C.char)
- AVPixFmtDescriptor uint8_t fields (uint8_t → C.uint8_t)
- AVPixFmtDescriptor uint64_t flags (uint64_t → C.uint64_t)
Tested: Full build passes with pixdesc.h enabled, all tests pass1 parent f3842e4 commit 9085327
9 files changed
Lines changed: 828 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
2325 | 2326 | | |
2326 | 2327 | | |
2327 | 2328 | | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
2328 | 2383 | | |
2329 | 2384 | | |
2330 | 2385 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
0 commit comments