Crash with TTreeFormula::Compile

Hi,

In the course of writing some code utilizing TTreeFormula, I noticed that too many calls in a row to the Compile method causes a crash. For example,

#include "TTreeFormula.h"
#include "TTree.h"
#include <iostream>

int main(int argc, char** argv) {
  if(argc< 2) return 1;

  int someBranch, ntries = atoi(argv[1]);
  TTree t ("t", "test tree");
  t.Branch("someBranch", &someBranch, "someBranch/I");

  TTreeFormula* f = new TTreeFormula("f", "someBranch", &t);

  for(int i = 0; i< ntries; ++i) {

#ifdef RECOMPILE
          f->Compile("someBranch");
#else
          delete f;
          f = new TTreeFormula("f", "someBranch", &t);
#endif
  }

  delete f;
}

If I compile the above using -DRECOMPILE (i.e. compiling the f->Compile() block), it crashes if run with too large of an argument (515 on my system, which is OsX Lion running ROOT version 5.30/02):


 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================

Thread 1 (process 3080):
#0  0x00007fff8f3b1168 in wait4 ()
#1  0x00007fff92ff45f5 in system ()
#2  0x000000010a9fada9 in TUnixSystem::StackTrace ()
#3  0x000000010a9f8b3a in TUnixSystem::DispatchSignals ()
#4  <signal handler called>
#5  0x000000010b9519e3 in TTreeFormula::EvalClass ()
#6  0x000000010b950597 in TTreeFormula::DefinedVariable ()
#7  0x000000010936c3db in TFormula::Analyze ()
#8  0x0000000109372981 in TFormula::Compile ()
#9  0x00000001091fea92 in main ()
===========================================================


The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x000000010b9519e3 in TTreeFormula::EvalClass ()
#6  0x000000010b950597 in TTreeFormula::DefinedVariable ()
#7  0x000000010936c3db in TFormula::Analyze ()
#8  0x0000000109372981 in TFormula::Compile ()
#9  0x00000001091fea92 in main ()
===========================================================

However, If I compile the branch that deletes and re-initializes f, it doesn’t seem to have a problem.

Is this a bug, or am I abusing TTreeFormula::Compile() ?

Thanks,
Greg

[quote]Is this a bug, or am I abusing TTreeFormula::Compile() ?[/quote]It is not a bug. The proper initialization of the TTreeFormula requires all the information gathered and setup to be done by the constructor. (i.e. don’t call Compile directly).

Cheers,
Philippe.