Skip to content

Segfault when adding destructor to class #20

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
usamec opened this issue Sep 23, 2017 · 1 comment · Fixed by #22
Closed

Segfault when adding destructor to class #20

usamec opened this issue Sep 23, 2017 · 1 comment · Fixed by #22

Comments

@usamec
Copy link

usamec commented Sep 23, 2017

This code

#[macro_use]
extern crate cpp;

cpp!{{
  #include <cstdio>
  #include <memory>

  using namespace std;

  class A {
   public:
    int x, y;
    A(): x(42), y(47) {}
    ~A() {
    }
  };
}}

#[repr(C)]
#[derive(Debug)]
pub struct A {
    pub _bindgen_opaque_blob: [u32; 2usize],
}

fn main() {
  loop {
    let x = unsafe {
      cpp!([] -> A as "A"  {
        return A();
      })
    };

    unsafe {
      cpp!([x as "A"] {
        printf("%d\n", x.x);
        printf("%d\n", x.y);
      })
    };
  }
}

Produces seqfault. However when destructor is not present code runs correctly without segfault.

@mystor
Copy link
Owner

mystor commented Sep 23, 2017

I think this is the same issue as #18

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

Successfully merging a pull request may close this issue.

2 participants