From 49b3432a7438e964c8fc187b40c147293b929233 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 28 Dec 2016 14:05:43 +0000 Subject: [PATCH] Allow sv = &PL_sv_undef; sv_set_undef(sv) to work 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). --- sv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sv.c b/sv.c index e3026f7..83d82fc 100644 --- a/sv.c +++ b/sv.c @@ -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)) -- 1.8.3.1