[antlr-interest] TokenStreamRewriteEngine and C++ and RefCounters
Ric Klaren
klaren at cs.utwente.nl
Wed Apr 28 03:50:56 PDT 2004
Hi,
On Wed, Apr 28, 2004 at 02:43:09AM +0700, Andrey R. Urazov wrote:
> Now that I have been using the ANTLR smart pointers for some time,
> I have to admit that ASTRefCount has to be rewritten as well. The
> current implementation turned out to be a bit buggy.
Didn't notice any bugs in them I hardly ever touch them. But maybe some of
the later changes introduce some new interaction that let's something bad
happen.
> As I've found out, `operator=(const T*)' and `operator T*()' are unsafe
The operator T*() I already replace in TokenRefCount with a operator bool()
which is somewhat safer.
> (in Boost, for example, these aren't defined at all). When implemented
> together, not only they are unsafe, they are rather dangerous since they
> can lead to nonshared ownership of a single object and therefore to its
> premature deletion.
I personally did not run into premature deletion problems (using a malloc
debugger very regularly to verify my project) There might be a resource
leak though but I'm not sure wether that's due to antlr or my own code.
> Consider the code from BaseAST.cpp (the problems I experience now are
> caused by the implicit misuse of smart pointers in this function):
I'll have a look at this when I'm not two days behind on sleep... (probably
a lot safer ;) )
> rule
> {
> RefAST ast = #[TOKEN];
> }
> :
> (
> index:expression
> {
> ast->addChild(#index);
> }
> )+
> ;
>
> And as the new `expression' is assigned to `index', the reference count
> for the old falls to zero and the object is deleted instead of staying
> in memory until the reference in the tree is released as well. When I
> then call getNumberOfChildren() the program hangs :(
Shouldn't there be a '!' on this rule to turn of automatic
treeconstruction? (unless you have it turned off on grammar level) This
might create a loop in the tree which might hang up getNumberOfChildren if
I'm not mistaken.
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755 ----
-----+++++*****************************************************+++++++++-------
Quidquid latine dictum sit, altum viditur.
(Whatever is said in Latin sounds profound.)
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list