develooper Front page | perl.perl5.porters | Postings from November 2014

[perl #123145] gv_const_sv broken in blead, suspect is 2eaf799e

From:
James E Keenan via RT
Date:
November 15, 2014 00:51
Subject:
[perl #123145] gv_const_sv broken in blead, suspect is 2eaf799e
Message ID:
rt-4.0.18-10855-1416012665-700.123145-15-0@perl.org
On Thu Nov 06 16:22:29 2014, sortiz wrote:
> 
> This is a bug report for perl from sog@msg.com.mx,
> generated with the help of perlbug 1.40 running under perl 5.21.6.
> 
> 
> Not used in core but gv_const_sv is documented to return NULL unless
> the passed
> GV references an inlineable subroutine, but after FC's commit 2eaf799e
> "Avoid creating GVs when subs are declared" it returns the CV unless
> the sub is
> declared with an explicit package.
> 
> I think that gv_const_sv should be fixed, and the changes in the stash
> content
> prominently documented.
> 
> Compare what is produced by the attached test in  <= 5.20.1 vs blead.
> 
> --
> sortiz
> 
> ======
> #!/usr/bin/perl
> 
> use Inline C => <<'END_OF_CODE';
> 
> void gv_const_test(SV *name) {
>     GV *gv;
>     if(SvTYPE(name) == SVt_PV) {
>         HV *stash = gv_stashpv("main",0);
>         HE *he = hv_fetch_ent(stash, name, 0, 0);
>         gv = (GV *)HeVAL(he);
>     }
>     else gv = (GV *)name;
>     if(SvROK(gv)) warn("Glob %s reftype:
> %d\n",SvPV_nolen(gv),SvTYPE(SvRV(gv)));
>     SV *sv = gv_const_sv(gv);
>     if(sv) {
>         warn("%s is constant: %s\n", SvPV_nolen(name),
> SvPV_nolen(sv));
>     } else {
>         warn("%s isn't constant.\n", SvPV_nolen(name));
>     }
> }
> 
> END_OF_CODE
> 
> sub one () { 1; }
> sub baz () { "baz"; }
> sub meth { my $self = shift; return $self; }
> sub main::foo { };
> 
> gv_const_test($_) for qw(one baz meth foo);
> gv_const_test($::{$_}) for qw(one baz meth foo);
> gv_const_test(*{$_}) for qw(one baz meth foo);
> 
> __END__

Data from running the OP's program on perl-5.20.1 and on blead:

#####
$ perl -v | head -2 | tail -1
This is perl 5, version 20, subversion 1 (v5.20.1) built for x86_64-linux

$ perl 123145.pl 
one is constant: 1
baz is constant: baz
meth isn't constant.
foo isn't constant.
*main::one is constant: 1
*main::baz is constant: baz
*main::meth isn't constant.
*main::foo isn't constant.
*main::one is constant: 1
*main::baz is constant: baz
*main::meth isn't constant.
*main::foo isn't constant.
#####
$ ./bin/perl -v | head -2 | tail -1

This is perl 5, version 21, subversion 6 (v5.21.6 (v5.21.5-462-g0d71ffa)) built for x86_64-linux

$ ./bin/perl -Ilib /home/jkeenan/learn/perl/p5p/123145.pl 
Glob SCALAR(0xf97dd8) reftype: 1
one is constant: 1
Glob SCALAR(0xf97da8) reftype: 3
baz is constant: baz
Glob CODE(0xf97d78) reftype: 13
meth is constant: 
foo isn't constant.
Glob SCALAR(0xf97dd8) reftype: 5
SCALAR(0xf97dd8) is constant: 1
Glob SCALAR(0xf97da8) reftype: 3
SCALAR(0xf97da8) is constant: baz
Glob CODE(0xf97d78) reftype: 13
CODE(0xf97d78) is constant: 
*main::foo isn't constant.
*main::one is constant: 1
*main::baz is constant: baz
*main::meth isn't constant.
*main::foo isn't constant.
#####

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=123145



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