-
Notifications
You must be signed in to change notification settings - Fork 9
Description
if you try to read a BoostStore from file using a pointer (BoostStore::Get(std::string name, T*& ptr)) it will automatically instantiate a BoostStore on the heap for you, but doesn't necessarily create the correct type (binary, text, multi-entry) of BoostStore, which can result in a segfault when you try to use the corresponding object.
So normally one can do, for example:
// read a std::vector<double> from a BoostStore called MyBoostStore, stored with the key 'mydoubles'
std::vector<double>* somevector;
MyBoostStore->Get("mydoubles", somevector);
std::cout<< somevector.size() << std::endl; // works just fine
and that would work. The BoostStore would construct a std::vector on the heap (which it owns), and set your pointer somevector to point at it.
Unfortunately this doesn't necessarily work to retrieve a BoostStore which is embedded in another BoostStore:
// read a type-2 (multi-entry) BoostStore nested within MyBoostStore with the key 'myBoostStore'
BoostStore* somebs;
MyBoostStore->Get("myBoostStore", somebs);
somebs->Print(false); // segfaults; somebs is malformed.
A workaround is to create the local BoostStore manually, with the correct type, and retrieve it by value rather than with a pointer:
BoostStore somebs(true, 2); // true= type-checking enabled, 2= mutli-entry binary boost-store. These must match the type of BoostStore you're retrieving.
MyBoostStore->Get("myBoostStore", somebs);
somebs.Print(false); // okay!
but this caught mattw out as his code was using pointers, and took me a little bit to debug because simply looking at the code there doesn't immediately appear to be anything syntactically incorrect.