cbindgen
cbindgen copied to clipboard
[bug] cbindgen treats structs with array types in which there is `as` opaque
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"
We'd need to test the constant code about basic casts.
Correction is in this pull request