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

[bug] cbindgen treats structs with array types in which there is as opaque #1031

Open
NilsIrl opened this issue Nov 17, 2024 · 0 comments
Open

Comments

@NilsIrl
Copy link

NilsIrl commented Nov 17, 2024

With the following input:

pub const SIZE: usize = 4;

#[repr(C)]
pub struct WithoutAs {
    items: [char; SIZE],
}

#[repr(C)]
pub struct WithAs {
    items: [char; SIZE as usize],
}

// dummy function to make `WithoutAs` and `WithAs` part of the public api
#[no_mangle]
pub extern fn some_fn(a: WithoutAs, b: WithAs) {}

cbindgen outputs

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

constexpr static const uintptr_t SIZE = 4;

struct WithAs;

struct WithoutAs {
  uint32_t items[SIZE];
};

extern "C" {

void some_fn(WithoutAs a, WithAs b);

} // extern "C"

But I would expect it to give or at least warn the user instead of just making the type opaque without any information as to why or even letter the user know the type is treated as opaque.

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

constexpr static const uintptr_t SIZE = 4;

struct WithAs {
  uint32_t items[(size_T) SIZE];
};

struct WithoutAs {
  uint32_t items[SIZE];
};

extern "C" {

void some_fn(WithoutAs a, WithAs b);

} // extern "C"
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