-
Notifications
You must be signed in to change notification settings - Fork 744
Added codegen for destructors #542
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! I think it requires a bit more work though, since I don't think in this state it compiles.
Also, this needs a test in bindgen-integration
, you can do something like:
// Test.h
// inside class Test {...
static bool sDestructorCalled;
~Test();
// lib.rs
impl Drop for Test {
fn drop(&mut self) {
self.destruct()
}
}
{
let test = Test::new();
}
assert!(Test_sDestructorCalled);
Or something like that.
@@ -52,3 +52,13 @@ fn bindgen_test_layout_UnionWithDtor() { | |||
"Alignment of field: " , stringify ! ( UnionWithDtor ) , "::" | |||
, stringify ! ( mBar ) )); | |||
} | |||
extern "C" { | |||
#[link_name = "_ZN13UnionWithDtorD1Ev"] | |||
pub fn UnionWithDtor_~UnionWithDtor(this: *mut UnionWithDtor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can possibly compile? We need to mangle this name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't that a valid identifier? I think Rust accepts all valid Unicode strings....
Edit: hmm...seems not, just tried using the identifier on playground.
@cynicaldevil how's this going? Anything we can do to help get this across the finish line? Questions we can answer? |
@fitzgen I have my midterms right now, but finally got a break in between, so I can work on this now. Any suggestions on what the mangled name of the destructor should be? |
|
e73dda4
to
29f199c
Compare
So I'm trying to name the function as |
@cynicaldevil is the The I would have expected |
It isn't because the name of the destructor starts with |
How can we strip away the |
Presumably in the I suggest just getting it working and then we can look at the code in review and decide if we think there is a better way or not. |
@fitzgen After adding countless |
@cynicaldevil It looks like this is failing a few tests with libclang 3.8 on Travis CI: extern "C" {
- #[link_name = "_ZN7nsSlotsD1Ev"]
+ #[link_name = "_ZN7nsSlotsD0Ev"]
pub fn nsSlots_nsSlots_destructor(this: *mut nsSlots);
} Do these test expectations just need to be updated or do we need to ignore these tests with libclang <= 3.8? If the latter, you can add |
I don't know why this is happening, all my expectations are already up-to-date, and I am using clang 3.9. |
Bump. I'm waiting for this feature :) |
Ok, I just looked into why tests are failing. That test has a virtual destructor, that we should avoid generating. So I'm going to pull this and land it with that fix. |
(I mean, it's not technically wrong to generate it, but I'd rather just do the proper thing for virtual methods instead) |
Superseded by #608, thanks for this work @cynicaldevil! :) |
Fixes #529
cc @emilio