| 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, 2023-2024 -- leonerd@leonerd.org.uk |
| 5 |
|
| */ |
| 6 |
|
| #define PERL_NO_GET_CONTEXT |
| 7 |
|
| |
| 8 |
|
| #include "EXTERN.h" |
| 9 |
|
| #include "perl.h" |
| 10 |
|
| #include "XSUB.h" |
| 11 |
|
| |
| 12 |
|
| #include "XSParseSublike.h" |
| 13 |
|
| |
| 14 |
|
| #define HAVE_PERL_VERSION(R, V, S) \ |
| 15 |
|
| (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S)))))) |
| 16 |
|
| |
| 17 |
|
| #include "compilerun_sv.c.inc" |
| 18 |
|
| |
| 19 |
|
| #include "DataChecks.h" |
| 20 |
|
| |
| 21 |
12 |
| static void apply_Checked(pTHX_ struct XPSSignatureParamContext *ctx, SV *attrvalue, void **attrdata_ptr, void *funcdata) |
| 22 |
|
| { |
| 23 |
12 |
| PADNAME *pn = PadnamelistARRAY(PL_comppad_name)[ctx->padix]; |
| 24 |
12 |
▶ | if(PadnamePV(pn)[0] != '$') |
Branch: 1 branch
| Branch | True | False | Total |
| if(PadnamePV(pn)[0] != '$') |
0 |
12 |
12 |
|
| 25 |
0 |
| croak("Can only apply the :Checked attribute to scalar parameters"); |
| 26 |
|
| |
| 27 |
|
| SV *checkspec; |
| 28 |
|
| |
| 29 |
|
| { |
| 30 |
12 |
| dSP; |
| 31 |
|
| |
| 32 |
12 |
| ENTER; |
| 33 |
12 |
| SAVETMPS; |
| 34 |
|
| |
| 35 |
|
| /* eval_sv() et.al. will forgets what package we're actually running in |
| 36 |
|
| * because during compiletime, CopSTASH(PL_curcop == &PL_compiling) isn't |
| 37 |
|
| * accurate. We need to help it along |
| 38 |
|
| */ |
| 39 |
|
| |
| 40 |
12 |
| SAVECOPSTASH_FREE(PL_curcop); |
| 41 |
12 |
| CopSTASH_set(PL_curcop, PL_curstash); |
| 42 |
|
| |
| 43 |
12 |
| compilerun_sv(attrvalue, G_SCALAR); |
| 44 |
|
| |
| 45 |
12 |
| SPAGAIN; |
| 46 |
|
| |
| 47 |
12 |
| checkspec = SvREFCNT_inc(POPs); |
| 48 |
|
| |
| 49 |
12 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
12 |
0 |
12 |
|
| 50 |
12 |
| LEAVE; |
| 51 |
|
| } |
| 52 |
|
| |
| 53 |
12 |
| struct DataChecks_Checker *checker = make_checkdata(checkspec); |
| 54 |
12 |
| SvREFCNT_dec(checkspec); |
| 55 |
|
| |
| 56 |
12 |
▶ | gen_assertmess(checker, |
Branch: 1 branch
| Branch | True | False | Total |
| gen_assertmess(checker, |
2 |
10 |
12 |
|
| 57 |
|
| sv_2mortal(newSVpvf(ctx->is_named ? "Named parameter :%s" : "Parameter %s", PadnamePV(pn))), |
| 58 |
|
| NULL); |
| 59 |
|
| |
| 60 |
12 |
| *attrdata_ptr = checker; |
| 61 |
12 |
| } |
| 62 |
|
| |
| 63 |
|
| #ifndef newPADxVOP |
| 64 |
|
| # define newPADxVOP(type, flags, padix) S_newPADxVOP(aTHX_ type, flags, padix) |
| 65 |
|
| static OP *S_newPADxVOP(pTHX_ I32 type, I32 flags, PADOFFSET padix) |
| 66 |
|
| { |
| 67 |
|
| OP *op = newOP(type, flags); |
| 68 |
|
| op->op_targ = padix; |
| 69 |
|
| return op; |
| 70 |
|
| } |
| 71 |
|
| #endif |
| 72 |
|
| |
| 73 |
12 |
| static void post_defop_Checked(pTHX_ struct XPSSignatureParamContext *ctx, void *attrdata, void *funcdata) |
| 74 |
|
| { |
| 75 |
12 |
| struct DataChecks_Checker *checker = attrdata; |
| 76 |
|
| |
| 77 |
12 |
| OP *assertop = make_assertop(checker, newPADxVOP(OP_PADSV, 0, ctx->padix)); |
| 78 |
|
| |
| 79 |
12 |
| ctx->op = op_append_elem(OP_SCOPE, |
| 80 |
|
| ctx->op, assertop); |
| 81 |
12 |
| } |
| 82 |
|
| |
| 83 |
0 |
| static void free_Checked(pTHX_ struct XPSSignatureParamContext *ctx, void *attrdata, void *funcdata) |
| 84 |
|
| { |
| 85 |
0 |
| struct DataChecks_Checker *checker = attrdata; |
| 86 |
0 |
| free_checkdata(checker); |
| 87 |
0 |
| } |
| 88 |
|
| |
| 89 |
|
| static const struct XPSSignatureAttributeFuncs funcs_Checked = { |
| 90 |
|
| .ver = XSPARSESUBLIKE_ABI_VERSION, |
| 91 |
|
| .permit_hintkey = "Signature::Attribute::Checked/Checked", |
| 92 |
|
| |
| 93 |
|
| .apply = apply_Checked, |
| 94 |
|
| .post_defop = post_defop_Checked, |
| 95 |
|
| }; |
| 96 |
|
| |
| 97 |
|
| MODULE = Signature::Attribute::Checked PACKAGE = Signature::Attribute::Checked |
| 98 |
|
| |
| 99 |
|
| BOOT: |
| 100 |
6 |
| boot_xs_parse_sublike(0.19); |
| 101 |
6 |
| boot_data_checks(0.09); |
| 102 |
|
| |
| 103 |
6 |
| register_xps_signature_attribute("Checked", &funcs_Checked, NULL); |