Skip to content

Commit cd84df2

Browse files
tonycozmauke
authored andcommitted
debugger source lines: use PVIV instead of PVMG for source lines
These were saved as PVMG but as bulk88 suggested in #23171 (comment) we only need PVIV, since the source lines don't need magic, aren't blessed and store an integer, not an NV. So create them as PVIV instead. If it turns out we do need PVMG instead for some future use, simply remove the test added here, it's simply to confirm we don't need PVMG here.
1 parent 35b2045 commit cd84df2

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

pp_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3735,7 +3735,7 @@ S_save_lines(pTHX_ AV *array, SV *sv)
37353735

37363736
while (s && s < send) {
37373737
const char *t;
3738-
SV * const tmpstr = newSV_type(SVt_PVMG);
3738+
SV * const tmpstr = newSV_type(SVt_PVIV);
37393739

37403740
t = (const char *)memchr(s, '\n', send - s);
37413741
if (t)

t/op/debug.t

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,64 @@ EXPECT
6161
);
6262
}
6363

64+
SKIP:
65+
{
66+
# Historically lines were stored as PVMG, but we don't need
67+
# magic on these lines.
68+
#
69+
# This checks that none of these lines get upgraded, ie. that
70+
# we don't need them to be PVMG
71+
#
72+
# If this test fails perhaps we do need to make them PVMG
73+
# and toke.c:S_update_debugger_info and pp_ctl.c:S_save_lines
74+
# can be switched back to using SVt_PVMG and this test
75+
# removed.
76+
#
77+
# See https://github.com/Perl/perl5/pull/23171#issuecomment-2780007725
78+
skip_if_miniperl("need B");
79+
local $ENV{PERL5DB} = 'sub DB::DB {}';
80+
fresh_perl_is(<<'CODE', <<'EXPECT',
81+
use B;
82+
83+
sub _do_eval {
84+
eval $_[0] or die $!;
85+
}
86+
87+
_do_eval(<<'EVAL');
88+
89+
sub some_code {
90+
print "Hello";
91+
}
92+
93+
1;
94+
EVAL
95+
96+
# check if any lines have been upgraded from PVIV
97+
my @files = grep /^_</, keys %::;
98+
for my $f (@files) {
99+
my $lineno = 0;
100+
101+
for my $l (@{$f}) {
102+
if ($l) {
103+
my $b = B::svref_2object(\$l);
104+
if (ref $b ne "B::PVIV") {
105+
print "Not PVIV for $f:$lineno: $l\n";
106+
last
107+
}
108+
}
109+
++$lineno;
110+
}
111+
}
112+
print "Done\n";
113+
CODE
114+
Done
115+
EXPECT
116+
{
117+
switches => [ '-d' ],
118+
stderr => 1,
119+
},
120+
"saved lines are all PVIV"
121+
);
122+
}
123+
64124
done_testing();

toke.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,10 +2012,11 @@ S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
20122012
AV *av = CopFILEAVx(PL_curcop);
20132013
if (av) {
20142014
SV * sv;
2015-
if (PL_parser->preambling == NOLINE) sv = newSV_type(SVt_PVMG);
2015+
if (PL_parser->preambling == NOLINE)
2016+
sv = newSV_type(SVt_PVIV);
20162017
else {
20172018
sv = *av_fetch(av, 0, 1);
2018-
SvUPGRADE(sv, SVt_PVMG);
2019+
SvUPGRADE(sv, SVt_PVIV);
20192020
}
20202021
if (!SvPOK(sv)) SvPVCLEAR(sv);
20212022
if (orig_sv)

0 commit comments

Comments
 (0)