File Coverage

hax/sv_numeq.c.inc
Criterion Covered Total %
statement 14 29 48.2
branch 16 90 17.7
condition n/a
subroutine n/a
pod n/a
total 30 119 25.2


line stmt bran cond sub pod time code
1             /* vi: set ft=c : */
2              
3             #ifndef sv_numeq_flags
4             # define sv_numeq_flags(lhs, rhs, flags) S_sv_numeq_flags(aTHX_ lhs, rhs, flags)
5 6           static bool S_sv_numeq_flags(pTHX_ SV *lhs, SV *rhs, U32 flags)
6             {
7 6 50         if(flags & SV_GMAGIC) {
8 0 0         if(lhs)
9 0 0         SvGETMAGIC(lhs);
10 0 0         if(rhs)
11 0 0         SvGETMAGIC(rhs);
12             }
13              
14 6 50         if(!lhs)
15             lhs = &PL_sv_undef;
16 6 50         if(!rhs)
17             rhs = &PL_sv_undef;
18              
19 6 50         if(!(flags & SV_SKIP_OVERLOAD) && (SvAMAGIC(lhs) || SvAMAGIC(rhs))) {
    50          
    0          
    0          
    50          
    0          
    0          
20 0           SV *ret = amagic_call(lhs, rhs, eq_amg, 0);
21 0 0         if(ret)
22 0 0         return SvTRUE(ret);
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
23             }
24              
25             /* We'd like to call Perl_do_ncmp, except that isn't an exported API function
26             * Here's a near-copy of it for num-equality testing purposes */
27             #ifndef HAVE_BOOL_SvIV_please_nomg
28             /* Before perl 5.18, SvIV_please_nomg() was void-returning */
29 6 100         SvIV_please_nomg(lhs);
    50          
30 6 50         SvIV_please_nomg(rhs);
    0          
31             #endif
32              
33 6 100         if(
34             #ifdef HAVE_BOOL_SvIV_please_nomg
35             SvIV_please_nomg(rhs) && SvIV_please_nomg(lhs)
36             #else
37 5 50         SvIOK(lhs) && SvIOK(rhs)
38             #endif
39             ) {
40             /* Compare as integers */
41 5 50         switch((SvUOK(lhs) ? 1 : 0) | (SvUOK(rhs) ? 2 : 0)) {
42             case 0: /* IV == IV */
43 5           return SvIVX(lhs) == SvIVX(rhs);
44              
45             case 1: /* UV == IV */
46             {
47 0           const IV riv = SvUVX(rhs);
48 0 0         if(riv < 0)
49             return 0;
50 0           return (SvUVX(lhs) == riv);
51             }
52              
53             case 2: /* IV == UV */
54             {
55 0           const IV liv = SvUVX(lhs);
56 0 0         if(liv < 0)
57             return 0;
58 0           return (liv == SvUVX(rhs));
59             }
60              
61             case 3: /* UV == UV */
62 0           return SvUVX(lhs) == SvUVX(rhs);
63             }
64             }
65             else {
66             /* Compare NVs */
67 1 50         NV const rnv = SvNV_nomg(rhs);
68 1 50         NV const lnv = SvNV_nomg(lhs);
69              
70 1           return lnv == rnv;
71             }
72 0           }
73             #endif
74              
75             #ifndef sv_numeq
76             # define sv_numeq(lhs, rhs) sv_numeq_flags(lhs, rhs, 0)
77             #endif