| 1 |
|
| #include <xs/Simple.h> |
| 2 |
|
| |
| 3 |
|
| namespace xs { |
| 4 |
|
| |
| 5 |
|
| const Simple Simple::undef(&PL_sv_undef); |
| 6 |
|
| const Simple Simple::yes(&PL_sv_yes); |
| 7 |
|
| const Simple Simple::no(&PL_sv_no); |
| 8 |
|
| |
| 9 |
8 |
| Simple Simple::format (const char*const pat, ...) { |
| 10 |
|
| va_list args; |
| 11 |
8 |
| va_start(args, pat); |
| 12 |
8 |
▶ | SV* sv = vnewSVpvf(pat, &args); |
Branch: 1 branch
| Branch | True | False | Total |
| SV* sv = vnewSVpvf(pat, &args); |
8 |
0 |
8 |
|
| 13 |
8 |
| va_end(args); |
| 14 |
16 |
▶ | return Simple::noinc(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| return Simple::noinc(sv); |
8 |
0 |
8 |
|
| 15 |
|
| } |
| 16 |
|
| |
| 17 |
2 |
| U32 Simple::hash () const { |
| 18 |
2 |
▶ | if (sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv) { |
1 |
1 |
2 |
|
| 19 |
1 |
▶ | if (SvIsCOW_shared_hash(sv)) return SvSHARED_HASH(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvIsCOW_shared_hash(sv)) return SvSHARED_HASH(sv); |
0 |
1 |
1 |
| if (SvIsCOW_shared_hash(sv)) return SvSHARED_HASH(sv); |
0 |
0 |
0 |
|
| 20 |
|
| U32 h; STRLEN len; |
| 21 |
1 |
| const char* buf = SvPV(sv, len); |
| 22 |
1 |
▶ | PERL_HASH(h, buf, len); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_HASH(h, buf, len); |
1 |
0 |
1 |
|
| 23 |
1 |
| return h; |
| 24 |
1 |
| } else return 0; |
| 25 |
|
| } |
| 26 |
|
| |
| 27 |
22 |
| void Simple::_validate_rest() { |
| 28 |
22 |
▶ | if (SvTYPE(sv) == SVt_PVLV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(sv) == SVt_PVLV) { |
0 |
22 |
22 |
|
| 29 |
0 |
| auto newval = newSVsv(sv); |
| 30 |
0 |
| reset(); // remove old sv |
| 31 |
0 |
| sv = newval; // newSVsv creates sv with refcnt=1, so no inc is required |
| 32 |
|
| } |
| 33 |
|
| |
| 34 |
22 |
▶ | if (SvTYPE(sv) > SVt_PVMG || SvROK(sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTYPE(sv) > SVt_PVMG || SvROK(sv)) { |
15 |
7 |
22 |
| if (SvTYPE(sv) > SVt_PVMG || SvROK(sv)) { |
15 |
0 |
15 |
|
| 35 |
22 |
| reset(); |
| 36 |
22 |
▶ | throw std::invalid_argument("SV is not a number or string"); |
Branch: 1 branch
| Branch | True | False | Total |
| throw std::invalid_argument("SV is not a number or string"); |
22 |
0 |
22 |
|
| 37 |
|
| } |
| 38 |
0 |
| } |
| 39 |
|
| |
| 40 |
37 |
| void Simple::__at_perl_destroy () { |
| 41 |
37 |
| const_cast<Simple*>(&undef)->reset(); |
| 42 |
37 |
| const_cast<Simple*>(&yes)->reset(); |
| 43 |
37 |
| const_cast<Simple*>(&no)->reset(); |
| 44 |
37 |
| } |
| 45 |
|
| |
| 46 |
|
| } |