This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get PerlIO::scalar to write to COWs
[perl5.git] / ext / PerlIO-scalar / scalar.xs
index e081c17..de98738 100644 (file)
@@ -22,9 +22,10 @@ PerlIOScalar_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg,
      * using, otherwise arg (from binmode presumably) is either NULL
      * or the _name_ of the scalar
      */
-    if (arg) {
+    if (arg && SvOK(arg)) {
        if (SvROK(arg)) {
-           if (SvREADONLY(SvRV(arg)) && mode && *mode != 'r') {
+           if (SvREADONLY(SvRV(arg)) && !SvIsCOW(SvRV(arg))
+            && mode && *mode != 'r') {
                if (ckWARN(WARN_LAYER))
                    Perl_warner(aTHX_ packWARN(WARN_LAYER), "%s", PL_no_modify);
                SETERRNO(EINVAL, SS_IVCHAN);