[antlr-interest] Re: My ASTNode gets deleted more than once

marcschellens m_schellens at hotmail.com
Thu Apr 3 23:46:54 PST 2003


--- In antlr-interest at yahoogroups.com, Ric Klaren <klaren at c...> wrote:
> Hi,
> 
> On Wed, Apr 02, 2003 at 10:16:57AM -0000, marcschellens wrote:
> > I wrote using ANTLR 2.7.1 with C++ an parser and a TreeParser.
> > I retrieve the trees from them via the getAST() method.
> > I use my own AST and AST factory in the manner Peter Morling
> > described.
> > But when the RefAST variables who store the AST (from getAST())
> > go out of scope, at least one node (possibly all, haven't checked)
> > gets deleted more than once.
> > How could this be?
> 
> This is with 'vanilla' usage? Or are you doing special stuff? Feel
free to
> send me a tarball/zip with all the stuff that demonstrates the problem.
> (preferably something that runs on unix)
> 
> Cheers,
> 
> Ric

Thank you very much for the offer.
Actually it is a quite large project with lots of 'special'
things.
But for the test I input only a very simple line to
scan/parse/treeparse/interpret so that mos of the stuff isn't used.
Anyhow, after more thourough testing, it seems to me that
not a node is actually deleted more than once, but it seems
to me that two different nodes containing the same info are
deleted.
Furthermore I defined ci constructor and operator= as private.
And the program runs through Parser/TreeParser and Interpreter
(the interpreter based on a TreeParser, but tree generation is set off
here).
I switched to 2.7.2 meanwhile but the problem is the same.
I overloaded CommonAST and set the factory accordingly like
you described in the doc.
Actually I was hoping for a hint to a common cave-eat.
Reducing the code to a minimal level seems to be a lot of work
and from my feeling the actual solution is probably something
fairly simple.

One thing I found out:

My input is just:

a=1

but when the via getTree() retrieved RefMyNode objects go out of scope
there seem to be more than one node containing '1'
I modified the increment and decrement functions of ASTRefCount.

for increment (decrement accordingly):
cout << "inc: " << this << " " << ptr << " " << count << " " <<
((MyNode*)ptr)->getText() << " " << endl;

and get the following at the end:

...
dec: 0x81a5950 0x81a5920 0 1
deletion of TreeParsers (getTree()) tree

dec: 0x819db38 0x81a5760 0 A
dec: 0x819dbc8 0x81a58f0 0 :=
dec: 0x819db20 0x819db48 0 VAR
dec: 0x81a58c8 0x81a5898 0 1
deletion of Parsers tree

here the segmetation fault takes place
(it happends in the destructor of MyNode)

So one question is:
How can a MyNode be there more than once?
I do some fancy stuff, but nowhere create or delete
MyNode directly.

I would be thankful for any hint,
thanks,
marc








Why a node containg '1'





















 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list