summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorJohn Tobey <jtobey@john-edwin-tobey.org>2000-10-20 18:03:27 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2000-10-21 14:26:45 +0000
commitbeab0874143b7208922720fecefc4a224011fa25 (patch)
tree3abffe8c491d477f0bb7cd037866ba7485ef9ee5 /sv.c
parent3a67c0c7529c0500df7fe90b2c6269508a51be07 (diff)
downloadperl-beab0874143b7208922720fecefc4a224011fa25.tar.gz
Re: Creating const subs for constants.
Message-Id: <m13mo0N-000FObC@feynman.localnet> p4raw-id: //depot/perl@7389
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/sv.c b/sv.c
index b795b299f3..148c7624c8 100644
--- a/sv.c
+++ b/sv.c
@@ -2745,12 +2745,7 @@ Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr)
if (!GvCVGEN((GV*)dstr) &&
(CvROOT(cv) || CvXSUB(cv)))
{
- SV *const_sv = cv_const_sv(cv);
- bool const_changed = TRUE;
- if(const_sv)
- const_changed = sv_cmp(const_sv,
- op_const_sv(CvSTART((CV*)sref),
- (CV*)sref));
+ SV *const_sv;
/* ahem, death to those who redefine
* active sort subs */
if (PL_curstackinfo->si_type == PERLSI_SORT &&
@@ -2758,11 +2753,20 @@ Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr)
Perl_croak(aTHX_
"Can't redefine active sort subroutine %s",
GvENAME((GV*)dstr));
- if ((const_changed && const_sv) || ckWARN(WARN_REDEFINE))
- Perl_warner(aTHX_ WARN_REDEFINE, const_sv ?
- "Constant subroutine %s redefined"
- : "Subroutine %s redefined",
- GvENAME((GV*)dstr));
+ /* Redefining a sub - warning is mandatory if
+ it was a const and its value changed. */
+ if (ckWARN(WARN_REDEFINE)
+ || (CvCONST(cv)
+ && (!CvCONST((CV*)sref)
+ || sv_cmp(cv_const_sv(cv),
+ cv_const_sv((CV*)sref)))))
+ {
+ Perl_warner(aTHX_ WARN_REDEFINE,
+ CvCONST(cv)
+ ? "Constant subroutine %s redefined"
+ : "Subroutine %s redefined",
+ GvENAME((GV*)dstr));
+ }
}
cv_ckproto(cv, (GV*)dstr,
SvPOK(sref) ? SvPVX(sref) : Nullch);