rust-lang / rust-lang/rust-bindgen

Properly implement extensions

Open
#2,288 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Input C/C++ Header
class Gyro {
 public:
  virtual void Calibrate() = 0;
};

class SomeGyro : public Gyro {
 public:
  void Calibrate() final;
};
Bindgen Invocation
$ bindgen test.hpp
Actual Results
/* automatically generated by rust-bindgen 0.59.2 */

#[repr(C)]
pub struct Gyro__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Gyro {
    pub vtable_: *const Gyro__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_Gyro() {
    assert_eq!(
        ::std::mem::size_of::<Gyro>(),
        8usize,
        concat!("Size of: ", stringify!(Gyro))
    );
    assert_eq!(
        ::std::mem::align_of::<Gyro>(),
        8usize,
        concat!("Alignment of ", stringify!(Gyro))
    );
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct SomeGyro {
    pub _base: Gyro,
}
#[test]
fn bindgen_test_layout_SomeGyro() {
    assert_eq!(
        ::std::mem::size_of::<SomeGyro>(),
        8usize,
        concat!("Size of: ", stringify!(SomeGyro))
    );
    assert_eq!(
        ::std::mem::align_of::<SomeGyro>(),
        8usize,
        concat!("Alignment of ", stringify!(SomeGyro))
    );
}
extern "C" {
    #[link_name = "\u{1}_ZN8SomeGyro9CalibrateEv"]
    pub fn SomeGyro_Calibrate(this: *mut ::std::os::raw::c_void);
}
Expected Results

An implementation of SomeGyro::Calibrate, instead of SomeGyro_Calibrate. Frankly, I'm not sure how I would get my hands on a *mut os::raw::c_void that points to a SomeGyro on the Rust side.

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

Reproduce the issue with the supplied C++ header in test.hpp and the bindgen test.hpp command, then trace how the generated Rust bindings represent SomeGyro::Calibrate. Compare the generated free function with the requested implementation behavior; done means the bindings expose the expected implementation rather than requiring an opaque *mut c_void.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
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.