8000 Multiple Inheritance + Polymorphism Seg Fault · Issue #188 · USCiLab/cereal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Multiple Inheritance + Polymorphism Seg Fault #188

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
AzothAmmo opened this issue Apr 29, 2015 · 10 comments
Closed

Multiple Inheritance + Polymorphism Seg Fault #188

AzothAmmo opened this issue Apr 29, 2015 · 10 comments

Comments

@AzothAmmo
Copy link
Contributor

See discussion on mailing list and related issue #187.

Minimal example provided by David Bond:

#include <cereal/archives/json.hpp>
#include <cereal/types/polymorphic.hpp>
#include <iostream>

struct Base {
    virtual void foo() { } 
    template<class Archive> void serialize(Archive& archive) { } 
};

struct Base2 {
    virtual void foo() { } 
    std::string var;
    template<class Archive> void serialize(Archive& archive) {   
        archive(cereal::make_nvp("var", var));
    }   
};

struct Derived : public Base2, public Base {
    template<class Archive> void serialize(Archive& archive) {   
        archive(cereal::make_nvp("Base2",
                                 cereal::base_class<Base2>(this)),
                cereal::make_nvp("Base",
                                 cereal::base_class<Base>(this)));
    }   
};

CEREAL_REGISTER_TYPE(Derived);

int main() {
    auto ptr = std::make_shared<Derived>();
    cereal::JSONOutputArchive ar(std::cout);
    ar(cereal::make_nvp("ptr", std::dynamic_pointer_cast<Base>(ptr)));

    return 0;
}
@AzothAmmo AzothAmmo added the bug label Apr 29, 2015
@AzothAmmo AzothAmmo added this to the v1.2.0 milestone Jun 11, 2015
@bbouzan
Copy link
bbouzan commented Jun 23, 2015

I have this same bug on my system, is there any workaround?

@AzothAmmo
Copy link
Contributor Author

No solution yet, I haven't had the time to look into it. Potentially related issue discussed on the mailing list here: https://groups.google.com/forum/#!topic/cerealcpp/ifoi4a36C5k

@Mokon
Copy link
Mokon commented Jul 22, 2015

@bbouzan on my project where I hit this I simply removed multiple inheritance. (In my case it was simply a output class that I could do that without any trouble.) That isn't really a solution though... But the key here is the internal code is casting a class to a void* then back to another of the types.

@ylobanov
Copy link

Hello,
In our project we are about to start implementation of serializatioin, and there is a choice between cereal and boost::serialization. Cereal looks much more attractive then boost, but this bug is an issue for us. I wonder if it is reasonable to wait for the fix or it's better to use boost. Do you have any estimates? Thanks

@AzothAmmo
Copy link
Contributor Author

All progress is on a mini-hiatus until December, when I'll have time to tackle the various issues. I can't estimate how long fixing this one individual bug will take, but that's the point when I'd start trying to fix it.

If this timeframe won't work for you, take a look at our boost transition page. It may be possible for you to easily switch to cereal once the issue is resolved as we support an identical syntax to that found in boost serialization.

@ylobanov
Copy link

Thanks for the information, we'll wait for December

@AzothAmmo
Copy link
Contributor Author

Small update on this: I've investigated the problem and know what is causing it though I haven't come up with a solution yet. David Bond correctly identified the source of the issue on the mailing list, we're ending up at an incorrect address do a void * cast.

@AzothAmmo
Copy link
Contributor Author

So we'll basically have to implement something very much like boost's void_cast_register.

@AzothAmmo
Copy link
Contributor Author

I have this fixed locally, finishing up documentation and cleanup and will push it through soon. This will involve a breaking change for certain polymorphic serialization situations.

@ylobanov
Copy link

thanks for updating!

AzothAmmo added a commit that referenced this issue Dec 23, 2015
Needs to be done in load direction + unit tests + attribution + cleanup
AzothAmmo added a commit that referenced this issue Dec 23, 2015
Added support for up and downcasting for polymorphism, see issue #188

Still needs final documentation + cleanup
AzothAmmo added a commit that referenced this issue Dec 23, 2015
Also some changes to make sandbox things work with the new casting

Made it so base_class doesn't need to know about polymorphism to work

All relates to #188
AzothAmmo added a commit that referenced this issue Dec 24, 2015
-removed some debug messages
-spruced up some documentation
-modified main.cpp for MSVC tests to properly compile given previously made changes in common.hpp
relates issue #188
AzothAmmo added a commit that referenced this issue Dec 26, 2015
AzothAmmo added a commit that referenced this issue Dec 26, 2015
resolves #188

still need to update website doc
AzothAmmo added a commit that referenced this issue Feb 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0