Hello,
I’m getting a segfault when I try to serialize an STL map (with std::string keys and values) into a TBufferFile in order to send it over a Unix socket. The following code reproduces the crash:
#include <map>
#include <string>
#include <TBufferFile.h>
#include <TApplication.h>
#include <TROOT.h>
using namespace std;
int main(int argc, char** argv)
{
TApplication app("test", &argc, argv);
map<string, string> m;
m["foo"] = "bar";
TClass *c = gROOT->FindSTLClass("std::map<std::string,std::string>", true);
TBufferFile b(TBuffer::kWrite);
b.WriteObjectAny(&m, c);
return 0;
}
Is there anything obviously wrong with my approach? It actually seems to work fine inside CINT/Cling, although I suspect this might be related to some sneaky behind-the-scenes conversions between std::string and TString. I am having no problem serializing/transmitting/reconstructing objects that derive from TObject. It’s just this STL map that’s giving me trouble. FindSTLClass does in fact return a valid TClass*, and GetName() returns “map<string,string”>.
I suppose that, in the worst case, I can switch to a TMap, but I’d really like to avoid that. If anyone can help me, I’d greatly appreciate it. For what it’s worth, below is a stack trace. The crash occurs in both ROOT 5.34 and 6.00.
#0 strlen () at ../sysdeps/x86_64/strlen.S:106
#1 0x00007ffff75cec75 in TString::TString(char const*) () from /home/mkramer/physics/root/lib/libCore.so
#2 0x00007ffff6fc859c in TEmulatedMapProxy::WriteMap(unsigned int, TBuffer&) ()
from /home/mkramer/physics/root/lib/libRIO.so
#3 0x00007ffff6fc87b0 in TEmulatedMapProxy::Streamer(TBuffer&) () from /home/mkramer/physics/root/lib/libRIO.so
#4 0x00007ffff6fbd308 in TCollectionStreamer::Streamer(TBuffer&, void*, int, TClass*) ()
from /home/mkramer/physics/root/lib/libRIO.so
#5 0x00007ffff6fba691 in TBufferFile::WriteObjectClass(void const*, TClass const*) ()
from /home/mkramer/physics/root/lib/libRIO.so
#6 0x00007ffff6fb74ed in TBufferFile::WriteObjectAny(void const*, TClass const*) ()
from /home/mkramer/physics/root/lib/libRIO.so
#7 0x00000000004058b9 in main (argc=1, argv=0x7fffffffd768) at stlbufcrash.cc:18