| 1 |
|
| /* You may distribute under the terms of either the GNU General Public License |
| 2 |
|
| * or the Artistic License (the same terms as Perl itself) |
| 3 |
|
| * |
| 4 |
|
| * (C) Paul Evans, 2024 -- leonerd@leonerd.org.uk |
| 5 |
|
| */ |
| 6 |
|
| |
| 7 |
|
| #include "EXTERN.h" |
| 8 |
|
| #include "perl.h" |
| 9 |
|
| #include "XSUB.h" |
| 10 |
|
| |
| 11 |
|
| #include "DataChecks.h" |
| 12 |
|
| |
| 13 |
|
| #define HAVE_PERL_VERSION(R, V, S) \ |
| 14 |
|
| (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S)))))) |
| 15 |
|
| |
| 16 |
|
| #include "optree-additions.c.inc" |
| 17 |
|
| |
| 18 |
|
| MODULE = t::test PACKAGE = t::test |
| 19 |
|
| |
| 20 |
|
| TYPEMAP: <<HERE |
| 21 |
|
| struct DataChecks_Checker * T_PTR |
| 22 |
|
| HERE |
| 23 |
|
| |
| 24 |
|
| struct DataChecks_Checker *make_checkdata(SV *checkspec, SV *name, SV *constraint = &PL_sv_undef) |
| 25 |
|
| CODE: |
| 26 |
30 |
| RETVAL = make_checkdata(checkspec); |
| 27 |
30 |
| gen_assertmess(RETVAL, name, constraint); |
| 28 |
|
| OUTPUT: |
| 29 |
|
| RETVAL |
| 30 |
|
| |
| 31 |
|
| void free_checkdata(struct DataChecks_Checker *checker); |
| 32 |
|
| |
| 33 |
|
| bool check_value(struct DataChecks_Checker *checker, SV *value) |
| 34 |
|
| |
| 35 |
|
| void assert_value(struct DataChecks_Checker *checker, SV *value) |
| 36 |
|
| |
| 37 |
|
| SV *make_asserter_sub(struct DataChecks_Checker *checker, SV *flagname = &PL_sv_undef) |
| 38 |
|
| CODE: |
| 39 |
|
| { |
| 40 |
6 |
▶ | if(!PL_parser) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!PL_parser) { |
6 |
0 |
6 |
|
| 41 |
|
| /* We need to generate just enough of a PL_parser to keep newSTATEOP() |
| 42 |
|
| * happy, otherwise it will SIGSEGV |
| 43 |
|
| */ |
| 44 |
6 |
| SAVEVPTR(PL_parser); |
| 45 |
6 |
| Newxz(PL_parser, 1, yy_parser); |
| 46 |
6 |
| SAVEFREEPV(PL_parser); |
| 47 |
|
| |
| 48 |
6 |
| PL_parser->copline = NOLINE; |
| 49 |
6 |
| PL_parser->preambling = NOLINE; |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
6 |
| U32 flags = 0; |
| 53 |
6 |
▶ | if(flagname && SvOK(flagname)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(flagname && SvOK(flagname)) { |
6 |
0 |
6 |
| if(flagname && SvOK(flagname)) { |
1 |
5 |
6 |
|
| 54 |
1 |
▶ | if(SvPOK(flagname) && strEQ(SvPVX(flagname), "void")) |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvPOK(flagname) && strEQ(SvPVX(flagname), "void")) |
1 |
0 |
1 |
| if(SvPOK(flagname) && strEQ(SvPVX(flagname), "void")) |
1 |
0 |
1 |
|
| 55 |
1 |
| flags = OPf_WANT_VOID; |
| 56 |
|
| } |
| 57 |
|
| |
| 58 |
6 |
| I32 floorix = start_subparse(FALSE, 0); |
| 59 |
6 |
| OP *body = newLISTOPn(OP_RETURN, 0, |
| 60 |
|
| make_assertop_flags(checker, flags, newSLUGOP(0)), |
| 61 |
|
| NULL); |
| 62 |
6 |
| CV *cv = newATTRSUB(floorix, NULL, NULL, NULL, body); |
| 63 |
6 |
| RETVAL = newRV_noinc((SV *)cv); |
| 64 |
|
| } |
| 65 |
|
| OUTPUT: |
| 66 |
|
| RETVAL |
| 67 |
|
| |
| 68 |
|
| BOOT: |
| 69 |
8 |
| boot_data_checks(0); |