Re: [ROOT] 2.24.05: bug in TMap and TObjArray

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Tue May 30 2000 - 12:09:51 MEST


Hi Matt,

   the problem is in the byte code compiler of CINT.
Run the example without byte code optimization (.O0) and it works.
The problem is caused by creating the TIter next_file() object on the
stack. It will work if you create the next_file iter on the heap:

      TIter *next_file = new TIter(files);
      while ((name2 = dynamic_cast< TObjString* >( next_file->Next() ) ) != 0)
         cout << name2->String() << endl;
      delete next_file;

I hope Masa will fix or elaborate on the problem as soon as he is back
from his business trip.

Cheers, Fons.




"Matthew D. Langston" wrote:
> 
> There is a bug in TMap and TObjArray in ROOT 2.24.05.  I can't be any
> more specific that this, because the error message printed by ROOT is
> meaningless (i.e. the ubiquitous "segmentation violation" message).
> 
> I have, however, attached a file named CollectionBug.cxx which
> reproduces the bug.  The bug is only present when CollectionBug.cxx is
> interpreted by ROOT.  It runs fine when compiled.
> 
> Here is the output from ROOT:
> 
>   root [0] .L CollectionBug.cxx
>   root [1] CollectionBug bug;
>   root [2] bug.Print();
>   baz
>   foo
>   bar
> 
>    *** Break *** segmentation violation
>   Root > Function Print() busy flag cleared
> 
> Regards, Matt
> 
> 
> --
> Matthew D. Langston
> SLD, Stanford Linear Accelerator Center
> langston@SLAC.Stanford.EDU
> 
>   --------------------------------------------------------------------------------
> #ifndef __CINT__
> #include <TObjString.h>
> #include <TObjArray.h>
> #include <TMap.h>
> #include <iostream>
> #endif
> 
> class CollectionBug
> {
>    public:
> 
>       CollectionBug();
> 
>       void Print();
> 
>    private:
> 
>       TMap*  fMap;
> };
> 
> #ifndef __CINT__
> int
> main( int argc, char* argv[] )
> {
>    CollectionBug bug;
>    bug.Print();
> }
> #endif
> 
> CollectionBug::CollectionBug()
> {
>    fMap = new TMap();
>    TObjArray* files;
> 
>    files = new TObjArray();
>    files->Add( new TObjString( "1" ) );
>    fMap->Add( new TObjString( "foo" ), files );
> 
>    files = new TObjArray();
>    files->Add( new TObjString( "1" ) );
>    fMap->Add( new TObjString( "bar" ), files );
> 
>    files = new TObjArray();
>    files->Add( new TObjString( "1" ) );
>    fMap->Add( new TObjString( "baz" ), files );
> }
> 
> 
> void
> CollectionBug::Print()
> {
>    TObjString* name;
>    TIter next_dataset( fMap );
>    while ( ( name = dynamic_cast< TObjString* >( next_dataset() ) ) != 0 )
>    {
>       cout << name->String() << endl;
>       TObjArray* files = dynamic_cast< TObjArray* >( fMap->GetValue( name ) );
>       TIter next_file( files );
>    }
> }
> 
> // Local variables:
> //  compile-command: "g++ `root-config --cflags --libs` -Wl,-rpath,$ROOTSYS/lib -Wall CollectionBug.cxx -o CollectionBug"
> // End:

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:26 MET