Description
A user reported this bug on the forum: https://root-forum.cern.ch/t/vector-tf1-crash-with-pyroot-6-08/24886/1
This is the reproducer:
import ROOT
|
ROOT.gInterpreter.Declare('''
|
class F {};
|
|
struct AA {
|
AA(){ f= new F();}
|
F* f;
|
|
};
|
|
struct BB {
|
std::vector<F*> vec;
|
void add(AA &a){vec.push_back(a.f);}
|
};
|
''')
|
|
a=ROOT.AA()
|
b=ROOT.BB()
|
|
b.add(a)
|
b.add(a)
|
print b.vec[0]
|
print b.vec[1]
|
b.vec.push_back(a.f)
|
# print b.vec[2] # crashes
|
The interposition of the Python layer in this case causes a problem. Sometimes ROOT informs the user about the fact that the memory location is invalid.
This can be verified as follows:
import ROOT
|
ROOT.gInterpreter.Declare('''
|
class F {};
|
|
struct AA {
|
AA(){ f= new F();}
|
F* f;
|
|
};
|
|
struct BB {
|
std::vector<F*> vec;
|
void add(AA &a){vec.push_back(a.f);}
|
};
|
AA a;
|
BB b;
|
''')
|
|
a = ROOT.a
|
b = ROOT.b
|
|
b.add(a)
|
b.add(a)
|
print b.vec[0]
|
print b.vec[1]
|
b.vec.push_back(a.f)
|
|
ROOT.gInterpreter.ProcessLine("b.vec[0]")
|
ROOT.gInterpreter.ProcessLine("b.vec[1]")
|
ROOT.gInterpreter.ProcessLine("b.vec[2]")
|