From 11609d9c96f9c025675f6215051ab94d6735ddd9 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 6 Aug 2013 06:08:21 -0700 Subject: [PATCH] [perl #119169] index with __PACKAGE__ for 2nd argument MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The refactoring of fbm_compile in 66379c06cd to prepare for c72a4eedff1 put in an SvIsCOW check before doing SvPV_force. I sim- ply changed the logic there so that SvPV_force would continue to have its effect but without tripping up on read-only variables for which SvPV_force would not need to make any changes anyway. Now, if a COW scalar is read-only, we can’t call SvPV_force on it, because it will die. It turns out that we don’t actually need to call SvPV_force on COWs. We can just go ahead and attach the BM magic and continue sharing the buffer. --- t/op/index.t | 5 ++++- util.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/t/op/index.t b/t/op/index.t index d534053..eaed4b3 100644 --- a/t/op/index.t +++ b/t/op/index.t @@ -7,7 +7,7 @@ BEGIN { } use strict; -plan( tests => 120 ); +plan( tests => 121 ); run_tests() unless caller; @@ -248,4 +248,7 @@ use constant u => undef; } is u, undef, 'undef constant is still undef'; +is index('the main road', __PACKAGE__), 4, + '[perl #119169] __PACKAGE__ as 2nd argument'; + } # end of sub run_tests diff --git a/util.c b/util.c index be75796..316f45d 100644 --- a/util.c +++ b/util.c @@ -539,7 +539,7 @@ Perl_fbm_compile(pTHX_ SV *sv, U32 flags) if (mg && mg->mg_len >= 0) mg->mg_len++; } - if (!SvPOK(sv) || SvNIOKp(sv) || SvIsCOW(sv)) + if (!SvPOK(sv) || SvNIOKp(sv)) s = (U8*)SvPV_force_mutable(sv, len); else s = (U8 *)SvPV_mutable(sv, len); if (len == 0) /* TAIL might be on a zero-length string. */ -- 1.8.3.1