This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv.c: Assert that sv_[ivp]v are not passed aggregates
authorFather Chrysostomos <sprout@cpan.org>
Fri, 19 Jul 2013 15:51:47 +0000 (08:51 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 19 Jul 2013 17:10:15 +0000 (10:10 -0700)
The lack of assertions can hide bugs.  See 32a609747bffb for instance

sv.c

diff --git a/sv.c b/sv.c
index 3ac0a2b..daa87f0 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2273,6 +2273,9 @@ Perl_sv_2iv_flags(pTHX_ SV *const sv, const I32 flags)
     if (!sv)
        return 0;
 
+    assert (SvTYPE(sv) != SVt_PVAV && SvTYPE(sv) != SVt_PVHV
+        && SvTYPE(sv) != SVt_PVFM);
+
     if (SvGMAGICAL(sv) && (flags & SV_GMAGIC))
        mg_get(sv);
 
@@ -2447,6 +2450,8 @@ Perl_sv_2nv_flags(pTHX_ SV *const sv, const I32 flags)
     dVAR;
     if (!sv)
        return 0.0;
+    assert (SvTYPE(sv) != SVt_PVAV && SvTYPE(sv) != SVt_PVHV
+        && SvTYPE(sv) != SVt_PVFM);
     if (SvGMAGICAL(sv) || SvVALID(sv) || isREGEXP(sv)) {
        /* FBMs use the space for SvIVX and SvNVX for other purposes, and use
           the same flag bit as SVf_IVisUV, so must not let them cache NVs.
@@ -2752,6 +2757,8 @@ Perl_sv_2pv_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags)
            *lp = 0;
        return (char *)"";
     }
+    assert (SvTYPE(sv) != SVt_PVAV && SvTYPE(sv) != SVt_PVHV
+        && SvTYPE(sv) != SVt_PVFM);
     if (SvGMAGICAL(sv) && (flags & SV_GMAGIC))
        mg_get(sv);
     if (SvROK(sv)) {