sv_unref(sv);
(void)SvUPGRADE(sv, SVt_PV);
tmplen = SvLEN(sv); /* remember if already alloced */
- if (!tmplen)
+ if (!tmplen && !SvREADONLY(sv))
Sv_Grow(sv, 80); /* try short-buffering it */
offset = 0;
if (type == OP_RCATLINE && SvOK(sv)) {
newlen = 0xFFFF;
#endif
}
- else {
- /* This is annoying, because sv_force_normal_flags will fix the flags,
- recurse into sv_grow to malloc a buffer of SvCUR(sv) + 1, then
- return back to us, only for us to potentially realloc the buffer.
- */
- if (SvIsCOW(sv))
- sv_force_normal_flags(sv, 0);
+ else
s = SvPVX(sv);
- }
if (newlen > SvLEN(sv)) { /* need more room? */
if (SvLEN(sv) && s) {
I32 rspara = 0;
I32 recsize;
- SV_CHECK_THINKFIRST_COW_DROP(sv);
+ if (SvTHINKFIRST(sv))
+ sv_force_normal_flags(sv, append ? 0 : SV_COW_DROP_PV);
/* XXX. If you make this PVIV, then copy on write can copy scalars read
from <>.
However, perlbench says it's slower, because the existing swipe code
require './test.pl';
}
-plan tests => 5;
+plan tests => 11;
eval { for (\2) { $_ = <FH> } };
like($@, 'Modification of a read-only value attempted', '[perl #19566]');
);
is ($result, "end", '[perl #21614] for length ' . length $k);
}
+
+
+foreach my $k ('perl', 'perl'x21) {
+ my $result
+ = runperl (switches => '-l', stdin => ' rules', stderr => 1,
+ prog => "%a = qw($k v); foreach (keys %a) {\$_ .= <>; print}",
+ );
+ is ($result, "$k rules", 'rcatline to shared sv for length ' . length $k);
+}
+
+foreach my $l (1, 82) {
+ my $k = $l;
+ $k = 'k' x $k;
+ my $copy = $k;
+ $k = <DATA>;
+ is ($k, "moo\n", 'catline to COW sv for length ' . length $copy);
+}
+
+
+foreach my $l (1, 21) {
+ my $k = $l;
+ $k = 'perl' x $k;
+ my $perl = $k;
+ $k .= <DATA>;
+ is ($k, "$perl rules\n", 'rcatline to COW sv for length ' . length $perl);
+}
+__DATA__
+moo
+moo
+ rules
+ rules