rust-lang / rust-lang/rust-bindgen

bindgen link wrong destructor in windows

Open
#2,092 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
class RustCThostFtdcMdSpi:CThostFtdcMdSpi
{
public:
	void *RustObject;
	RustCThostFtdcMdSpi(void *RustObject)
}
RustCThostFtdcMdSpi::RustCThostFtdcMdSpi(void *RustObject):RustObject(RustObject){}
RustCThostFtdcMdSpi::~RustCThostFtdcMdSpi(){}

but the right address is 'RustCThostFtdcMdSpi@@QEAA@XZ'

Bindgen Invocation
  let bindings = bindgen::Builder::default()
      .header("src/wrapper.hpp")
      .derive_debug(true)
      .derive_default(true)
      .generate()
      .expect("Unable to generate  bindings");

the bindgen function is

extern "C" {
    #[link_name = "\u{1}??_DRustCThostFtdcMdSpi@@QEAAXXZ"]
    pub fn RustCThostFtdcMdSpi_RustCThostFtdcMdSpi_destructor(this: *mut RustCThostFtdcMdSpi);
}

but the right link address is RustCThostFtdcMdSpi@@QEAA@XZ

I guess there is something wrong

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the C++ declaration in src/wrapper.hpp and the bindgen::Builder invocation shown in the issue. Inspect the generated extern block and compare the destructor's Windows link_name with the expected symbol address. Done means bindgen emits the correct destructor symbol for this input without breaking related C++ destructor bindings.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.