From: Alexandre Ferrieux on
On Mar 2, 11:12 pm, Alan Grunwald <alan-clt-pos...(a)nospam.demon.co.uk>
wrote:
> drscr...(a)gmail.com wrote:
> > Alexandre Ferrieux wrote:
> >> Sounds weird in our EIAS world :}
> >> If it could happen in 8.6 HEAD (don't know if tdom can) I'd display
> >> [::tcl::unsupported::representation $parsed] before and after function
> >> return (look at the refcount).
>
> > No, this is on 8.4 with different subversions.  Here is some code that
> > might help you to reproduce it including a sample xml file:
>
> > package req tdom
> > package req Tk
>
> > proc get_x {fname} {
> >  set xfile [open $fname r]
> >  dom parse [read $xfile] xdoc
> >  close $xfile
> >  puts "xml doc: [$xdoc childNodes]"
> >  return $xdoc
> > }
>
> > set f [tk_getOpenFile]
>
> > set xdoc [get_x $f]
> > puts "xml doc: [$xdoc childNodes]"
>
> > This is a sample xml file:
> > <?xml version="1.0" encoding="UTF-8" ?>
> > <employee>
> > <name>Jane</name>
> > <salary>30000</salary>
> > </employee>
>
> >> -Alex
>
> I think this is expected and documented behaviour. If you do
>
>      dom parse $data doc
>
> then doc is deleted and tidied up when it goes out of scope. If you do
>
>      set doc [dom parse $data]
>
> then you need to clean up after yourself.
>
> So, if you change your proc to
>
>      proc get_x {fname} {
>          set xfile [open $fname r]
>          set xdoc [dom parse [read $xfile]
>          close $xfile
>
>          puts "xml doc: [$xdoc childnodes]
>          return $xdoc
>      }
>
> all should be well.
>
> For the sake of tidiness, you should also
>
>      $xdoc delete
>
> when you've finished with it.
>
> Alan

For those of us unfamiliar with Tdom, can you explain the difference ?
Isn't it the same value stored in the same local variable in both
cases ?

-Alex
From: Donal K. Fellows on
On 3 Mar, 08:33, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com>
wrote:
> For those of us unfamiliar with Tdom, can you explain the difference ?
> Isn't it the same value stored in the same local variable in both
> cases ?

At a guess, it's setting an unset trace on the variable to perform the
cleanup of the document object (and its node tree) when the variable
goes away. Or at least that's the way I'd do it. :-)

Donal.
From: Alexandre Ferrieux on
On Mar 3, 10:41 am, "Donal K. Fellows"
<donal.k.fell...(a)manchester.ac.uk> wrote:
> On 3 Mar, 08:33, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com>
> wrote:
>
> > For those of us unfamiliar with Tdom, can you explain the difference ?
> > Isn't it the same value stored in the same local variable in both
> > cases ?
>
> At a guess, it's setting an unset trace on the variable to perform the
> cleanup of the document object (and its node tree) when the variable
> goes away. Or at least that's the way I'd do it. :-)
>
> Donal.

Ah, yet another of those automagical, Feather-like, EIAS-violators
that are supposed to help us, and that we end up fighting all day
long :/

-Alex
From: Rolf Ade on
Donal K. Fellows <donal.k.fellows(a)manchester.ac.uk> wrote:
>On 3 Mar, 08:33, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com>
>wrote:
>> For those of us unfamiliar with Tdom, can you explain the difference ?
>> Isn't it the same value stored in the same local variable in both
>> cases ?
>
>At a guess, it's setting an unset trace on the variable to perform the
>cleanup of the document object (and its node tree) when the variable
>goes away. Or at least that's the way I'd do it. :-)

Yes, that's right.

As well as the explanation earlier in this thread:

set docVar [dom parse $xml]

creates a 'persistent' tree, which you (the programmer) have to clean
up with an explicite [$docVar delete], if you're done with it.

dom parse $xml docVar

cleans up the tree in docVar automatically if the local var docVar is
"removed from the stack".

As already noted in the thread that's documented behavior

rolf
From: tom.rmadilo on
On Mar 4, 5:01 am, points...(a)gmx.net (Rolf Ade) wrote:
> Donal K. Fellows <donal.k.fell...(a)manchester.ac.uk> wrote:
>
> >On 3 Mar, 08:33, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com>
> >wrote:
> >> For those of us unfamiliar with Tdom, can you explain the difference ?
> >> Isn't it the same value stored in the same local variable in both
> >> cases ?
>
> >At a guess, it's setting an unset trace on the variable to perform the
> >cleanup of the document object (and its node tree) when the variable
> >goes away. Or at least that's the way I'd do it. :-)
>
> Yes, that's right.
>
> As well as the explanation earlier in this thread:
>
> set docVar [dom parse $xml]
>
> creates a 'persistent' tree, which you (the programmer) have to clean
> up with an explicite [$docVar delete], if you're done with it.
>
> dom parse $xml docVar
>
> cleans up the tree in docVar automatically if the local var docVar is
> "removed from the stack".
>
> As already noted in the thread that's documented behavior

Since a document consumes resources and creates commands, which can't
be deleted without the name (stored in docVar), it seems unsafe to use
the persistent form ([set docVar ...]) without adding an additional
cleanup system/callback. Any uncaught error after this command returns
will result in leaked memory. Of course this is okay in a simple
script, but not in a long running interp.