[antlr-interest] Re: ATTN: Ric Klaren. Bug in the AST copy ctor

Alexander Lenski alenski at dca.net
Wed Feb 19 19:34:36 PST 2003


Hi Ram,
Sorry, you did not hit the point.

Explanation:
  1. Initial point: We need to make a deep copy of the CommonAST nodes created in some rule.
  2. We call some of the ASTFactory::dup...( RefAST t ) function.
  3. The dup... calls the ASTFactory::dup( RefAST t ) and the dup calls the CommonAST::clone().
  4. Definition of the clone function:
              RefAST CommonAST::clone( void ) const
              { CommonAST *ast = new CommonAST( *this );
                return RefAST(ast);
              }
      Inside the clone(), this->ref references this object (original).
  5. The CommonAST( const CommonAST& other ) calls the AST( const AST& other ) : ref(other.ref->increment()) {}.
  6. The ref(other.ref->increment()) sets ref of the copy with the ref's pointer from the other (original, this is wrong!!!).
  7. Definition of the RefAST (it is synonym of the ASTRefCount) ctor:
              ASTRefCount::ASTRefCount( const AST* p = 0 )
                : ref( p ? ASTRef::getRef( p ) : 0 )
              {
              }
      The ASTRef::getRef( p ) returns pointer to the ASTRef object bound to the other (original, see steps 5 and 6).
      The clone() creates the RefAST object bound to the other (original, see steps 4, 5 and 6).
  8. Finally, the clone() returns the RefAST object bound to the original and the copy is suspended in nowhere.

Alex

----- Original Message ----- 
From: <cintyram at yahoo.com>
To: <antlr-interest at yahoogroups.com>
Sent: Wednesday, February 19, 2003 4:53 PM
Subject: [antlr-interest] Re: ATTN: Ric Klaren. Bug in tne AST copy ctor


> hi alexander and ric,
>   i had made the following change ..
> 
>  AST(const AST& other) : ref(other.ref ? other.ref->increment() : 0) {}
> //ram /  AST(const AST& other) : ref(other.ref->increment()) {}
> 
> as the constructors of all the other classes look like the uncommented
> code;
> 
> actually i did not notice any effects of the change ;
> 
> but since yesterday i have a funny problem
> 
> if i call ast->toStrinList() where ast is the tree returned by the
> parser, the call is going ot BaseAST::toSTringTree() ;
> 
> if i call ast->toStringTree() i get an error message which says 
> "the calue of ESP was not properly saved across a function call ... "
> 
> dont now how to fix it, everything was working fine till day before
> yesterday and without making any changes to the code, suddenly this
> condition appears :)
> 
> cheers
> ram
> 
> 
> --- In antlr-interest at yahoogroups.com, "Alexander Lenski"
> <alenski at d...> wrote:
> > Hi,
> > Sorry for persistence, I did not get any feedback. What should the
> clone functions of the AST... classes create? Is it about deep copies
> or what? In other words, am I correct with the original msg or not?
> > 
> > Thanks a lot,
> > Alex
> >   ----- Original Message ----- 
> >   From: Alexander Lenski 
> >   To: antlr-interest at yahoogroups.com 
> >   Sent: Friday, February 14, 2003 12:34 AM
> >   Subject: [antlr-interest] ATTN: Ric Klaren. Bug in tne AST copy ctor
> > 
> > 
> >   Hi,
> >   The AST's copy ctor is defined in the 2.7.2 as
> > 
> >       AST(const AST& other) : ref(other.ref->increment()) {}
> > 
> >   The ref(other.ref->increment()) sets ref of the copy with the
> ref's pointer from the other. As a consequence, all clone funcs of the
> AST... classes and subsequently the dup... funcs of the ASTFactory
> produce memory leaks, perform corrupted operations instead of expected
> functionality.
> > 
> >   In the 2.7.1 we had
> > 
> >       AST(const AST& other) : ref( 0 ) {}
> > 
> >   This fixes the problem and works just fine. If I did not miss
> something, couldn't you fix that please.
> >   BTW, the antlr.dll (VC7.0) works just fine. I have built my
> lexers-parsers in the dll form too, no problems at all with running
> the clients.
> > 
> >   Thanks,
> >   Alex
> > 
> > 
> >   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030219/9a63bcfe/attachment.html


More information about the antlr-interest mailing list