Re: Close($file) required in Perl 6, unlike Perl 5
On Mon, Jul 18, 2011 at 11:26:49AM -0400, Andrew Whitworth wrote: > On Mon, Jul 18, 2011 at 10:41 AM, Peter Lobsinger 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
Re: Close($file) required in Perl 6, unlike Perl 5
On Sun, Jul 17, 2011 at 4:21 AM, 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. 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
On Sun, Jul 17, 2011 at 11:00 AM, Patrick R. Michaud 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
On Mon, Jul 18, 2011 at 10:41 AM, Peter Lobsinger 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
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 > 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
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? 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 Pm
Re: Close($file) required in Perl 6, unlike Perl 5
On 07/13/2011 10:00 PM, Parrot Raiser wrote: > The following program: > > my $skeleton = "bones\n"; > my $new_file = "grave"; > my $handle = open($new_file, :w); > $handle.print($skeleton); > > opens the "grave" file, but leaves it empty. A last line: > > close($handle);# "close()" generates an error message. > > is required to get any contents in the file, unlike the equivalent Perl 5 > code: That's because Rakudo isn't yet able to execute any code (like a DESTROY method in Perl 5) when the garbage collector detects that an object is not referenced anywhere anymore. So it's a limitation in Rakudo, not a change in the language. An intrinsic difference is that Perl 5 guarantees a timely execution of such methods (because it is reference counted), whereas Perl 6 does not. 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. Cheers, Moritz
Close($file) required in Perl 6, unlike Perl 5
The following program: my $skeleton = "bones\n"; my $new_file = "grave"; my $handle = open($new_file, :w); $handle.print($skeleton); opens the "grave" file, but leaves it empty. A last line: close($handle);# "close()" generates an error message. is required to get any contents in the file, unlike the equivalent Perl 5 code: my $skeleton = "bones\n"; my $new_file = "grave"; open(my $handle, ">", $new_file) or die "$!"; print $handle $skeleton; This might be a perfectly reasonable design decision, but I haven't noticed it mentioned.