In S_doparseform(), don't force the pattern to a string. This resolves #79532
authorNicholas Clark <nick@ccl4.org>
Mon, 2 May 2011 11:37:30 +0000 (12:37 +0100)
committerNicholas Clark <nick@ccl4.org>
Wed, 18 May 2011 18:11:03 +0000 (19:11 +0100)
Previously S_doparseform() was using SvPV_force(), because the pattern had to
be forced to a string, because the compiled format was stored in the string's
buffer. Now that the compiled format is stored in the magic struct, this isn't
necessary.

Additionally, removing the call to SvPV_force() removes the need to hack with
the SvREADONLY() flag in pp_formline.

pp_ctl.c
t/op/write.t

index 28e258b..a30e16d 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -554,13 +554,7 @@ PP(pp_formline)
     }
 
     if(!mg) {
-       if (SvREADONLY(tmpForm)) {
-           SvREADONLY_off(tmpForm);
-           mg = doparseform(tmpForm);
-           SvREADONLY_on(tmpForm);
-       }
-       else
-           mg = doparseform(tmpForm);
+       mg = doparseform(tmpForm);
        assert(mg);
     }
     fpc = (U32*)mg->mg_ptr;
@@ -4923,7 +4917,7 @@ static MAGIC *
 S_doparseform(pTHX_ SV *sv)
 {
     STRLEN len;
-    register char *s = SvPV_force(sv, len);
+    register char *s = SvPV(sv, len);
     register char * const send = s + len;
     register char *base = NULL;
     register I32 skipspaces = 0;
index b19db71..36cb2ad 100644 (file)
@@ -61,7 +61,7 @@ for my $tref ( @NumTests ){
 my $bas_tests = 20;
 
 # number of tests in section 3
-my $bug_tests = 4 + 3 * 3 * 5 * 2 * 3 + 2 + 2 + 1;
+my $bug_tests = 4 + 3 * 3 * 5 * 2 * 3 + 2 + 2 + 1 + 1;
 
 # number of tests in section 4
 my $hmb_tests = 35;
@@ -639,6 +639,15 @@ format =
 write;
 EOP
 
+fresh_perl_is(<<'EOP', ">ARRAY<\ncrunch_eth\n", {stderr => 1}, '#79532 - formline coerces its arguments');
+use strict;
+use warnings;
+my $zamm = ['crunch_eth'];
+formline $zamm;
+printf ">%s<\n", ref $zamm;
+print "$zamm->[0]\n";
+EOP
+
 #############################
 ## Section 4
 ## Add new tests *above* here