From ba2fdce662d9a18bdc2020e77aeaf62e95c35c7c Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 2 Jan 2007 18:14:26 +0000 Subject: [PATCH] Copying to FORMATs should work (and not fail assertions if the value is floating point). Copying to ARRAYs and HASHes can't work and should croak. p4raw-id: //depot/perl@29666 --- pod/perldiag.pod | 5 +++++ sv.c | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index c219182..4651661 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -493,6 +493,11 @@ then tried to access that symbol via conventional Perl syntax. The access triggers Perl to autovivify that typeglob, but it there is no legal conversion from that type of reference to a typeglob. +=item Cannot copy to %s in %s + +(P) Perl detected an attempt to copy a value to an internal type that cannot +be directly assigned not. + =item Can only compress unsigned integers in pack (F) An argument to pack("w",...) was not an integer. The BER compressed diff --git a/sv.c b/sv.c index a98c70b..5f066c7 100644 --- a/sv.c +++ b/sv.c @@ -3489,7 +3489,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) dtype = SvTYPE(dstr); sflags = SvFLAGS(sstr); - if (dtype == SVt_PVCV) { + if (dtype == SVt_PVCV || dtype == SVt_PVFM) { /* Assigning to a subroutine sets the prototype. */ if (SvOK(sstr)) { STRLEN len; @@ -3499,9 +3499,16 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) Copy(ptr, SvPVX(dstr), len + 1, char); SvCUR_set(dstr, len); SvPOK_only(dstr); + SvFLAGS(dstr) |= sflags & SVf_UTF8; } else { SvOK_off(dstr); } + } else if (dtype == SVt_PVAV || dtype == SVt_PVHV) { + const char * const type = sv_reftype(dstr,0); + if (PL_op) + Perl_croak(aTHX_ "Cannot copy to %s in %s", type, OP_NAME(PL_op)); + else + Perl_croak(aTHX_ "Cannot copy to %s", type); } else if (sflags & SVf_ROK) { if (isGV_with_GP(dstr) && dtype == SVt_PVGV && SvTYPE(SvRV(sstr)) == SVt_PVGV) { -- 2.7.4