Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-18 Thread Patrick R. Michaud
On Mon, Jul 18, 2011 at 10:41:30AM -0400, Peter Lobsinger wrote:
 On Sun, Jul 17, 2011 at 11:00 AM, Patrick R. Michaud pmich...@pobox.com 
 wrote:
  On Sun, Jul 17, 2011 at 10:21:19AM +0200, Moritz Lenz wrote:
 
  Question to the Parrot developers: How could I implement DESTROY methods
  in Rakudo? Is there any vtable I can override, or so? Note that such a
  method might itself allocate new GCables. While not urgent, it's
  important for us in the long run.
 
  A possibly related (and more relevant) question for Parrot devs:
  is there any reason that FileHandle PMCs do not automatically
  flush + close on destruction?
 
 The destructor does exactly that, but is not triggered by global teardown.

To be a bit more direct, then:  Several of Parrot's target languages 
have the semantic that normal program exit will cause any open 
filehandles to be flushed and closed automatically.  How does a HLL
writer achieve this in Parrot?

Pm


Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-18 Thread Andrew Whitworth
On Mon, Jul 18, 2011 at 10:41 AM, Peter Lobsinger plobs...@gmail.com wrote:
 The destructor does exactly that, but is not triggered by global teardown.

That seems wrong to me, we should be sweeping pools and destroying
PMCs on global teardown. If we aren't doing that, it's a bug.

--Andrew Whitworth


Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-18 Thread Peter Lobsinger
On Sun, Jul 17, 2011 at 11:00 AM, Patrick R. Michaud pmich...@pobox.com wrote:
 On Sun, Jul 17, 2011 at 10:21:19AM +0200, Moritz Lenz wrote:

 Question to the Parrot developers: How could I implement DESTROY methods
 in Rakudo? Is there any vtable I can override, or so? Note that such a
 method might itself allocate new GCables. While not urgent, it's
 important for us in the long run.

 A possibly related (and more relevant) question for Parrot devs:
 is there any reason that FileHandle PMCs do not automatically
 flush + close on destruction?

The destructor does exactly that, but is not triggered by global teardown.

    pmichaud@kiwi:~/nom$ cat fh.pir
    .sub 'main' :main
        $P0 = new ['FileHandle']
        $P1 = $P0.'open'('test.txt', 'w')
        $P1.'print'(Hello\n)
    .end

    pmichaud@kiwi:~/nom$ install/bin/parrot fh.pir
    pmichaud@kiwi:~/nom$ cat test.txt
    pmichaud@kiwi:~/nom$ ls -l test.txt
    -rw-r--r-- 1 pmichaud pmichaud 0 2011-07-17 09:57 test.txt

.sub 'main' :main
 $P0 = new ['FileHandle']
 $P0.'open'('test.txt', 'w')
 $P0.'print'(Hello\n)
 $P0 = null
 sweep 1
.end

 Pm
 ___
 http://lists.parrot.org/mailman/listinfo/parrot-dev



Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-18 Thread Andrew Whitworth
On Sun, Jul 17, 2011 at 4:21 AM, Moritz Lenz mor...@faui2k3.org wrote:
 Question to the Parrot developers: How could I implement DESTROY methods
 in Rakudo? Is there any vtable I can override, or so? Note that such a
 method might itself allocate new GCables. While not urgent, it's
 important for us in the long run.

We do have the ability to override VTABLE_destroy in a C-based PMC
type, but that is not exposed through Object PMC. I suspect this
capability could be exposed through 6model and the Rakudo PMC
infrastructure, and a Sub could be invoked from there. Because of the
sensitive nature of the timing, and because this has obviously not
gotten any good test coverage or developer attention, it probably
won't work so well.

This hasn't been a high-priority issue so far, either amonst users or
developers. If people are interested in seeing this happen, failing
use-cases or even tickets requesting fixes would be a great place to
start. My suggestion so far would be to add in a destroy override to
6model, try to use it, and see what blows up. Then open a ticket with
Parrot and we'll do our best to make it work the way you need.

--Andrew Whitworth


Re: Close($file) required in Perl 6, unlike Perl 5

2011-07-18 Thread Patrick R. Michaud
On Mon, Jul 18, 2011 at 11:26:49AM -0400, Andrew Whitworth wrote:
 On Mon, Jul 18, 2011 at 10:41 AM, Peter Lobsinger plobs...@gmail.com wrote:
  The destructor does exactly that, but is not triggered by global teardown.
 
 That seems wrong to me, we should be sweeping pools and destroying
 PMCs on global teardown. If we aren't doing that, it's a bug.

Now added as TT #2157, at least for the FileHandle not closing part.

Pm