cbindgen
cbindgen copied to clipboard
VecDeque has 1 params but is being instantiated with 2 values
We use a custom (private) crate with collections, that accepts as a second generic parameter additional type. After adding a private alias (e.g. type MyVec = Vec<X, Y>;) the cbindgen (both 0.19 and master) panics with the following trace (git master):
thread 'main' panicked at 'VecDeque has 1 params but is being instantiated with 2 values', src/bindgen/ir/opaque.rs:114:9
stack backtrace:
0: rust_begin_unwind
at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:493:5
1: std::panicking::begin_panic_fmt
at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:435:5
2: <cbindgen::bindgen::ir::opaque::OpaqueItem as cbindgen::bindgen::ir::item::Item>::instantiate_monomorph
at cbindgen/src/bindgen/ir/opaque.rs:114:9
3: cbindgen::bindgen::ir::ty::Type::add_monomorphs
at cbindgen/src/bindgen/ir/ty.rs:814:25
4: cbindgen::bindgen::ir::typedef::Typedef::add_monomorphs
at cbindgen/src/bindgen/ir/typedef.rs:103:9
5: cbindgen::bindgen::library::Library::instantiate_monomorphs::{{closure}}
at cbindgen/src/bindgen/library.rs:393:13
6: cbindgen::bindgen::ir::item::ItemMap<T>::for_all_items
at cbindgen/src/bindgen/ir/item.rs:190:48
7: cbindgen::bindgen::library::Library::instantiate_monomorphs
at cbindgen/src/bindgen/library.rs:392:9
8: cbindgen::bindgen::library::Library::generate
at cbindgen/src/bindgen/library.rs:66:13
9: cbindgen::bindgen::builder::Builder::generate
at cbindgen/src/bindgen/builder.rs:370:9
10: cbindgen::load_bindings
at cbindgen/src/main.rs:126:5
11: cbindgen::main
at cbindgen/src/main.rs:291:26
12: core::ops::function::FnOnce::call_once
at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/ops/function.rs:227:5
Unfortunately I cannot reproduce it yet with a minimal example and the code that leads to cbindgen panic is private (and huge). Perhaps there are some similar issues? I'll try to come up with a working example ASAP.
language = "C", if that's matter.
It seems that VecDeque is hardcoded, MRE:
pub struct VecDeque<T, Y> {
pub _x: (T, Y),
}
pub type MyType = VecDeque<i32, usize>;
As a temporary workaround, renaming my collection works (i.e. use Vec as MyVecT; type MyVec = MyVecT<X, Y>;). Also it would be handy to configure skiping std types generation like this:
Patch for configure std_types
diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs
index 76a142c..f7b8787 100644
--- a/src/bindgen/builder.rs
+++ b/src/bindgen/builder.rs
@@ -283,6 +283,7 @@ impl Builder {
#[allow(unused)]
pub fn with_config(mut self, config: Config) -> Builder {
+ self.std_types = config.std_types;
self.config = config;
self
}
diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs
index 62fd7d6..4d9e719 100644
--- a/src/bindgen/config.rs
+++ b/src/bindgen/config.rs
@@ -875,6 +875,8 @@ pub struct Config {
pub include_guard: Option<String>,
/// Add a `#pragma once` guard
pub pragma_once: bool,
+ /// Generate types for std
+ pub std_types: bool,
/// Generates no includes at all. Overrides all other include options
///
/// This option is useful when using cbindgen with tools such as python's cffi which
@@ -987,6 +989,7 @@ impl Default for Config {
trailer: None,
include_guard: None,
pragma_once: false,
+ std_types: false,
autogen_warning: None,
include_version: false,
no_includes: false,