rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.48k stars 700 forks source link

Types with flexible array member generic does not propagate to other types using the type #2939

Open i509VCB opened 2 months ago

i509VCB commented 2 months ago

If a type has a flexible array member, any other types which use the type with a flexible array member in their own type does not have the generic for the flexible array member propagated.

For example, scan_params has an FAM (with a regex pass to wrap the FAM in a ManuallyDrop (see https://github.com/rust-lang/rust-bindgen/issues/2936): https://github.com/i509VCB/nrf70/blob/issue/fam-bindgen/fw/bindings.rs#L3209-L3236

#[repr(C, packed)]
pub struct scan_params<FAM: ?Sized = [::core::ffi::c_uint; 0]> {
    #[doc = " If 0x1, RPU force passive scan on all channels"]
    pub passive_scan: ::core::ffi::c_ushort,
    #[doc = " Number of ssid's in scan_ssids parameter"]
    pub num_scan_ssids: ::core::ffi::c_uchar,
    #[doc = " Specific SSID's to scan for"]
    pub scan_ssids: [ssid; 2usize],
    #[doc = " used to send probe requests at non CCK rate in 2GHz band"]
    pub no_cck: ::core::ffi::c_uchar,
    #[doc = "  Bitmap of bands to be scanned. Value Zero will scan both 2.4 and 5 GHZ"]
    pub bands: ::core::ffi::c_uchar,
    #[doc = " Information element(s) data ie"]
    pub ie: ie,
    #[doc = " MAC address"]
    pub mac_addr: [::core::ffi::c_uchar; 6usize],
    #[doc = " Max scan duration in active scan. If zero rpu programs 50msec"]
    pub dwell_time_active: ::core::ffi::c_ushort,
    #[doc = " Max scan duration in passive scan. If zero rpu programs 150msec"]
    pub dwell_time_passive: ::core::ffi::c_ushort,
    #[doc = " Number of channels to be scanned"]
    pub num_scan_channels: ::core::ffi::c_ushort,
    #[doc = " If true, skip local and IANA Unicast reserved MACs"]
    pub skip_local_admin_macs: ::core::ffi::c_uchar,
    #[doc = " specific channels to be scanned"]
    pub center_frequency: ::core::mem::ManuallyDrop<FAM>,
}

But then scan_params when used in umac_scan_info, the FAM type is not expanded: https://github.com/i509VCB/nrf70/blob/issue/fam-bindgen/fw/bindings.rs#L3489-L3495

#[repr(C, packed)]
pub struct umac_scan_info {
    #[doc = " scan type see &enum scan_reason"]
    pub scan_reason: ::core::ffi::c_int,
    #[doc = " scan parameters scan_params"]
    pub scan_params: scan_params,
}

Since the FAM type is not propagated to umac_scan_info, it is not possible to use the FAM parameter

Bindgen invocation: https://github.com/i509VCB/nrf70/blob/issue/fam-bindgen/gen.py#L111-L124

emilio commented 2 months ago

cc @jsgf

jsgf commented 2 months ago

Yeah I guess the DSTness of types need to propagate up to their containing structures.