From: Nicholas Clark Date: Wed, 26 Dec 2007 11:55:15 +0000 (+0000) Subject: Swap SVt_RV and SVt_NV in the SV ordering. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b53eecb41cfe1ac98c147076b9df0047426f32f2;p=p5sagit%2Fp5-mst-13.2.git Swap SVt_RV and SVt_NV in the SV ordering. p4raw-id: //depot/perl@32725 --- diff --git a/dump.c b/dump.c index 2a3439a..c6a9557 100644 --- a/dump.c +++ b/dump.c @@ -31,8 +31,8 @@ static const char* const svtypenames[SVt_LAST] = { "NULL", "BIND", "IV", - "NV", "RV", + "NV", "PV", "PVIV", "PVNV", @@ -51,8 +51,8 @@ static const char* const svshorttypenames[SVt_LAST] = { "UNDEF", "BIND", "IV", - "NV", "RV", + "NV", "PV", "PVIV", "PVNV", diff --git a/ext/B/B.xs b/ext/B/B.xs index 380e4ed..e6af7a1 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -25,8 +25,8 @@ static const char* const svclassnames[] = { "B::BIND", #endif "B::IV", - "B::NV", "B::RV", + "B::NV", "B::PV", "B::PVIV", "B::PVNV", diff --git a/ext/Storable/Storable.xs b/ext/Storable/Storable.xs index 0ac2b66..e284163 100644 --- a/ext/Storable/Storable.xs +++ b/ext/Storable/Storable.xs @@ -4497,7 +4497,7 @@ static SV *retrieve_ref(pTHX_ stcxt_t *cxt, const char *cname) if (cname) { /* No need to do anything, as rv will already be PVMG. */ - assert (SvTYPE(rv) >= SVt_RV); + assert (SvTYPE(rv) == SVt_RV || SvTYPE(rv) >= SVt_PV); } else { sv_upgrade(rv, SVt_RV); } diff --git a/pp.c b/pp.c index f5ff461..349e91f 100644 --- a/pp.c +++ b/pp.c @@ -172,7 +172,7 @@ PP(pp_rv2gv) const char * const name = CopSTASHPV(PL_curcop); gv = newGVgen(name); } - if (SvTYPE(sv) < SVt_RV) + if (SvTYPE(sv) < SVt_RV || SvTYPE(sv) == SVt_NV) sv_upgrade(sv, SVt_RV); else if (SvPVX_const(sv)) { SvPV_free(sv); diff --git a/pp_hot.c b/pp_hot.c index 367f03e..ca34f91 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -2940,7 +2940,7 @@ Perl_vivify_ref(pTHX_ SV *sv, U32 to_what) if (!SvOK(sv)) { if (SvREADONLY(sv)) Perl_croak(aTHX_ PL_no_modify); - if (SvTYPE(sv) < SVt_RV) + if (SvTYPE(sv) < SVt_RV || SvTYPE(sv) == SVt_NV) sv_upgrade(sv, SVt_RV); else if (SvTYPE(sv) >= SVt_PV) { SvPV_free(sv); diff --git a/sv.c b/sv.c index bd90934..fda7935 100644 --- a/sv.c +++ b/sv.c @@ -890,13 +890,13 @@ static const struct body_details bodies_by_type[] = { FIT_ARENA(0, sizeof(struct ptr_tbl_ent)) }, + /* RVs are in the head now. */ + { 0, 0, 0, SVt_RV, FALSE, NONV, NOARENA, 0 }, + /* 8 bytes on most ILP32 with IEEE doubles */ { sizeof(NV), sizeof(NV), 0, SVt_NV, FALSE, HADNV, HASARENA, FIT_ARENA(0, sizeof(NV)) }, - /* RVs are in the head now. */ - { 0, 0, 0, SVt_RV, FALSE, NONV, NOARENA, 0 }, - /* 8 bytes on most ILP32 with IEEE doubles */ { sizeof(xpv_allocated), copy_length(XPV, xpv_len) @@ -1235,7 +1235,11 @@ Perl_sv_upgrade(pTHX_ register SV *sv, svtype new_type) return; case SVt_RV: assert(old_type == SVt_NULL); - SvANY(sv) = &sv->sv_u.svu_rv; + SvANY(sv) = (XPVIV*)((char*)&(sv->sv_u.svu_iv) - STRUCT_OFFSET(XPVIV, xiv_iv)); + /* Could leave this in, but changing it happens to make the next step + clearler. The key part is that SvANY(sv) is not NULL: + SvANY(sv) = &sv->sv_u.svu_rv; + */ SvRV_set(sv, 0); return; case SVt_PVHV: @@ -1286,7 +1290,7 @@ Perl_sv_upgrade(pTHX_ register SV *sv, svtype new_type) The target created by newSVrv also is, and it can have magic. However, it never has SvPVX set. */ - if (old_type >= SVt_RV) { + if (old_type == SVt_RV || old_type >= SVt_PV) { assert(SvPVX_const(sv) == 0); } @@ -1357,7 +1361,7 @@ Perl_sv_upgrade(pTHX_ register SV *sv, svtype new_type) if (new_type == SVt_PVIO) IoPAGE_LEN(sv) = 60; - if (old_type < SVt_RV) + if (old_type < SVt_RV || old_type == SVt_NV) SvPV_set(sv, NULL); break; default: @@ -3483,7 +3487,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) goto undef_sstr; case SVt_RV: - if (dtype < SVt_RV) + if (dtype < SVt_PV && dtype != SVt_RV) sv_upgrade(dstr, SVt_RV); break; case SVt_PVFM: @@ -7856,7 +7860,7 @@ Perl_newSVrv(pTHX_ SV *rv, const char *classname) sv_upgrade(rv, SVt_RV); } else if (SvROK(rv)) { SvREFCNT_dec(SvRV(rv)); - } else if (SvTYPE(rv) < SVt_RV) + } else if (SvTYPE(rv) < SVt_RV || SvTYPE(rv) == SVt_NV) sv_upgrade(rv, SVt_RV); else if (SvTYPE(rv) > SVt_RV) { SvPV_free(rv); diff --git a/sv.h b/sv.h index 63eccbd..db2843b 100644 --- a/sv.h +++ b/sv.h @@ -47,8 +47,8 @@ typedef enum { SVt_NULL, /* 0 */ SVt_BIND, /* 1 */ SVt_IV, /* 2 */ - SVt_NV, /* 3 */ - SVt_RV, /* 4 */ + SVt_RV, /* 3 */ + SVt_NV, /* 4 */ SVt_PV, /* 5 */ SVt_PVIV, /* 6 */ SVt_PVNV, /* 7 */ @@ -1298,7 +1298,7 @@ the scalar's value cannot change unless written to. })) # define SvRV(sv) \ (*({ SV *const _svi = (SV *) (sv); \ - assert(SvTYPE(_svi) >= SVt_RV); \ + assert(SvTYPE(_svi) >= SVt_PV || SvTYPE(_svi) == SVt_RV); \ assert(SvTYPE(_svi) != SVt_PVAV); \ assert(SvTYPE(_svi) != SVt_PVHV); \ assert(SvTYPE(_svi) != SVt_PVCV); \ @@ -1383,7 +1383,7 @@ the scalar's value cannot change unless written to. assert(!isGV_with_GP(sv)); \ (((XPVUV*)SvANY(sv))->xuv_uv = (val)); } STMT_END #define SvRV_set(sv, val) \ - STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ + STMT_START { assert(SvTYPE(sv) >= SVt_PV || SvTYPE(sv) == SVt_RV); \ assert(SvTYPE(sv) != SVt_PVAV); \ assert(SvTYPE(sv) != SVt_PVHV); \ assert(SvTYPE(sv) != SVt_PVCV); \