Re: A TFile on the stack or the heap doesn't seem to behave the same way...

From: Masaharu Goto (gotom@hpyiddq.jpn.hp.com)
Date: Wed Oct 15 1997 - 01:54:25 MEST


Fons,

 I replyed this matter to Gordon already. Problem was file name extention.
 When it is geven as .c , cint takes it as C source which ignores
 TFile f(filename); as funtion prototype. Using .C instead will solve
 the problem.

Masaharu Goto

> 
> Hi Gordon,
> 
>    on Unix I get the following using your script:
> 
> void test (char *filename)
> {
>    printf("file = %s\n", filename);
>    TFile f (filename);
>    if (!f.IsOpen()) printf("f is not open\n");
>    if (f.IsZombie()) printf("f is a Zombie\n");
>    TFile *t = new TFile (filename);
>    if (!t->IsOpen()) printf("t is not open\n");
>    if (t->IsZombie()) printf("t is a Zombie\n");
>    TFile z ("junk.txt");
>    if (!z.IsOpen()) printf("z is not open\n");
>    if (z.IsZombie()) printf("z is a Zombie\n");
> }
> 
> root [5] .x test.C("junk.txt")
> file = junk.txt
> Error in <TFile::TFile>: file junk.txt does not exist
> f is not open
> f is a Zombie
> Error in <TFile::TFile>: file junk.txt does not exist
> t is not open
> t is a Zombie
> Error in <TFile::TFile>: file junk.txt does not exist
> z is not open
> z is a Zombie
> NULL
> root [6] 
> 
> this is ok. Also after executing test() the object
> and pointers are not accessable anymore (out of scope).
> 
> And when you do:
> 
> root [10] gDebug=1
> (int)1
> root [11] .x test.C("junk.txt")
> 
> you will see that the TFile dtors are correctly called for
> the two stack based TFile objects f and z.
> 
> If you don't get the same output on NT then there is something
> wrong with the NT version. Let me know.
> 
> Cheers, Fons.
> 
> 
> 
> Gordon Watts (Brown University) wrote:
> > 
> > Hi,
> >   I'm running 1.03/04 on WindowsNT 4.0, Service pack 3. I have the
> > following macro in a file test.c:
> > 
> > void test (char *filename)
> > {
> >         TFile f (filename);
> >         TFile *t = new TFile (filename);
> >         TFile z ("junk.txt");
> > }
> > 
> > In root I run it with ".X test.c("junk.txt");" Junk.txt does not exist in
> > my current directory, so I expect all three statements to fail. Runnning it
> > shows that the second two do, indeed, produce an error message. No error
> > message is forthcoming from the first TFile delc. In fact, the object "f"
> > doesn't even seem to exist! (i.e. I can't do a IsOpen on it). I searched
> > the web site and documentation the best I could and the only clue I could
> > come up with is that TFile's constructor wants an argument of Text_t. I
> > tried replacing the char * with a Text_t * but it didn't change anything.
> > BTW, the error message from the second TFile decl indicates that the
> > "junk.txt" string is getting in just fine.
> > 
> > I also looked at the root/cint docs to see if there was some restriction on
> > stack created objects, but I didn't see any references...
> > 
> >         Cheers,
> >                 Gordon.
> 
> -- 
> Org:    CERN, European Laboratory for Particle Physics.
> Mail:   1211 Geneve 23, Switzerland          Phone: +41 22 7679248
> E-Mail: Fons.Rademakers@cern.ch              Fax:   +41 22 7677910
> 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:21 MET