This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add MUTABLE_CV(), and eliminate (CV *) casts in *.c.
[perl5.git] / gv.c
diff --git a/gv.c b/gv.c
index fa01807..7d737de 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1,7 +1,7 @@
 /*    gv.c
  *
- *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- *    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, by Larry Wall and others
+ *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+ *    2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -602,6 +602,8 @@ S_gv_get_super_pkg(pTHX_ const char* name, I32 namelen)
 GV *
 Perl_gv_fetchmethod_autoload(pTHX_ HV *stash, const char *name, I32 autoload)
 {
+    PERL_ARGS_ASSERT_GV_FETCHMETHOD_AUTOLOAD;
+
     return gv_fetchmethod_flags(stash, name, autoload ? GV_AUTOLOAD : 0);
 }
 
@@ -620,10 +622,15 @@ Perl_gv_fetchmethod_flags(pTHX_ HV *stash, const char *name, U32 flags)
     const U32 autoload = flags & GV_AUTOLOAD;
     const U32 do_croak = flags & GV_CROAK;
 
-    PERL_ARGS_ASSERT_GV_FETCHMETHOD_AUTOLOAD;
+    PERL_ARGS_ASSERT_GV_FETCHMETHOD_FLAGS;
 
-    if (stash && SvTYPE(stash) < SVt_PVHV)
+    if (SvTYPE(stash) < SVt_PVHV)
        stash = NULL;
+    else {
+       /* The only way stash can become NULL later on is if nsplit is set,
+          which in turn means that there is no need for a SVt_PVHV case
+          the error reporting code.  */
+    }
 
     for (nend = name; *nend; nend++) {
        if (*nend == '\'') {
@@ -671,20 +678,15 @@ Perl_gv_fetchmethod_flags(pTHX_ HV *stash, const char *name, U32 flags)
            if (stash) {
                Perl_croak(aTHX_
                           "Can't locate object method \"%s\" via package \"%.*s\"",
-                          name, HvNAMELEN_get(stash), HvNAME_get(stash));
+                          name, (int)HvNAMELEN_get(stash), HvNAME_get(stash));
            }
            else {
                STRLEN packlen;
                const char *packname;
 
-               assert(error_report);
-
                if (nsplit) {
                    packlen = nsplit - origname;
                    packname = origname;
-               } else if (SvTYPE(error_report) == SVt_PVHV) {
-                   packlen = HvNAMELEN_get(error_report);
-                   packname = HvNAME_get(error_report);
                } else {
                    packname = SvPV_const(error_report, packlen);
                }
@@ -1509,7 +1511,7 @@ Perl_newIO(pTHX)
     /* unless exists($main::{FileHandle}) and defined(%main::FileHandle::) */
     if (!(iogv && GvHV(iogv) && HvARRAY(GvHV(iogv))))
       iogv = gv_fetchpvs("IO::Handle::", GV_ADD, SVt_PVHV);
-    SvSTASH_set(io, (HV*)SvREFCNT_inc(GvHV(iogv)));
+    SvSTASH_set(io, MUTABLE_HV(SvREFCNT_inc(GvHV(iogv))));
     return io;
 }
 
@@ -1762,10 +1764,10 @@ Perl_Gv_AMupdate(pTHX_ HV *stash)
            if (i < DESTROY_amg)
                have_ovl = 1;
        } else if (gv) {                /* Autoloaded... */
-           cv = (CV*)gv;
+           cv = MUTABLE_CV(gv);
            filled = 1;
        }
-       amt.table[i]=(CV*)SvREFCNT_inc_simple(cv);
+       amt.table[i]=MUTABLE_CV(SvREFCNT_inc_simple(cv));
     }
     if (filled) {
       AMT_AMAGIC_on(&amt);
@@ -1920,7 +1922,7 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
                   Hence we can't use SvAMAGIC_on()
                */
                SvFLAGS(newref) |= SVf_AMAGIC;
-               SvSTASH_set(newref, (HV*)SvREFCNT_inc(SvSTASH(tmpRef)));
+               SvSTASH_set(newref, MUTABLE_HV(SvREFCNT_inc(SvSTASH(tmpRef))));
                return newref;
             }
           }