Skip to content
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

class on free aborts on invalid pointer #83

Open
andyjsbell opened this issue Jul 16, 2020 · 5 comments
Open

class on free aborts on invalid pointer #83

andyjsbell opened this issue Jul 16, 2020 · 5 comments

Comments

@andyjsbell
Copy link

Using the cpp_class! macro with a simple class aborts on freeing the resource. This is happening on Ubuntu 1804. Code snippet reproducing the issue:

use cpp::cpp;
use cpp::cpp_class;

cpp!{{
    #include <iostream>
    
    using std::string;

    class Test {
    public:
        Test() {
            std::cout << "creating" << std::endl;
        }
        virtual ~Test() {
            std::cout << "destroying" << std::endl;
        }

    protected:
        std::string message; // -> removing this and we don't get the issue
    };
}}

cpp_class!(pub unsafe struct Test as "Test");
impl Test {
    fn new() -> Self {
        unsafe { cpp!([] -> Test as "Test" { return Test(); }) }
    }
}

fn main() {
    let test = Test::new();
}
@ogoffart
Copy link
Collaborator

Yeah, cpp_class only work with class that are relocatable.

This is documented there: https://docs.rs/cpp/0.5.5/cpp/macro.cpp_class.html#relocatable-classes

Perhaps the documentation should be more explicit, or extra warning should be in order.

@andyjsbell
Copy link
Author

I decided to test this out on OSX and Windows. Interestingly both Windows and OSX did not have the issue.

@ogoffart
Copy link
Collaborator

This depends on the implementation of the standard library.

@LastLightSith
Copy link

Hi, out of curiosity, why test is relocatable immediately ? it is used only once.

@ogoffart
Copy link
Collaborator

Internally it is returned from the Test::new() function so that's one possible relocation (even if it might be optimized)
Also internally in the cpp! macro

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

No branches or pull requests

3 participants