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

Ric Klaren klaren at cs.utwente.nl
Fri Apr 4 02:26:38 PST 2003


On Fri, Apr 04, 2003 at 07:46:54AM -0000, marcschellens wrote:
> 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.

2.7.2 contains a refcount bug though :/

Fix:

==== //depot/code/org.antlr/main/main/lib/cpp/antlr/AST.hpp#7 (ktext) ====
@@ -5,7 +5,7 @@
  * Project led by Terence Parr at http://www.jGuru.com
  * Software rights: http://www.antlr.org/RIGHTS.html
  *
- * $Id: //depot/code/org.antlr/main/main/lib/cpp/antlr/AST.hpp#6 $
+ * $Id: //depot/code/org.antlr/main/main/lib/cpp/antlr/AST.hpp#7 $
  */

 #include <antlr/config.hpp>
@@ -23,7 +23,7 @@
 class ANTLR_API AST {
 public:
 	AST() : ref(0) {}
-	AST(const AST& other) : ref(other.ref->increment()) {}
+	AST(const AST& other) : ref(0) {}
 	virtual ~AST() {}

 	/// Return the type name for this AST node. (for XML output)

> I overloaded CommonAST and set the factory accordingly like
> you described in the doc.

My suspicion would be that there's a problem in there. You could send the
file to me and I'll have a look. Another option might be that somewhere the
lowlevel ASTRefcount methods are used to create a new ast.

> Actually I was hoping for a hint to a common cave-eat.

Double delete's I've never seen with the ASTRefcount of antlr. (most of the
time I'm running with a memory debugger that would catch those errors) Also
I know of no common caveats with this stuff.

> 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?

You tell me ;) I'm not seeing anything really disturbing in the trace above
(except for the sigsegv) You might add a trace in the destructor of MyNode
(with the address of the thing so you know for certain there's a thing
being destroyed twice). A gdb backtrace would also be helpfull. Or more
information...

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  "I think we better split up."
  "Good idea. We can do more damage that way."
  --- Ghostbusters


 

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




More information about the antlr-interest mailing list