In a nutshell, the forks pragma is a drop-in replacement for ithreads, useful primarily for
non-threaded perl builds (including Perl 5.6.x) or for scripts that wish to use ithreads but
have memory growth/leak issues when using CPAN modules with native ithreads.
To accomplish this, one of the features it must support is the 'shared' attribute to emulate
threads::shared variable declaration behavior. Attribute declaration is currently handled
using CPAN Attribute::Handlers, which in turn depends on Perl core distribution
attribute.pm.
The issue is that there was a small bug since perl 5.8.0 that allowed the otherwise reserved
'shared' attribute name to "leak" out to custom attribute handlers, as described here:
http://www.nntp.perl.org/group/perl.perl5.porters/2006/08/msg115950.html
The core patch, already included in Perl 5.10.0, is referenced here:
http://archives.devshed.com/forums/perl-102/change-28753-don-t-promulgate-perl-
attributes-1951997.html
This behavior change "broke" the CPAN forks::shared module on perl 5.10.0 and now also
Perl 5.8.8 patched maintenance builds that include this patch (I assume intended to be
included in Perl 5.8.9). The initial workaround was to use a source filter to re-write all '$var :
shared' as '$var : Forks_shared', such that the attribute could be trapped by a custom
attribute handler.
Due to the usual dangers & limitations associations with source filters, I've recently rewritten
this (not yet released) to override the internal function that Perl depends on to handle
reserved attribute names, like the following:
{
my $old = \&attributes::_modify_attrs;
no warnings 'redefine';
*attributes::_modify_attrs = sub {
my ($ref, @attr) = @_;
return ($old->(@_), (grep(/^shared$/o, @attr) ? 'Forks_shared' : ()));
};
}
Personally, I wish there were an interface to override the now trapped 'shared' attribute, like
what has been available in Perl 5.6 & 5.8. Perhaps some sort of boolean flag interface in
attribute.pm, like:
attributes::configure(&attributes::ALLOW_RESERVED_ATTR ||
&attributes::NO_RESERVED_ATTR_WARNINGS)
that allows reserved attributes to be returned to custom handlers (and also prevents them
from throwing spurious usage warnings throughout user code when use warnings 'reserved'
or $^W==1).
Regards,
Eric
On Thu Oct 02 09:41:54 2008, nick@ccl4.org wrote:
Show quoted text> On Wed, Oct 01, 2008 at 11:37:57AM -0400, Eric Rybski via RT wrote:
> 30039 as already
> > implemented for perl 5.9.x and later (5.10.x).
> >
> > I wish there were a more elegant way to hook into "reserved word"
> attributes, other than a
> > source filter. Any suggestions would be appreciated. Used to be
> trivial to overload when the
> > 'shared' attribute was passed in the handler chain.
>
> The bug report on rt.cpan.org references CPAN testers, and in turn
> that
> contains fail reports, but I don't find any actual description of what
> the
> cause is, or why.
>
> So it's not clear to me - is this a legitimate bug fix, which fixes a
> bug
> that code happened to be relying on? Or is it actually a bad idea?
>
> Nicholas Clark