Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding not added if we use a typedef to a wrongly-sized replacement type #3158

Open
adetaylor opened this issue Feb 26, 2025 · 0 comments
Open

Comments

@adetaylor
Copy link
Contributor

Reproduction:

/**
* <div rustbindgen="true" replaces="std::string">
*/
class CxxString {
    char* ptr;
};
#include <string>
#include <cstdint>
typedef std::string my_string;
struct A {
   my_string a;
};
struct B {
   std::string a;
};

Command:

cargo run -- test.hpp --no-layout-tests --allowlist-type A --allowlist-type B --enable-cxx-namespaces

Bindgen version 20aa65a (today's main).

Rust generated:

/* automatically generated by rust-bindgen 0.71.1 */

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    pub mod std {
        #[allow(unused_imports)]
        use self::super::super::root;
        #[doc = " <div rustbindgen=\"true\" replaces=\"std::string\">"]
        #[repr(C)]
        #[derive(Debug, Copy, Clone)]
        pub struct string {
            pub ptr: *mut ::std::os::raw::c_char,
        }
    }
    pub type my_string = root::std::string;
    #[repr(C)]
    #[derive(Debug, Copy, Clone)]
    pub struct A {
        pub a: root::my_string,
    }
    #[repr(C)]
    #[derive(Debug, Copy, Clone)]
    pub struct B {
        pub a: root::std::string,
        pub __bindgen_padding_0: [u64; 2usize],
    }
}

Note that struct B contains padding, but struct A doesn't. This means the size of struct A is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant