| 1 |
|
| #define PERL_NO_GET_CONTEXT 1 |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "callchecker0.h" |
| 5 |
|
| #include "XSUB.h" |
| 6 |
|
| |
| 7 |
|
| #define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s) |
| 8 |
|
| #define PERL_DECIMAL_VERSION \ |
| 9 |
|
| PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION) |
| 10 |
|
| #define PERL_VERSION_GE(r,v,s) \ |
| 11 |
|
| (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s)) |
| 12 |
|
| |
| 13 |
|
| #if !PERL_VERSION_GE(5,7,2) |
| 14 |
|
| # undef dNOOP |
| 15 |
|
| # define dNOOP extern int Perl___notused_func(void) |
| 16 |
|
| #endif /* <5.7.2 */ |
| 17 |
|
| |
| 18 |
|
| #ifndef cBOOL |
| 19 |
|
| # define cBOOL(x) ((bool)!!(x)) |
| 20 |
|
| #endif /* !cBOOL */ |
| 21 |
|
| |
| 22 |
|
| #ifndef PERL_UNUSED_VAR |
| 23 |
|
| # define PERL_UNUSED_VAR(x) ((void)x) |
| 24 |
|
| #endif /* !PERL_UNUSED_VAR */ |
| 25 |
|
| |
| 26 |
|
| #ifndef PERL_UNUSED_ARG |
| 27 |
|
| # define PERL_UNUSED_ARG(x) PERL_UNUSED_VAR(x) |
| 28 |
|
| #endif /* !PERL_UNUSED_ARG */ |
| 29 |
|
| |
| 30 |
|
| #ifndef Newx |
| 31 |
|
| # define Newx(v,n,t) New(0,v,n,t) |
| 32 |
|
| #endif /* !Newx */ |
| 33 |
|
| |
| 34 |
|
| #ifndef HvNAME_get |
| 35 |
|
| # define HvNAME_get(hv) HvNAME(hv) |
| 36 |
|
| #endif |
| 37 |
|
| |
| 38 |
|
| #ifndef newSVpvs_share |
| 39 |
|
| # define newSVpvs_share(s) newSVpvn_share(""s"", (sizeof(""s"")-1), 0) |
| 40 |
|
| #endif /* !newSVpvs_share */ |
| 41 |
|
| |
| 42 |
|
| #ifndef newSVpvn_share |
| 43 |
|
| # define newSVpvn_share(s, l, h) newSVpvn(s, l) |
| 44 |
|
| #endif /* !newSVpvn_share */ |
| 45 |
|
| |
| 46 |
|
| #if PERL_VERSION_GE(5,19,4) |
| 47 |
|
| typedef SSize_t array_ix_t; |
| 48 |
|
| #else /* <5.19.4 */ |
| 49 |
|
| typedef I32 array_ix_t; |
| 50 |
|
| #endif /* <5.19.4 */ |
| 51 |
|
| |
| 52 |
|
| #ifndef DPTR2FPTR |
| 53 |
|
| # define DPTR2FPTR(t,x) ((t)(UV)(x)) |
| 54 |
|
| #endif /* !DPTR2FPTR */ |
| 55 |
|
| |
| 56 |
|
| #ifndef FPTR2DPTR |
| 57 |
|
| # define FPTR2DPTR(t,x) ((t)(UV)(x)) |
| 58 |
|
| #endif /* !FPTR2DPTR */ |
| 59 |
|
| |
| 60 |
|
| #ifndef OpMORESIB_set |
| 61 |
|
| # define OpMORESIB_set(o, sib) ((o)->op_sibling = (sib)) |
| 62 |
|
| # define OpLASTSIB_set(o, parent) ((o)->op_sibling = NULL) |
| 63 |
|
| # define OpMAYBESIB_set(o, sib, parent) ((o)->op_sibling = (sib)) |
| 64 |
|
| #endif /* !OpMORESIB_set */ |
| 65 |
|
| #ifndef OpSIBLING |
| 66 |
|
| # define OpHAS_SIBLING(o) (cBOOL((o)->op_sibling)) |
| 67 |
|
| # define OpSIBLING(o) (0 + (o)->op_sibling) |
| 68 |
|
| #endif /* !OpSIBLING */ |
| 69 |
|
| |
| 70 |
|
| #ifdef cv_set_call_checker |
| 71 |
|
| # define QUSE_CUSTOM_OPS 1 |
| 72 |
|
| #else /* !cv_set_call_checker */ |
| 73 |
|
| # define QUSE_CUSTOM_OPS 0 |
| 74 |
|
| #endif /* !cv_set_call_checker */ |
| 75 |
|
| |
| 76 |
|
| #if defined(QUSE_CUSTOM_OPS) && !defined(ptr_table_new) |
| 77 |
|
| |
| 78 |
|
| struct q_ptr_tbl_ent { |
| 79 |
|
| struct q_ptr_tbl_ent *next; |
| 80 |
|
| void *from, *to; |
| 81 |
|
| }; |
| 82 |
|
| |
| 83 |
|
| # undef PTR_TBL_t |
| 84 |
|
| # define PTR_TBL_t struct q_ptr_tbl_ent * |
| 85 |
|
| |
| 86 |
|
| # define ptr_table_new() THX_ptr_table_new(aTHX) |
| 87 |
|
| static PTR_TBL_t *THX_ptr_table_new(pTHX) |
| 88 |
|
| { |
| 89 |
|
| PTR_TBL_t *tbl; |
| 90 |
|
| Newx(tbl, 1, PTR_TBL_t); |
| 91 |
|
| *tbl = NULL; |
| 92 |
|
| return tbl; |
| 93 |
|
| } |
| 94 |
|
| |
| 95 |
|
| # if 0 |
| 96 |
|
| # define ptr_table_free(tbl) THX_ptr_table_free(aTHX_ tbl) |
| 97 |
|
| static void THX_ptr_table_free(pTHX_ PTR_TBL_t *tbl) |
| 98 |
|
| { |
| 99 |
|
| struct q_ptr_tbl_ent *ent = *tbl; |
| 100 |
|
| Safefree(tbl); |
| 101 |
|
| while(ent) { |
| 102 |
|
| struct q_ptr_tbl_ent *nent = ent->next; |
| 103 |
|
| Safefree(ent); |
| 104 |
|
| ent = nent; |
| 105 |
|
| } |
| 106 |
|
| } |
| 107 |
|
| # endif /* 0 */ |
| 108 |
|
| |
| 109 |
|
| # define ptr_table_store(tbl, from, to) THX_ptr_table_store(aTHX_ tbl, from, to) |
| 110 |
|
| static void THX_ptr_table_store(pTHX_ PTR_TBL_t *tbl, void *from, void *to) |
| 111 |
|
| { |
| 112 |
|
| struct q_ptr_tbl_ent *ent; |
| 113 |
|
| Newx(ent, 1, struct q_ptr_tbl_ent); |
| 114 |
|
| ent->next = *tbl; |
| 115 |
|
| ent->from = from; |
| 116 |
|
| ent->to = to; |
| 117 |
|
| *tbl = ent; |
| 118 |
|
| } |
| 119 |
|
| |
| 120 |
|
| # define ptr_table_fetch(tbl, from) THX_ptr_table_fetch(aTHX_ tbl, from) |
| 121 |
|
| static void *THX_ptr_table_fetch(pTHX_ PTR_TBL_t *tbl, void *from) |
| 122 |
|
| { |
| 123 |
|
| struct q_ptr_tbl_ent *ent; |
| 124 |
|
| for(ent = *tbl; ent; ent = ent->next) { |
| 125 |
|
| if(ent->from == from) return ent->to; |
| 126 |
|
| } |
| 127 |
|
| return NULL; |
| 128 |
|
| } |
| 129 |
|
| |
| 130 |
|
| #endif /* QUSE_CUSTOM_OPS && !ptr_table_new */ |
| 131 |
|
| |
| 132 |
|
| #if PERL_VERSION_GE(5,7,3) |
| 133 |
|
| # define PERL_UNUSED_THX() NOOP |
| 134 |
|
| #else /* <5.7.3 */ |
| 135 |
|
| # define PERL_UNUSED_THX() ((void)(aTHX+0)) |
| 136 |
|
| #endif /* <5.7.3 */ |
| 137 |
|
| |
| 138 |
|
| #if PERL_VERSION_GE(5,11,0) |
| 139 |
|
| # define case_SVt_RV_ |
| 140 |
|
| #else /* <5.11.0 */ |
| 141 |
|
| # define case_SVt_RV_ case SVt_RV: |
| 142 |
|
| #endif /* <5.11.0 */ |
| 143 |
|
| |
| 144 |
|
| #if PERL_VERSION_GE(5,9,5) |
| 145 |
|
| # define case_SVt_PVBM_ |
| 146 |
|
| #else /* <5.11.0 */ |
| 147 |
|
| # define case_SVt_PVBM_ case SVt_PVBM: |
| 148 |
|
| #endif /* <5.11.0 */ |
| 149 |
|
| |
| 150 |
|
| #if PERL_VERSION_GE(5,11,0) |
| 151 |
|
| # define case_SVt_REGEXP_ case SVt_REGEXP: |
| 152 |
|
| #else /* <5.11.0 */ |
| 153 |
|
| # define case_SVt_REGEXP_ |
| 154 |
|
| #endif /* <5.11.0 */ |
| 155 |
|
| |
| 156 |
|
| #define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV) |
| 157 |
|
| |
| 158 |
|
| #if PERL_VERSION_GE(5,11,0) |
| 159 |
|
| # define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP) |
| 160 |
|
| #else /* <5.11.0 */ |
| 161 |
|
| # define sv_is_regexp(sv) 0 |
| 162 |
|
| #endif /* <5.11.0 */ |
| 163 |
|
| |
| 164 |
|
| #define sv_is_undef(sv) (!sv_is_glob(sv) && !sv_is_regexp(sv) && !SvOK(sv)) |
| 165 |
|
| |
| 166 |
|
| #define sv_is_string(sv) \ |
| 167 |
|
| (!sv_is_glob(sv) && !sv_is_regexp(sv) && \ |
| 168 |
|
| (SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK))) |
| 169 |
|
| |
| 170 |
|
| #define sv_is_untyped_ref(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv))) |
| 171 |
|
| #define sv_is_untyped_blessed(sv) (SvROK(sv) && SvOBJECT(SvRV(sv))) |
| 172 |
|
| |
| 173 |
106 |
| static bool THX_sv_is_undef(pTHX_ SV *sv) { |
| 174 |
|
| PERL_UNUSED_THX(); |
| 175 |
106 |
▶ | return cBOOL(sv_is_undef(sv)); |
Branch: 3 branches
| Branch | True | False | Total |
| return cBOOL(sv_is_undef(sv)); |
100 |
6 |
106 |
| return cBOOL(sv_is_undef(sv)); |
94 |
6 |
100 |
| return cBOOL(sv_is_undef(sv)); |
6 |
88 |
94 |
|
| 176 |
|
| } |
| 177 |
|
| |
| 178 |
212 |
| static bool THX_sv_is_string(pTHX_ SV *sv) { |
| 179 |
|
| PERL_UNUSED_THX(); |
| 180 |
212 |
▶ | return cBOOL(sv_is_string(sv)); |
Branch: 3 branches
| Branch | True | False | Total |
| return cBOOL(sv_is_string(sv)); |
200 |
12 |
212 |
| return cBOOL(sv_is_string(sv)); |
188 |
12 |
200 |
| return cBOOL(sv_is_string(sv)); |
72 |
116 |
188 |
|
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
106 |
| static bool THX_sv_is_glob(pTHX_ SV *sv) { |
| 184 |
|
| PERL_UNUSED_THX(); |
| 185 |
106 |
| return cBOOL(sv_is_glob(sv)); |
| 186 |
|
| } |
| 187 |
|
| |
| 188 |
106 |
| static bool THX_sv_is_regexp(pTHX_ SV *sv) { |
| 189 |
|
| PERL_UNUSED_THX(); |
| 190 |
|
| PERL_UNUSED_ARG(sv); |
| 191 |
106 |
| return cBOOL(sv_is_regexp(sv)); |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
130 |
| static bool THX_sv_is_untyped_ref(pTHX_ SV *sv) { |
| 195 |
|
| PERL_UNUSED_THX(); |
| 196 |
130 |
▶ | return cBOOL(sv_is_untyped_ref(sv)); |
Branch: 2 branches
| Branch | True | False | Total |
| return cBOOL(sv_is_untyped_ref(sv)); |
68 |
62 |
130 |
| return cBOOL(sv_is_untyped_ref(sv)); |
44 |
24 |
68 |
|
| 197 |
|
| } |
| 198 |
|
| |
| 199 |
322 |
| static bool THX_sv_is_untyped_blessed(pTHX_ SV *sv) { |
| 200 |
|
| PERL_UNUSED_THX(); |
| 201 |
322 |
▶ | return cBOOL(sv_is_untyped_blessed(sv)); |
Branch: 2 branches
| Branch | True | False | Total |
| return cBOOL(sv_is_untyped_blessed(sv)); |
172 |
150 |
322 |
| return cBOOL(sv_is_untyped_blessed(sv)); |
80 |
92 |
172 |
|
| 202 |
|
| } |
| 203 |
|
| |
| 204 |
|
| enum { |
| 205 |
|
| SCLASS_UNDEF, |
| 206 |
|
| SCLASS_STRING, |
| 207 |
|
| SCLASS_GLOB, |
| 208 |
|
| SCLASS_REGEXP, |
| 209 |
|
| SCLASS_REF, |
| 210 |
|
| SCLASS_BLESSED, |
| 211 |
|
| SCLASS_COUNT |
| 212 |
|
| }; |
| 213 |
|
| |
| 214 |
|
| static struct sclass_metadata { |
| 215 |
|
| char const *desc_adj_or_noun_phrase, *keyword_pv; |
| 216 |
|
| SV *keyword_sv; |
| 217 |
|
| bool (*THX_sv_is_sclass)(pTHX_ SV *); |
| 218 |
|
| } sclass_metadata[SCLASS_COUNT] = { |
| 219 |
|
| { "undefined", "UNDEF", NULL, THX_sv_is_undef }, |
| 220 |
|
| { "a string", "STRING", NULL, THX_sv_is_string }, |
| 221 |
|
| { "a typeglob", "GLOB", NULL, THX_sv_is_glob }, |
| 222 |
|
| { "a regexp", "REGEXP", NULL, THX_sv_is_regexp }, |
| 223 |
|
| { "a reference to plain object", |
| 224 |
|
| "REF", NULL, THX_sv_is_untyped_ref }, |
| 225 |
|
| { "a reference to blessed object", |
| 226 |
|
| "BLESSED", NULL, THX_sv_is_untyped_blessed }, |
| 227 |
|
| }; |
| 228 |
|
| |
| 229 |
|
| enum { |
| 230 |
|
| RTYPE_SCALAR, |
| 231 |
|
| RTYPE_ARRAY, |
| 232 |
|
| RTYPE_HASH, |
| 233 |
|
| RTYPE_CODE, |
| 234 |
|
| RTYPE_FORMAT, |
| 235 |
|
| RTYPE_IO, |
| 236 |
|
| RTYPE_COUNT |
| 237 |
|
| }; |
| 238 |
|
| |
| 239 |
|
| static struct rtype_metadata { |
| 240 |
|
| char const *desc_noun, *keyword_pv; |
| 241 |
|
| SV *keyword_sv; |
| 242 |
|
| } rtype_metadata[RTYPE_COUNT] = { |
| 243 |
|
| { "scalar", "SCALAR", NULL }, |
| 244 |
|
| { "array", "ARRAY", NULL }, |
| 245 |
|
| { "hash", "HASH", NULL }, |
| 246 |
|
| { "code", "CODE", NULL }, |
| 247 |
|
| { "format", "FORMAT", NULL }, |
| 248 |
|
| { "io", "IO", NULL }, |
| 249 |
|
| }; |
| 250 |
|
| |
| 251 |
|
| #define PC_TYPE_MASK 0x00f |
| 252 |
|
| #define PC_CROAK 0x010 |
| 253 |
|
| #define PC_STRICTBLESS 0x020 |
| 254 |
|
| #define PC_ABLE 0x040 |
| 255 |
|
| #define PC_ALLOW_UNARY 0x100 |
| 256 |
|
| #define PC_ALLOW_BINARY 0x200 |
| 257 |
|
| |
| 258 |
|
| #define scalar_class(arg) THX_scalar_class(aTHX_ arg) |
| 259 |
22 |
| static I32 THX_scalar_class(pTHX_ SV *arg) |
| 260 |
|
| { |
| 261 |
|
| PERL_UNUSED_THX(); |
| 262 |
22 |
▶ | if(sv_is_glob(arg)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(sv_is_glob(arg)) { |
2 |
20 |
22 |
|
| 263 |
2 |
| return SCLASS_GLOB; |
| 264 |
20 |
▶ | } else if(sv_is_regexp(arg)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(sv_is_regexp(arg)) { |
2 |
18 |
20 |
|
| 265 |
2 |
| return SCLASS_REGEXP; |
| 266 |
18 |
▶ | } else if(!SvOK(arg)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(!SvOK(arg)) { |
2 |
16 |
18 |
|
| 267 |
2 |
| return SCLASS_UNDEF; |
| 268 |
16 |
▶ | } else if(SvROK(arg)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(SvROK(arg)) { |
4 |
12 |
16 |
|
| 269 |
4 |
▶ | return SvOBJECT(SvRV(arg)) ? SCLASS_BLESSED : SCLASS_REF; |
Branch: 1 branch
| Branch | True | False | Total |
| return SvOBJECT(SvRV(arg)) ? SCLASS_BLESSED : SCLASS_REF; |
2 |
2 |
4 |
|
| 270 |
12 |
▶ | } else if(SvFLAGS(arg) & |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(SvFLAGS(arg) & |
12 |
0 |
12 |
|
| 271 |
|
| (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK)) { |
| 272 |
12 |
| return SCLASS_STRING; |
| 273 |
|
| } else { |
| 274 |
0 |
| croak("unknown scalar class, please update Params::Classify\n"); |
| 275 |
|
| } |
| 276 |
|
| } |
| 277 |
|
| |
| 278 |
|
| #define read_reftype_or_neg(reftype) THX_read_reftype_or_neg(aTHX_ reftype) |
| 279 |
992 |
| static I32 THX_read_reftype_or_neg(pTHX_ SV *reftype) |
| 280 |
|
| { |
| 281 |
|
| char *p; |
| 282 |
|
| STRLEN l; |
| 283 |
992 |
▶ | if(!sv_is_string(reftype)) return -2; |
Branch: 3 branches
| Branch | True | False | Total |
| if(!sv_is_string(reftype)) return -2; |
968 |
24 |
992 |
| if(!sv_is_string(reftype)) return -2; |
968 |
0 |
968 |
| if(!sv_is_string(reftype)) return -2; |
48 |
920 |
968 |
|
| 284 |
920 |
| p = SvPV(reftype, l); |
| 285 |
920 |
▶ | if(strlen(p) != l) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if(strlen(p) != l) return -1; |
0 |
920 |
920 |
|
| 286 |
920 |
| switch(p[0]) { |
| 287 |
145 |
| case 'S': |
| 288 |
145 |
▶ | if(!strcmp(p, "SCALAR")) return RTYPE_SCALAR; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strcmp(p, "SCALAR")) return RTYPE_SCALAR; |
145 |
0 |
145 |
|
| 289 |
0 |
| return -1; |
| 290 |
145 |
| case 'A': |
| 291 |
145 |
▶ | if(!strcmp(p, "ARRAY")) return RTYPE_ARRAY; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strcmp(p, "ARRAY")) return RTYPE_ARRAY; |
145 |
0 |
145 |
|
| 292 |
0 |
| return -1; |
| 293 |
145 |
| case 'H': |
| 294 |
145 |
▶ | if(!strcmp(p, "HASH")) return RTYPE_HASH; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strcmp(p, "HASH")) return RTYPE_HASH; |
145 |
0 |
145 |
|
| 295 |
0 |
| return -1; |
| 296 |
145 |
| case 'C': |
| 297 |
145 |
▶ | if(!strcmp(p, "CODE")) return RTYPE_CODE; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strcmp(p, "CODE")) return RTYPE_CODE; |
145 |
0 |
145 |
|
| 298 |
0 |
| return -1; |
| 299 |
145 |
| case 'F': |
| 300 |
145 |
▶ | if(!strcmp(p, "FORMAT")) return RTYPE_FORMAT; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strcmp(p, "FORMAT")) return RTYPE_FORMAT; |
145 |
0 |
145 |
|
| 301 |
0 |
| return -1; |
| 302 |
145 |
| case 'I': |
| 303 |
145 |
▶ | if(!strcmp(p, "IO")) return RTYPE_IO; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!strcmp(p, "IO")) return RTYPE_IO; |
145 |
0 |
145 |
|
| 304 |
0 |
| return -1; |
| 305 |
50 |
| default: |
| 306 |
50 |
| return -1; |
| 307 |
|
| } |
| 308 |
|
| } |
| 309 |
|
| |
| 310 |
|
| #define read_reftype(reftype) THX_read_reftype(aTHX_ reftype) |
| 311 |
966 |
| static I32 THX_read_reftype(pTHX_ SV *reftype) |
| 312 |
|
| { |
| 313 |
966 |
| I32 rtype = read_reftype_or_neg(reftype); |
| 314 |
966 |
▶ | if(rtype < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if(rtype < 0) |
120 |
846 |
966 |
|
| 315 |
120 |
▶ | croak(rtype == -2 ? |
Branch: 1 branch
| Branch | True | False | Total |
| croak(rtype == -2 ? |
72 |
48 |
120 |
|
| 316 |
|
| "reference type argument is not a string\n" : |
| 317 |
|
| "invalid reference type\n"); |
| 318 |
846 |
| return rtype; |
| 319 |
|
| } |
| 320 |
|
| |
| 321 |
|
| #define ref_type(referent) THX_ref_type(aTHX_ referent) |
| 322 |
518 |
| static I32 THX_ref_type(pTHX_ SV *referent) |
| 323 |
|
| { |
| 324 |
|
| PERL_UNUSED_THX(); |
| 325 |
518 |
| switch(SvTYPE(referent)) { |
| 326 |
222 |
| case SVt_NULL: case SVt_IV: case SVt_NV: case_SVt_RV_ |
| 327 |
|
| case SVt_PV: case SVt_PVIV: case SVt_PVNV: |
| 328 |
|
| case SVt_PVMG: case SVt_PVLV: case SVt_PVGV: |
| 329 |
|
| case_SVt_PVBM_ case_SVt_REGEXP_ |
| 330 |
222 |
| return RTYPE_SCALAR; |
| 331 |
74 |
| case SVt_PVAV: |
| 332 |
74 |
| return RTYPE_ARRAY; |
| 333 |
74 |
| case SVt_PVHV: |
| 334 |
74 |
| return RTYPE_HASH; |
| 335 |
74 |
| case SVt_PVCV: |
| 336 |
74 |
| return RTYPE_CODE; |
| 337 |
74 |
| case SVt_PVFM: |
| 338 |
74 |
| return RTYPE_FORMAT; |
| 339 |
0 |
| case SVt_PVIO: |
| 340 |
0 |
| return RTYPE_IO; |
| 341 |
0 |
| default: |
| 342 |
0 |
| croak("unknown SvTYPE, " |
| 343 |
|
| "please update Params::Classify\n"); |
| 344 |
|
| } |
| 345 |
|
| } |
| 346 |
|
| |
| 347 |
|
| #define blessed_class(referent) THX_blessed_class(aTHX_ referent) |
| 348 |
70 |
| static const char *THX_blessed_class(pTHX_ SV *referent) |
| 349 |
|
| { |
| 350 |
70 |
| HV *stash = SvSTASH(referent); |
| 351 |
70 |
▶ | const char *name = HvNAME_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| const char *name = HvNAME_get(stash); |
70 |
0 |
70 |
| const char *name = HvNAME_get(stash); |
70 |
0 |
70 |
| const char *name = HvNAME_get(stash); |
0 |
70 |
70 |
| const char *name = HvNAME_get(stash); |
0 |
0 |
0 |
| const char *name = HvNAME_get(stash); |
70 |
0 |
70 |
| const char *name = HvNAME_get(stash); |
0 |
70 |
70 |
|
| 352 |
|
| PERL_UNUSED_THX(); |
| 353 |
70 |
▶ | return name ? name : "__ANON__"; |
Branch: 1 branch
| Branch | True | False | Total |
| return name ? name : "__ANON__"; |
70 |
0 |
70 |
|
| 354 |
|
| } |
| 355 |
|
| |
| 356 |
|
| #define call_bool_method(objref, methodname, arg) \ |
| 357 |
|
| THX_call_bool_method(aTHX_ objref, methodname, arg) |
| 358 |
142 |
| static bool THX_call_bool_method(pTHX_ SV *objref, const char *methodname, |
| 359 |
|
| SV *arg) |
| 360 |
|
| { |
| 361 |
142 |
| dSP; |
| 362 |
|
| int retcount; |
| 363 |
|
| SV *ret; |
| 364 |
|
| bool retval; |
| 365 |
142 |
| ENTER; |
| 366 |
142 |
| SAVETMPS; |
| 367 |
142 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
142 |
142 |
|
| 368 |
142 |
▶ | XPUSHs(objref); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(objref); |
0 |
142 |
142 |
|
| 369 |
142 |
▶ | XPUSHs(arg); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(arg); |
0 |
142 |
142 |
|
| 370 |
142 |
| PUTBACK; |
| 371 |
142 |
| retcount = call_method(methodname, G_SCALAR); |
| 372 |
142 |
| SPAGAIN; |
| 373 |
142 |
▶ | if(retcount != 1) croak("call_method misbehaving\n"); |
Branch: 1 branch
| Branch | True | False | Total |
| if(retcount != 1) croak("call_method misbehaving\n"); |
0 |
142 |
142 |
|
| 374 |
142 |
| ret = POPs; |
| 375 |
142 |
| retval = cBOOL(SvTRUE(ret)); |
| 376 |
142 |
| PUTBACK; |
| 377 |
142 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
142 |
0 |
142 |
|
| 378 |
142 |
| LEAVE; |
| 379 |
142 |
| return retval; |
| 380 |
|
| } |
| 381 |
|
| |
| 382 |
|
| #define pp1_scalar_class() THX_pp1_scalar_class(aTHX) |
| 383 |
22 |
| static void THX_pp1_scalar_class(pTHX) |
| 384 |
|
| { |
| 385 |
22 |
| dSP; |
| 386 |
22 |
| SV *arg = TOPs; |
| 387 |
22 |
| TOPs = sclass_metadata[scalar_class(arg)].keyword_sv; |
| 388 |
22 |
| } |
| 389 |
|
| |
| 390 |
|
| #define pp1_ref_type() THX_pp1_ref_type(aTHX) |
| 391 |
24 |
| static void THX_pp1_ref_type(pTHX) |
| 392 |
|
| { |
| 393 |
24 |
| dSP; |
| 394 |
|
| SV *arg, *referent; |
| 395 |
24 |
| arg = TOPs; |
| 396 |
16 |
▶ | TOPs = !SvROK(arg) || (referent = SvRV(arg), SvOBJECT(referent)) ? |
Branch: 1 branch
| Branch | True | False | Total |
| TOPs = !SvROK(arg) || (referent = SvRV(arg), SvOBJECT(referent)) ? |
14 |
2 |
16 |
|
| 397 |
40 |
▶ | &PL_sv_undef : |
Branch: 1 branch
| Branch | True | False | Total |
| &PL_sv_undef : |
16 |
8 |
24 |
|
| 398 |
14 |
| rtype_metadata[ref_type(referent)].keyword_sv; |
| 399 |
24 |
| } |
| 400 |
|
| |
| 401 |
|
| #define pp1_blessed_class() THX_pp1_blessed_class(aTHX) |
| 402 |
16 |
| static void THX_pp1_blessed_class(pTHX) |
| 403 |
|
| { |
| 404 |
16 |
| dSP; |
| 405 |
|
| SV *arg, *referent; |
| 406 |
16 |
| arg = TOPs; |
| 407 |
8 |
▶ | TOPs = !SvROK(arg) || (referent = SvRV(arg), !SvOBJECT(referent)) ? |
Branch: 1 branch
| Branch | True | False | Total |
| TOPs = !SvROK(arg) || (referent = SvRV(arg), !SvOBJECT(referent)) ? |
6 |
2 |
8 |
|
| 408 |
18 |
▶ | &PL_sv_undef : |
Branch: 1 branch
| Branch | True | False | Total |
| &PL_sv_undef : |
8 |
8 |
16 |
|
| 409 |
6 |
| sv_2mortal(newSVpv(blessed_class(referent), 0)); |
| 410 |
16 |
| } |
| 411 |
|
| |
| 412 |
|
| #define pp1_check_sclass(t) THX_pp1_check_sclass(aTHX_ t) |
| 413 |
982 |
| static void THX_pp1_check_sclass(pTHX_ I32 t) |
| 414 |
|
| { |
| 415 |
982 |
| dSP; |
| 416 |
982 |
| SV *arg = POPs; |
| 417 |
982 |
| struct sclass_metadata const *sclassmeta = |
| 418 |
982 |
| &sclass_metadata[t & PC_TYPE_MASK]; |
| 419 |
|
| bool matches; |
| 420 |
982 |
| PUTBACK; |
| 421 |
982 |
| matches = sclassmeta->THX_sv_is_sclass(aTHX_ arg); |
| 422 |
982 |
| SPAGAIN; |
| 423 |
982 |
▶ | if(t & PC_CROAK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(t & PC_CROAK) { |
336 |
646 |
982 |
|
| 424 |
336 |
▶ | if(!matches) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!matches) |
274 |
62 |
336 |
|
| 425 |
274 |
| croak("argument is not %s\n", |
| 426 |
|
| sclassmeta->desc_adj_or_noun_phrase); |
| 427 |
62 |
▶ | if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
0 |
62 |
62 |
| if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
0 |
0 |
0 |
|
| 428 |
|
| } else { |
| 429 |
646 |
▶ | SV *result = boolSV(matches); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *result = boolSV(matches); |
152 |
494 |
646 |
|
| 430 |
646 |
▶ | XPUSHs(result); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(result); |
0 |
646 |
646 |
|
| 431 |
|
| } |
| 432 |
708 |
| PUTBACK; |
| 433 |
708 |
| } |
| 434 |
|
| |
| 435 |
|
| #define pp1_check_rtype(t) THX_pp1_check_rtype(aTHX_ t) |
| 436 |
1296 |
| static void THX_pp1_check_rtype(pTHX_ I32 t) |
| 437 |
|
| { |
| 438 |
1296 |
| dSP; |
| 439 |
1296 |
| SV *arg = POPs, *referent; |
| 440 |
1296 |
| I32 rtype = t & PC_TYPE_MASK; |
| 441 |
1296 |
| struct rtype_metadata const *rtypemeta = &rtype_metadata[rtype]; |
| 442 |
3360 |
| bool matches = SvROK(arg) && |
| 443 |
1800 |
▶ | (referent = SvRV(arg), !SvOBJECT(referent)) && |
Branch: 1 branch
| Branch | True | False | Total |
| (referent = SvRV(arg), !SvOBJECT(referent)) && |
768 |
528 |
1296 |
|
| 444 |
504 |
| ref_type(referent) == rtype; |
| 445 |
1296 |
▶ | if(t & PC_CROAK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(t & PC_CROAK) { |
504 |
792 |
1296 |
|
| 446 |
504 |
▶ | if(!matches) |
Branch: 1 branch
| Branch | True | False | Total |
| if(!matches) |
476 |
28 |
504 |
|
| 447 |
476 |
| croak("argument is not a reference to plain %s\n", |
| 448 |
|
| rtypemeta->desc_noun); |
| 449 |
28 |
▶ | if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
0 |
28 |
28 |
| if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
0 |
0 |
0 |
|
| 450 |
|
| } else { |
| 451 |
792 |
▶ | SV *result = boolSV(matches); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *result = boolSV(matches); |
56 |
736 |
792 |
|
| 452 |
792 |
▶ | XPUSHs(result); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(result); |
0 |
792 |
792 |
|
| 453 |
|
| } |
| 454 |
820 |
| PUTBACK; |
| 455 |
820 |
| } |
| 456 |
|
| |
| 457 |
|
| #define pp1_check_dyn_rtype(t) THX_pp1_check_dyn_rtype(aTHX_ t) |
| 458 |
966 |
| static void THX_pp1_check_dyn_rtype(pTHX_ I32 t) |
| 459 |
|
| { |
| 460 |
966 |
| dSP; |
| 461 |
966 |
| SV *type_sv = POPs; |
| 462 |
966 |
| PUTBACK; |
| 463 |
966 |
| pp1_check_rtype(t | read_reftype(type_sv)); |
| 464 |
489 |
| } |
| 465 |
|
| |
| 466 |
|
| #define pp1_check_dyn_battr(t) THX_pp1_check_dyn_battr(aTHX_ t) |
| 467 |
1084 |
| static void THX_pp1_check_dyn_battr(pTHX_ I32 t) |
| 468 |
|
| { |
| 469 |
1084 |
| dSP; |
| 470 |
1084 |
| SV *attr, *arg, *meth = NULL; |
| 471 |
|
| bool matches; |
| 472 |
1084 |
| attr = POPs; |
| 473 |
1084 |
▶ | if(t & PC_ABLE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(t & PC_ABLE) { |
476 |
608 |
1084 |
|
| 474 |
476 |
▶ | if(sv_is_string(attr)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if(sv_is_string(attr)) { |
452 |
24 |
476 |
| if(sv_is_string(attr)) { |
452 |
0 |
452 |
| if(sv_is_string(attr)) { |
164 |
288 |
452 |
|
| 475 |
164 |
| meth = attr; |
| 476 |
|
| } else { |
| 477 |
|
| AV *methods_av; |
| 478 |
|
| array_ix_t alen, pos; |
| 479 |
312 |
▶ | if(!SvROK(attr) || SvOBJECT(SvRV(attr)) || |
Branch: 2 branches
| Branch | True | False | Total |
| if(!SvROK(attr) || SvOBJECT(SvRV(attr)) || |
264 |
48 |
312 |
| if(!SvROK(attr) || SvOBJECT(SvRV(attr)) || |
264 |
0 |
264 |
|
| 480 |
264 |
▶ | SvTYPE(SvRV(attr)) != SVt_PVAV) |
Branch: 1 branch
| Branch | True | False | Total |
| SvTYPE(SvRV(attr)) != SVt_PVAV) |
24 |
240 |
264 |
|
| 481 |
72 |
| croak("methods argument is not " |
| 482 |
|
| "a string or array\n"); |
| 483 |
240 |
| methods_av = (AV*)SvRV(attr); |
| 484 |
240 |
| alen = av_len(methods_av); |
| 485 |
408 |
▶ | for(pos = 0; pos <= alen; pos++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(pos = 0; pos <= alen; pos++) { |
240 |
168 |
408 |
|
| 486 |
240 |
| SV **m_ptr = av_fetch(methods_av, pos, 0); |
| 487 |
240 |
▶ | if(!m_ptr || !sv_is_string(*m_ptr)) |
Branch: 4 branches
| Branch | True | False | Total |
| if(!m_ptr || !sv_is_string(*m_ptr)) |
240 |
0 |
240 |
| if(!m_ptr || !sv_is_string(*m_ptr)) |
216 |
24 |
240 |
| if(!m_ptr || !sv_is_string(*m_ptr)) |
216 |
0 |
216 |
| if(!m_ptr || !sv_is_string(*m_ptr)) |
48 |
168 |
216 |
|
| 488 |
72 |
| croak("method name is not a string\n"); |
| 489 |
|
| } |
| 490 |
168 |
▶ | if(alen != -1) meth = *av_fetch(methods_av, 0, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| if(alen != -1) meth = *av_fetch(methods_av, 0, 0); |
84 |
84 |
168 |
|
| 491 |
|
| } |
| 492 |
|
| } else { |
| 493 |
608 |
▶ | if(!sv_is_string(attr)) |
Branch: 3 branches
| Branch | True | False | Total |
| if(!sv_is_string(attr)) |
560 |
48 |
608 |
| if(!sv_is_string(attr)) |
560 |
0 |
560 |
| if(!sv_is_string(attr)) |
96 |
464 |
560 |
|
| 494 |
144 |
| croak("class argument is not a string\n"); |
| 495 |
|
| } |
| 496 |
796 |
| arg = POPs; |
| 497 |
796 |
▶ | if((matches = SvROK(arg) && SvOBJECT(SvRV(arg)))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if((matches = SvROK(arg) && SvOBJECT(SvRV(arg)))) { |
440 |
356 |
796 |
| if((matches = SvROK(arg) && SvOBJECT(SvRV(arg)))) { |
218 |
222 |
440 |
| if((matches = SvROK(arg) && SvOBJECT(SvRV(arg)))) { |
218 |
578 |
796 |
|
| 498 |
218 |
▶ | if(t & PC_ABLE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(t & PC_ABLE) { |
90 |
128 |
218 |
|
| 499 |
90 |
| PUTBACK; |
| 500 |
90 |
▶ | if(!SvROK(attr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvROK(attr)) { |
50 |
40 |
90 |
|
| 501 |
50 |
| meth = attr; |
| 502 |
50 |
| matches = call_bool_method(arg, "can", attr); |
| 503 |
|
| } else { |
| 504 |
40 |
| AV *methods_av = (AV*)SvRV(attr); |
| 505 |
40 |
| array_ix_t alen = av_len(methods_av), pos; |
| 506 |
56 |
▶ | for(pos = 0; pos <= alen; pos++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(pos = 0; pos <= alen; pos++) { |
28 |
28 |
56 |
|
| 507 |
28 |
| meth = *av_fetch(methods_av, pos, 0); |
| 508 |
28 |
▶ | if(!call_bool_method(arg, "can", |
Branch: 1 branch
| Branch | True | False | Total |
| if(!call_bool_method(arg, "can", |
12 |
16 |
28 |
|
| 509 |
|
| meth)) { |
| 510 |
12 |
| matches = 0; |
| 511 |
12 |
| break; |
| 512 |
|
| } |
| 513 |
|
| } |
| 514 |
|
| } |
| 515 |
90 |
| SPAGAIN; |
| 516 |
128 |
▶ | } else if(t & PC_STRICTBLESS) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(t & PC_STRICTBLESS) { |
64 |
64 |
128 |
|
| 517 |
64 |
| char const *actual_class = blessed_class(SvRV(arg)); |
| 518 |
|
| char const *check_class; |
| 519 |
|
| STRLEN check_len; |
| 520 |
64 |
| check_class = SvPV(attr, check_len); |
| 521 |
88 |
▶ | matches = check_len == strlen(actual_class) && |
Branch: 1 branch
| Branch | True | False | Total |
| matches = check_len == strlen(actual_class) && |
24 |
40 |
64 |
|
| 522 |
24 |
▶ | !strcmp(check_class, actual_class); |
Branch: 1 branch
| Branch | True | False | Total |
| !strcmp(check_class, actual_class); |
12 |
12 |
24 |
|
| 523 |
|
| } else { |
| 524 |
64 |
| PUTBACK; |
| 525 |
64 |
| matches = call_bool_method(arg, "isa", attr); |
| 526 |
64 |
| SPAGAIN; |
| 527 |
|
| } |
| 528 |
|
| } |
| 529 |
796 |
▶ | if(t & PC_CROAK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(t & PC_CROAK) { |
294 |
502 |
796 |
|
| 530 |
294 |
▶ | if(!matches) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(!matches) { |
266 |
28 |
294 |
|
| 531 |
266 |
▶ | if(t & PC_ABLE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(t & PC_ABLE) { |
108 |
158 |
266 |
|
| 532 |
108 |
▶ | if(meth) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(meth) { |
76 |
32 |
108 |
|
| 533 |
76 |
| croak("argument is not able to " |
| 534 |
|
| "perform method \"%s\"\n", |
| 535 |
|
| SvPV_nolen(meth)); |
| 536 |
|
| } else { |
| 537 |
32 |
| croak("argument is not able to " |
| 538 |
|
| "perform at all\n"); |
| 539 |
|
| } |
| 540 |
|
| } else { |
| 541 |
158 |
▶ | croak("argument is not a reference to " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("argument is not a reference to " |
80 |
78 |
158 |
|
| 542 |
|
| "%sblessed %s\n", |
| 543 |
|
| t & PC_STRICTBLESS ? "strictly " : "", |
| 544 |
|
| SvPV_nolen(attr)); |
| 545 |
|
| } |
| 546 |
|
| } |
| 547 |
28 |
▶ | if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
0 |
28 |
28 |
| if(GIMME_V == G_SCALAR) XPUSHs(&PL_sv_undef); |
0 |
0 |
0 |
|
| 548 |
|
| } else { |
| 549 |
502 |
▶ | SV *result = boolSV(matches); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *result = boolSV(matches); |
60 |
442 |
502 |
|
| 550 |
502 |
▶ | XPUSHs(result); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(result); |
0 |
502 |
502 |
|
| 551 |
|
| } |
| 552 |
530 |
| PUTBACK; |
| 553 |
530 |
| } |
| 554 |
|
| |
| 555 |
|
| #if QUSE_CUSTOM_OPS |
| 556 |
|
| |
| 557 |
11 |
| static OP *THX_pp_scalar_class(pTHX) |
| 558 |
|
| { |
| 559 |
11 |
| pp1_scalar_class(); |
| 560 |
11 |
| return NORMAL; |
| 561 |
|
| } |
| 562 |
|
| |
| 563 |
12 |
| static OP *THX_pp_ref_type(pTHX) |
| 564 |
|
| { |
| 565 |
12 |
| pp1_ref_type(); |
| 566 |
12 |
| return NORMAL; |
| 567 |
|
| } |
| 568 |
|
| |
| 569 |
8 |
| static OP *THX_pp_blessed_class(pTHX) |
| 570 |
|
| { |
| 571 |
8 |
| pp1_blessed_class(); |
| 572 |
8 |
| return NORMAL; |
| 573 |
|
| } |
| 574 |
|
| |
| 575 |
606 |
| static OP *THX_pp_check_sclass(pTHX) |
| 576 |
|
| { |
| 577 |
606 |
| pp1_check_sclass(PL_op->op_private); |
| 578 |
469 |
| return NORMAL; |
| 579 |
|
| } |
| 580 |
|
| |
| 581 |
450 |
| static OP *THX_pp_check_rtype(pTHX) |
| 582 |
|
| { |
| 583 |
450 |
| pp1_check_rtype(PL_op->op_private); |
| 584 |
331 |
| return NORMAL; |
| 585 |
|
| } |
| 586 |
|
| |
| 587 |
510 |
| static OP *THX_pp_check_dyn_rtype(pTHX) |
| 588 |
|
| { |
| 589 |
510 |
| pp1_check_dyn_rtype(PL_op->op_private); |
| 590 |
331 |
| return NORMAL; |
| 591 |
|
| } |
| 592 |
|
| |
| 593 |
689 |
| static OP *THX_pp_check_dyn_battr(pTHX) |
| 594 |
|
| { |
| 595 |
689 |
| pp1_check_dyn_battr(PL_op->op_private); |
| 596 |
412 |
| return NORMAL; |
| 597 |
|
| } |
| 598 |
|
| |
| 599 |
|
| #endif /* QUSE_CUSTOM_OPS */ |
| 600 |
|
| |
| 601 |
|
| #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE |
| 602 |
|
| static void S_croak_xs_usage(const CV *, const char *); |
| 603 |
|
| # define croak_xs_usage(cv, params) S_croak_xs_usage(cv, params) |
| 604 |
|
| #endif /* !PERL_ARGS_ASSERT_CROAK_XS_USAGE */ |
| 605 |
|
| |
| 606 |
11 |
| static void THX_xsfunc_scalar_class(pTHX_ CV *cv) |
| 607 |
|
| { |
| 608 |
11 |
| dMARK; dSP; |
| 609 |
11 |
▶ | if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
Branch: 1 branch
| Branch | True | False | Total |
| if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
0 |
11 |
11 |
|
| 610 |
11 |
| pp1_scalar_class(); |
| 611 |
11 |
| } |
| 612 |
|
| |
| 613 |
12 |
| static void THX_xsfunc_ref_type(pTHX_ CV *cv) |
| 614 |
|
| { |
| 615 |
12 |
| dMARK; dSP; |
| 616 |
12 |
▶ | if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
Branch: 1 branch
| Branch | True | False | Total |
| if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
0 |
12 |
12 |
|
| 617 |
12 |
| pp1_ref_type(); |
| 618 |
12 |
| } |
| 619 |
|
| |
| 620 |
8 |
| static void THX_xsfunc_blessed_class(pTHX_ CV *cv) |
| 621 |
|
| { |
| 622 |
8 |
| dMARK; dSP; |
| 623 |
8 |
▶ | if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
Branch: 1 branch
| Branch | True | False | Total |
| if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
0 |
8 |
8 |
|
| 624 |
8 |
| pp1_blessed_class(); |
| 625 |
8 |
| } |
| 626 |
|
| |
| 627 |
234 |
| static void THX_xsfunc_check_sclass(pTHX_ CV *cv) |
| 628 |
|
| { |
| 629 |
234 |
| dMARK; dSP; |
| 630 |
234 |
▶ | if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
Branch: 1 branch
| Branch | True | False | Total |
| if(SP - MARK != 1) croak_xs_usage(cv, "arg"); |
0 |
234 |
234 |
|
| 631 |
234 |
| pp1_check_sclass(CvXSUBANY(cv).any_i32); |
| 632 |
159 |
| } |
| 633 |
|
| |
| 634 |
500 |
| static void THX_xsfunc_check_ref(pTHX_ CV *cv) |
| 635 |
|
| { |
| 636 |
500 |
| I32 cvflags = CvXSUBANY(cv).any_i32; |
| 637 |
500 |
| dMARK; dSP; |
| 638 |
500 |
| switch(SP - MARK) { |
| 639 |
44 |
| case 1: pp1_check_sclass(cvflags); break; |
| 640 |
456 |
| case 2: pp1_check_dyn_rtype(cvflags & ~PC_TYPE_MASK); break; |
| 641 |
0 |
| default: croak_xs_usage(cv, "arg, type"); |
| 642 |
|
| } |
| 643 |
188 |
| } |
| 644 |
|
| |
| 645 |
493 |
| static void THX_xsfunc_check_blessed(pTHX_ CV *cv) |
| 646 |
|
| { |
| 647 |
493 |
| I32 cvflags = CvXSUBANY(cv).any_i32; |
| 648 |
493 |
| dMARK; dSP; |
| 649 |
493 |
| switch(SP - MARK) { |
| 650 |
98 |
| case 1: pp1_check_sclass(cvflags); break; |
| 651 |
395 |
| case 2: pp1_check_dyn_battr(cvflags & ~PC_TYPE_MASK); break; |
| 652 |
0 |
| default: croak_xs_usage(cv, "arg, class"); |
| 653 |
|
| } |
| 654 |
168 |
| } |
| 655 |
|
| |
| 656 |
|
| #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE |
| 657 |
|
| # undef croak_xs_usage |
| 658 |
|
| #endif /* !PERL_ARGS_ASSERT_CROAK_XS_USAGE */ |
| 659 |
|
| |
| 660 |
|
| #if QUSE_CUSTOM_OPS |
| 661 |
|
| |
| 662 |
|
| static PTR_TBL_t *ppmap; |
| 663 |
|
| |
| 664 |
103 |
| static OP *THX_ck_entersub_pc(pTHX_ OP *entersubop, GV *namegv, SV *protosv) |
| 665 |
|
| { |
| 666 |
103 |
| CV *cv = (CV*)protosv; |
| 667 |
103 |
| OP *(*THX_ppfunc)(pTHX) = |
| 668 |
103 |
| DPTR2FPTR(OP*(*)(pTHX), ptr_table_fetch(ppmap, cv)); |
| 669 |
103 |
| I32 cvflags = CvXSUBANY(cv).any_i32; |
| 670 |
|
| OP *pushop, *aop, *bop, *cop, *op; |
| 671 |
103 |
| entersubop = ck_entersub_args_proto(entersubop, namegv, protosv); |
| 672 |
103 |
| pushop = cUNOPx(entersubop)->op_first; |
| 673 |
103 |
▶ | if(!OpHAS_SIBLING(pushop)) pushop = cUNOPx(pushop)->op_first; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!OpHAS_SIBLING(pushop)) pushop = cUNOPx(pushop)->op_first; |
103 |
0 |
103 |
|
| 674 |
103 |
▶ | aop = OpSIBLING(pushop); |
Branch: 1 branch
| Branch | True | False | Total |
| aop = OpSIBLING(pushop); |
103 |
0 |
103 |
|
| 675 |
103 |
▶ | bop = OpSIBLING(aop); |
Branch: 1 branch
| Branch | True | False | Total |
| bop = OpSIBLING(aop); |
103 |
0 |
103 |
|
| 676 |
103 |
▶ | cop = bop ? OpSIBLING(bop) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| cop = bop ? OpSIBLING(bop) : NULL; |
103 |
0 |
103 |
| cop = bop ? OpSIBLING(bop) : NULL; |
66 |
37 |
103 |
|
| 677 |
103 |
▶ | if(bop && !cop) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(bop && !cop) { |
103 |
0 |
103 |
| if(bop && !cop) { |
37 |
66 |
103 |
|
| 678 |
37 |
▶ | if(!(cvflags & PC_ALLOW_UNARY)) return entersubop; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!(cvflags & PC_ALLOW_UNARY)) return entersubop; |
0 |
37 |
37 |
|
| 679 |
37 |
| unary: |
| 680 |
61 |
| OpMORESIB_set(pushop, bop); |
| 681 |
61 |
| OpLASTSIB_set(aop, NULL); |
| 682 |
61 |
| op_free(entersubop); |
| 683 |
61 |
| op = newUNOP(OP_NULL, 0, aop); |
| 684 |
61 |
| op->op_type = OP_RAND; |
| 685 |
61 |
| op->op_ppaddr = THX_ppfunc; |
| 686 |
61 |
| op->op_private = (U8)cvflags; |
| 687 |
61 |
| return op; |
| 688 |
66 |
▶ | } else if(cop && !OpHAS_SIBLING(cop)) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if(cop && !OpHAS_SIBLING(cop)) { |
66 |
0 |
66 |
| } else if(cop && !OpHAS_SIBLING(cop)) { |
66 |
0 |
66 |
|
| 689 |
66 |
▶ | if(!(cvflags & PC_ALLOW_BINARY)) return entersubop; |
Branch: 1 branch
| Branch | True | False | Total |
| if(!(cvflags & PC_ALLOW_BINARY)) return entersubop; |
0 |
66 |
66 |
|
| 690 |
66 |
▶ | if(THX_ppfunc == THX_pp_check_sclass && |
Branch: 1 branch
| Branch | True | False | Total |
| if(THX_ppfunc == THX_pp_check_sclass && |
66 |
0 |
66 |
|
| 691 |
66 |
▶ | (cvflags & PC_TYPE_MASK) == SCLASS_REF) { |
Branch: 1 branch
| Branch | True | False | Total |
| (cvflags & PC_TYPE_MASK) == SCLASS_REF) { |
34 |
32 |
66 |
|
| 692 |
|
| I32 rtype; |
| 693 |
34 |
| cvflags &= ~PC_TYPE_MASK; |
| 694 |
60 |
| if(bop->op_type == OP_CONST && |
| 695 |
26 |
| (rtype = read_reftype_or_neg(cSVOPx_sv(bop))) |
| 696 |
|
| >= 0) { |
| 697 |
24 |
| cvflags |= rtype; |
| 698 |
24 |
| THX_ppfunc = THX_pp_check_rtype; |
| 699 |
24 |
| goto unary; |
| 700 |
|
| } |
| 701 |
10 |
| THX_ppfunc = THX_pp_check_dyn_rtype; |
| 702 |
32 |
▶ | } else if(THX_ppfunc == THX_pp_check_sclass && |
Branch: 1 branch
| Branch | True | False | Total |
| } else if(THX_ppfunc == THX_pp_check_sclass && |
32 |
0 |
32 |
|
| 703 |
32 |
▶ | (cvflags & PC_TYPE_MASK) == SCLASS_BLESSED) { |
Branch: 1 branch
| Branch | True | False | Total |
| (cvflags & PC_TYPE_MASK) == SCLASS_BLESSED) { |
32 |
0 |
32 |
|
| 704 |
32 |
| cvflags &= ~PC_TYPE_MASK; |
| 705 |
32 |
| THX_ppfunc = THX_pp_check_dyn_battr; |
| 706 |
|
| } |
| 707 |
42 |
| OpMORESIB_set(pushop, cop); |
| 708 |
42 |
| OpLASTSIB_set(aop, NULL); |
| 709 |
42 |
| OpLASTSIB_set(bop, NULL); |
| 710 |
42 |
| op_free(entersubop); |
| 711 |
42 |
| op = newBINOP(OP_NULL, 0, aop, bop); |
| 712 |
42 |
| op->op_type = OP_RAND; |
| 713 |
42 |
| op->op_ppaddr = THX_ppfunc; |
| 714 |
42 |
| op->op_private = (U8)cvflags; |
| 715 |
42 |
| return op; |
| 716 |
|
| } else { |
| 717 |
0 |
| return entersubop; |
| 718 |
|
| } |
| 719 |
|
| } |
| 720 |
|
| |
| 721 |
|
| #endif /* QUSE_CUSTOM_OPS */ |
| 722 |
|
| |
| 723 |
|
| MODULE = Params::Classify PACKAGE = Params::Classify |
| 724 |
|
| |
| 725 |
|
| PROTOTYPES: DISABLE |
| 726 |
|
| |
| 727 |
|
| BOOT: |
| 728 |
|
| { |
| 729 |
|
| int i; |
| 730 |
42 |
▶ | for(i = RTYPE_COUNT; i--; ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = RTYPE_COUNT; i--; ) { |
36 |
6 |
42 |
|
| 731 |
36 |
| struct rtype_metadata *rtypemeta = &rtype_metadata[i]; |
| 732 |
36 |
| rtypemeta->keyword_sv = |
| 733 |
36 |
| newSVpvn_share(rtypemeta->keyword_pv, |
| 734 |
|
| strlen(rtypemeta->keyword_pv), 0); |
| 735 |
|
| } |
| 736 |
|
| } |
| 737 |
|
| { |
| 738 |
|
| int i; |
| 739 |
6 |
| SV *tsv = sv_2mortal(newSV(0)); |
| 740 |
|
| #if QUSE_CUSTOM_OPS |
| 741 |
6 |
| ppmap = ptr_table_new(); |
| 742 |
|
| # define SETUP_CUSTOM_OP(pcv, THX_ppfunc) \ |
| 743 |
|
| do { \ |
| 744 |
|
| ptr_table_store(ppmap, FPTR2DPTR(void*, pcv), \ |
| 745 |
|
| FPTR2DPTR(void*, THX_ppfunc)); \ |
| 746 |
|
| cv_set_call_checker(pcv, THX_ck_entersub_pc, (SV*)pcv); \ |
| 747 |
|
| } while(0) |
| 748 |
|
| #else /* !QUSE_CUSTOM_OPS */ |
| 749 |
|
| # define SETUP_CUSTOM_OP(pcv, THX_ppfunc) ((void)0) |
| 750 |
|
| #endif /* !QUSE_CUSTOM_OPS */ |
| 751 |
|
| #define SETUP_SIMPLE_UNARY_XSUB(NAME) \ |
| 752 |
|
| do { \ |
| 753 |
|
| CV *pcv = newXSproto_portable("Params::Classify::"#NAME, \ |
| 754 |
|
| THX_xsfunc_##NAME, __FILE__, "$"); \ |
| 755 |
|
| CvXSUBANY(pcv).any_i32 = PC_ALLOW_UNARY; \ |
| 756 |
|
| SETUP_CUSTOM_OP(pcv, THX_pp_##NAME); \ |
| 757 |
|
| } while(0) |
| 758 |
6 |
| SETUP_SIMPLE_UNARY_XSUB(scalar_class); |
| 759 |
6 |
| SETUP_SIMPLE_UNARY_XSUB(ref_type); |
| 760 |
6 |
| SETUP_SIMPLE_UNARY_XSUB(blessed_class); |
| 761 |
42 |
▶ | for(i = SCLASS_COUNT; i--; ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = SCLASS_COUNT; i--; ) { |
36 |
6 |
42 |
|
| 762 |
36 |
| bool is_refish = i >= SCLASS_REF; |
| 763 |
36 |
| struct sclass_metadata *sclassmeta = &sclass_metadata[i]; |
| 764 |
36 |
| char const *keyword_pv = sclassmeta->keyword_pv, *p; |
| 765 |
|
| char lckeyword[8], *q; |
| 766 |
36 |
▶ | I32 cvflags = PC_ALLOW_UNARY | |
Branch: 1 branch
| Branch | True | False | Total |
| I32 cvflags = PC_ALLOW_UNARY | |
12 |
24 |
36 |
|
| 767 |
|
| (is_refish ? PC_ALLOW_BINARY : 0) | i; |
| 768 |
36 |
▶ | I32 variant = (i == SCLASS_BLESSED ? PC_ABLE : 0) | PC_CROAK; |
Branch: 1 branch
| Branch | True | False | Total |
| I32 variant = (i == SCLASS_BLESSED ? PC_ABLE : 0) | PC_CROAK; |
6 |
30 |
36 |
|
| 769 |
36 |
| void (*THX_xsfunc)(pTHX_ CV*) = |
| 770 |
66 |
▶ | i == SCLASS_REF ? THX_xsfunc_check_ref : |
Branch: 1 branch
| Branch | True | False | Total |
| i == SCLASS_REF ? THX_xsfunc_check_ref : |
30 |
6 |
36 |
|
| 771 |
30 |
▶ | i == SCLASS_BLESSED ? THX_xsfunc_check_blessed : |
Branch: 1 branch
| Branch | True | False | Total |
| i == SCLASS_BLESSED ? THX_xsfunc_check_blessed : |
6 |
24 |
30 |
|
| 772 |
|
| THX_xsfunc_check_sclass; |
| 773 |
222 |
▶ | for(p = keyword_pv, q = lckeyword; *p; p++, q++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(p = keyword_pv, q = lckeyword; *p; p++, q++) |
186 |
36 |
222 |
|
| 774 |
186 |
| *q = *p | 0x20; |
| 775 |
36 |
| *q = 0; |
| 776 |
36 |
| sclassmeta->keyword_sv = |
| 777 |
36 |
| newSVpvn_share(keyword_pv, strlen(keyword_pv), 0); |
| 778 |
132 |
▶ | for(; variant >= 0; variant -= PC_CROAK) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(; variant >= 0; variant -= PC_CROAK) { |
96 |
36 |
132 |
|
| 779 |
|
| CV *pcv; |
| 780 |
96 |
▶ | sv_setpvf(tsv, "Params::Classify::%s_%s", |
Branch: 3 branches
| Branch | True | False | Total |
| sv_setpvf(tsv, "Params::Classify::%s_%s", |
84 |
12 |
96 |
| sv_setpvf(tsv, "Params::Classify::%s_%s", |
72 |
12 |
84 |
| sv_setpvf(tsv, "Params::Classify::%s_%s", |
48 |
48 |
96 |
|
| 781 |
|
| variant & PC_CROAK ? "check" : "is", |
| 782 |
|
| variant & PC_ABLE ? "able" : |
| 783 |
|
| variant & PC_STRICTBLESS ? "strictly_blessed" : |
| 784 |
|
| lckeyword); |
| 785 |
96 |
▶ | pcv = newXSproto_portable(SvPVX(tsv), |
Branch: 1 branch
| Branch | True | False | Total |
| pcv = newXSproto_portable(SvPVX(tsv), |
48 |
48 |
96 |
|
| 786 |
|
| THX_xsfunc, __FILE__, is_refish ? "$;$" : "$"); |
| 787 |
96 |
| CvXSUBANY(pcv).any_i32 = cvflags | variant; |
| 788 |
96 |
| SETUP_CUSTOM_OP(pcv, THX_pp_check_sclass); |
| 789 |
|
| } |
| 790 |
|
| } |
| 791 |
|
| } |