This Week on perl5-porters (28 June / 4 July 2004)

This Week on perl5-porters (28 June / 4 July 2004)

This was a week rich in discussion. Read about programming with threads, UTF-8 crashes and leaks (and fixes), parsing, globbing, deparsing, and other things.

Destructors and ithreads

Eric Garland shares his thoughts about how destructors work with ithreads. Destructors are mostly used to free some external resources (managed by a library) and thus should be run in most cases at application exit time (and not at thread destruction time). Thus, with the current implementation of desctructors (where objects are cloned among threads and destroyed when the thread ends), destructors should refcount external resources by hand and free them only at appropriately late times.

Elizabeth Mattijsen submits a pure perl solution, that uses CLONE() (and says that it's probably too late to change the meaning of destructors in perl.) Eric proposes to make variables selectively cloneable. Dave Mitchell points out that it would be impractical.

Stas Bekman wishes that, in addition of being a class method, CLONE() could be also called on each object that can() CLONE() at thread creation time. This would be easier than maintaining by hand a list of weak references to each object created. Nicholas Clark proposes to call the class method CLONE() with all objects into @_, which could be cumbersome if there are lots of objects. Dave wonders about the potential problems that would be caused by inheritance.

B::Deparse and postponed for() scoping

Torsten Hofmann reports that the following construct is not handled correctly by B::Deparse, due to the scoping of the lexicals : (bug #30504)

    do_something() for my ($foo, $bar, $baz);

Stephen McCamant sent a proof-of-concept patch. Yves Orton asked about the deparsing of my $foo if 0, to which Rafael answered that B::Deparse had no easy way to reconstruct the original code -- which corresponds to a deprecated construct anyway.

Memory leak with eq and UTF-8

Bug #30509, about the string comparison operator eq leaking memory with UTF-8 strings in a function defined before the encoding module is loaded, was promptly fixed by Dave Mitchell.

UTF8 stack crash in Safe compartments

Dave also fixed bug #30258, which was reported a couple of weeks ago: perl panics when one tries to use split() on an UTF-8 string from an Safe compartment.

Parser corruption

Andrew Pimlott produced a malformed program that causes memory corruption in the parser. This doesn't happen in bleadperl, since byacc has been replaced by bison in it. (Bug #30518.)

More parsing

Peter Dintelmann finds out that keys %! produces a warning, Use of "keys" without parentheses is ambiguous. Rafael says that this kind of warning is implemented by heuristics that only try to be accurate in most cases. Nicholas finds that the % is optional for the argument of keys().

File::Glob and shell idioms

Jaap Karssenberg reports (bug #30553) some oddities about the behavior of File::Glob regarding brace expansion (th{is,at}), existing files, and options; notably when there is only one item between the braces. Rafael points out that the underlying implementation conforms to BSD standards (in fact it's ripped from OpenBSD) and that he's not very surprised by the current behaviour (see the mails for details.)

Magic and lvalues

Bug #30582 demonstrates that you can't return an hash element from an lvalue subroutine when the hash has magic attached to it.

Splicing oneself

Glenn Linderman provided an example of splice() that doesn't produce the intuitive result (bug #30568) :

    @stk = ( 1, 2, 3 ); splice @stk, -2, 2, $stk[ -2 ];

Dave Mitchell explains what happens behind the scenes. Ton Hospel comments that it maybe hasn't to be fixed, since strictly speaking it's like using $i + $i++. Wolfgang Laun tweaks the above code so that it produces a segfault.

Dup'ing PerlIO handles between different layers

Stas Bekman says that he's unable to convert an existing perlio handle into one that is handled by a different perlio layer which requires extra arguments to open. More precisely,

    open my $fh2, "<&:crlf", $fh or die $!;

works, whereas

    open my $fh2, "<&:APR", $fh, $p;

doesn't (note the extra argument.) Nick Ing-Simmons suggests another way to do it, more correct regarding the language, but this other way is yet to be implemented.


Nicholas Clark posted a first draft of the perldelta for perl 5.8.5.

Rafael uploaded a new version of Safe to the CPAN, incorporating the latest fixes in bleadperl.

Marcus Holland-Moritz glanced at microperl.

Uri Azoulay is trying to build perl on some more or less exotic systems (HP-UX 11.00, AIX, OSF).

About this summary

This summary was written by Rafael Garcia-Suarez. Weekly summaries are published on and posted on a mailing list, which subscription address is Comments and corrections welcome.