rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Duplicate definitions for Write1

Open Bqleine opened this issue 3 years ago • 3 comments

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 avatar May 11 '22 16:05 Bqleine

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

Bqleine avatar May 11 '22 16:05 Bqleine

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 avatar May 11 '22 18:05 Bqleine

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:

https://github.com/rust-lang/rust-bindgen/blob/4d18f7606a2bc8a18b181b3e9639c9464a9dc896/src/codegen/mod.rs#L2446

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

emilio avatar Jun 05 '22 16:06 emilio