CINT limitation?

Dear ROOT developers and users,

I am using Version 5.12/00e on SUSE LINUX Enterprise Server 9 (x86_64).
Following simple script crashes although that compiled with ALiC runs fine.
Is this one of CINT limitations?

#include "TFile.h"
#include "TH1.h"

void addn(const char *filename, Int_t n)
  TFile f(filename, "update");
  TH1F hn("hn", "Number of event", 2, 0, 2);
  hn.SetBinContent(1, n);
root [0] .L addn.C
root [1] addn("mono290_bc-1.root", 400000)

 *** Break *** illegal instruction
 Generating stack trace...
 0x00000000027b8761 in <unknown>
Root > Function addn() busy flag cleared


this is a bit unfortunate :-/ When you close the TFile, it checks whether the histogram (which it owns, see object ownership in the user’s guide) was created on the heap; if it was, it’ll take care of deleting it. When compiling your macro it all works nicely - the histogram is created on the stack, so the TFile won’t delete it.

But CINT has to emulate the stack: it creates it on the heap and rememebrs to delete it when the function returns, just as if it was a stack object going out of scope. This of course clashes with TFile’s interpretation of who’s responsible for deleting it. The solution is to add the line “hn.SetDirectory(0);”. This should not change anything for the compiled case, but is a work-around for the interpreted case.

Cheers, Axel.

Hi Axel,

Thank you for kindly telling me what’s going on inside.
So, I suppose that another convenient solution is making sure to create objects always on heap.

that’s correct.
Cheers, Axel.