From: Andy Lester Date: Sun, 11 Jun 2006 22:44:34 +0000 (-0500) Subject: Proper use of enums X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=42d0e0b77a1ef47b81ab3e346a1a4dc0af5b9bec;p=p5sagit%2Fp5-mst-13.2.git Proper use of enums Message-ID: <20060612034434.GA21588@petdance.com> p4raw-id: //depot/perl@28381 --- diff --git a/embed.fnc b/embed.fnc index 9710cae..e04236f 100644 --- a/embed.fnc +++ b/embed.fnc @@ -862,7 +862,7 @@ Apd |int |sv_unmagic |NN SV* sv|int type Apdmb |void |sv_unref |NN SV* sv Apd |void |sv_unref_flags |NN SV* sv|U32 flags Apd |void |sv_untaint |NN SV* sv -Apd |void |sv_upgrade |NN SV* sv|U32 mt +Apd |void |sv_upgrade |NN SV* sv|svtype new_type Apdmb |void |sv_usepvn |NN SV* sv|NULLOK char* ptr|STRLEN len Apd |void |sv_usepvn_flags|NN SV* sv|NULLOK char* ptr|STRLEN len\ |U32 flags diff --git a/gv.c b/gv.c index 1c8d981..4187c18 100644 --- a/gv.c +++ b/gv.c @@ -204,6 +204,7 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi) case SVt_PVIO: Perl_croak(aTHX_ "Cannot convert a reference to %s to typeglob", sv_reftype(has_constant, 0)); + default: NOOP; } SvRV_set(gv, NULL); SvROK_off(gv); diff --git a/op.c b/op.c index 0e668fb..6324b52 100644 --- a/op.c +++ b/op.c @@ -6071,24 +6071,24 @@ Perl_ck_rvconst(pTHX_ register OP *o) /* Is it a constant from cv_const_sv()? */ if (SvROK(kidsv) && SvREADONLY(kidsv)) { SV * const rsv = SvRV(kidsv); - const int svtype = SvTYPE(rsv); + const svtype type = SvTYPE(rsv); const char *badtype = NULL; switch (o->op_type) { case OP_RV2SV: - if (svtype > SVt_PVMG) + if (type > SVt_PVMG) badtype = "a SCALAR"; break; case OP_RV2AV: - if (svtype != SVt_PVAV) + if (type != SVt_PVAV) badtype = "an ARRAY"; break; case OP_RV2HV: - if (svtype != SVt_PVHV) + if (type != SVt_PVHV) badtype = "a HASH"; break; case OP_RV2CV: - if (svtype != SVt_PVCV) + if (type != SVt_PVCV) badtype = "a CODE"; break; } diff --git a/perlio.c b/perlio.c index 2f8820e..30e3e6c 100644 --- a/perlio.c +++ b/perlio.c @@ -1431,8 +1431,9 @@ PerlIO_layer_from_ref(pTHX_ SV *sv) return PerlIO_find_layer(aTHX_ STR_WITH_LEN("Code"), 0); case SVt_PVGV: return PerlIO_find_layer(aTHX_ STR_WITH_LEN("Glob"), 0); + default: + return NULL; } - return NULL; } PerlIO_list_t * diff --git a/pod/perlapi.pod b/pod/perlapi.pod index d852746..ca9dfa3 100644 --- a/pod/perlapi.pod +++ b/pod/perlapi.pod @@ -5891,7 +5891,7 @@ Upgrade an SV to a more complex form. Generally adds a new body type to the SV, then copies across as much information as possible from the old body. You generally want to use the C macro wrapper. See also C. - void sv_upgrade(SV* sv, U32 mt) + void sv_upgrade(SV* sv, svtype new_type) =for hackers Found in file sv.c diff --git a/pp.c b/pp.c index 8100336..638b1e1 100644 --- a/pp.c +++ b/pp.c @@ -239,6 +239,7 @@ PP(pp_rv2sv) case SVt_PVFM: case SVt_PVIO: DIE(aTHX_ "Not a SCALAR reference"); + default: NOOP; } } else { diff --git a/proto.h b/proto.h index 8460990..8bfa8c6 100644 --- a/proto.h +++ b/proto.h @@ -2356,7 +2356,7 @@ PERL_CALLCONV void Perl_sv_unref_flags(pTHX_ SV* sv, U32 flags) PERL_CALLCONV void Perl_sv_untaint(pTHX_ SV* sv) __attribute__nonnull__(pTHX_1); -PERL_CALLCONV void Perl_sv_upgrade(pTHX_ SV* sv, U32 mt) +PERL_CALLCONV void Perl_sv_upgrade(pTHX_ SV* sv, svtype new_type) __attribute__nonnull__(pTHX_1); /* PERL_CALLCONV void Perl_sv_usepvn(pTHX_ SV* sv, char* ptr, STRLEN len) diff --git a/sv.c b/sv.c index 029d0fa..6fbcd00 100644 --- a/sv.c +++ b/sv.c @@ -1120,12 +1120,12 @@ You generally want to use the C macro wrapper. See also C. */ void -Perl_sv_upgrade(pTHX_ register SV *sv, U32 new_type) +Perl_sv_upgrade(pTHX_ register SV *sv, svtype new_type) { dVAR; void* old_body; void* new_body; - const U32 old_type = SvTYPE(sv); + const svtype old_type = SvTYPE(sv); const struct body_details *new_type_details; const struct body_details *const old_type_details = bodies_by_type + old_type; @@ -1496,6 +1496,7 @@ Perl_sv_setiv(pTHX_ register SV *sv, IV i) case SVt_PVIO: Perl_croak(aTHX_ "Can't coerce %s to integer in %s", sv_reftype(sv,0), OP_DESC(PL_op)); + default: NOOP; } (void)SvIOK_only(sv); /* validate number */ SvIV_set(sv, i); @@ -1596,6 +1597,7 @@ Perl_sv_setnv(pTHX_ register SV *sv, NV num) case SVt_PVIO: Perl_croak(aTHX_ "Can't coerce %s to number in %s", sv_reftype(sv,0), OP_NAME(PL_op)); + default: NOOP; } SvNV_set(sv, num); (void)SvNOK_only(sv); /* validate number */ @@ -3348,7 +3350,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) dVAR; register U32 sflags; register int dtype; - register int stype; + register svtype stype; if (sstr == dstr) return; @@ -3483,7 +3485,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) if (stype == SVt_PVLV) SvUPGRADE(dstr, SVt_PVNV); else - SvUPGRADE(dstr, (U32)stype); + SvUPGRADE(dstr, (svtype)stype); } /* dstr may have been upgraded. */ diff --git a/sv.h b/sv.h index 75c45bf..ab09bba 100644 --- a/sv.h +++ b/sv.h @@ -266,7 +266,7 @@ perform the upgrade if necessary. See C. #endif #define SVTYPEMASK 0xff -#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) +#define SvTYPE(sv) (svtype)((sv)->sv_flags & SVTYPEMASK) /* Sadly there are some parts of the core that have pointers to already-freed SV heads, and rely on being able to tell that they are now free. So mark