pp_ctl.c: pp_caller UTF8 cleanup.

This commit is contained in:
Brian Fraser 2011-09-26 15:32:45 -07:00 committed by Father Chrysostomos
parent 1bac5ecc10
commit d527ce7c36
3 changed files with 82 additions and 7 deletions

View File

@ -5234,6 +5234,7 @@ t/test.pl Simple testing library
t/thread_it.pl Run regression tests in a new thread
t/uni/bless.t See if Unicode bless works
t/uni/cache.t See if Unicode swash caching works
t/uni/caller.t See if Unicode doesn't get mangled in caller()
t/uni/case.pl See if Unicode casing works
t/uni/chomp.t See if Unicode chomp works
t/uni/chr.t See if Unicode chr works

View File

@ -1869,7 +1869,7 @@ PP(pp_caller)
register const PERL_CONTEXT *cx;
const PERL_CONTEXT *dbcx;
I32 gimme;
const char *stashname;
const HEK *stash_hek;
I32 count = 0;
bool has_arg = MAXARG && TOPs;
@ -1888,14 +1888,14 @@ PP(pp_caller)
RETURN;
}
stashname = CopSTASHPV(cx->blk_oldcop);
stash_hek = HvNAME_HEK((HV*)CopSTASH(cx->blk_oldcop));
if (GIMME != G_ARRAY) {
EXTEND(SP, 1);
if (!stashname)
if (!stash_hek)
PUSHs(&PL_sv_undef);
else {
dTARGET;
sv_setpv(TARG, stashname);
sv_sethek(TARG, stash_hek);
PUSHs(TARG);
}
RETURN;
@ -1903,10 +1903,13 @@ PP(pp_caller)
EXTEND(SP, 11);
if (!stashname)
if (!stash_hek)
PUSHs(&PL_sv_undef);
else
mPUSHs(newSVpv(stashname, 0));
else {
dTARGET;
sv_sethek(TARG, stash_hek);
PUSHTARG;
}
mPUSHs(newSVpv(OutCopFILE(cx->blk_oldcop), 0));
mPUSHi((I32)CopLINE(cx->blk_oldcop));
if (!has_arg)

71
t/uni/caller.t Normal file
View File

@ -0,0 +1,71 @@
#!./perl
# Tests for caller()
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
plan( tests => 18 );
}
use utf8;
use open qw( :utf8 :std );
package ;
{
local $@;
eval 'ok(1);';
::like $@, qr/Undefined subroutine &::ok called at/u;
}
my @c;
sub { @c = caller(0) } -> ();
::is( $c[3], "::__ANON__", "anonymous subroutine name" );
::ok( $c[4], "hasargs true with anon sub" );
# Bug 20020517.003, used to dump core
sub { @c = caller(0) }
my $fooref = delete $::{};
$fooref -> ();
::is( $c[3], "::__ANON__", "deleted subroutine name" );
::ok( $c[4], "hasargs true with deleted sub" );
print "# Tests with caller(1)\n";
sub { @c = caller(1) }
sub { (); }
();
::is( $c[3], "::", "subroutine name" );
::ok( $c[4], "hasargs true with ()" );
&;
::ok( !$c[4], "hasargs false with &" );
eval { () };
::is( $c[3], "(eval)", "subroutine name in an eval {}" );
::ok( !$c[4], "hasargs false in an eval {}" );
eval q{ () };
::is( $c[3], "(eval)", "subroutine name in an eval ''" );
::ok( !$c[4], "hasargs false in an eval ''" );
sub { () } -> ();
::is( $c[3], "::__ANON__", "anonymous subroutine name" );
::ok( $c[4], "hasargs true with anon sub" );
sub 2 { () }
my $fooref2 = delete $::{2};
$fooref2 -> ();
::is( $c[3], "::__ANON__", "deleted subroutine name" );
::ok( $c[4], "hasargs true with deleted sub" );
sub { return (caller(0))[3] }
::is( eval '()', '::', "actually return the right function name" );
my $saved_perldb = $^P;
$^P = 16;
$^P = $saved_perldb;
::is( eval '()', '::', 'actually return the right function name even if $^P had been on at some point' );