Skip to content

std::vector<int>::iterator creates trouble #1839

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

Open
Volker-Weissmann opened this issue Jul 26, 2020 · 7 comments
Open

std::vector<int>::iterator creates trouble #1839

Volker-Weissmann opened this issue Jul 26, 2020 · 7 comments

Comments

@Volker-Weissmann
Copy link
Contributor

Input C/C++ Header

#include <vector>
namespace MySpace {
	std::vector<int>::iterator x;
}

Bindgen Invocation

bindgen::Builder::default()
        .header("wrapper.hpp")
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .clang_arg("-x")
        .clang_arg("c++")
        .opaque_type("std::.*")
        .whitelist_var("MySpace::.*")
        .whitelist_type("MySpace::.*")
        .whitelist_function("MySpace::.*")
        .generate()
        .expect("Unable to generate bindings");

Actual Results

... 89 lines of code ...
pub type pointer = pointer;
pub type pointer = pointer;
pub type pointer = pointer;
pub type pointer = *mut ::std::os::raw::c_int;

If you try to compile this, you get:

error[E0428]: the name `pointer` is defined multiple times
  --> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:91:1
   |
90 | pub type pointer = pointer;
   | --------------------------- previous definition of the type `pointer` here
91 | pub type pointer = pointer;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pointer` redefined here
   |
   = note: `pointer` must be defined only once in the type namespace of this module

error[E0428]: the name `pointer` is defined multiple times
  --> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:92:1
   |
90 | pub type pointer = pointer;
   | --------------------------- previous definition of the type `pointer` here
91 | pub type pointer = pointer;
92 | pub type pointer = pointer;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pointer` redefined here
   |
   = note: `pointer` must be defined only once in the type namespace of this module

error[E0428]: the name `pointer` is defined multiple times
  --> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:93:1
   |
90 | pub type pointer = pointer;
   | --------------------------- previous definition of the type `pointer` here
...
93 | pub type pointer = *mut ::std::os::raw::c_int;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pointer` redefined here
   |
   = note: `pointer` must be defined only once in the type namespace of this module

error[E0391]: cycle detected when processing `pointer`
  --> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:90:20
   |
90 | pub type pointer = pointer;
   |                    ^^^^^^^
   |
   = note: ...which again requires processing `pointer`, completing the cycle
note: cycle used when processing `MySpace_x`
  --> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:88:59
   |
88 |     pub static mut MySpace_x: __gnu_cxx___normal_iterator<pointer>;
   |                                                           ^^^^^^^

Expected Results

No compile errors?

@kulp
Copy link
Member

kulp commented Jul 27, 2020

This might be, sadly, just a case of the STL not being supported very well by bindgen. See #1808 (comment) and #1597 (comment).

@emilio
Copy link
Contributor

emilio commented Jul 27, 2020

Yeah, these are not necessarily unfixable though :)

I think we should not generate a bunch of these constants #1838. Same goes for the typedefs.

I haven't been catching up lately with all the rust improvements, but chances are that a few of those can be "properly" supported with stuff inside generic impl blocks like:

impl<T> Generic<T> {
   pub type Bar = Foo<T>;
}

Or such.

@emilio
Copy link
Contributor

emilio commented Jul 27, 2020

I appreciate a lot all the reduced test-cases @Volker-Weissmann, thank you!

@Volker-Weissmann
Copy link
Contributor Author

What I did for my code is write a script that removes all pub type pointer = pointer;. It is a super hacky solution, but it worked so far.

@wangbj
Copy link

wangbj commented Mar 3, 2022

@Volker-Weissmann Does adding pointer to block list solve this issue?

@Volker-Weissmann
Copy link
Contributor Author

Idk, I don't work on this project anymore.

@wangbj
Copy link

wangbj commented Mar 3, 2022

No worries, I had a similar issue because bindgen generates duplicate types (from typedef), basically two pub type iterator consecutively:

pub type iterator = root::std::_Bit_iterator;

I added iterator to blocklist the issue went away.

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

No branches or pull requests

4 participants