From: Nicholas Clark Date: Wed, 29 Oct 2008 23:20:01 +0000 (+0000) Subject: Add MUTABLE_IO(), and eliminate (IO *) casts in *.c. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a45c7426c93f17067d1734c68cb400246e1db490;p=p5sagit%2Fp5-mst-13.2.git Add MUTABLE_IO(), and eliminate (IO *) casts in *.c. p4raw-id: //depot/perl@34654 --- diff --git a/doio.c b/doio.c index b0dd4f2..5064705 100644 --- a/doio.c +++ b/doio.c @@ -1316,7 +1316,7 @@ Perl_my_stat(pTHX) goto do_fstat; } else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) { - io = (IO*)SvRV(sv); + io = MUTABLE_IO(SvRV(sv)); gv = NULL; goto do_fstat_have_io; } diff --git a/gv.c b/gv.c index 77c65a4..aa27f4a 100644 --- a/gv.c +++ b/gv.c @@ -1499,7 +1499,7 @@ Perl_newIO(pTHX) { dVAR; GV *iogv; - IO * const io = (IO*)newSV_type(SVt_PVIO); + IO * const io = MUTABLE_IO(newSV_type(SVt_PVIO)); /* This used to read SvREFCNT(io) = 1; It's not clear why the reference count needed an explicit reset. NWC */ diff --git a/handy.h b/handy.h index 32239b9..d488922 100644 --- a/handy.h +++ b/handy.h @@ -57,6 +57,7 @@ Null SV pointer. (No longer available when C is defined.) #define MUTABLE_AV(p) ((AV *)MUTABLE_PTR(p)) #define MUTABLE_CV(p) ((CV *)MUTABLE_PTR(p)) #define MUTABLE_HV(p) ((HV *)MUTABLE_PTR(p)) +#define MUTABLE_IO(p) ((IO *)MUTABLE_PTR(p)) #define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p)) /* XXX Configure ought to have a test for a boolean type, if I can diff --git a/perl.c b/perl.c index 7b8cd86..cca22c5 100644 --- a/perl.c +++ b/perl.c @@ -4554,7 +4554,7 @@ S_init_predump_symbols(pTHX) IoIFP(io) = PerlIO_stdin(); tmpgv = gv_fetchpvs("stdin", GV_ADD|GV_NOTQUAL, SVt_PV); GvMULTI_on(tmpgv); - GvIOp(tmpgv) = (IO*)SvREFCNT_inc_simple(io); + GvIOp(tmpgv) = MUTABLE_IO(SvREFCNT_inc_simple(io)); tmpgv = gv_fetchpvs("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); GvMULTI_on(tmpgv); @@ -4564,7 +4564,7 @@ S_init_predump_symbols(pTHX) setdefout(tmpgv); tmpgv = gv_fetchpvs("stdout", GV_ADD|GV_NOTQUAL, SVt_PV); GvMULTI_on(tmpgv); - GvIOp(tmpgv) = (IO*)SvREFCNT_inc_simple(io); + GvIOp(tmpgv) = MUTABLE_IO(SvREFCNT_inc_simple(io)); PL_stderrgv = gv_fetchpvs("STDERR", GV_ADD|GV_NOTQUAL, SVt_PVIO); GvMULTI_on(PL_stderrgv); @@ -4573,7 +4573,7 @@ S_init_predump_symbols(pTHX) IoOFP(io) = IoIFP(io) = PerlIO_stderr(); tmpgv = gv_fetchpvs("stderr", GV_ADD|GV_NOTQUAL, SVt_PV); GvMULTI_on(tmpgv); - GvIOp(tmpgv) = (IO*)SvREFCNT_inc_simple(io); + GvIOp(tmpgv) = MUTABLE_IO(SvREFCNT_inc_simple(io)); PL_statname = newSV(0); /* last filename we did stat on */ diff --git a/pp.c b/pp.c index fb66c08..8234a77 100644 --- a/pp.c +++ b/pp.c @@ -139,7 +139,7 @@ PP(pp_rv2gv) if (SvTYPE(sv) == SVt_PVIO) { GV * const gv = (GV*) sv_newmortal(); gv_init(gv, 0, "", 0, 0); - GvIOp(gv) = (IO *)sv; + GvIOp(gv) = MUTABLE_IO(sv); SvREFCNT_inc_void_NN(sv); sv = (SV*) gv; } diff --git a/pp_sys.c b/pp_sys.c index 033482d..0181e7e 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -2207,7 +2207,7 @@ PP(pp_truncate) goto do_ftruncate_gv; } else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) { - io = (IO*) SvRV(sv); /* *main::FRED{IO} for example */ + io = MUTABLE_IO(SvRV(sv)); /* *main::FRED{IO} for example */ goto do_ftruncate_io; } @@ -2854,7 +2854,7 @@ PP(pp_stat) goto do_fstat_warning_check; goto do_fstat; } else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) { - io = (IO*)SvRV(sv); + io = MUTABLE_IO(SvRV(sv)); if (PL_op->op_type == OP_LSTAT) goto do_fstat_warning_check; goto do_fstat_have_io; diff --git a/sv.c b/sv.c index 3293a91..cce7b6d 100644 --- a/sv.c +++ b/sv.c @@ -4736,7 +4736,7 @@ Perl_sv_magicext(pTHX_ SV *const sv, SV *const obj, const int how, */ if (how == PERL_MAGIC_tiedscalar && SvTYPE(sv) == SVt_PVIO && - obj && SvROK(obj) && GvIO(SvRV(obj)) == (IO*)sv) + obj && SvROK(obj) && GvIO(SvRV(obj)) == (const IO *)sv) { sv_rvweaken(obj); } @@ -5494,7 +5494,7 @@ Perl_sv_clear(pTHX_ register SV *const sv) IoIFP(sv) != PerlIO_stdout() && IoIFP(sv) != PerlIO_stderr()) { - io_close((IO*)sv, FALSE); + io_close(MUTABLE_IO(sv), FALSE); } if (IoDIRP(sv) && !(IoFLAGS(sv) & IOf_FAKE_DIRP)) PerlDir_close(IoDIRP(sv)); @@ -7889,7 +7889,7 @@ Perl_sv_2io(pTHX_ SV *const sv) switch (SvTYPE(sv)) { case SVt_PVIO: - io = (IO*)sv; + io = MUTABLE_IO(sv); break; case SVt_PVGV: if (isGV_with_GP(sv)) { @@ -10090,8 +10090,8 @@ ptr_table_* functions. #define hv_dup_inc(s,t) MUTABLE_HV(SvREFCNT_inc(sv_dup((const SV *)s,t))) #define cv_dup(s,t) MUTABLE_CV(sv_dup((SV*)s,t)) #define cv_dup_inc(s,t) MUTABLE_CV(SvREFCNT_inc(sv_dup((const SV *)s,t))) -#define io_dup(s,t) (IO*)sv_dup((SV*)s,t) -#define io_dup_inc(s,t) (IO*)SvREFCNT_inc(sv_dup((const SV *)s,t)) +#define io_dup(s,t) MUTABLE_IO(sv_dup((SV*)s,t)) +#define io_dup_inc(s,t) MUTABLE_IO(SvREFCNT_inc(sv_dup((const SV *)s,t))) #define gv_dup(s,t) (GV*)sv_dup((SV*)s,t) #define gv_dup_inc(s,t) (GV*)SvREFCNT_inc(sv_dup((const SV *)s,t)) #define SAVEPV(p) ((p) ? savepv(p) : NULL)