Skip to content

Duplicate definitions for Write1 #2202

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

Closed
Bqleine opened this issue May 11, 2022 · 3 comments · Fixed by #2341
Closed

Duplicate definitions for Write1 #2202

Bqleine opened this issue May 11, 2022 · 3 comments · Fixed by #2341

Comments

@Bqleine
Copy link

Bqleine commented May 11, 2022

Input C/C++ Header

I don't quite understand the header I'm using so I'm not able to make a simple example but I'm using RakNet https://github.com/facebookarchive/RakNet.
The header with these functions is BitStream.h

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .header("wrapper.hpp")
        .enable_cxx_namespaces()
        .layout_tests(false)

        .allowlist_type("Rak.*")
        .allowlist_type("DefaultMessageIDTypes")

        .generate()
        .expect("Unable to generate bindings");

Actual Results

error[E0201]: duplicate definitions with name `Write1`:
    --> /home/bloup/Code/raknet/target/debug/build/raknet-d5cd88364ce5f684/out/bindings.rs:3003:13
     |
2811 | /             pub unsafe fn Write1(
2812 | |                 &mut self,
2813 | |                 bitStream: *mut root::RakNet::BitStream,
2814 | |                 numberOfBits: root::RakNet::BitSize_t,
2815 | |             ) {
2816 | |                 BitStream_Write1(self, bitStream, numberOfBits)
2817 | |             }
     | |_____________- previous definition of `Write1` here
...
3003 | /             pub unsafe fn Write1(&mut self) {
3004 | |                 BitStream_Write11(self)
3005 | |             }
     | |_____________^ duplicate definition

Expected Results

I would expect the second Write1 to be Write11 and not cause issues.

@Bqleine
Copy link
Author

Bqleine commented May 11, 2022

Here are the full generated bindings: https://pastebin.com/9mWz1S4j

@Bqleine
Copy link
Author

Bqleine commented May 11, 2022

This seems to happen because there is a function named Write and a function named Write1 in the header, the Bitstream_Write1 gets correctly renamed to Bitstream_Write11 to avoid duplicate definitions but not its c++ namespace counterpart Bitstream.Write1 that stays this way.

The issue indeed doesn't happen without enable_cxx_namespaces()

@Bqleine Bqleine closed this as completed May 11, 2022
@Bqleine Bqleine reopened this May 11, 2022
@emilio
Copy link
Contributor

emilio commented Jun 5, 2022

A reduced test-case would be:

class BitStream {
 public:
  void Write(const char *inputByteArray, unsigned int numberOfBytes);
  void Write(BitStream *bitStream, unsigned numberOfBits);
  void Write1();
};

This happens with or without the enable_cxx_namespaces, fwiw.

It should probably be fixed here:

let count = method_names.entry(name.clone()).or_insert(0);

That code doesn't deal with the method name with multiple uses colliding with the existing one.

pvdrz added a commit to ferrous-systems/rust-bindgen that referenced this issue Nov 9, 2022
Even though this change does name deduplication in a slower way, it
avoids name collisions without any breaking changes in the test suite.

Fixes rust-lang#2202
pvdrz added a commit that referenced this issue Nov 11, 2022
Even though this change does name deduplication in a slower way, it
avoids name collisions without any breaking changes in the test suite.

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

Successfully merging a pull request may close this issue.

2 participants