develooper Front page | perl.perl5.porters | Postings from December 2021

Re: "no snails"; or having signatured subs complain about @_

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
December 8, 2021 20:40
Subject:
Re: "no snails"; or having signatured subs complain about @_
Message ID:
YbEYO9CsxoKw2SeA@etla.org
On Tue, Dec 07, 2021 at 12:28:20AM +0000, Paul "LeoNerd" Evans wrote:
> I now have a partial attack on this, on a branch
> 
>   https://github.com/leonerd/perl5/tree/no-snails

> Actually rather than a tied array (because tie is so annoying to create
> from inside core), I just created a new kind of magic; "forbid" magic.
> This totally disallows any kind of access - all of its magic vtable
> calls immediately croak.

That's a better solution than mine.

> And already this code has caught something. I can't even build perl
> right now, because the build system makes miniperl and then uses
> miniperl to build the unicore tables, getting as far as:
> 
> ./miniperl -Ilib lib/unicore/mktables -C lib/unicore -P pod -maketest -makelist -p
> Access to the @_ variable is forbidden (lenmagic) at lib/unicore/mktables line 1983.
> make: *** [makefile:408: uni.data] Error 25
> 
> Hah! It really works :)

Nice.

> Lets peek at the source code:
> 
>   1883      sub set_access($name, $field, @accessors) {
> ...
>   1983                  if (grep { /^a/i } @_
>   1984                      or length($access) > length('readable_'))
> 
> Inside a real signatured sub, we already have code that tries to access
> @_. Oops.
> 
> I suspect this code is supposed to read one of
> 
>   if(grep { /^a/i } @accessors
> 
> or
> 
>   if(grep { /^a/i } ($name, $field, @accessors)
> 
> but I can't immediately tell from context which. Perhaps someone

which is interesting, because effectively this new strictness has found
a bug.

(Rather than a missing feature - this isn't about the value of scalar @_
to determine how many arguments were passed/which are defaults)

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About