Loading ...
Sorry, an error occurred while loading the content.

Re: My ASTNode gets deleted more than once

Expand Messages
  • marcschellens
    ... free to ... 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
    Message 1 of 4 , Apr 3, 2003
    • 0 Attachment
      --- In antlr-interest@yahoogroups.com, Ric Klaren <klaren@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'
    • Ric Klaren
      ... 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
      Message 2 of 4 , Apr 4, 2003
      • 0 Attachment
        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@... ----- +31 53 4893722 ----
        -----+++++*****************************************************+++++++++-------
        "I think we better split up."
        "Good idea. We can do more damage that way."
        --- Ghostbusters
      Your message has been successfully submitted and would be delivered to recipients shortly.