This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv.c:sv_grow: accept read-only COWs
authorFather Chrysostomos <sprout@cpan.org>
Sun, 11 Aug 2013 21:38:08 +0000 (14:38 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 12 Aug 2013 08:53:26 +0000 (01:53 -0700)
sv_grow has long been permitted on read-only scalars.  This stopped
being the case all the time when 9a0a85075 and 1620522e4 allowed read-
nly copy-on-write scalars.  Because sv_force_normal has multiple
uses, sv_grow ended up croaking on *these* read-only scalars, but
not others.

This commit makes things consistent with the way they used to be.

sv.c

diff --git a/sv.c b/sv.c
index 593f942..de0831c 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -1470,6 +1470,8 @@ Use the C<SvGROW> wrapper instead.
 =cut
 */
 
+static void S_sv_uncow(pTHX_ SV * const sv, const U32 flags);
+
 char *
 Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen)
 {
@@ -1502,7 +1504,7 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen)
     }
     else
     {
-       if (SvIsCOW(sv)) sv_force_normal(sv);
+       if (SvIsCOW(sv)) S_sv_uncow(aTHX_ sv, 0);
        s = SvPVX_mutable(sv);
     }
 
@@ -3256,8 +3258,6 @@ especially if it could return the position of the first one.
 
 */
 
-static void S_sv_uncow(pTHX_ SV * const sv, const U32 flags);
-
 STRLEN
 Perl_sv_utf8_upgrade_flags_grow(pTHX_ SV *const sv, const I32 flags, STRLEN extra)
 {