Skip to content

Commit 9085327

Browse files
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 pass
1 parent f3842e4 commit 9085327

9 files changed

Lines changed: 828 additions & 18 deletions

File tree

callbacks.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import "unsafe"
7979
// #include <libavutil/murmur3.h>
8080
// #include <libavutil/opt.h>
8181
// #include <libavutil/parseutils.h>
82+
// #include <libavutil/pixdesc.h>
8283
// #include <libavutil/pixelutils.h>
8384
// #include <libavutil/pixfmt.h>
8485
// #include <libavutil/random_seed.h>

constants.gen.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ package ffmpeg
7777
// #include <libavutil/murmur3.h>
7878
// #include <libavutil/opt.h>
7979
// #include <libavutil/parseutils.h>
80+
// #include <libavutil/pixdesc.h>
8081
// #include <libavutil/pixelutils.h>
8182
// #include <libavutil/pixfmt.h>
8283
// #include <libavutil/random_seed.h>
@@ -2325,6 +2326,60 @@ const AVOptSerializeSearchChildren = C.AV_OPT_SERIALIZE_SEARCH_CHILDREN
23252326
// AVOptFlagImplicitKey wraps AV_OPT_FLAG_IMPLICIT_KEY.
23262327
const AVOptFlagImplicitKey = C.AV_OPT_FLAG_IMPLICIT_KEY
23272328

2329+
// AVPixFmtFlagBe wraps AV_PIX_FMT_FLAG_BE.
2330+
const AVPixFmtFlagBe = C.AV_PIX_FMT_FLAG_BE
2331+
2332+
// AVPixFmtFlagPal wraps AV_PIX_FMT_FLAG_PAL.
2333+
const AVPixFmtFlagPal = C.AV_PIX_FMT_FLAG_PAL
2334+
2335+
// AVPixFmtFlagBitstream wraps AV_PIX_FMT_FLAG_BITSTREAM.
2336+
const AVPixFmtFlagBitstream = C.AV_PIX_FMT_FLAG_BITSTREAM
2337+
2338+
// AVPixFmtFlagHWAccel wraps AV_PIX_FMT_FLAG_HWACCEL.
2339+
const AVPixFmtFlagHWAccel = C.AV_PIX_FMT_FLAG_HWACCEL
2340+
2341+
// AVPixFmtFlagPlanar wraps AV_PIX_FMT_FLAG_PLANAR.
2342+
const AVPixFmtFlagPlanar = C.AV_PIX_FMT_FLAG_PLANAR
2343+
2344+
// AVPixFmtFlagRgb wraps AV_PIX_FMT_FLAG_RGB.
2345+
const AVPixFmtFlagRgb = C.AV_PIX_FMT_FLAG_RGB
2346+
2347+
// AVPixFmtFlagAlpha wraps AV_PIX_FMT_FLAG_ALPHA.
2348+
const AVPixFmtFlagAlpha = C.AV_PIX_FMT_FLAG_ALPHA
2349+
2350+
// AVPixFmtFlagBayer wraps AV_PIX_FMT_FLAG_BAYER.
2351+
const AVPixFmtFlagBayer = C.AV_PIX_FMT_FLAG_BAYER
2352+
2353+
// AVPixFmtFlagFloat wraps AV_PIX_FMT_FLAG_FLOAT.
2354+
const AVPixFmtFlagFloat = C.AV_PIX_FMT_FLAG_FLOAT
2355+
2356+
// AVPixFmtFlagXyz wraps AV_PIX_FMT_FLAG_XYZ.
2357+
const AVPixFmtFlagXyz = C.AV_PIX_FMT_FLAG_XYZ
2358+
2359+
// FFLossResolution wraps FF_LOSS_RESOLUTION.
2360+
const FFLossResolution = C.FF_LOSS_RESOLUTION
2361+
2362+
// FFLossDepth wraps FF_LOSS_DEPTH.
2363+
const FFLossDepth = C.FF_LOSS_DEPTH
2364+
2365+
// FFLossColorspace wraps FF_LOSS_COLORSPACE.
2366+
const FFLossColorspace = C.FF_LOSS_COLORSPACE
2367+
2368+
// FFLossAlpha wraps FF_LOSS_ALPHA.
2369+
const FFLossAlpha = C.FF_LOSS_ALPHA
2370+
2371+
// FFLossColorquant wraps FF_LOSS_COLORQUANT.
2372+
const FFLossColorquant = C.FF_LOSS_COLORQUANT
2373+
2374+
// FFLossChroma wraps FF_LOSS_CHROMA.
2375+
const FFLossChroma = C.FF_LOSS_CHROMA
2376+
2377+
// FFLossExcessResolution wraps FF_LOSS_EXCESS_RESOLUTION.
2378+
const FFLossExcessResolution = C.FF_LOSS_EXCESS_RESOLUTION
2379+
2380+
// FFLossExcessDepth wraps FF_LOSS_EXCESS_DEPTH.
2381+
const FFLossExcessDepth = C.FF_LOSS_EXCESS_DEPTH
2382+
23282383
// AVPaletteSize wraps AVPALETTE_SIZE.
23292384
const AVPaletteSize = C.AVPALETTE_SIZE
23302385

enums.gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import "unsafe"
7979
// #include <libavutil/murmur3.h>
8080
// #include <libavutil/opt.h>
8181
// #include <libavutil/parseutils.h>
82+
// #include <libavutil/pixdesc.h>
8283
// #include <libavutil/pixelutils.h>
8384
// #include <libavutil/pixfmt.h>
8485
// #include <libavutil/random_seed.h>

0 commit comments

Comments
 (0)