Skip to content

Commit

Permalink
Allow sv = &PL_sv_undef; sv_set_undef(sv) to work
Browse files Browse the repository at this point in the history
RT #130385

Technically

    sv = &PL_sv_undef;
    ....
    sv_set_undef(sv)

is modifying a read-only variable and so should croak, but some XS code
relies on the behaviour previous to the introduction of sv_set_undef(),
where:

    sv = &PL_sv_undef;
    ....
    sv_setsv(sv, &PL_undef)

silently succeeds (sv_setsv() returns immediately if src and dst
addresses are the same).
  • Loading branch information
iabyn committed Dec 28, 2016
1 parent 33f1827 commit 49b3432
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4808,8 +4808,13 @@ Perl_sv_set_undef(pTHX_ SV *sv)

if (type <= SVt_IV) {
assert(!SvGMAGICAL(sv));
if (SvREADONLY(sv))
if (SvREADONLY(sv)) {
/* does undeffing PL_sv_undef count as modifying a read-only
* variable? Some XS code does this */
if (sv == &PL_sv_undef)
return;
Perl_croak_no_modify();
}

if (SvROK(sv)) {
if (SvWEAKREF(sv))
Expand Down

0 comments on commit 49b3432

Please sign in to comment.