Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-8809

push_back on a vector of pointers may not work in PyROOT

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • High
    • 6.10/00, 6.08/08
    • 6.08/06
    • PyROOT
    • None
    • all

    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]")

      Attachments

        Activity

          People

            mato Pere Mato Vila
            dpiparo Danilo Piparo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Actual End: