| 1 | #define PERL_IN_XS_APITEST |
| 2 | #include "EXTERN.h" |
| 3 | #include "perl.h" |
| 4 | #include "XSUB.h" |
| 5 | |
| 6 | typedef SV *SVREF; |
| 7 | typedef PTR_TBL_t *XS__APItest__PtrTable; |
| 8 | |
| 9 | #define croak_fail() croak("fail at " __FILE__ " line %d", __LINE__) |
| 10 | #define croak_fail_ne(h, w) croak("fail %p!=%p at " __FILE__ " line %d", (h), (w), __LINE__) |
| 11 | |
| 12 | /* for my_cxt tests */ |
| 13 | |
| 14 | #define MY_CXT_KEY "XS::APItest::_guts" XS_VERSION |
| 15 | |
| 16 | typedef struct { |
| 17 | int i; |
| 18 | SV *sv; |
| 19 | GV *cscgv; |
| 20 | AV *cscav; |
| 21 | AV *bhkav; |
| 22 | bool bhk_record; |
| 23 | peep_t orig_peep; |
| 24 | peep_t orig_rpeep; |
| 25 | int peep_recording; |
| 26 | AV *peep_recorder; |
| 27 | AV *rpeep_recorder; |
| 28 | AV *xop_record; |
| 29 | } my_cxt_t; |
| 30 | |
| 31 | START_MY_CXT |
| 32 | |
| 33 | MGVTBL vtbl_foo, vtbl_bar; |
| 34 | |
| 35 | /* indirect functions to test the [pa]MY_CXT macros */ |
| 36 | |
| 37 | int |
| 38 | my_cxt_getint_p(pMY_CXT) |
| 39 | { |
| 40 | return MY_CXT.i; |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | my_cxt_setint_p(pMY_CXT_ int i) |
| 45 | { |
| 46 | MY_CXT.i = i; |
| 47 | } |
| 48 | |
| 49 | SV* |
| 50 | my_cxt_getsv_interp_context(void) |
| 51 | { |
| 52 | dTHX; |
| 53 | dMY_CXT_INTERP(my_perl); |
| 54 | return MY_CXT.sv; |
| 55 | } |
| 56 | |
| 57 | SV* |
| 58 | my_cxt_getsv_interp(void) |
| 59 | { |
| 60 | dMY_CXT; |
| 61 | return MY_CXT.sv; |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | my_cxt_setsv_p(SV* sv _pMY_CXT) |
| 66 | { |
| 67 | MY_CXT.sv = sv; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* from exception.c */ |
| 72 | int apitest_exception(int); |
| 73 | |
| 74 | /* from core_or_not.inc */ |
| 75 | bool sv_setsv_cow_hashkey_core(void); |
| 76 | bool sv_setsv_cow_hashkey_notcore(void); |
| 77 | |
| 78 | /* A routine to test hv_delayfree_ent |
| 79 | (which itself is tested by testing on hv_free_ent */ |
| 80 | |
| 81 | typedef void (freeent_function)(pTHX_ HV *, register HE *); |
| 82 | |
| 83 | void |
| 84 | test_freeent(freeent_function *f) { |
| 85 | dTHX; |
| 86 | dSP; |
| 87 | HV *test_hash = newHV(); |
| 88 | HE *victim; |
| 89 | SV *test_scalar; |
| 90 | U32 results[4]; |
| 91 | int i; |
| 92 | |
| 93 | #ifdef PURIFY |
| 94 | victim = (HE*)safemalloc(sizeof(HE)); |
| 95 | #else |
| 96 | /* Storing then deleting something should ensure that a hash entry is |
| 97 | available. */ |
| 98 | (void) hv_store(test_hash, "", 0, &PL_sv_yes, 0); |
| 99 | (void) hv_delete(test_hash, "", 0, 0); |
| 100 | |
| 101 | /* We need to "inline" new_he here as it's static, and the functions we |
| 102 | test expect to be able to call del_HE on the HE */ |
| 103 | if (!PL_body_roots[HE_SVSLOT]) |
| 104 | croak("PL_he_root is 0"); |
| 105 | victim = (HE*) PL_body_roots[HE_SVSLOT]; |
| 106 | PL_body_roots[HE_SVSLOT] = HeNEXT(victim); |
| 107 | #endif |
| 108 | |
| 109 | victim->hent_hek = Perl_share_hek(aTHX_ "", 0, 0); |
| 110 | |
| 111 | test_scalar = newSV(0); |
| 112 | SvREFCNT_inc(test_scalar); |
| 113 | HeVAL(victim) = test_scalar; |
| 114 | |
| 115 | /* Need this little game else we free the temps on the return stack. */ |
| 116 | results[0] = SvREFCNT(test_scalar); |
| 117 | SAVETMPS; |
| 118 | results[1] = SvREFCNT(test_scalar); |
| 119 | f(aTHX_ test_hash, victim); |
| 120 | results[2] = SvREFCNT(test_scalar); |
| 121 | FREETMPS; |
| 122 | results[3] = SvREFCNT(test_scalar); |
| 123 | |
| 124 | i = 0; |
| 125 | do { |
| 126 | mPUSHu(results[i]); |
| 127 | } while (++i < (int)(sizeof(results)/sizeof(results[0]))); |
| 128 | |
| 129 | /* Goodbye to our extra reference. */ |
| 130 | SvREFCNT_dec(test_scalar); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static I32 |
| 135 | bitflip_key(pTHX_ IV action, SV *field) { |
| 136 | MAGIC *mg = mg_find(field, PERL_MAGIC_uvar); |
| 137 | SV *keysv; |
| 138 | PERL_UNUSED_ARG(action); |
| 139 | if (mg && (keysv = mg->mg_obj)) { |
| 140 | STRLEN len; |
| 141 | const char *p = SvPV(keysv, len); |
| 142 | |
| 143 | if (len) { |
| 144 | SV *newkey = newSV(len); |
| 145 | char *new_p = SvPVX(newkey); |
| 146 | |
| 147 | if (SvUTF8(keysv)) { |
| 148 | const char *const end = p + len; |
| 149 | while (p < end) { |
| 150 | STRLEN len; |
| 151 | UV chr = utf8_to_uvuni_buf((U8 *)p, (U8 *) end, &len); |
| 152 | new_p = (char *)uvuni_to_utf8((U8 *)new_p, chr ^ 32); |
| 153 | p += len; |
| 154 | } |
| 155 | SvUTF8_on(newkey); |
| 156 | } else { |
| 157 | while (len--) |
| 158 | *new_p++ = *p++ ^ 32; |
| 159 | } |
| 160 | *new_p = '\0'; |
| 161 | SvCUR_set(newkey, SvCUR(keysv)); |
| 162 | SvPOK_on(newkey); |
| 163 | |
| 164 | mg->mg_obj = newkey; |
| 165 | } |
| 166 | } |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static I32 |
| 171 | rot13_key(pTHX_ IV action, SV *field) { |
| 172 | MAGIC *mg = mg_find(field, PERL_MAGIC_uvar); |
| 173 | SV *keysv; |
| 174 | PERL_UNUSED_ARG(action); |
| 175 | if (mg && (keysv = mg->mg_obj)) { |
| 176 | STRLEN len; |
| 177 | const char *p = SvPV(keysv, len); |
| 178 | |
| 179 | if (len) { |
| 180 | SV *newkey = newSV(len); |
| 181 | char *new_p = SvPVX(newkey); |
| 182 | |
| 183 | /* There's a deliberate fencepost error here to loop len + 1 times |
| 184 | to copy the trailing \0 */ |
| 185 | do { |
| 186 | char new_c = *p++; |
| 187 | /* Try doing this cleanly and clearly in EBCDIC another way: */ |
| 188 | switch (new_c) { |
| 189 | case 'A': new_c = 'N'; break; |
| 190 | case 'B': new_c = 'O'; break; |
| 191 | case 'C': new_c = 'P'; break; |
| 192 | case 'D': new_c = 'Q'; break; |
| 193 | case 'E': new_c = 'R'; break; |
| 194 | case 'F': new_c = 'S'; break; |
| 195 | case 'G': new_c = 'T'; break; |
| 196 | case 'H': new_c = 'U'; break; |
| 197 | case 'I': new_c = 'V'; break; |
| 198 | case 'J': new_c = 'W'; break; |
| 199 | case 'K': new_c = 'X'; break; |
| 200 | case 'L': new_c = 'Y'; break; |
| 201 | case 'M': new_c = 'Z'; break; |
| 202 | case 'N': new_c = 'A'; break; |
| 203 | case 'O': new_c = 'B'; break; |
| 204 | case 'P': new_c = 'C'; break; |
| 205 | case 'Q': new_c = 'D'; break; |
| 206 | case 'R': new_c = 'E'; break; |
| 207 | case 'S': new_c = 'F'; break; |
| 208 | case 'T': new_c = 'G'; break; |
| 209 | case 'U': new_c = 'H'; break; |
| 210 | case 'V': new_c = 'I'; break; |
| 211 | case 'W': new_c = 'J'; break; |
| 212 | case 'X': new_c = 'K'; break; |
| 213 | case 'Y': new_c = 'L'; break; |
| 214 | case 'Z': new_c = 'M'; break; |
| 215 | case 'a': new_c = 'n'; break; |
| 216 | case 'b': new_c = 'o'; break; |
| 217 | case 'c': new_c = 'p'; break; |
| 218 | case 'd': new_c = 'q'; break; |
| 219 | case 'e': new_c = 'r'; break; |
| 220 | case 'f': new_c = 's'; break; |
| 221 | case 'g': new_c = 't'; break; |
| 222 | case 'h': new_c = 'u'; break; |
| 223 | case 'i': new_c = 'v'; break; |
| 224 | case 'j': new_c = 'w'; break; |
| 225 | case 'k': new_c = 'x'; break; |
| 226 | case 'l': new_c = 'y'; break; |
| 227 | case 'm': new_c = 'z'; break; |
| 228 | case 'n': new_c = 'a'; break; |
| 229 | case 'o': new_c = 'b'; break; |
| 230 | case 'p': new_c = 'c'; break; |
| 231 | case 'q': new_c = 'd'; break; |
| 232 | case 'r': new_c = 'e'; break; |
| 233 | case 's': new_c = 'f'; break; |
| 234 | case 't': new_c = 'g'; break; |
| 235 | case 'u': new_c = 'h'; break; |
| 236 | case 'v': new_c = 'i'; break; |
| 237 | case 'w': new_c = 'j'; break; |
| 238 | case 'x': new_c = 'k'; break; |
| 239 | case 'y': new_c = 'l'; break; |
| 240 | case 'z': new_c = 'm'; break; |
| 241 | } |
| 242 | *new_p++ = new_c; |
| 243 | } while (len--); |
| 244 | SvCUR_set(newkey, SvCUR(keysv)); |
| 245 | SvPOK_on(newkey); |
| 246 | if (SvUTF8(keysv)) |
| 247 | SvUTF8_on(newkey); |
| 248 | |
| 249 | mg->mg_obj = newkey; |
| 250 | } |
| 251 | } |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | STATIC I32 |
| 256 | rmagical_a_dummy(pTHX_ IV idx, SV *sv) { |
| 257 | PERL_UNUSED_ARG(idx); |
| 258 | PERL_UNUSED_ARG(sv); |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | STATIC MGVTBL rmagical_b = { 0 }; |
| 263 | |
| 264 | STATIC void |
| 265 | blockhook_csc_start(pTHX_ int full) |
| 266 | { |
| 267 | dMY_CXT; |
| 268 | AV *const cur = GvAV(MY_CXT.cscgv); |
| 269 | |
| 270 | PERL_UNUSED_ARG(full); |
| 271 | SAVEGENERICSV(GvAV(MY_CXT.cscgv)); |
| 272 | |
| 273 | if (cur) { |
| 274 | I32 i; |
| 275 | AV *const new_av = newAV(); |
| 276 | |
| 277 | for (i = 0; i <= av_len(cur); i++) { |
| 278 | av_store(new_av, i, newSVsv(*av_fetch(cur, i, 0))); |
| 279 | } |
| 280 | |
| 281 | GvAV(MY_CXT.cscgv) = new_av; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | STATIC void |
| 286 | blockhook_csc_pre_end(pTHX_ OP **o) |
| 287 | { |
| 288 | dMY_CXT; |
| 289 | |
| 290 | PERL_UNUSED_ARG(o); |
| 291 | /* if we hit the end of a scope we missed the start of, we need to |
| 292 | * unconditionally clear @CSC */ |
| 293 | if (GvAV(MY_CXT.cscgv) == MY_CXT.cscav && MY_CXT.cscav) { |
| 294 | av_clear(MY_CXT.cscav); |
| 295 | } |
| 296 | |
| 297 | } |
| 298 | |
| 299 | STATIC void |
| 300 | blockhook_test_start(pTHX_ int full) |
| 301 | { |
| 302 | dMY_CXT; |
| 303 | AV *av; |
| 304 | |
| 305 | if (MY_CXT.bhk_record) { |
| 306 | av = newAV(); |
| 307 | av_push(av, newSVpvs("start")); |
| 308 | av_push(av, newSViv(full)); |
| 309 | av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av))); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | STATIC void |
| 314 | blockhook_test_pre_end(pTHX_ OP **o) |
| 315 | { |
| 316 | dMY_CXT; |
| 317 | |
| 318 | PERL_UNUSED_ARG(o); |
| 319 | if (MY_CXT.bhk_record) |
| 320 | av_push(MY_CXT.bhkav, newSVpvs("pre_end")); |
| 321 | } |
| 322 | |
| 323 | STATIC void |
| 324 | blockhook_test_post_end(pTHX_ OP **o) |
| 325 | { |
| 326 | dMY_CXT; |
| 327 | |
| 328 | PERL_UNUSED_ARG(o); |
| 329 | if (MY_CXT.bhk_record) |
| 330 | av_push(MY_CXT.bhkav, newSVpvs("post_end")); |
| 331 | } |
| 332 | |
| 333 | STATIC void |
| 334 | blockhook_test_eval(pTHX_ OP *const o) |
| 335 | { |
| 336 | dMY_CXT; |
| 337 | AV *av; |
| 338 | |
| 339 | if (MY_CXT.bhk_record) { |
| 340 | av = newAV(); |
| 341 | av_push(av, newSVpvs("eval")); |
| 342 | av_push(av, newSVpv(OP_NAME(o), 0)); |
| 343 | av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av))); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | STATIC BHK bhk_csc, bhk_test; |
| 348 | |
| 349 | STATIC void |
| 350 | my_peep (pTHX_ OP *o) |
| 351 | { |
| 352 | dMY_CXT; |
| 353 | |
| 354 | if (!o) |
| 355 | return; |
| 356 | |
| 357 | MY_CXT.orig_peep(aTHX_ o); |
| 358 | |
| 359 | if (!MY_CXT.peep_recording) |
| 360 | return; |
| 361 | |
| 362 | for (; o; o = o->op_next) { |
| 363 | if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) { |
| 364 | av_push(MY_CXT.peep_recorder, newSVsv(cSVOPx_sv(o))); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | STATIC void |
| 370 | my_rpeep (pTHX_ OP *o) |
| 371 | { |
| 372 | dMY_CXT; |
| 373 | |
| 374 | if (!o) |
| 375 | return; |
| 376 | |
| 377 | MY_CXT.orig_rpeep(aTHX_ o); |
| 378 | |
| 379 | if (!MY_CXT.peep_recording) |
| 380 | return; |
| 381 | |
| 382 | for (; o; o = o->op_next) { |
| 383 | if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) { |
| 384 | av_push(MY_CXT.rpeep_recorder, newSVsv(cSVOPx_sv(o))); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | STATIC OP * |
| 390 | THX_ck_entersub_args_lists(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) |
| 391 | { |
| 392 | PERL_UNUSED_ARG(namegv); |
| 393 | PERL_UNUSED_ARG(ckobj); |
| 394 | return ck_entersub_args_list(entersubop); |
| 395 | } |
| 396 | |
| 397 | STATIC OP * |
| 398 | THX_ck_entersub_args_scalars(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) |
| 399 | { |
| 400 | OP *aop = cUNOPx(entersubop)->op_first; |
| 401 | PERL_UNUSED_ARG(namegv); |
| 402 | PERL_UNUSED_ARG(ckobj); |
| 403 | if (!aop->op_sibling) |
| 404 | aop = cUNOPx(aop)->op_first; |
| 405 | for (aop = aop->op_sibling; aop->op_sibling; aop = aop->op_sibling) { |
| 406 | op_contextualize(aop, G_SCALAR); |
| 407 | } |
| 408 | return entersubop; |
| 409 | } |
| 410 | |
| 411 | STATIC OP * |
| 412 | THX_ck_entersub_multi_sum(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) |
| 413 | { |
| 414 | OP *sumop = NULL; |
| 415 | OP *pushop = cUNOPx(entersubop)->op_first; |
| 416 | PERL_UNUSED_ARG(namegv); |
| 417 | PERL_UNUSED_ARG(ckobj); |
| 418 | if (!pushop->op_sibling) |
| 419 | pushop = cUNOPx(pushop)->op_first; |
| 420 | while (1) { |
| 421 | OP *aop = pushop->op_sibling; |
| 422 | if (!aop->op_sibling) |
| 423 | break; |
| 424 | pushop->op_sibling = aop->op_sibling; |
| 425 | aop->op_sibling = NULL; |
| 426 | op_contextualize(aop, G_SCALAR); |
| 427 | if (sumop) { |
| 428 | sumop = newBINOP(OP_ADD, 0, sumop, aop); |
| 429 | } else { |
| 430 | sumop = aop; |
| 431 | } |
| 432 | } |
| 433 | if (!sumop) |
| 434 | sumop = newSVOP(OP_CONST, 0, newSViv(0)); |
| 435 | op_free(entersubop); |
| 436 | return sumop; |
| 437 | } |
| 438 | |
| 439 | STATIC void test_op_list_describe_part(SV *res, OP *o); |
| 440 | STATIC void |
| 441 | test_op_list_describe_part(SV *res, OP *o) |
| 442 | { |
| 443 | sv_catpv(res, PL_op_name[o->op_type]); |
| 444 | switch (o->op_type) { |
| 445 | case OP_CONST: { |
| 446 | sv_catpvf(res, "(%d)", (int)SvIV(cSVOPx(o)->op_sv)); |
| 447 | } break; |
| 448 | } |
| 449 | if (o->op_flags & OPf_KIDS) { |
| 450 | OP *k; |
| 451 | sv_catpvs(res, "["); |
| 452 | for (k = cUNOPx(o)->op_first; k; k = k->op_sibling) |
| 453 | test_op_list_describe_part(res, k); |
| 454 | sv_catpvs(res, "]"); |
| 455 | } else { |
| 456 | sv_catpvs(res, "."); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | STATIC char * |
| 461 | test_op_list_describe(OP *o) |
| 462 | { |
| 463 | SV *res = sv_2mortal(newSVpvs("")); |
| 464 | if (o) |
| 465 | test_op_list_describe_part(res, o); |
| 466 | return SvPVX(res); |
| 467 | } |
| 468 | |
| 469 | /* the real new*OP functions have a tendency to call fold_constants, and |
| 470 | * other such unhelpful things, so we need our own versions for testing */ |
| 471 | |
| 472 | #define mkUNOP(t, f) THX_mkUNOP(aTHX_ (t), (f)) |
| 473 | static OP * |
| 474 | THX_mkUNOP(pTHX_ U32 type, OP *first) |
| 475 | { |
| 476 | UNOP *unop; |
| 477 | NewOp(1103, unop, 1, UNOP); |
| 478 | unop->op_type = (OPCODE)type; |
| 479 | unop->op_first = first; |
| 480 | unop->op_flags = OPf_KIDS; |
| 481 | return (OP *)unop; |
| 482 | } |
| 483 | |
| 484 | #define mkBINOP(t, f, l) THX_mkBINOP(aTHX_ (t), (f), (l)) |
| 485 | static OP * |
| 486 | THX_mkBINOP(pTHX_ U32 type, OP *first, OP *last) |
| 487 | { |
| 488 | BINOP *binop; |
| 489 | NewOp(1103, binop, 1, BINOP); |
| 490 | binop->op_type = (OPCODE)type; |
| 491 | binop->op_first = first; |
| 492 | binop->op_flags = OPf_KIDS; |
| 493 | binop->op_last = last; |
| 494 | first->op_sibling = last; |
| 495 | return (OP *)binop; |
| 496 | } |
| 497 | |
| 498 | #define mkLISTOP(t, f, s, l) THX_mkLISTOP(aTHX_ (t), (f), (s), (l)) |
| 499 | static OP * |
| 500 | THX_mkLISTOP(pTHX_ U32 type, OP *first, OP *sib, OP *last) |
| 501 | { |
| 502 | LISTOP *listop; |
| 503 | NewOp(1103, listop, 1, LISTOP); |
| 504 | listop->op_type = (OPCODE)type; |
| 505 | listop->op_flags = OPf_KIDS; |
| 506 | listop->op_first = first; |
| 507 | first->op_sibling = sib; |
| 508 | sib->op_sibling = last; |
| 509 | listop->op_last = last; |
| 510 | return (OP *)listop; |
| 511 | } |
| 512 | |
| 513 | static char * |
| 514 | test_op_linklist_describe(OP *start) |
| 515 | { |
| 516 | SV *rv = sv_2mortal(newSVpvs("")); |
| 517 | OP *o; |
| 518 | o = start = LINKLIST(start); |
| 519 | do { |
| 520 | sv_catpvs(rv, "."); |
| 521 | sv_catpv(rv, OP_NAME(o)); |
| 522 | if (o->op_type == OP_CONST) |
| 523 | sv_catsv(rv, cSVOPo->op_sv); |
| 524 | o = o->op_next; |
| 525 | } while (o && o != start); |
| 526 | return SvPVX(rv); |
| 527 | } |
| 528 | |
| 529 | /** establish_cleanup operator, ripped off from Scope::Cleanup **/ |
| 530 | |
| 531 | STATIC void |
| 532 | THX_run_cleanup(pTHX_ void *cleanup_code_ref) |
| 533 | { |
| 534 | dSP; |
| 535 | ENTER; |
| 536 | SAVETMPS; |
| 537 | PUSHMARK(SP); |
| 538 | call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD); |
| 539 | FREETMPS; |
| 540 | LEAVE; |
| 541 | } |
| 542 | |
| 543 | STATIC OP * |
| 544 | THX_pp_establish_cleanup(pTHX) |
| 545 | { |
| 546 | dSP; |
| 547 | SV *cleanup_code_ref; |
| 548 | cleanup_code_ref = newSVsv(POPs); |
| 549 | SAVEFREESV(cleanup_code_ref); |
| 550 | SAVEDESTRUCTOR_X(THX_run_cleanup, cleanup_code_ref); |
| 551 | if(GIMME_V != G_VOID) PUSHs(&PL_sv_undef); |
| 552 | RETURN; |
| 553 | } |
| 554 | |
| 555 | STATIC OP * |
| 556 | THX_ck_entersub_establish_cleanup(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) |
| 557 | { |
| 558 | OP *pushop, *argop, *estop; |
| 559 | ck_entersub_args_proto(entersubop, namegv, ckobj); |
| 560 | pushop = cUNOPx(entersubop)->op_first; |
| 561 | if(!pushop->op_sibling) pushop = cUNOPx(pushop)->op_first; |
| 562 | argop = pushop->op_sibling; |
| 563 | pushop->op_sibling = argop->op_sibling; |
| 564 | argop->op_sibling = NULL; |
| 565 | op_free(entersubop); |
| 566 | NewOpSz(0, estop, sizeof(UNOP)); |
| 567 | estop->op_type = OP_RAND; |
| 568 | estop->op_ppaddr = THX_pp_establish_cleanup; |
| 569 | cUNOPx(estop)->op_flags = OPf_KIDS; |
| 570 | cUNOPx(estop)->op_first = argop; |
| 571 | PL_hints |= HINT_BLOCK_SCOPE; |
| 572 | return estop; |
| 573 | } |
| 574 | |
| 575 | STATIC OP * |
| 576 | THX_ck_entersub_postinc(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) |
| 577 | { |
| 578 | OP *pushop, *argop; |
| 579 | ck_entersub_args_proto(entersubop, namegv, ckobj); |
| 580 | pushop = cUNOPx(entersubop)->op_first; |
| 581 | if(!pushop->op_sibling) pushop = cUNOPx(pushop)->op_first; |
| 582 | argop = pushop->op_sibling; |
| 583 | pushop->op_sibling = argop->op_sibling; |
| 584 | argop->op_sibling = NULL; |
| 585 | op_free(entersubop); |
| 586 | return newUNOP(OP_POSTINC, 0, |
| 587 | op_lvalue(op_contextualize(argop, G_SCALAR), OP_POSTINC)); |
| 588 | } |
| 589 | |
| 590 | STATIC OP * |
| 591 | THX_ck_entersub_pad_scalar(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) |
| 592 | { |
| 593 | OP *pushop, *argop; |
| 594 | PADOFFSET padoff = NOT_IN_PAD; |
| 595 | SV *a0, *a1; |
| 596 | ck_entersub_args_proto(entersubop, namegv, ckobj); |
| 597 | pushop = cUNOPx(entersubop)->op_first; |
| 598 | if(!pushop->op_sibling) pushop = cUNOPx(pushop)->op_first; |
| 599 | argop = pushop->op_sibling; |
| 600 | if(argop->op_type != OP_CONST || argop->op_sibling->op_type != OP_CONST) |
| 601 | croak("bad argument expression type for pad_scalar()"); |
| 602 | a0 = cSVOPx_sv(argop); |
| 603 | a1 = cSVOPx_sv(argop->op_sibling); |
| 604 | switch(SvIV(a0)) { |
| 605 | case 1: { |
| 606 | SV *namesv = sv_2mortal(newSVpvs("$")); |
| 607 | sv_catsv(namesv, a1); |
| 608 | padoff = pad_findmy_sv(namesv, 0); |
| 609 | } break; |
| 610 | case 2: { |
| 611 | char *namepv; |
| 612 | STRLEN namelen; |
| 613 | SV *namesv = sv_2mortal(newSVpvs("$")); |
| 614 | sv_catsv(namesv, a1); |
| 615 | namepv = SvPV(namesv, namelen); |
| 616 | padoff = pad_findmy_pvn(namepv, namelen, SvUTF8(namesv)); |
| 617 | } break; |
| 618 | case 3: { |
| 619 | char *namepv; |
| 620 | SV *namesv = sv_2mortal(newSVpvs("$")); |
| 621 | sv_catsv(namesv, a1); |
| 622 | namepv = SvPV_nolen(namesv); |
| 623 | padoff = pad_findmy_pv(namepv, SvUTF8(namesv)); |
| 624 | } break; |
| 625 | case 4: { |
| 626 | padoff = pad_findmy_pvs("$foo", 0); |
| 627 | } break; |
| 628 | default: croak("bad type value for pad_scalar()"); |
| 629 | } |
| 630 | op_free(entersubop); |
| 631 | if(padoff == NOT_IN_PAD) { |
| 632 | return newSVOP(OP_CONST, 0, newSVpvs("NOT_IN_PAD")); |
| 633 | } else if(PAD_COMPNAME_FLAGS_isOUR(padoff)) { |
| 634 | return newSVOP(OP_CONST, 0, newSVpvs("NOT_MY")); |
| 635 | } else { |
| 636 | OP *padop = newOP(OP_PADSV, 0); |
| 637 | padop->op_targ = padoff; |
| 638 | return padop; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | /** RPN keyword parser **/ |
| 643 | |
| 644 | #define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV) |
| 645 | #define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP) |
| 646 | #define sv_is_string(sv) \ |
| 647 | (!sv_is_glob(sv) && !sv_is_regexp(sv) && \ |
| 648 | (SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK))) |
| 649 | |
| 650 | static SV *hintkey_rpn_sv, *hintkey_calcrpn_sv, *hintkey_stufftest_sv; |
| 651 | static SV *hintkey_swaptwostmts_sv, *hintkey_looprest_sv; |
| 652 | static SV *hintkey_scopelessblock_sv; |
| 653 | static SV *hintkey_stmtasexpr_sv, *hintkey_stmtsasexpr_sv; |
| 654 | static SV *hintkey_loopblock_sv, *hintkey_blockasexpr_sv; |
| 655 | static SV *hintkey_swaplabel_sv, *hintkey_labelconst_sv; |
| 656 | static SV *hintkey_arrayfullexpr_sv, *hintkey_arraylistexpr_sv; |
| 657 | static SV *hintkey_arraytermexpr_sv, *hintkey_arrayarithexpr_sv; |
| 658 | static SV *hintkey_arrayexprflags_sv; |
| 659 | static int (*next_keyword_plugin)(pTHX_ char *, STRLEN, OP **); |
| 660 | |
| 661 | /* low-level parser helpers */ |
| 662 | |
| 663 | #define PL_bufptr (PL_parser->bufptr) |
| 664 | #define PL_bufend (PL_parser->bufend) |
| 665 | |
| 666 | /* RPN parser */ |
| 667 | |
| 668 | #define parse_var() THX_parse_var(aTHX) |
| 669 | static OP *THX_parse_var(pTHX) |
| 670 | { |
| 671 | char *s = PL_bufptr; |
| 672 | char *start = s; |
| 673 | PADOFFSET varpos; |
| 674 | OP *padop; |
| 675 | if(*s != '$') croak("RPN syntax error"); |
| 676 | while(1) { |
| 677 | char c = *++s; |
| 678 | if(!isALNUM(c)) break; |
| 679 | } |
| 680 | if(s-start < 2) croak("RPN syntax error"); |
| 681 | lex_read_to(s); |
| 682 | varpos = pad_findmy_pvn(start, s-start, 0); |
| 683 | if(varpos == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(varpos)) |
| 684 | croak("RPN only supports \"my\" variables"); |
| 685 | padop = newOP(OP_PADSV, 0); |
| 686 | padop->op_targ = varpos; |
| 687 | return padop; |
| 688 | } |
| 689 | |
| 690 | #define push_rpn_item(o) \ |
| 691 | (tmpop = (o), tmpop->op_sibling = stack, stack = tmpop) |
| 692 | #define pop_rpn_item() \ |
| 693 | (!stack ? (croak("RPN stack underflow"), (OP*)NULL) : \ |
| 694 | (tmpop = stack, stack = stack->op_sibling, \ |
| 695 | tmpop->op_sibling = NULL, tmpop)) |
| 696 | |
| 697 | #define parse_rpn_expr() THX_parse_rpn_expr(aTHX) |
| 698 | static OP *THX_parse_rpn_expr(pTHX) |
| 699 | { |
| 700 | OP *stack = NULL, *tmpop; |
| 701 | while(1) { |
| 702 | I32 c; |
| 703 | lex_read_space(0); |
| 704 | c = lex_peek_unichar(0); |
| 705 | switch(c) { |
| 706 | case /*(*/')': case /*{*/'}': { |
| 707 | OP *result = pop_rpn_item(); |
| 708 | if(stack) croak("RPN expression must return a single value"); |
| 709 | return result; |
| 710 | } break; |
| 711 | case '0': case '1': case '2': case '3': case '4': |
| 712 | case '5': case '6': case '7': case '8': case '9': { |
| 713 | UV val = 0; |
| 714 | do { |
| 715 | lex_read_unichar(0); |
| 716 | val = 10*val + (c - '0'); |
| 717 | c = lex_peek_unichar(0); |
| 718 | } while(c >= '0' && c <= '9'); |
| 719 | push_rpn_item(newSVOP(OP_CONST, 0, newSVuv(val))); |
| 720 | } break; |
| 721 | case '$': { |
| 722 | push_rpn_item(parse_var()); |
| 723 | } break; |
| 724 | case '+': { |
| 725 | OP *b = pop_rpn_item(); |
| 726 | OP *a = pop_rpn_item(); |
| 727 | lex_read_unichar(0); |
| 728 | push_rpn_item(newBINOP(OP_I_ADD, 0, a, b)); |
| 729 | } break; |
| 730 | case '-': { |
| 731 | OP *b = pop_rpn_item(); |
| 732 | OP *a = pop_rpn_item(); |
| 733 | lex_read_unichar(0); |
| 734 | push_rpn_item(newBINOP(OP_I_SUBTRACT, 0, a, b)); |
| 735 | } break; |
| 736 | case '*': { |
| 737 | OP *b = pop_rpn_item(); |
| 738 | OP *a = pop_rpn_item(); |
| 739 | lex_read_unichar(0); |
| 740 | push_rpn_item(newBINOP(OP_I_MULTIPLY, 0, a, b)); |
| 741 | } break; |
| 742 | case '/': { |
| 743 | OP *b = pop_rpn_item(); |
| 744 | OP *a = pop_rpn_item(); |
| 745 | lex_read_unichar(0); |
| 746 | push_rpn_item(newBINOP(OP_I_DIVIDE, 0, a, b)); |
| 747 | } break; |
| 748 | case '%': { |
| 749 | OP *b = pop_rpn_item(); |
| 750 | OP *a = pop_rpn_item(); |
| 751 | lex_read_unichar(0); |
| 752 | push_rpn_item(newBINOP(OP_I_MODULO, 0, a, b)); |
| 753 | } break; |
| 754 | default: { |
| 755 | croak("RPN syntax error"); |
| 756 | } break; |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | #define parse_keyword_rpn() THX_parse_keyword_rpn(aTHX) |
| 762 | static OP *THX_parse_keyword_rpn(pTHX) |
| 763 | { |
| 764 | OP *op; |
| 765 | lex_read_space(0); |
| 766 | if(lex_peek_unichar(0) != '('/*)*/) |
| 767 | croak("RPN expression must be parenthesised"); |
| 768 | lex_read_unichar(0); |
| 769 | op = parse_rpn_expr(); |
| 770 | if(lex_peek_unichar(0) != /*(*/')') |
| 771 | croak("RPN expression must be parenthesised"); |
| 772 | lex_read_unichar(0); |
| 773 | return op; |
| 774 | } |
| 775 | |
| 776 | #define parse_keyword_calcrpn() THX_parse_keyword_calcrpn(aTHX) |
| 777 | static OP *THX_parse_keyword_calcrpn(pTHX) |
| 778 | { |
| 779 | OP *varop, *exprop; |
| 780 | lex_read_space(0); |
| 781 | varop = parse_var(); |
| 782 | lex_read_space(0); |
| 783 | if(lex_peek_unichar(0) != '{'/*}*/) |
| 784 | croak("RPN expression must be braced"); |
| 785 | lex_read_unichar(0); |
| 786 | exprop = parse_rpn_expr(); |
| 787 | if(lex_peek_unichar(0) != /*{*/'}') |
| 788 | croak("RPN expression must be braced"); |
| 789 | lex_read_unichar(0); |
| 790 | return newASSIGNOP(OPf_STACKED, varop, 0, exprop); |
| 791 | } |
| 792 | |
| 793 | #define parse_keyword_stufftest() THX_parse_keyword_stufftest(aTHX) |
| 794 | static OP *THX_parse_keyword_stufftest(pTHX) |
| 795 | { |
| 796 | I32 c; |
| 797 | bool do_stuff; |
| 798 | lex_read_space(0); |
| 799 | do_stuff = lex_peek_unichar(0) == '+'; |
| 800 | if(do_stuff) { |
| 801 | lex_read_unichar(0); |
| 802 | lex_read_space(0); |
| 803 | } |
| 804 | c = lex_peek_unichar(0); |
| 805 | if(c == ';') { |
| 806 | lex_read_unichar(0); |
| 807 | } else if(c != /*{*/'}') { |
| 808 | croak("syntax error"); |
| 809 | } |
| 810 | if(do_stuff) lex_stuff_pvs(" ", 0); |
| 811 | return newOP(OP_NULL, 0); |
| 812 | } |
| 813 | |
| 814 | #define parse_keyword_swaptwostmts() THX_parse_keyword_swaptwostmts(aTHX) |
| 815 | static OP *THX_parse_keyword_swaptwostmts(pTHX) |
| 816 | { |
| 817 | OP *a, *b; |
| 818 | a = parse_fullstmt(0); |
| 819 | b = parse_fullstmt(0); |
| 820 | if(a && b) |
| 821 | PL_hints |= HINT_BLOCK_SCOPE; |
| 822 | return op_append_list(OP_LINESEQ, b, a); |
| 823 | } |
| 824 | |
| 825 | #define parse_keyword_looprest() THX_parse_keyword_looprest(aTHX) |
| 826 | static OP *THX_parse_keyword_looprest(pTHX) |
| 827 | { |
| 828 | return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes), |
| 829 | parse_stmtseq(0), NULL, 1); |
| 830 | } |
| 831 | |
| 832 | #define parse_keyword_scopelessblock() THX_parse_keyword_scopelessblock(aTHX) |
| 833 | static OP *THX_parse_keyword_scopelessblock(pTHX) |
| 834 | { |
| 835 | I32 c; |
| 836 | OP *body; |
| 837 | lex_read_space(0); |
| 838 | if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error"); |
| 839 | lex_read_unichar(0); |
| 840 | body = parse_stmtseq(0); |
| 841 | c = lex_peek_unichar(0); |
| 842 | if(c != /*{*/'}' && c != /*[*/']' && c != /*(*/')') croak("syntax error"); |
| 843 | lex_read_unichar(0); |
| 844 | return body; |
| 845 | } |
| 846 | |
| 847 | #define parse_keyword_stmtasexpr() THX_parse_keyword_stmtasexpr(aTHX) |
| 848 | static OP *THX_parse_keyword_stmtasexpr(pTHX) |
| 849 | { |
| 850 | OP *o = parse_barestmt(0); |
| 851 | if (!o) o = newOP(OP_STUB, 0); |
| 852 | if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS; |
| 853 | return op_scope(o); |
| 854 | } |
| 855 | |
| 856 | #define parse_keyword_stmtsasexpr() THX_parse_keyword_stmtsasexpr(aTHX) |
| 857 | static OP *THX_parse_keyword_stmtsasexpr(pTHX) |
| 858 | { |
| 859 | OP *o; |
| 860 | lex_read_space(0); |
| 861 | if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error"); |
| 862 | lex_read_unichar(0); |
| 863 | o = parse_stmtseq(0); |
| 864 | lex_read_space(0); |
| 865 | if(lex_peek_unichar(0) != /*{*/'}') croak("syntax error"); |
| 866 | lex_read_unichar(0); |
| 867 | if (!o) o = newOP(OP_STUB, 0); |
| 868 | if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS; |
| 869 | return op_scope(o); |
| 870 | } |
| 871 | |
| 872 | #define parse_keyword_loopblock() THX_parse_keyword_loopblock(aTHX) |
| 873 | static OP *THX_parse_keyword_loopblock(pTHX) |
| 874 | { |
| 875 | return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes), |
| 876 | parse_block(0), NULL, 1); |
| 877 | } |
| 878 | |
| 879 | #define parse_keyword_blockasexpr() THX_parse_keyword_blockasexpr(aTHX) |
| 880 | static OP *THX_parse_keyword_blockasexpr(pTHX) |
| 881 | { |
| 882 | OP *o = parse_block(0); |
| 883 | if (!o) o = newOP(OP_STUB, 0); |
| 884 | if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS; |
| 885 | return op_scope(o); |
| 886 | } |
| 887 | |
| 888 | #define parse_keyword_swaplabel() THX_parse_keyword_swaplabel(aTHX) |
| 889 | static OP *THX_parse_keyword_swaplabel(pTHX) |
| 890 | { |
| 891 | OP *sop = parse_barestmt(0); |
| 892 | SV *label = parse_label(PARSE_OPTIONAL); |
| 893 | if (label) sv_2mortal(label); |
| 894 | return newSTATEOP(label ? SvUTF8(label) : 0, |
| 895 | label ? savepv(SvPVX(label)) : NULL, |
| 896 | sop); |
| 897 | } |
| 898 | |
| 899 | #define parse_keyword_labelconst() THX_parse_keyword_labelconst(aTHX) |
| 900 | static OP *THX_parse_keyword_labelconst(pTHX) |
| 901 | { |
| 902 | return newSVOP(OP_CONST, 0, parse_label(0)); |
| 903 | } |
| 904 | |
| 905 | #define parse_keyword_arrayfullexpr() THX_parse_keyword_arrayfullexpr(aTHX) |
| 906 | static OP *THX_parse_keyword_arrayfullexpr(pTHX) |
| 907 | { |
| 908 | return newANONLIST(parse_fullexpr(0)); |
| 909 | } |
| 910 | |
| 911 | #define parse_keyword_arraylistexpr() THX_parse_keyword_arraylistexpr(aTHX) |
| 912 | static OP *THX_parse_keyword_arraylistexpr(pTHX) |
| 913 | { |
| 914 | return newANONLIST(parse_listexpr(0)); |
| 915 | } |
| 916 | |
| 917 | #define parse_keyword_arraytermexpr() THX_parse_keyword_arraytermexpr(aTHX) |
| 918 | static OP *THX_parse_keyword_arraytermexpr(pTHX) |
| 919 | { |
| 920 | return newANONLIST(parse_termexpr(0)); |
| 921 | } |
| 922 | |
| 923 | #define parse_keyword_arrayarithexpr() THX_parse_keyword_arrayarithexpr(aTHX) |
| 924 | static OP *THX_parse_keyword_arrayarithexpr(pTHX) |
| 925 | { |
| 926 | return newANONLIST(parse_arithexpr(0)); |
| 927 | } |
| 928 | |
| 929 | #define parse_keyword_arrayexprflags() THX_parse_keyword_arrayexprflags(aTHX) |
| 930 | static OP *THX_parse_keyword_arrayexprflags(pTHX) |
| 931 | { |
| 932 | U32 flags = 0; |
| 933 | I32 c; |
| 934 | OP *o; |
| 935 | lex_read_space(0); |
| 936 | c = lex_peek_unichar(0); |
| 937 | if (c != '!' && c != '?') croak("syntax error"); |
| 938 | lex_read_unichar(0); |
| 939 | if (c == '?') flags |= PARSE_OPTIONAL; |
| 940 | o = parse_listexpr(flags); |
| 941 | return o ? newANONLIST(o) : newANONHASH(newOP(OP_STUB, 0)); |
| 942 | } |
| 943 | |
| 944 | /* plugin glue */ |
| 945 | |
| 946 | #define keyword_active(hintkey_sv) THX_keyword_active(aTHX_ hintkey_sv) |
| 947 | static int THX_keyword_active(pTHX_ SV *hintkey_sv) |
| 948 | { |
| 949 | HE *he; |
| 950 | if(!GvHV(PL_hintgv)) return 0; |
| 951 | he = hv_fetch_ent(GvHV(PL_hintgv), hintkey_sv, 0, |
| 952 | SvSHARED_HASH(hintkey_sv)); |
| 953 | return he && SvTRUE(HeVAL(he)); |
| 954 | } |
| 955 | |
| 956 | static int my_keyword_plugin(pTHX_ |
| 957 | char *keyword_ptr, STRLEN keyword_len, OP **op_ptr) |
| 958 | { |
| 959 | if(keyword_len == 3 && strnEQ(keyword_ptr, "rpn", 3) && |
| 960 | keyword_active(hintkey_rpn_sv)) { |
| 961 | *op_ptr = parse_keyword_rpn(); |
| 962 | return KEYWORD_PLUGIN_EXPR; |
| 963 | } else if(keyword_len == 7 && strnEQ(keyword_ptr, "calcrpn", 7) && |
| 964 | keyword_active(hintkey_calcrpn_sv)) { |
| 965 | *op_ptr = parse_keyword_calcrpn(); |
| 966 | return KEYWORD_PLUGIN_STMT; |
| 967 | } else if(keyword_len == 9 && strnEQ(keyword_ptr, "stufftest", 9) && |
| 968 | keyword_active(hintkey_stufftest_sv)) { |
| 969 | *op_ptr = parse_keyword_stufftest(); |
| 970 | return KEYWORD_PLUGIN_STMT; |
| 971 | } else if(keyword_len == 12 && |
| 972 | strnEQ(keyword_ptr, "swaptwostmts", 12) && |
| 973 | keyword_active(hintkey_swaptwostmts_sv)) { |
| 974 | *op_ptr = parse_keyword_swaptwostmts(); |
| 975 | return KEYWORD_PLUGIN_STMT; |
| 976 | } else if(keyword_len == 8 && strnEQ(keyword_ptr, "looprest", 8) && |
| 977 | keyword_active(hintkey_looprest_sv)) { |
| 978 | *op_ptr = parse_keyword_looprest(); |
| 979 | return KEYWORD_PLUGIN_STMT; |
| 980 | } else if(keyword_len == 14 && strnEQ(keyword_ptr, "scopelessblock", 14) && |
| 981 | keyword_active(hintkey_scopelessblock_sv)) { |
| 982 | *op_ptr = parse_keyword_scopelessblock(); |
| 983 | return KEYWORD_PLUGIN_STMT; |
| 984 | } else if(keyword_len == 10 && strnEQ(keyword_ptr, "stmtasexpr", 10) && |
| 985 | keyword_active(hintkey_stmtasexpr_sv)) { |
| 986 | *op_ptr = parse_keyword_stmtasexpr(); |
| 987 | return KEYWORD_PLUGIN_EXPR; |
| 988 | } else if(keyword_len == 11 && strnEQ(keyword_ptr, "stmtsasexpr", 11) && |
| 989 | keyword_active(hintkey_stmtsasexpr_sv)) { |
| 990 | *op_ptr = parse_keyword_stmtsasexpr(); |
| 991 | return KEYWORD_PLUGIN_EXPR; |
| 992 | } else if(keyword_len == 9 && strnEQ(keyword_ptr, "loopblock", 9) && |
| 993 | keyword_active(hintkey_loopblock_sv)) { |
| 994 | *op_ptr = parse_keyword_loopblock(); |
| 995 | return KEYWORD_PLUGIN_STMT; |
| 996 | } else if(keyword_len == 11 && strnEQ(keyword_ptr, "blockasexpr", 11) && |
| 997 | keyword_active(hintkey_blockasexpr_sv)) { |
| 998 | *op_ptr = parse_keyword_blockasexpr(); |
| 999 | return KEYWORD_PLUGIN_EXPR; |
| 1000 | } else if(keyword_len == 9 && strnEQ(keyword_ptr, "swaplabel", 9) && |
| 1001 | keyword_active(hintkey_swaplabel_sv)) { |
| 1002 | *op_ptr = parse_keyword_swaplabel(); |
| 1003 | return KEYWORD_PLUGIN_STMT; |
| 1004 | } else if(keyword_len == 10 && strnEQ(keyword_ptr, "labelconst", 10) && |
| 1005 | keyword_active(hintkey_labelconst_sv)) { |
| 1006 | *op_ptr = parse_keyword_labelconst(); |
| 1007 | return KEYWORD_PLUGIN_EXPR; |
| 1008 | } else if(keyword_len == 13 && strnEQ(keyword_ptr, "arrayfullexpr", 13) && |
| 1009 | keyword_active(hintkey_arrayfullexpr_sv)) { |
| 1010 | *op_ptr = parse_keyword_arrayfullexpr(); |
| 1011 | return KEYWORD_PLUGIN_EXPR; |
| 1012 | } else if(keyword_len == 13 && strnEQ(keyword_ptr, "arraylistexpr", 13) && |
| 1013 | keyword_active(hintkey_arraylistexpr_sv)) { |
| 1014 | *op_ptr = parse_keyword_arraylistexpr(); |
| 1015 | return KEYWORD_PLUGIN_EXPR; |
| 1016 | } else if(keyword_len == 13 && strnEQ(keyword_ptr, "arraytermexpr", 13) && |
| 1017 | keyword_active(hintkey_arraytermexpr_sv)) { |
| 1018 | *op_ptr = parse_keyword_arraytermexpr(); |
| 1019 | return KEYWORD_PLUGIN_EXPR; |
| 1020 | } else if(keyword_len == 14 && strnEQ(keyword_ptr, "arrayarithexpr", 14) && |
| 1021 | keyword_active(hintkey_arrayarithexpr_sv)) { |
| 1022 | *op_ptr = parse_keyword_arrayarithexpr(); |
| 1023 | return KEYWORD_PLUGIN_EXPR; |
| 1024 | } else if(keyword_len == 14 && strnEQ(keyword_ptr, "arrayexprflags", 14) && |
| 1025 | keyword_active(hintkey_arrayexprflags_sv)) { |
| 1026 | *op_ptr = parse_keyword_arrayexprflags(); |
| 1027 | return KEYWORD_PLUGIN_EXPR; |
| 1028 | } else { |
| 1029 | return next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | static XOP my_xop; |
| 1034 | |
| 1035 | static OP * |
| 1036 | pp_xop(pTHX) |
| 1037 | { |
| 1038 | return PL_op->op_next; |
| 1039 | } |
| 1040 | |
| 1041 | static void |
| 1042 | peep_xop(pTHX_ OP *o, OP *oldop) |
| 1043 | { |
| 1044 | dMY_CXT; |
| 1045 | av_push(MY_CXT.xop_record, newSVpvf("peep:%"UVxf, PTR2UV(o))); |
| 1046 | av_push(MY_CXT.xop_record, newSVpvf("oldop:%"UVxf, PTR2UV(oldop))); |
| 1047 | } |
| 1048 | |
| 1049 | static I32 |
| 1050 | filter_call(pTHX_ int idx, SV *buf_sv, int maxlen) |
| 1051 | { |
| 1052 | SV *my_sv = FILTER_DATA(idx); |
| 1053 | char *p; |
| 1054 | char *end; |
| 1055 | int n = FILTER_READ(idx + 1, buf_sv, maxlen); |
| 1056 | |
| 1057 | if (n<=0) return n; |
| 1058 | |
| 1059 | p = SvPV_force_nolen(buf_sv); |
| 1060 | end = p + SvCUR(buf_sv); |
| 1061 | while (p < end) { |
| 1062 | if (*p == 'o') *p = 'e'; |
| 1063 | p++; |
| 1064 | } |
| 1065 | return SvCUR(buf_sv); |
| 1066 | } |
| 1067 | |
| 1068 | static AV * |
| 1069 | myget_linear_isa(pTHX_ HV *stash, U32 level) { |
| 1070 | GV **gvp = (GV **)hv_fetchs(stash, "ISA", 0); |
| 1071 | PERL_UNUSED_ARG(level); |
| 1072 | return gvp && *gvp && GvAV(*gvp) |
| 1073 | ? GvAV(*gvp) |
| 1074 | : (AV *)sv_2mortal((SV *)newAV()); |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_undef); |
| 1079 | XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_empty); |
| 1080 | XS_EXTERNAL(XS_XS__APItest__XSUB_XS_APIVERSION_invalid); |
| 1081 | |
| 1082 | static struct mro_alg mymro; |
| 1083 | |
| 1084 | static Perl_check_t addissub_nxck_add; |
| 1085 | |
| 1086 | static OP * |
| 1087 | addissub_myck_add(pTHX_ OP *op) |
| 1088 | { |
| 1089 | SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addissub", 0); |
| 1090 | OP *aop, *bop; |
| 1091 | U8 flags; |
| 1092 | if (!(flag_svp && SvTRUE(*flag_svp) && (op->op_flags & OPf_KIDS) && |
| 1093 | (aop = cBINOPx(op)->op_first) && (bop = aop->op_sibling) && |
| 1094 | !bop->op_sibling)) |
| 1095 | return addissub_nxck_add(aTHX_ op); |
| 1096 | aop->op_sibling = NULL; |
| 1097 | cBINOPx(op)->op_first = NULL; |
| 1098 | op->op_flags &= ~OPf_KIDS; |
| 1099 | flags = op->op_flags; |
| 1100 | op_free(op); |
| 1101 | return newBINOP(OP_SUBTRACT, flags, aop, bop); |
| 1102 | } |
| 1103 | |
| 1104 | #include "const-c.inc" |
| 1105 | |
| 1106 | MODULE = XS::APItest PACKAGE = XS::APItest |
| 1107 | |
| 1108 | INCLUDE: const-xs.inc |
| 1109 | |
| 1110 | INCLUDE: numeric.xs |
| 1111 | |
| 1112 | MODULE = XS::APItest::utf8 PACKAGE = XS::APItest::utf8 |
| 1113 | |
| 1114 | int |
| 1115 | bytes_cmp_utf8(bytes, utf8) |
| 1116 | SV *bytes |
| 1117 | SV *utf8 |
| 1118 | PREINIT: |
| 1119 | const U8 *b; |
| 1120 | STRLEN blen; |
| 1121 | const U8 *u; |
| 1122 | STRLEN ulen; |
| 1123 | CODE: |
| 1124 | b = (const U8 *)SvPVbyte(bytes, blen); |
| 1125 | u = (const U8 *)SvPVbyte(utf8, ulen); |
| 1126 | RETVAL = bytes_cmp_utf8(b, blen, u, ulen); |
| 1127 | OUTPUT: |
| 1128 | RETVAL |
| 1129 | |
| 1130 | AV * |
| 1131 | test_utf8n_to_uvuni(s, len, flags) |
| 1132 | |
| 1133 | SV *s |
| 1134 | SV *len |
| 1135 | SV *flags |
| 1136 | PREINIT: |
| 1137 | STRLEN retlen; |
| 1138 | UV ret; |
| 1139 | STRLEN slen; |
| 1140 | |
| 1141 | CODE: |
| 1142 | /* Call utf8n_to_uvuni() with the inputs. It always asks for the |
| 1143 | * actual length to be returned |
| 1144 | * |
| 1145 | * Length to assume <s> is; not checked, so could have buffer overflow |
| 1146 | */ |
| 1147 | RETVAL = newAV(); |
| 1148 | sv_2mortal((SV*)RETVAL); |
| 1149 | |
| 1150 | ret |
| 1151 | = utf8n_to_uvuni((U8*) SvPV(s, slen), SvUV(len), &retlen, SvUV(flags)); |
| 1152 | |
| 1153 | /* Returns the return value in [0]; <retlen> in [1] */ |
| 1154 | av_push(RETVAL, newSVuv(ret)); |
| 1155 | if (retlen == (STRLEN) -1) { |
| 1156 | av_push(RETVAL, newSViv(-1)); |
| 1157 | } |
| 1158 | else { |
| 1159 | av_push(RETVAL, newSVuv(retlen)); |
| 1160 | } |
| 1161 | |
| 1162 | OUTPUT: |
| 1163 | RETVAL |
| 1164 | |
| 1165 | MODULE = XS::APItest:Overload PACKAGE = XS::APItest::Overload |
| 1166 | |
| 1167 | void |
| 1168 | amagic_deref_call(sv, what) |
| 1169 | SV *sv |
| 1170 | int what |
| 1171 | PPCODE: |
| 1172 | /* The reference is owned by something else. */ |
| 1173 | PUSHs(amagic_deref_call(sv, what)); |
| 1174 | |
| 1175 | # I'd certainly like to discourage the use of this macro, given that we now |
| 1176 | # have amagic_deref_call |
| 1177 | |
| 1178 | void |
| 1179 | tryAMAGICunDEREF_var(sv, what) |
| 1180 | SV *sv |
| 1181 | int what |
| 1182 | PPCODE: |
| 1183 | { |
| 1184 | SV **sp = &sv; |
| 1185 | switch(what) { |
| 1186 | case to_av_amg: |
| 1187 | tryAMAGICunDEREF(to_av); |
| 1188 | break; |
| 1189 | case to_cv_amg: |
| 1190 | tryAMAGICunDEREF(to_cv); |
| 1191 | break; |
| 1192 | case to_gv_amg: |
| 1193 | tryAMAGICunDEREF(to_gv); |
| 1194 | break; |
| 1195 | case to_hv_amg: |
| 1196 | tryAMAGICunDEREF(to_hv); |
| 1197 | break; |
| 1198 | case to_sv_amg: |
| 1199 | tryAMAGICunDEREF(to_sv); |
| 1200 | break; |
| 1201 | default: |
| 1202 | croak("Invalid value %d passed to tryAMAGICunDEREF_var", what); |
| 1203 | } |
| 1204 | } |
| 1205 | /* The reference is owned by something else. */ |
| 1206 | PUSHs(sv); |
| 1207 | |
| 1208 | MODULE = XS::APItest PACKAGE = XS::APItest::XSUB |
| 1209 | |
| 1210 | BOOT: |
| 1211 | newXS("XS::APItest::XSUB::XS_VERSION_undef", XS_XS__APItest__XSUB_XS_VERSION_undef, __FILE__); |
| 1212 | newXS("XS::APItest::XSUB::XS_VERSION_empty", XS_XS__APItest__XSUB_XS_VERSION_empty, __FILE__); |
| 1213 | newXS("XS::APItest::XSUB::XS_APIVERSION_invalid", XS_XS__APItest__XSUB_XS_APIVERSION_invalid, __FILE__); |
| 1214 | |
| 1215 | void |
| 1216 | XS_VERSION_defined(...) |
| 1217 | PPCODE: |
| 1218 | XS_VERSION_BOOTCHECK; |
| 1219 | XSRETURN_EMPTY; |
| 1220 | |
| 1221 | void |
| 1222 | XS_APIVERSION_valid(...) |
| 1223 | PPCODE: |
| 1224 | XS_APIVERSION_BOOTCHECK; |
| 1225 | XSRETURN_EMPTY; |
| 1226 | |
| 1227 | MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash |
| 1228 | |
| 1229 | void |
| 1230 | rot13_hash(hash) |
| 1231 | HV *hash |
| 1232 | CODE: |
| 1233 | { |
| 1234 | struct ufuncs uf; |
| 1235 | uf.uf_val = rot13_key; |
| 1236 | uf.uf_set = 0; |
| 1237 | uf.uf_index = 0; |
| 1238 | |
| 1239 | sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf)); |
| 1240 | } |
| 1241 | |
| 1242 | void |
| 1243 | bitflip_hash(hash) |
| 1244 | HV *hash |
| 1245 | CODE: |
| 1246 | { |
| 1247 | struct ufuncs uf; |
| 1248 | uf.uf_val = bitflip_key; |
| 1249 | uf.uf_set = 0; |
| 1250 | uf.uf_index = 0; |
| 1251 | |
| 1252 | sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf)); |
| 1253 | } |
| 1254 | |
| 1255 | #define UTF8KLEN(sv, len) (SvUTF8(sv) ? -(I32)len : (I32)len) |
| 1256 | |
| 1257 | bool |
| 1258 | exists(hash, key_sv) |
| 1259 | PREINIT: |
| 1260 | STRLEN len; |
| 1261 | const char *key; |
| 1262 | INPUT: |
| 1263 | HV *hash |
| 1264 | SV *key_sv |
| 1265 | CODE: |
| 1266 | key = SvPV(key_sv, len); |
| 1267 | RETVAL = hv_exists(hash, key, UTF8KLEN(key_sv, len)); |
| 1268 | OUTPUT: |
| 1269 | RETVAL |
| 1270 | |
| 1271 | bool |
| 1272 | exists_ent(hash, key_sv) |
| 1273 | PREINIT: |
| 1274 | INPUT: |
| 1275 | HV *hash |
| 1276 | SV *key_sv |
| 1277 | CODE: |
| 1278 | RETVAL = hv_exists_ent(hash, key_sv, 0); |
| 1279 | OUTPUT: |
| 1280 | RETVAL |
| 1281 | |
| 1282 | SV * |
| 1283 | delete(hash, key_sv, flags = 0) |
| 1284 | PREINIT: |
| 1285 | STRLEN len; |
| 1286 | const char *key; |
| 1287 | INPUT: |
| 1288 | HV *hash |
| 1289 | SV *key_sv |
| 1290 | I32 flags; |
| 1291 | CODE: |
| 1292 | key = SvPV(key_sv, len); |
| 1293 | /* It's already mortal, so need to increase reference count. */ |
| 1294 | RETVAL |
| 1295 | = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags)); |
| 1296 | OUTPUT: |
| 1297 | RETVAL |
| 1298 | |
| 1299 | SV * |
| 1300 | delete_ent(hash, key_sv, flags = 0) |
| 1301 | INPUT: |
| 1302 | HV *hash |
| 1303 | SV *key_sv |
| 1304 | I32 flags; |
| 1305 | CODE: |
| 1306 | /* It's already mortal, so need to increase reference count. */ |
| 1307 | RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0)); |
| 1308 | OUTPUT: |
| 1309 | RETVAL |
| 1310 | |
| 1311 | SV * |
| 1312 | store_ent(hash, key, value) |
| 1313 | PREINIT: |
| 1314 | SV *copy; |
| 1315 | HE *result; |
| 1316 | INPUT: |
| 1317 | HV *hash |
| 1318 | SV *key |
| 1319 | SV *value |
| 1320 | CODE: |
| 1321 | copy = newSV(0); |
| 1322 | result = hv_store_ent(hash, key, copy, 0); |
| 1323 | SvSetMagicSV(copy, value); |
| 1324 | if (!result) { |
| 1325 | SvREFCNT_dec(copy); |
| 1326 | XSRETURN_EMPTY; |
| 1327 | } |
| 1328 | /* It's about to become mortal, so need to increase reference count. |
| 1329 | */ |
| 1330 | RETVAL = SvREFCNT_inc(HeVAL(result)); |
| 1331 | OUTPUT: |
| 1332 | RETVAL |
| 1333 | |
| 1334 | SV * |
| 1335 | store(hash, key_sv, value) |
| 1336 | PREINIT: |
| 1337 | STRLEN len; |
| 1338 | const char *key; |
| 1339 | SV *copy; |
| 1340 | SV **result; |
| 1341 | INPUT: |
| 1342 | HV *hash |
| 1343 | SV *key_sv |
| 1344 | SV *value |
| 1345 | CODE: |
| 1346 | key = SvPV(key_sv, len); |
| 1347 | copy = newSV(0); |
| 1348 | result = hv_store(hash, key, UTF8KLEN(key_sv, len), copy, 0); |
| 1349 | SvSetMagicSV(copy, value); |
| 1350 | if (!result) { |
| 1351 | SvREFCNT_dec(copy); |
| 1352 | XSRETURN_EMPTY; |
| 1353 | } |
| 1354 | /* It's about to become mortal, so need to increase reference count. |
| 1355 | */ |
| 1356 | RETVAL = SvREFCNT_inc(*result); |
| 1357 | OUTPUT: |
| 1358 | RETVAL |
| 1359 | |
| 1360 | SV * |
| 1361 | fetch_ent(hash, key_sv) |
| 1362 | PREINIT: |
| 1363 | HE *result; |
| 1364 | INPUT: |
| 1365 | HV *hash |
| 1366 | SV *key_sv |
| 1367 | CODE: |
| 1368 | result = hv_fetch_ent(hash, key_sv, 0, 0); |
| 1369 | if (!result) { |
| 1370 | XSRETURN_EMPTY; |
| 1371 | } |
| 1372 | /* Force mg_get */ |
| 1373 | RETVAL = newSVsv(HeVAL(result)); |
| 1374 | OUTPUT: |
| 1375 | RETVAL |
| 1376 | |
| 1377 | SV * |
| 1378 | fetch(hash, key_sv) |
| 1379 | PREINIT: |
| 1380 | STRLEN len; |
| 1381 | const char *key; |
| 1382 | SV **result; |
| 1383 | INPUT: |
| 1384 | HV *hash |
| 1385 | SV *key_sv |
| 1386 | CODE: |
| 1387 | key = SvPV(key_sv, len); |
| 1388 | result = hv_fetch(hash, key, UTF8KLEN(key_sv, len), 0); |
| 1389 | if (!result) { |
| 1390 | XSRETURN_EMPTY; |
| 1391 | } |
| 1392 | /* Force mg_get */ |
| 1393 | RETVAL = newSVsv(*result); |
| 1394 | OUTPUT: |
| 1395 | RETVAL |
| 1396 | |
| 1397 | #if defined (hv_common) |
| 1398 | |
| 1399 | SV * |
| 1400 | common(params) |
| 1401 | INPUT: |
| 1402 | HV *params |
| 1403 | PREINIT: |
| 1404 | HE *result; |
| 1405 | HV *hv = NULL; |
| 1406 | SV *keysv = NULL; |
| 1407 | const char *key = NULL; |
| 1408 | STRLEN klen = 0; |
| 1409 | int flags = 0; |
| 1410 | int action = 0; |
| 1411 | SV *val = NULL; |
| 1412 | U32 hash = 0; |
| 1413 | SV **svp; |
| 1414 | CODE: |
| 1415 | if ((svp = hv_fetchs(params, "hv", 0))) { |
| 1416 | SV *const rv = *svp; |
| 1417 | if (!SvROK(rv)) |
| 1418 | croak("common passed a non-reference for parameter hv"); |
| 1419 | hv = (HV *)SvRV(rv); |
| 1420 | } |
| 1421 | if ((svp = hv_fetchs(params, "keysv", 0))) |
| 1422 | keysv = *svp; |
| 1423 | if ((svp = hv_fetchs(params, "keypv", 0))) { |
| 1424 | key = SvPV_const(*svp, klen); |
| 1425 | if (SvUTF8(*svp)) |
| 1426 | flags = HVhek_UTF8; |
| 1427 | } |
| 1428 | if ((svp = hv_fetchs(params, "action", 0))) |
| 1429 | action = SvIV(*svp); |
| 1430 | if ((svp = hv_fetchs(params, "val", 0))) |
| 1431 | val = newSVsv(*svp); |
| 1432 | if ((svp = hv_fetchs(params, "hash", 0))) |
| 1433 | hash = SvUV(*svp); |
| 1434 | |
| 1435 | if ((svp = hv_fetchs(params, "hash_pv", 0))) { |
| 1436 | PERL_HASH(hash, key, klen); |
| 1437 | } |
| 1438 | if ((svp = hv_fetchs(params, "hash_sv", 0))) { |
| 1439 | STRLEN len; |
| 1440 | const char *const p = SvPV(keysv, len); |
| 1441 | PERL_HASH(hash, p, len); |
| 1442 | } |
| 1443 | |
| 1444 | result = (HE *)hv_common(hv, keysv, key, klen, flags, action, val, hash); |
| 1445 | if (!result) { |
| 1446 | XSRETURN_EMPTY; |
| 1447 | } |
| 1448 | /* Force mg_get */ |
| 1449 | RETVAL = newSVsv(HeVAL(result)); |
| 1450 | OUTPUT: |
| 1451 | RETVAL |
| 1452 | |
| 1453 | #endif |
| 1454 | |
| 1455 | void |
| 1456 | test_hv_free_ent() |
| 1457 | PPCODE: |
| 1458 | test_freeent(&Perl_hv_free_ent); |
| 1459 | XSRETURN(4); |
| 1460 | |
| 1461 | void |
| 1462 | test_hv_delayfree_ent() |
| 1463 | PPCODE: |
| 1464 | test_freeent(&Perl_hv_delayfree_ent); |
| 1465 | XSRETURN(4); |
| 1466 | |
| 1467 | SV * |
| 1468 | test_share_unshare_pvn(input) |
| 1469 | PREINIT: |
| 1470 | STRLEN len; |
| 1471 | U32 hash; |
| 1472 | char *pvx; |
| 1473 | char *p; |
| 1474 | INPUT: |
| 1475 | SV *input |
| 1476 | CODE: |
| 1477 | pvx = SvPV(input, len); |
| 1478 | PERL_HASH(hash, pvx, len); |
| 1479 | p = sharepvn(pvx, len, hash); |
| 1480 | RETVAL = newSVpvn(p, len); |
| 1481 | unsharepvn(p, len, hash); |
| 1482 | OUTPUT: |
| 1483 | RETVAL |
| 1484 | |
| 1485 | #if PERL_VERSION >= 9 |
| 1486 | |
| 1487 | bool |
| 1488 | refcounted_he_exists(key, level=0) |
| 1489 | SV *key |
| 1490 | IV level |
| 1491 | CODE: |
| 1492 | if (level) { |
| 1493 | croak("level must be zero, not %"IVdf, level); |
| 1494 | } |
| 1495 | RETVAL = (cop_hints_fetch_sv(PL_curcop, key, 0, 0) != &PL_sv_placeholder); |
| 1496 | OUTPUT: |
| 1497 | RETVAL |
| 1498 | |
| 1499 | SV * |
| 1500 | refcounted_he_fetch(key, level=0) |
| 1501 | SV *key |
| 1502 | IV level |
| 1503 | CODE: |
| 1504 | if (level) { |
| 1505 | croak("level must be zero, not %"IVdf, level); |
| 1506 | } |
| 1507 | RETVAL = cop_hints_fetch_sv(PL_curcop, key, 0, 0); |
| 1508 | SvREFCNT_inc(RETVAL); |
| 1509 | OUTPUT: |
| 1510 | RETVAL |
| 1511 | |
| 1512 | #endif |
| 1513 | |
| 1514 | =pod |
| 1515 | |
| 1516 | sub TIEHASH { bless {}, $_[0] } |
| 1517 | sub STORE { $_[0]->{$_[1]} = $_[2] } |
| 1518 | sub FETCH { $_[0]->{$_[1]} } |
| 1519 | sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} } |
| 1520 | sub NEXTKEY { each %{$_[0]} } |
| 1521 | sub EXISTS { exists $_[0]->{$_[1]} } |
| 1522 | sub DELETE { delete $_[0]->{$_[1]} } |
| 1523 | sub CLEAR { %{$_[0]} = () } |
| 1524 | |
| 1525 | =cut |
| 1526 | |
| 1527 | MODULE = XS::APItest:TempLv PACKAGE = XS::APItest::TempLv |
| 1528 | |
| 1529 | void |
| 1530 | make_temp_mg_lv(sv) |
| 1531 | SV* sv |
| 1532 | PREINIT: |
| 1533 | SV * const lv = newSV_type(SVt_PVLV); |
| 1534 | STRLEN len; |
| 1535 | PPCODE: |
| 1536 | SvPV(sv, len); |
| 1537 | |
| 1538 | sv_magic(lv, NULL, PERL_MAGIC_substr, NULL, 0); |
| 1539 | LvTYPE(lv) = 'x'; |
| 1540 | LvTARG(lv) = SvREFCNT_inc_simple(sv); |
| 1541 | LvTARGOFF(lv) = len == 0 ? 0 : 1; |
| 1542 | LvTARGLEN(lv) = len < 2 ? 0 : len-2; |
| 1543 | |
| 1544 | EXTEND(SP, 1); |
| 1545 | ST(0) = sv_2mortal(lv); |
| 1546 | XSRETURN(1); |
| 1547 | |
| 1548 | |
| 1549 | MODULE = XS::APItest::PtrTable PACKAGE = XS::APItest::PtrTable PREFIX = ptr_table_ |
| 1550 | |
| 1551 | void |
| 1552 | ptr_table_new(classname) |
| 1553 | const char * classname |
| 1554 | PPCODE: |
| 1555 | PUSHs(sv_setref_pv(sv_newmortal(), classname, (void*)ptr_table_new())); |
| 1556 | |
| 1557 | void |
| 1558 | DESTROY(table) |
| 1559 | XS::APItest::PtrTable table |
| 1560 | CODE: |
| 1561 | ptr_table_free(table); |
| 1562 | |
| 1563 | void |
| 1564 | ptr_table_store(table, from, to) |
| 1565 | XS::APItest::PtrTable table |
| 1566 | SVREF from |
| 1567 | SVREF to |
| 1568 | CODE: |
| 1569 | ptr_table_store(table, from, to); |
| 1570 | |
| 1571 | UV |
| 1572 | ptr_table_fetch(table, from) |
| 1573 | XS::APItest::PtrTable table |
| 1574 | SVREF from |
| 1575 | CODE: |
| 1576 | RETVAL = PTR2UV(ptr_table_fetch(table, from)); |
| 1577 | OUTPUT: |
| 1578 | RETVAL |
| 1579 | |
| 1580 | void |
| 1581 | ptr_table_split(table) |
| 1582 | XS::APItest::PtrTable table |
| 1583 | |
| 1584 | void |
| 1585 | ptr_table_clear(table) |
| 1586 | XS::APItest::PtrTable table |
| 1587 | |
| 1588 | MODULE = XS::APItest::AutoLoader PACKAGE = XS::APItest::AutoLoader |
| 1589 | |
| 1590 | SV * |
| 1591 | AUTOLOAD() |
| 1592 | CODE: |
| 1593 | RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv)); |
| 1594 | OUTPUT: |
| 1595 | RETVAL |
| 1596 | |
| 1597 | SV * |
| 1598 | AUTOLOADp(...) |
| 1599 | PROTOTYPE: *$ |
| 1600 | CODE: |
| 1601 | RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv)); |
| 1602 | OUTPUT: |
| 1603 | RETVAL |
| 1604 | |
| 1605 | |
| 1606 | MODULE = XS::APItest PACKAGE = XS::APItest |
| 1607 | |
| 1608 | PROTOTYPES: DISABLE |
| 1609 | |
| 1610 | BOOT: |
| 1611 | mymro.resolve = myget_linear_isa; |
| 1612 | mymro.name = "justisa"; |
| 1613 | mymro.length = 7; |
| 1614 | mymro.kflags = 0; |
| 1615 | mymro.hash = 0; |
| 1616 | Perl_mro_register(aTHX_ &mymro); |
| 1617 | |
| 1618 | HV * |
| 1619 | xop_custom_ops () |
| 1620 | CODE: |
| 1621 | RETVAL = PL_custom_ops; |
| 1622 | OUTPUT: |
| 1623 | RETVAL |
| 1624 | |
| 1625 | HV * |
| 1626 | xop_custom_op_names () |
| 1627 | CODE: |
| 1628 | PL_custom_op_names = newHV(); |
| 1629 | RETVAL = PL_custom_op_names; |
| 1630 | OUTPUT: |
| 1631 | RETVAL |
| 1632 | |
| 1633 | HV * |
| 1634 | xop_custom_op_descs () |
| 1635 | CODE: |
| 1636 | PL_custom_op_descs = newHV(); |
| 1637 | RETVAL = PL_custom_op_descs; |
| 1638 | OUTPUT: |
| 1639 | RETVAL |
| 1640 | |
| 1641 | void |
| 1642 | xop_register () |
| 1643 | CODE: |
| 1644 | XopENTRY_set(&my_xop, xop_name, "my_xop"); |
| 1645 | XopENTRY_set(&my_xop, xop_desc, "XOP for testing"); |
| 1646 | XopENTRY_set(&my_xop, xop_class, OA_UNOP); |
| 1647 | XopENTRY_set(&my_xop, xop_peep, peep_xop); |
| 1648 | Perl_custom_op_register(aTHX_ pp_xop, &my_xop); |
| 1649 | |
| 1650 | void |
| 1651 | xop_clear () |
| 1652 | CODE: |
| 1653 | XopDISABLE(&my_xop, xop_name); |
| 1654 | XopDISABLE(&my_xop, xop_desc); |
| 1655 | XopDISABLE(&my_xop, xop_class); |
| 1656 | XopDISABLE(&my_xop, xop_peep); |
| 1657 | |
| 1658 | IV |
| 1659 | xop_my_xop () |
| 1660 | CODE: |
| 1661 | RETVAL = PTR2IV(&my_xop); |
| 1662 | OUTPUT: |
| 1663 | RETVAL |
| 1664 | |
| 1665 | IV |
| 1666 | xop_ppaddr () |
| 1667 | CODE: |
| 1668 | RETVAL = PTR2IV(pp_xop); |
| 1669 | OUTPUT: |
| 1670 | RETVAL |
| 1671 | |
| 1672 | IV |
| 1673 | xop_OA_UNOP () |
| 1674 | CODE: |
| 1675 | RETVAL = OA_UNOP; |
| 1676 | OUTPUT: |
| 1677 | RETVAL |
| 1678 | |
| 1679 | AV * |
| 1680 | xop_build_optree () |
| 1681 | CODE: |
| 1682 | dMY_CXT; |
| 1683 | UNOP *unop; |
| 1684 | OP *kid; |
| 1685 | |
| 1686 | MY_CXT.xop_record = newAV(); |
| 1687 | |
| 1688 | kid = newSVOP(OP_CONST, 0, newSViv(42)); |
| 1689 | |
| 1690 | NewOp(1102, unop, 1, UNOP); |
| 1691 | unop->op_type = OP_CUSTOM; |
| 1692 | unop->op_ppaddr = pp_xop; |
| 1693 | unop->op_flags = OPf_KIDS; |
| 1694 | unop->op_private = 0; |
| 1695 | unop->op_first = kid; |
| 1696 | unop->op_next = NULL; |
| 1697 | kid->op_next = (OP*)unop; |
| 1698 | |
| 1699 | av_push(MY_CXT.xop_record, newSVpvf("unop:%"UVxf, PTR2UV(unop))); |
| 1700 | av_push(MY_CXT.xop_record, newSVpvf("kid:%"UVxf, PTR2UV(kid))); |
| 1701 | |
| 1702 | av_push(MY_CXT.xop_record, newSVpvf("NAME:%s", OP_NAME((OP*)unop))); |
| 1703 | av_push(MY_CXT.xop_record, newSVpvf("DESC:%s", OP_DESC((OP*)unop))); |
| 1704 | av_push(MY_CXT.xop_record, newSVpvf("CLASS:%d", (int)OP_CLASS((OP*)unop))); |
| 1705 | |
| 1706 | PL_rpeepp(aTHX_ kid); |
| 1707 | |
| 1708 | FreeOp(kid); |
| 1709 | FreeOp(unop); |
| 1710 | |
| 1711 | RETVAL = MY_CXT.xop_record; |
| 1712 | MY_CXT.xop_record = NULL; |
| 1713 | OUTPUT: |
| 1714 | RETVAL |
| 1715 | |
| 1716 | BOOT: |
| 1717 | { |
| 1718 | MY_CXT_INIT; |
| 1719 | |
| 1720 | MY_CXT.i = 99; |
| 1721 | MY_CXT.sv = newSVpv("initial",0); |
| 1722 | |
| 1723 | MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI); |
| 1724 | MY_CXT.bhk_record = 0; |
| 1725 | |
| 1726 | BhkENTRY_set(&bhk_test, bhk_start, blockhook_test_start); |
| 1727 | BhkENTRY_set(&bhk_test, bhk_pre_end, blockhook_test_pre_end); |
| 1728 | BhkENTRY_set(&bhk_test, bhk_post_end, blockhook_test_post_end); |
| 1729 | BhkENTRY_set(&bhk_test, bhk_eval, blockhook_test_eval); |
| 1730 | Perl_blockhook_register(aTHX_ &bhk_test); |
| 1731 | |
| 1732 | MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER", |
| 1733 | GV_ADDMULTI, SVt_PVAV); |
| 1734 | MY_CXT.cscav = GvAV(MY_CXT.cscgv); |
| 1735 | |
| 1736 | BhkENTRY_set(&bhk_csc, bhk_start, blockhook_csc_start); |
| 1737 | BhkENTRY_set(&bhk_csc, bhk_pre_end, blockhook_csc_pre_end); |
| 1738 | Perl_blockhook_register(aTHX_ &bhk_csc); |
| 1739 | |
| 1740 | MY_CXT.peep_recorder = newAV(); |
| 1741 | MY_CXT.rpeep_recorder = newAV(); |
| 1742 | |
| 1743 | MY_CXT.orig_peep = PL_peepp; |
| 1744 | MY_CXT.orig_rpeep = PL_rpeepp; |
| 1745 | PL_peepp = my_peep; |
| 1746 | PL_rpeepp = my_rpeep; |
| 1747 | } |
| 1748 | |
| 1749 | void |
| 1750 | CLONE(...) |
| 1751 | CODE: |
| 1752 | MY_CXT_CLONE; |
| 1753 | PERL_UNUSED_VAR(items); |
| 1754 | MY_CXT.sv = newSVpv("initial_clone",0); |
| 1755 | MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER", |
| 1756 | GV_ADDMULTI, SVt_PVAV); |
| 1757 | MY_CXT.cscav = NULL; |
| 1758 | MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI); |
| 1759 | MY_CXT.bhk_record = 0; |
| 1760 | MY_CXT.peep_recorder = newAV(); |
| 1761 | MY_CXT.rpeep_recorder = newAV(); |
| 1762 | |
| 1763 | void |
| 1764 | print_double(val) |
| 1765 | double val |
| 1766 | CODE: |
| 1767 | printf("%5.3f\n",val); |
| 1768 | |
| 1769 | int |
| 1770 | have_long_double() |
| 1771 | CODE: |
| 1772 | #ifdef HAS_LONG_DOUBLE |
| 1773 | RETVAL = 1; |
| 1774 | #else |
| 1775 | RETVAL = 0; |
| 1776 | #endif |
| 1777 | OUTPUT: |
| 1778 | RETVAL |
| 1779 | |
| 1780 | void |
| 1781 | print_long_double() |
| 1782 | CODE: |
| 1783 | #ifdef HAS_LONG_DOUBLE |
| 1784 | # if defined(PERL_PRIfldbl) && (LONG_DOUBLESIZE > DOUBLESIZE) |
| 1785 | long double val = 7.0; |
| 1786 | printf("%5.3" PERL_PRIfldbl "\n",val); |
| 1787 | # else |
| 1788 | double val = 7.0; |
| 1789 | printf("%5.3f\n",val); |
| 1790 | # endif |
| 1791 | #endif |
| 1792 | |
| 1793 | void |
| 1794 | print_int(val) |
| 1795 | int val |
| 1796 | CODE: |
| 1797 | printf("%d\n",val); |
| 1798 | |
| 1799 | void |
| 1800 | print_long(val) |
| 1801 | long val |
| 1802 | CODE: |
| 1803 | printf("%ld\n",val); |
| 1804 | |
| 1805 | void |
| 1806 | print_float(val) |
| 1807 | float val |
| 1808 | CODE: |
| 1809 | printf("%5.3f\n",val); |
| 1810 | |
| 1811 | void |
| 1812 | print_flush() |
| 1813 | CODE: |
| 1814 | fflush(stdout); |
| 1815 | |
| 1816 | void |
| 1817 | mpushp() |
| 1818 | PPCODE: |
| 1819 | EXTEND(SP, 3); |
| 1820 | mPUSHp("one", 3); |
| 1821 | mPUSHp("two", 3); |
| 1822 | mPUSHp("three", 5); |
| 1823 | XSRETURN(3); |
| 1824 | |
| 1825 | void |
| 1826 | mpushn() |
| 1827 | PPCODE: |
| 1828 | EXTEND(SP, 3); |
| 1829 | mPUSHn(0.5); |
| 1830 | mPUSHn(-0.25); |
| 1831 | mPUSHn(0.125); |
| 1832 | XSRETURN(3); |
| 1833 | |
| 1834 | void |
| 1835 | mpushi() |
| 1836 | PPCODE: |
| 1837 | EXTEND(SP, 3); |
| 1838 | mPUSHi(-1); |
| 1839 | mPUSHi(2); |
| 1840 | mPUSHi(-3); |
| 1841 | XSRETURN(3); |
| 1842 | |
| 1843 | void |
| 1844 | mpushu() |
| 1845 | PPCODE: |
| 1846 | EXTEND(SP, 3); |
| 1847 | mPUSHu(1); |
| 1848 | mPUSHu(2); |
| 1849 | mPUSHu(3); |
| 1850 | XSRETURN(3); |
| 1851 | |
| 1852 | void |
| 1853 | mxpushp() |
| 1854 | PPCODE: |
| 1855 | mXPUSHp("one", 3); |
| 1856 | mXPUSHp("two", 3); |
| 1857 | mXPUSHp("three", 5); |
| 1858 | XSRETURN(3); |
| 1859 | |
| 1860 | void |
| 1861 | mxpushn() |
| 1862 | PPCODE: |
| 1863 | mXPUSHn(0.5); |
| 1864 | mXPUSHn(-0.25); |
| 1865 | mXPUSHn(0.125); |
| 1866 | XSRETURN(3); |
| 1867 | |
| 1868 | void |
| 1869 | mxpushi() |
| 1870 | PPCODE: |
| 1871 | mXPUSHi(-1); |
| 1872 | mXPUSHi(2); |
| 1873 | mXPUSHi(-3); |
| 1874 | XSRETURN(3); |
| 1875 | |
| 1876 | void |
| 1877 | mxpushu() |
| 1878 | PPCODE: |
| 1879 | mXPUSHu(1); |
| 1880 | mXPUSHu(2); |
| 1881 | mXPUSHu(3); |
| 1882 | XSRETURN(3); |
| 1883 | |
| 1884 | |
| 1885 | void |
| 1886 | call_sv(sv, flags, ...) |
| 1887 | SV* sv |
| 1888 | I32 flags |
| 1889 | PREINIT: |
| 1890 | I32 i; |
| 1891 | PPCODE: |
| 1892 | for (i=0; i<items-2; i++) |
| 1893 | ST(i) = ST(i+2); /* pop first two args */ |
| 1894 | PUSHMARK(SP); |
| 1895 | SP += items - 2; |
| 1896 | PUTBACK; |
| 1897 | i = call_sv(sv, flags); |
| 1898 | SPAGAIN; |
| 1899 | EXTEND(SP, 1); |
| 1900 | PUSHs(sv_2mortal(newSViv(i))); |
| 1901 | |
| 1902 | void |
| 1903 | call_pv(subname, flags, ...) |
| 1904 | char* subname |
| 1905 | I32 flags |
| 1906 | PREINIT: |
| 1907 | I32 i; |
| 1908 | PPCODE: |
| 1909 | for (i=0; i<items-2; i++) |
| 1910 | ST(i) = ST(i+2); /* pop first two args */ |
| 1911 | PUSHMARK(SP); |
| 1912 | SP += items - 2; |
| 1913 | PUTBACK; |
| 1914 | i = call_pv(subname, flags); |
| 1915 | SPAGAIN; |
| 1916 | EXTEND(SP, 1); |
| 1917 | PUSHs(sv_2mortal(newSViv(i))); |
| 1918 | |
| 1919 | void |
| 1920 | call_method(methname, flags, ...) |
| 1921 | char* methname |
| 1922 | I32 flags |
| 1923 | PREINIT: |
| 1924 | I32 i; |
| 1925 | PPCODE: |
| 1926 | for (i=0; i<items-2; i++) |
| 1927 | ST(i) = ST(i+2); /* pop first two args */ |
| 1928 | PUSHMARK(SP); |
| 1929 | SP += items - 2; |
| 1930 | PUTBACK; |
| 1931 | i = call_method(methname, flags); |
| 1932 | SPAGAIN; |
| 1933 | EXTEND(SP, 1); |
| 1934 | PUSHs(sv_2mortal(newSViv(i))); |
| 1935 | |
| 1936 | void |
| 1937 | newCONSTSUB_type(stash, name, flags, type, sv) |
| 1938 | HV* stash |
| 1939 | SV* name |
| 1940 | I32 flags |
| 1941 | int type |
| 1942 | SV* sv |
| 1943 | PREINIT: |
| 1944 | CV* cv; |
| 1945 | STRLEN len; |
| 1946 | const char *pv = SvPV(name, len); |
| 1947 | PPCODE: |
| 1948 | switch (type) { |
| 1949 | case 0: |
| 1950 | cv = newCONSTSUB(stash, pv, SvOK(sv) ? sv : NULL); |
| 1951 | break; |
| 1952 | case 1: |
| 1953 | cv = newCONSTSUB_flags( |
| 1954 | stash, pv, len, flags | SvUTF8(name), SvOK(sv) ? sv : NULL |
| 1955 | ); |
| 1956 | break; |
| 1957 | } |
| 1958 | EXTEND(SP, 2); |
| 1959 | PUSHs( CvCONST(cv) ? &PL_sv_yes : &PL_sv_no ); |
| 1960 | PUSHs((SV*)CvGV(cv)); |
| 1961 | |
| 1962 | void |
| 1963 | gv_init_type(namesv, multi, flags, type) |
| 1964 | SV* namesv |
| 1965 | int multi |
| 1966 | I32 flags |
| 1967 | int type |
| 1968 | PREINIT: |
| 1969 | STRLEN len; |
| 1970 | const char * const name = SvPV_const(namesv, len); |
| 1971 | GV *gv = *(GV**)hv_fetch(PL_defstash, name, len, TRUE); |
| 1972 | PPCODE: |
| 1973 | if (SvTYPE(gv) == SVt_PVGV) |
| 1974 | Perl_croak(aTHX_ "GV is already a PVGV"); |
| 1975 | if (multi) flags |= GV_ADDMULTI; |
| 1976 | switch (type) { |
| 1977 | case 0: |
| 1978 | gv_init(gv, PL_defstash, name, len, multi); |
| 1979 | break; |
| 1980 | case 1: |
| 1981 | gv_init_sv(gv, PL_defstash, namesv, flags); |
| 1982 | break; |
| 1983 | case 2: |
| 1984 | gv_init_pv(gv, PL_defstash, name, flags | SvUTF8(namesv)); |
| 1985 | break; |
| 1986 | case 3: |
| 1987 | gv_init_pvn(gv, PL_defstash, name, len, flags | SvUTF8(namesv)); |
| 1988 | break; |
| 1989 | } |
| 1990 | XPUSHs( gv ? (SV*)gv : &PL_sv_undef); |
| 1991 | |
| 1992 | void |
| 1993 | gv_fetchmeth_type(stash, methname, type, level, flags) |
| 1994 | HV* stash |
| 1995 | SV* methname |
| 1996 | int type |
| 1997 | I32 level |
| 1998 | I32 flags |
| 1999 | PREINIT: |
| 2000 | STRLEN len; |
| 2001 | const char * const name = SvPV_const(methname, len); |
| 2002 | GV* gv; |
| 2003 | PPCODE: |
| 2004 | switch (type) { |
| 2005 | case 0: |
| 2006 | gv = gv_fetchmeth(stash, name, len, level); |
| 2007 | break; |
| 2008 | case 1: |
| 2009 | gv = gv_fetchmeth_sv(stash, methname, level, flags); |
| 2010 | break; |
| 2011 | case 2: |
| 2012 | gv = gv_fetchmeth_pv(stash, name, level, flags | SvUTF8(methname)); |
| 2013 | break; |
| 2014 | case 3: |
| 2015 | gv = gv_fetchmeth_pvn(stash, name, len, level, flags | SvUTF8(methname)); |
| 2016 | break; |
| 2017 | } |
| 2018 | XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef ); |
| 2019 | |
| 2020 | void |
| 2021 | gv_fetchmeth_autoload_type(stash, methname, type, level, flags) |
| 2022 | HV* stash |
| 2023 | SV* methname |
| 2024 | int type |
| 2025 | I32 level |
| 2026 | I32 flags |
| 2027 | PREINIT: |
| 2028 | STRLEN len; |
| 2029 | const char * const name = SvPV_const(methname, len); |
| 2030 | GV* gv; |
| 2031 | PPCODE: |
| 2032 | switch (type) { |
| 2033 | case 0: |
| 2034 | gv = gv_fetchmeth_autoload(stash, name, len, level); |
| 2035 | break; |
| 2036 | case 1: |
| 2037 | gv = gv_fetchmeth_sv_autoload(stash, methname, level, flags); |
| 2038 | break; |
| 2039 | case 2: |
| 2040 | gv = gv_fetchmeth_pv_autoload(stash, name, level, flags | SvUTF8(methname)); |
| 2041 | break; |
| 2042 | case 3: |
| 2043 | gv = gv_fetchmeth_pvn_autoload(stash, name, len, level, flags | SvUTF8(methname)); |
| 2044 | break; |
| 2045 | } |
| 2046 | XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef ); |
| 2047 | |
| 2048 | void |
| 2049 | gv_fetchmethod_flags_type(stash, methname, type, flags) |
| 2050 | HV* stash |
| 2051 | SV* methname |
| 2052 | int type |
| 2053 | I32 flags |
| 2054 | PREINIT: |
| 2055 | GV* gv; |
| 2056 | PPCODE: |
| 2057 | switch (type) { |
| 2058 | case 0: |
| 2059 | gv = gv_fetchmethod_flags(stash, SvPVX_const(methname), flags); |
| 2060 | break; |
| 2061 | case 1: |
| 2062 | gv = gv_fetchmethod_sv_flags(stash, methname, flags); |
| 2063 | break; |
| 2064 | case 2: |
| 2065 | gv = gv_fetchmethod_pv_flags(stash, SvPV_nolen(methname), flags | SvUTF8(methname)); |
| 2066 | break; |
| 2067 | case 3: { |
| 2068 | STRLEN len; |
| 2069 | const char * const name = SvPV_const(methname, len); |
| 2070 | gv = gv_fetchmethod_pvn_flags(stash, name, len, flags | SvUTF8(methname)); |
| 2071 | break; |
| 2072 | } |
| 2073 | } |
| 2074 | XPUSHs( gv ? (SV*)gv : &PL_sv_undef); |
| 2075 | |
| 2076 | void |
| 2077 | gv_autoload_type(stash, methname, type, method) |
| 2078 | HV* stash |
| 2079 | SV* methname |
| 2080 | int type |
| 2081 | I32 method |
| 2082 | PREINIT: |
| 2083 | STRLEN len; |
| 2084 | const char * const name = SvPV_const(methname, len); |
| 2085 | GV* gv; |
| 2086 | I32 flags = method ? GV_AUTOLOAD_ISMETHOD : 0; |
| 2087 | PPCODE: |
| 2088 | switch (type) { |
| 2089 | case 0: |
| 2090 | gv = gv_autoload4(stash, name, len, method); |
| 2091 | break; |
| 2092 | case 1: |
| 2093 | gv = gv_autoload_sv(stash, methname, flags); |
| 2094 | break; |
| 2095 | case 2: |
| 2096 | gv = gv_autoload_pv(stash, name, flags | SvUTF8(methname)); |
| 2097 | break; |
| 2098 | case 3: |
| 2099 | gv = gv_autoload_pvn(stash, name, len, flags | SvUTF8(methname)); |
| 2100 | break; |
| 2101 | } |
| 2102 | XPUSHs( gv ? (SV*)gv : &PL_sv_undef); |
| 2103 | |
| 2104 | void |
| 2105 | whichsig_type(namesv, type) |
| 2106 | SV* namesv |
| 2107 | int type |
| 2108 | PREINIT: |
| 2109 | STRLEN len; |
| 2110 | const char * const name = SvPV_const(namesv, len); |
| 2111 | I32 i; |
| 2112 | PPCODE: |
| 2113 | switch (type) { |
| 2114 | case 0: |
| 2115 | i = whichsig(name); |
| 2116 | break; |
| 2117 | case 1: |
| 2118 | i = whichsig_sv(namesv); |
| 2119 | break; |
| 2120 | case 2: |
| 2121 | i = whichsig_pv(name); |
| 2122 | break; |
| 2123 | case 3: |
| 2124 | i = whichsig_pvn(name, len); |
| 2125 | break; |
| 2126 | } |
| 2127 | XPUSHs(sv_2mortal(newSViv(i))); |
| 2128 | |
| 2129 | void |
| 2130 | eval_sv(sv, flags) |
| 2131 | SV* sv |
| 2132 | I32 flags |
| 2133 | PREINIT: |
| 2134 | I32 i; |
| 2135 | PPCODE: |
| 2136 | PUTBACK; |
| 2137 | i = eval_sv(sv, flags); |
| 2138 | SPAGAIN; |
| 2139 | EXTEND(SP, 1); |
| 2140 | PUSHs(sv_2mortal(newSViv(i))); |
| 2141 | |
| 2142 | void |
| 2143 | eval_pv(p, croak_on_error) |
| 2144 | const char* p |
| 2145 | I32 croak_on_error |
| 2146 | PPCODE: |
| 2147 | PUTBACK; |
| 2148 | EXTEND(SP, 1); |
| 2149 | PUSHs(eval_pv(p, croak_on_error)); |
| 2150 | |
| 2151 | void |
| 2152 | require_pv(pv) |
| 2153 | const char* pv |
| 2154 | PPCODE: |
| 2155 | PUTBACK; |
| 2156 | require_pv(pv); |
| 2157 | |
| 2158 | int |
| 2159 | apitest_exception(throw_e) |
| 2160 | int throw_e |
| 2161 | OUTPUT: |
| 2162 | RETVAL |
| 2163 | |
| 2164 | void |
| 2165 | mycroak(sv) |
| 2166 | SV* sv |
| 2167 | CODE: |
| 2168 | if (SvOK(sv)) { |
| 2169 | Perl_croak(aTHX_ "%s", SvPV_nolen(sv)); |
| 2170 | } |
| 2171 | else { |
| 2172 | Perl_croak(aTHX_ NULL); |
| 2173 | } |
| 2174 | |
| 2175 | SV* |
| 2176 | strtab() |
| 2177 | CODE: |
| 2178 | RETVAL = newRV_inc((SV*)PL_strtab); |
| 2179 | OUTPUT: |
| 2180 | RETVAL |
| 2181 | |
| 2182 | int |
| 2183 | my_cxt_getint() |
| 2184 | CODE: |
| 2185 | dMY_CXT; |
| 2186 | RETVAL = my_cxt_getint_p(aMY_CXT); |
| 2187 | OUTPUT: |
| 2188 | RETVAL |
| 2189 | |
| 2190 | void |
| 2191 | my_cxt_setint(i) |
| 2192 | int i; |
| 2193 | CODE: |
| 2194 | dMY_CXT; |
| 2195 | my_cxt_setint_p(aMY_CXT_ i); |
| 2196 | |
| 2197 | void |
| 2198 | my_cxt_getsv(how) |
| 2199 | bool how; |
| 2200 | PPCODE: |
| 2201 | EXTEND(SP, 1); |
| 2202 | ST(0) = how ? my_cxt_getsv_interp_context() : my_cxt_getsv_interp(); |
| 2203 | XSRETURN(1); |
| 2204 | |
| 2205 | void |
| 2206 | my_cxt_setsv(sv) |
| 2207 | SV *sv; |
| 2208 | CODE: |
| 2209 | dMY_CXT; |
| 2210 | SvREFCNT_dec(MY_CXT.sv); |
| 2211 | my_cxt_setsv_p(sv _aMY_CXT); |
| 2212 | SvREFCNT_inc(sv); |
| 2213 | |
| 2214 | bool |
| 2215 | sv_setsv_cow_hashkey_core() |
| 2216 | |
| 2217 | bool |
| 2218 | sv_setsv_cow_hashkey_notcore() |
| 2219 | |
| 2220 | void |
| 2221 | sv_set_deref(SV *sv, SV *sv2, int which) |
| 2222 | CODE: |
| 2223 | { |
| 2224 | STRLEN len; |
| 2225 | const char *pv = SvPV(sv2,len); |
| 2226 | if (!SvROK(sv)) croak("Not a ref"); |
| 2227 | sv = SvRV(sv); |
| 2228 | switch (which) { |
| 2229 | case 0: sv_setsv(sv,sv2); break; |
| 2230 | case 1: sv_setpv(sv,pv); break; |
| 2231 | case 2: sv_setpvn(sv,pv,len); break; |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | void |
| 2236 | rmagical_cast(sv, type) |
| 2237 | SV *sv; |
| 2238 | SV *type; |
| 2239 | PREINIT: |
| 2240 | struct ufuncs uf; |
| 2241 | PPCODE: |
| 2242 | if (!SvOK(sv) || !SvROK(sv) || !SvOK(type)) { XSRETURN_UNDEF; } |
| 2243 | sv = SvRV(sv); |
| 2244 | if (SvTYPE(sv) != SVt_PVHV) { XSRETURN_UNDEF; } |
| 2245 | uf.uf_val = rmagical_a_dummy; |
| 2246 | uf.uf_set = NULL; |
| 2247 | uf.uf_index = 0; |
| 2248 | if (SvTRUE(type)) { /* b */ |
| 2249 | sv_magicext(sv, NULL, PERL_MAGIC_ext, &rmagical_b, NULL, 0); |
| 2250 | } else { /* a */ |
| 2251 | sv_magic(sv, NULL, PERL_MAGIC_uvar, (char *) &uf, sizeof(uf)); |
| 2252 | } |
| 2253 | XSRETURN_YES; |
| 2254 | |
| 2255 | void |
| 2256 | rmagical_flags(sv) |
| 2257 | SV *sv; |
| 2258 | PPCODE: |
| 2259 | if (!SvOK(sv) || !SvROK(sv)) { XSRETURN_UNDEF; } |
| 2260 | sv = SvRV(sv); |
| 2261 | EXTEND(SP, 3); |
| 2262 | mXPUSHu(SvFLAGS(sv) & SVs_GMG); |
| 2263 | mXPUSHu(SvFLAGS(sv) & SVs_SMG); |
| 2264 | mXPUSHu(SvFLAGS(sv) & SVs_RMG); |
| 2265 | XSRETURN(3); |
| 2266 | |
| 2267 | void |
| 2268 | my_caller(level) |
| 2269 | I32 level |
| 2270 | PREINIT: |
| 2271 | const PERL_CONTEXT *cx, *dbcx; |
| 2272 | const char *pv; |
| 2273 | const GV *gv; |
| 2274 | HV *hv; |
| 2275 | PPCODE: |
| 2276 | cx = caller_cx(level, &dbcx); |
| 2277 | EXTEND(SP, 8); |
| 2278 | |
| 2279 | pv = CopSTASHPV(cx->blk_oldcop); |
| 2280 | ST(0) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef; |
| 2281 | gv = CvGV(cx->blk_sub.cv); |
| 2282 | ST(1) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef; |
| 2283 | |
| 2284 | pv = CopSTASHPV(dbcx->blk_oldcop); |
| 2285 | ST(2) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef; |
| 2286 | gv = CvGV(dbcx->blk_sub.cv); |
| 2287 | ST(3) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef; |
| 2288 | |
| 2289 | ST(4) = cop_hints_fetch_pvs(cx->blk_oldcop, "foo", 0); |
| 2290 | ST(5) = cop_hints_fetch_pvn(cx->blk_oldcop, "foo", 3, 0, 0); |
| 2291 | ST(6) = cop_hints_fetch_sv(cx->blk_oldcop, |
| 2292 | sv_2mortal(newSVpvn("foo", 3)), 0, 0); |
| 2293 | |
| 2294 | hv = cop_hints_2hv(cx->blk_oldcop, 0); |
| 2295 | ST(7) = hv ? sv_2mortal(newRV_noinc((SV *)hv)) : &PL_sv_undef; |
| 2296 | |
| 2297 | XSRETURN(8); |
| 2298 | |
| 2299 | void |
| 2300 | DPeek (sv) |
| 2301 | SV *sv |
| 2302 | |
| 2303 | PPCODE: |
| 2304 | ST (0) = newSVpv (Perl_sv_peek (aTHX_ sv), 0); |
| 2305 | XSRETURN (1); |
| 2306 | |
| 2307 | void |
| 2308 | BEGIN() |
| 2309 | CODE: |
| 2310 | sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI)); |
| 2311 | |
| 2312 | void |
| 2313 | CHECK() |
| 2314 | CODE: |
| 2315 | sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI)); |
| 2316 | |
| 2317 | void |
| 2318 | UNITCHECK() |
| 2319 | CODE: |
| 2320 | sv_inc(get_sv("XS::APItest::UNITCHECK_called", GV_ADD|GV_ADDMULTI)); |
| 2321 | |
| 2322 | void |
| 2323 | INIT() |
| 2324 | CODE: |
| 2325 | sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI)); |
| 2326 | |
| 2327 | void |
| 2328 | END() |
| 2329 | CODE: |
| 2330 | sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI)); |
| 2331 | |
| 2332 | void |
| 2333 | utf16_to_utf8 (sv, ...) |
| 2334 | SV* sv |
| 2335 | ALIAS: |
| 2336 | utf16_to_utf8_reversed = 1 |
| 2337 | PREINIT: |
| 2338 | STRLEN len; |
| 2339 | U8 *source; |
| 2340 | SV *dest; |
| 2341 | I32 got; /* Gah, badly thought out APIs */ |
| 2342 | CODE: |
| 2343 | source = (U8 *)SvPVbyte(sv, len); |
| 2344 | /* Optionally only convert part of the buffer. */ |
| 2345 | if (items > 1) { |
| 2346 | len = SvUV(ST(1)); |
| 2347 | } |
| 2348 | /* Mortalise this right now, as we'll be testing croak()s */ |
| 2349 | dest = sv_2mortal(newSV(len * 3 / 2 + 1)); |
| 2350 | if (ix) { |
| 2351 | utf16_to_utf8_reversed(source, (U8 *)SvPVX(dest), len, &got); |
| 2352 | } else { |
| 2353 | utf16_to_utf8(source, (U8 *)SvPVX(dest), len, &got); |
| 2354 | } |
| 2355 | SvCUR_set(dest, got); |
| 2356 | SvPVX(dest)[got] = '\0'; |
| 2357 | SvPOK_on(dest); |
| 2358 | ST(0) = dest; |
| 2359 | XSRETURN(1); |
| 2360 | |
| 2361 | void |
| 2362 | my_exit(int exitcode) |
| 2363 | PPCODE: |
| 2364 | my_exit(exitcode); |
| 2365 | |
| 2366 | U8 |
| 2367 | first_byte(sv) |
| 2368 | SV *sv |
| 2369 | CODE: |
| 2370 | char *s; |
| 2371 | STRLEN len; |
| 2372 | s = SvPVbyte(sv, len); |
| 2373 | RETVAL = s[0]; |
| 2374 | OUTPUT: |
| 2375 | RETVAL |
| 2376 | |
| 2377 | I32 |
| 2378 | sv_count() |
| 2379 | CODE: |
| 2380 | RETVAL = PL_sv_count; |
| 2381 | OUTPUT: |
| 2382 | RETVAL |
| 2383 | |
| 2384 | void |
| 2385 | bhk_record(bool on) |
| 2386 | CODE: |
| 2387 | dMY_CXT; |
| 2388 | MY_CXT.bhk_record = on; |
| 2389 | if (on) |
| 2390 | av_clear(MY_CXT.bhkav); |
| 2391 | |
| 2392 | void |
| 2393 | test_magic_chain() |
| 2394 | PREINIT: |
| 2395 | SV *sv; |
| 2396 | MAGIC *callmg, *uvarmg; |
| 2397 | CODE: |
| 2398 | sv = sv_2mortal(newSV(0)); |
| 2399 | if (SvTYPE(sv) >= SVt_PVMG) croak_fail(); |
| 2400 | if (SvMAGICAL(sv)) croak_fail(); |
| 2401 | sv_magic(sv, &PL_sv_yes, PERL_MAGIC_checkcall, (char*)&callmg, 0); |
| 2402 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
| 2403 | if (!SvMAGICAL(sv)) croak_fail(); |
| 2404 | if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail(); |
| 2405 | callmg = mg_find(sv, PERL_MAGIC_checkcall); |
| 2406 | if (!callmg) croak_fail(); |
| 2407 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
| 2408 | croak_fail(); |
| 2409 | sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0); |
| 2410 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
| 2411 | if (!SvMAGICAL(sv)) croak_fail(); |
| 2412 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); |
| 2413 | uvarmg = mg_find(sv, PERL_MAGIC_uvar); |
| 2414 | if (!uvarmg) croak_fail(); |
| 2415 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
| 2416 | croak_fail(); |
| 2417 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
| 2418 | croak_fail(); |
| 2419 | mg_free_type(sv, PERL_MAGIC_vec); |
| 2420 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
| 2421 | if (!SvMAGICAL(sv)) croak_fail(); |
| 2422 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); |
| 2423 | if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail(); |
| 2424 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
| 2425 | croak_fail(); |
| 2426 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
| 2427 | croak_fail(); |
| 2428 | mg_free_type(sv, PERL_MAGIC_uvar); |
| 2429 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
| 2430 | if (!SvMAGICAL(sv)) croak_fail(); |
| 2431 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); |
| 2432 | if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail(); |
| 2433 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
| 2434 | croak_fail(); |
| 2435 | sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0); |
| 2436 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
| 2437 | if (!SvMAGICAL(sv)) croak_fail(); |
| 2438 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); |
| 2439 | uvarmg = mg_find(sv, PERL_MAGIC_uvar); |
| 2440 | if (!uvarmg) croak_fail(); |
| 2441 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
| 2442 | croak_fail(); |
| 2443 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
| 2444 | croak_fail(); |
| 2445 | mg_free_type(sv, PERL_MAGIC_checkcall); |
| 2446 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
| 2447 | if (!SvMAGICAL(sv)) croak_fail(); |
| 2448 | if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail(); |
| 2449 | if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail(); |
| 2450 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
| 2451 | croak_fail(); |
| 2452 | mg_free_type(sv, PERL_MAGIC_uvar); |
| 2453 | if (SvMAGICAL(sv)) croak_fail(); |
| 2454 | if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail(); |
| 2455 | if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail(); |
| 2456 | |
| 2457 | void |
| 2458 | test_op_contextualize() |
| 2459 | PREINIT: |
| 2460 | OP *o; |
| 2461 | CODE: |
| 2462 | o = newSVOP(OP_CONST, 0, newSViv(0)); |
| 2463 | o->op_flags &= ~OPf_WANT; |
| 2464 | o = op_contextualize(o, G_SCALAR); |
| 2465 | if (o->op_type != OP_CONST || |
| 2466 | (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR) |
| 2467 | croak_fail(); |
| 2468 | op_free(o); |
| 2469 | o = newSVOP(OP_CONST, 0, newSViv(0)); |
| 2470 | o->op_flags &= ~OPf_WANT; |
| 2471 | o = op_contextualize(o, G_ARRAY); |
| 2472 | if (o->op_type != OP_CONST || |
| 2473 | (o->op_flags & OPf_WANT) != OPf_WANT_LIST) |
| 2474 | croak_fail(); |
| 2475 | op_free(o); |
| 2476 | o = newSVOP(OP_CONST, 0, newSViv(0)); |
| 2477 | o->op_flags &= ~OPf_WANT; |
| 2478 | o = op_contextualize(o, G_VOID); |
| 2479 | if (o->op_type != OP_NULL) croak_fail(); |
| 2480 | op_free(o); |
| 2481 | |
| 2482 | void |
| 2483 | test_rv2cv_op_cv() |
| 2484 | PROTOTYPE: |
| 2485 | PREINIT: |
| 2486 | GV *troc_gv, *wibble_gv; |
| 2487 | CV *troc_cv; |
| 2488 | OP *o; |
| 2489 | CODE: |
| 2490 | troc_gv = gv_fetchpv("XS::APItest::test_rv2cv_op_cv", 0, SVt_PVGV); |
| 2491 | troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0); |
| 2492 | wibble_gv = gv_fetchpv("XS::APItest::wibble", 0, SVt_PVGV); |
| 2493 | o = newCVREF(0, newGVOP(OP_GV, 0, troc_gv)); |
| 2494 | if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail(); |
| 2495 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv) |
| 2496 | croak_fail(); |
| 2497 | o->op_private |= OPpENTERSUB_AMPER; |
| 2498 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
| 2499 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); |
| 2500 | o->op_private &= ~OPpENTERSUB_AMPER; |
| 2501 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
| 2502 | if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail(); |
| 2503 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
| 2504 | op_free(o); |
| 2505 | o = newSVOP(OP_CONST, 0, newSVpv("XS::APItest::test_rv2cv_op_cv", 0)); |
| 2506 | o->op_private = OPpCONST_BARE; |
| 2507 | o = newCVREF(0, o); |
| 2508 | if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail(); |
| 2509 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv) |
| 2510 | croak_fail(); |
| 2511 | o->op_private |= OPpENTERSUB_AMPER; |
| 2512 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
| 2513 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); |
| 2514 | op_free(o); |
| 2515 | o = newCVREF(0, newSVOP(OP_CONST, 0, newRV_inc((SV*)troc_cv))); |
| 2516 | if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail(); |
| 2517 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv) |
| 2518 | croak_fail(); |
| 2519 | o->op_private |= OPpENTERSUB_AMPER; |
| 2520 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
| 2521 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); |
| 2522 | o->op_private &= ~OPpENTERSUB_AMPER; |
| 2523 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
| 2524 | if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail(); |
| 2525 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
| 2526 | op_free(o); |
| 2527 | o = newCVREF(0, newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0)))); |
| 2528 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
| 2529 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); |
| 2530 | o->op_private |= OPpENTERSUB_AMPER; |
| 2531 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
| 2532 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); |
| 2533 | o->op_private &= ~OPpENTERSUB_AMPER; |
| 2534 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
| 2535 | if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY)) croak_fail(); |
| 2536 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
| 2537 | op_free(o); |
| 2538 | o = newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0))); |
| 2539 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
| 2540 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); |
| 2541 | op_free(o); |
| 2542 | |
| 2543 | void |
| 2544 | test_cv_getset_call_checker() |
| 2545 | PREINIT: |
| 2546 | CV *troc_cv, *tsh_cv; |
| 2547 | Perl_call_checker ckfun; |
| 2548 | SV *ckobj; |
| 2549 | CODE: |
| 2550 | #define check_cc(cv, xckfun, xckobj) \ |
| 2551 | do { \ |
| 2552 | cv_get_call_checker((cv), &ckfun, &ckobj); \ |
| 2553 | if (ckfun != (xckfun)) croak_fail_ne(FPTR2DPTR(void *, ckfun), xckfun); \ |
| 2554 | if (ckobj != (xckobj)) croak_fail_ne(FPTR2DPTR(void *, ckobj), xckobj); \ |
| 2555 | } while(0) |
| 2556 | troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0); |
| 2557 | tsh_cv = get_cv("XS::APItest::test_savehints", 0); |
| 2558 | check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv); |
| 2559 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv); |
| 2560 | cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list, |
| 2561 | &PL_sv_yes); |
| 2562 | check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv); |
| 2563 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes); |
| 2564 | cv_set_call_checker(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no); |
| 2565 | check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no); |
| 2566 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes); |
| 2567 | cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list, |
| 2568 | (SV*)tsh_cv); |
| 2569 | check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no); |
| 2570 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv); |
| 2571 | cv_set_call_checker(troc_cv, Perl_ck_entersub_args_proto_or_list, |
| 2572 | (SV*)troc_cv); |
| 2573 | check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv); |
| 2574 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv); |
| 2575 | if (SvMAGICAL((SV*)troc_cv) || SvMAGIC((SV*)troc_cv)) croak_fail(); |
| 2576 | if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail(); |
| 2577 | #undef check_cc |
| 2578 | |
| 2579 | void |
| 2580 | cv_set_call_checker_lists(CV *cv) |
| 2581 | CODE: |
| 2582 | cv_set_call_checker(cv, THX_ck_entersub_args_lists, &PL_sv_undef); |
| 2583 | |
| 2584 | void |
| 2585 | cv_set_call_checker_scalars(CV *cv) |
| 2586 | CODE: |
| 2587 | cv_set_call_checker(cv, THX_ck_entersub_args_scalars, &PL_sv_undef); |
| 2588 | |
| 2589 | void |
| 2590 | cv_set_call_checker_proto(CV *cv, SV *proto) |
| 2591 | CODE: |
| 2592 | if (SvROK(proto)) |
| 2593 | proto = SvRV(proto); |
| 2594 | cv_set_call_checker(cv, Perl_ck_entersub_args_proto, proto); |
| 2595 | |
| 2596 | void |
| 2597 | cv_set_call_checker_proto_or_list(CV *cv, SV *proto) |
| 2598 | CODE: |
| 2599 | if (SvROK(proto)) |
| 2600 | proto = SvRV(proto); |
| 2601 | cv_set_call_checker(cv, Perl_ck_entersub_args_proto_or_list, proto); |
| 2602 | |
| 2603 | void |
| 2604 | cv_set_call_checker_multi_sum(CV *cv) |
| 2605 | CODE: |
| 2606 | cv_set_call_checker(cv, THX_ck_entersub_multi_sum, &PL_sv_undef); |
| 2607 | |
| 2608 | void |
| 2609 | test_cophh() |
| 2610 | PREINIT: |
| 2611 | COPHH *a, *b; |
| 2612 | CODE: |
| 2613 | #define check_ph(EXPR) \ |
| 2614 | do { if((EXPR) != &PL_sv_placeholder) croak("fail"); } while(0) |
| 2615 | #define check_iv(EXPR, EXPECT) \ |
| 2616 | do { if(SvIV(EXPR) != (EXPECT)) croak("fail"); } while(0) |
| 2617 | #define msvpvs(STR) sv_2mortal(newSVpvs(STR)) |
| 2618 | #define msviv(VALUE) sv_2mortal(newSViv(VALUE)) |
| 2619 | a = cophh_new_empty(); |
| 2620 | check_ph(cophh_fetch_pvn(a, "foo_1", 5, 0, 0)); |
| 2621 | check_ph(cophh_fetch_pvs(a, "foo_1", 0)); |
| 2622 | check_ph(cophh_fetch_pv(a, "foo_1", 0, 0)); |
| 2623 | check_ph(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0)); |
| 2624 | a = cophh_store_pvn(a, "foo_1abc", 5, 0, msviv(111), 0); |
| 2625 | a = cophh_store_pvs(a, "foo_2", msviv(222), 0); |
| 2626 | a = cophh_store_pv(a, "foo_3", 0, msviv(333), 0); |
| 2627 | a = cophh_store_sv(a, msvpvs("foo_4"), 0, msviv(444), 0); |
| 2628 | check_iv(cophh_fetch_pvn(a, "foo_1xyz", 5, 0, 0), 111); |
| 2629 | check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111); |
| 2630 | check_iv(cophh_fetch_pv(a, "foo_1", 0, 0), 111); |
| 2631 | check_iv(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0), 111); |
| 2632 | check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222); |
| 2633 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); |
| 2634 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); |
| 2635 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); |
| 2636 | b = cophh_copy(a); |
| 2637 | b = cophh_store_pvs(b, "foo_1", msviv(1111), 0); |
| 2638 | check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111); |
| 2639 | check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222); |
| 2640 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); |
| 2641 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); |
| 2642 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); |
| 2643 | check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111); |
| 2644 | check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222); |
| 2645 | check_iv(cophh_fetch_pvs(b, "foo_3", 0), 333); |
| 2646 | check_iv(cophh_fetch_pvs(b, "foo_4", 0), 444); |
| 2647 | check_ph(cophh_fetch_pvs(b, "foo_5", 0)); |
| 2648 | a = cophh_delete_pvn(a, "foo_1abc", 5, 0, 0); |
| 2649 | a = cophh_delete_pvs(a, "foo_2", 0); |
| 2650 | b = cophh_delete_pv(b, "foo_3", 0, 0); |
| 2651 | b = cophh_delete_sv(b, msvpvs("foo_4"), 0, 0); |
| 2652 | check_ph(cophh_fetch_pvs(a, "foo_1", 0)); |
| 2653 | check_ph(cophh_fetch_pvs(a, "foo_2", 0)); |
| 2654 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); |
| 2655 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); |
| 2656 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); |
| 2657 | check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111); |
| 2658 | check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222); |
| 2659 | check_ph(cophh_fetch_pvs(b, "foo_3", 0)); |
| 2660 | check_ph(cophh_fetch_pvs(b, "foo_4", 0)); |
| 2661 | check_ph(cophh_fetch_pvs(b, "foo_5", 0)); |
| 2662 | b = cophh_delete_pvs(b, "foo_3", 0); |
| 2663 | b = cophh_delete_pvs(b, "foo_5", 0); |
| 2664 | check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111); |
| 2665 | check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222); |
| 2666 | check_ph(cophh_fetch_pvs(b, "foo_3", 0)); |
| 2667 | check_ph(cophh_fetch_pvs(b, "foo_4", 0)); |
| 2668 | check_ph(cophh_fetch_pvs(b, "foo_5", 0)); |
| 2669 | cophh_free(b); |
| 2670 | check_ph(cophh_fetch_pvs(a, "foo_1", 0)); |
| 2671 | check_ph(cophh_fetch_pvs(a, "foo_2", 0)); |
| 2672 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); |
| 2673 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); |
| 2674 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); |
| 2675 | a = cophh_store_pvs(a, "foo_1", msviv(11111), COPHH_KEY_UTF8); |
| 2676 | a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0); |
| 2677 | a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8); |
| 2678 | a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8); |
| 2679 | a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8); |
| 2680 | check_iv(cophh_fetch_pvs(a, "foo_1", 0), 11111); |
| 2681 | check_iv(cophh_fetch_pvs(a, "foo_1", COPHH_KEY_UTF8), 11111); |
| 2682 | check_iv(cophh_fetch_pvs(a, "foo_\xaa", 0), 123); |
| 2683 | check_iv(cophh_fetch_pvs(a, "foo_\xc2\xaa", COPHH_KEY_UTF8), 123); |
| 2684 | check_ph(cophh_fetch_pvs(a, "foo_\xc2\xaa", 0)); |
| 2685 | check_iv(cophh_fetch_pvs(a, "foo_\xbb", 0), 456); |
| 2686 | check_iv(cophh_fetch_pvs(a, "foo_\xc2\xbb", COPHH_KEY_UTF8), 456); |
| 2687 | check_ph(cophh_fetch_pvs(a, "foo_\xc2\xbb", 0)); |
| 2688 | check_iv(cophh_fetch_pvs(a, "foo_\xcc", 0), 789); |
| 2689 | check_iv(cophh_fetch_pvs(a, "foo_\xc3\x8c", COPHH_KEY_UTF8), 789); |
| 2690 | check_ph(cophh_fetch_pvs(a, "foo_\xc2\x8c", 0)); |
| 2691 | check_iv(cophh_fetch_pvs(a, "foo_\xd9\xa6", COPHH_KEY_UTF8), 666); |
| 2692 | check_ph(cophh_fetch_pvs(a, "foo_\xd9\xa6", 0)); |
| 2693 | ENTER; |
| 2694 | SAVEFREECOPHH(a); |
| 2695 | LEAVE; |
| 2696 | #undef check_ph |
| 2697 | #undef check_iv |
| 2698 | #undef msvpvs |
| 2699 | #undef msviv |
| 2700 | |
| 2701 | void |
| 2702 | test_coplabel() |
| 2703 | PREINIT: |
| 2704 | COP *cop; |
| 2705 | const char *label; |
| 2706 | STRLEN len; |
| 2707 | U32 utf8; |
| 2708 | CODE: |
| 2709 | cop = &PL_compiling; |
| 2710 | Perl_cop_store_label(aTHX_ cop, "foo", 3, 0); |
| 2711 | label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8); |
| 2712 | if (strcmp(label,"foo")) croak("fail # cop_fetch_label label"); |
| 2713 | if (len != 3) croak("fail # cop_fetch_label len"); |
| 2714 | if (utf8) croak("fail # cop_fetch_label utf8"); |
| 2715 | /* SMALL GERMAN UMLAUT A */ |
| 2716 | Perl_cop_store_label(aTHX_ cop, "fo\xc3\xa4", 4, SVf_UTF8); |
| 2717 | label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8); |
| 2718 | if (strcmp(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label"); |
| 2719 | if (len != 4) croak("fail # cop_fetch_label len"); |
| 2720 | if (!utf8) croak("fail # cop_fetch_label utf8"); |
| 2721 | |
| 2722 | |
| 2723 | HV * |
| 2724 | example_cophh_2hv() |
| 2725 | PREINIT: |
| 2726 | COPHH *a; |
| 2727 | CODE: |
| 2728 | #define msviv(VALUE) sv_2mortal(newSViv(VALUE)) |
| 2729 | a = cophh_new_empty(); |
| 2730 | a = cophh_store_pvs(a, "foo_0", msviv(999), 0); |
| 2731 | a = cophh_store_pvs(a, "foo_1", msviv(111), 0); |
| 2732 | a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0); |
| 2733 | a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8); |
| 2734 | a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8); |
| 2735 | a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8); |
| 2736 | a = cophh_delete_pvs(a, "foo_0", 0); |
| 2737 | a = cophh_delete_pvs(a, "foo_2", 0); |
| 2738 | RETVAL = cophh_2hv(a, 0); |
| 2739 | cophh_free(a); |
| 2740 | #undef msviv |
| 2741 | OUTPUT: |
| 2742 | RETVAL |
| 2743 | |
| 2744 | void |
| 2745 | test_savehints() |
| 2746 | PREINIT: |
| 2747 | SV **svp, *sv; |
| 2748 | CODE: |
| 2749 | #define store_hint(KEY, VALUE) \ |
| 2750 | sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), KEY, 1), (VALUE)) |
| 2751 | #define hint_ok(KEY, EXPECT) \ |
| 2752 | ((svp = hv_fetchs(GvHV(PL_hintgv), KEY, 0)) && \ |
| 2753 | (sv = *svp) && SvIV(sv) == (EXPECT) && \ |
| 2754 | (sv = cop_hints_fetch_pvs(&PL_compiling, KEY, 0)) && \ |
| 2755 | SvIV(sv) == (EXPECT)) |
| 2756 | #define check_hint(KEY, EXPECT) \ |
| 2757 | do { if (!hint_ok(KEY, EXPECT)) croak_fail(); } while(0) |
| 2758 | PL_hints |= HINT_LOCALIZE_HH; |
| 2759 | ENTER; |
| 2760 | SAVEHINTS(); |
| 2761 | PL_hints &= HINT_INTEGER; |
| 2762 | store_hint("t0", 123); |
| 2763 | store_hint("t1", 456); |
| 2764 | if (PL_hints & HINT_INTEGER) croak_fail(); |
| 2765 | check_hint("t0", 123); check_hint("t1", 456); |
| 2766 | ENTER; |
| 2767 | SAVEHINTS(); |
| 2768 | if (PL_hints & HINT_INTEGER) croak_fail(); |
| 2769 | check_hint("t0", 123); check_hint("t1", 456); |
| 2770 | PL_hints |= HINT_INTEGER; |
| 2771 | store_hint("t0", 321); |
| 2772 | if (!(PL_hints & HINT_INTEGER)) croak_fail(); |
| 2773 | check_hint("t0", 321); check_hint("t1", 456); |
| 2774 | LEAVE; |
| 2775 | if (PL_hints & HINT_INTEGER) croak_fail(); |
| 2776 | check_hint("t0", 123); check_hint("t1", 456); |
| 2777 | ENTER; |
| 2778 | SAVEHINTS(); |
| 2779 | if (PL_hints & HINT_INTEGER) croak_fail(); |
| 2780 | check_hint("t0", 123); check_hint("t1", 456); |
| 2781 | store_hint("t1", 654); |
| 2782 | if (PL_hints & HINT_INTEGER) croak_fail(); |
| 2783 | check_hint("t0", 123); check_hint("t1", 654); |
| 2784 | LEAVE; |
| 2785 | if (PL_hints & HINT_INTEGER) croak_fail(); |
| 2786 | check_hint("t0", 123); check_hint("t1", 456); |
| 2787 | LEAVE; |
| 2788 | #undef store_hint |
| 2789 | #undef hint_ok |
| 2790 | #undef check_hint |
| 2791 | |
| 2792 | void |
| 2793 | test_copyhints() |
| 2794 | PREINIT: |
| 2795 | HV *a, *b; |
| 2796 | CODE: |
| 2797 | PL_hints |= HINT_LOCALIZE_HH; |
| 2798 | ENTER; |
| 2799 | SAVEHINTS(); |
| 2800 | sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), "t0", 1), 123); |
| 2801 | if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123) |
| 2802 | croak_fail(); |
| 2803 | a = newHVhv(GvHV(PL_hintgv)); |
| 2804 | sv_2mortal((SV*)a); |
| 2805 | sv_setiv_mg(*hv_fetchs(a, "t0", 1), 456); |
| 2806 | if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123) |
| 2807 | croak_fail(); |
| 2808 | b = hv_copy_hints_hv(a); |
| 2809 | sv_2mortal((SV*)b); |
| 2810 | sv_setiv_mg(*hv_fetchs(b, "t0", 1), 789); |
| 2811 | if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 789) |
| 2812 | croak_fail(); |
| 2813 | LEAVE; |
| 2814 | |
| 2815 | void |
| 2816 | test_op_list() |
| 2817 | PREINIT: |
| 2818 | OP *a; |
| 2819 | CODE: |
| 2820 | #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv)) |
| 2821 | #define check_op(o, expect) \ |
| 2822 | do { \ |
| 2823 | if (strcmp(test_op_list_describe(o), (expect))) \ |
| 2824 | croak("fail %s %s", test_op_list_describe(o), (expect)); \ |
| 2825 | } while(0) |
| 2826 | a = op_append_elem(OP_LIST, NULL, NULL); |
| 2827 | check_op(a, ""); |
| 2828 | a = op_append_elem(OP_LIST, iv_op(1), a); |
| 2829 | check_op(a, "const(1)."); |
| 2830 | a = op_append_elem(OP_LIST, NULL, a); |
| 2831 | check_op(a, "const(1)."); |
| 2832 | a = op_append_elem(OP_LIST, a, iv_op(2)); |
| 2833 | check_op(a, "list[pushmark.const(1).const(2).]"); |
| 2834 | a = op_append_elem(OP_LIST, a, iv_op(3)); |
| 2835 | check_op(a, "list[pushmark.const(1).const(2).const(3).]"); |
| 2836 | a = op_append_elem(OP_LIST, a, NULL); |
| 2837 | check_op(a, "list[pushmark.const(1).const(2).const(3).]"); |
| 2838 | a = op_append_elem(OP_LIST, NULL, a); |
| 2839 | check_op(a, "list[pushmark.const(1).const(2).const(3).]"); |
| 2840 | a = op_append_elem(OP_LIST, iv_op(4), a); |
| 2841 | check_op(a, "list[pushmark.const(4)." |
| 2842 | "list[pushmark.const(1).const(2).const(3).]]"); |
| 2843 | a = op_append_elem(OP_LIST, a, iv_op(5)); |
| 2844 | check_op(a, "list[pushmark.const(4)." |
| 2845 | "list[pushmark.const(1).const(2).const(3).]const(5).]"); |
| 2846 | a = op_append_elem(OP_LIST, a, |
| 2847 | op_append_elem(OP_LIST, iv_op(7), iv_op(6))); |
| 2848 | check_op(a, "list[pushmark.const(4)." |
| 2849 | "list[pushmark.const(1).const(2).const(3).]const(5)." |
| 2850 | "list[pushmark.const(7).const(6).]]"); |
| 2851 | op_free(a); |
| 2852 | a = op_append_elem(OP_LINESEQ, iv_op(1), iv_op(2)); |
| 2853 | check_op(a, "lineseq[const(1).const(2).]"); |
| 2854 | a = op_append_elem(OP_LINESEQ, a, iv_op(3)); |
| 2855 | check_op(a, "lineseq[const(1).const(2).const(3).]"); |
| 2856 | op_free(a); |
| 2857 | a = op_append_elem(OP_LINESEQ, |
| 2858 | op_append_elem(OP_LIST, iv_op(1), iv_op(2)), |
| 2859 | iv_op(3)); |
| 2860 | check_op(a, "lineseq[list[pushmark.const(1).const(2).]const(3).]"); |
| 2861 | op_free(a); |
| 2862 | a = op_prepend_elem(OP_LIST, NULL, NULL); |
| 2863 | check_op(a, ""); |
| 2864 | a = op_prepend_elem(OP_LIST, a, iv_op(1)); |
| 2865 | check_op(a, "const(1)."); |
| 2866 | a = op_prepend_elem(OP_LIST, a, NULL); |
| 2867 | check_op(a, "const(1)."); |
| 2868 | a = op_prepend_elem(OP_LIST, iv_op(2), a); |
| 2869 | check_op(a, "list[pushmark.const(2).const(1).]"); |
| 2870 | a = op_prepend_elem(OP_LIST, iv_op(3), a); |
| 2871 | check_op(a, "list[pushmark.const(3).const(2).const(1).]"); |
| 2872 | a = op_prepend_elem(OP_LIST, NULL, a); |
| 2873 | check_op(a, "list[pushmark.const(3).const(2).const(1).]"); |
| 2874 | a = op_prepend_elem(OP_LIST, a, NULL); |
| 2875 | check_op(a, "list[pushmark.const(3).const(2).const(1).]"); |
| 2876 | a = op_prepend_elem(OP_LIST, a, iv_op(4)); |
| 2877 | check_op(a, "list[pushmark." |
| 2878 | "list[pushmark.const(3).const(2).const(1).]const(4).]"); |
| 2879 | a = op_prepend_elem(OP_LIST, iv_op(5), a); |
| 2880 | check_op(a, "list[pushmark.const(5)." |
| 2881 | "list[pushmark.const(3).const(2).const(1).]const(4).]"); |
| 2882 | a = op_prepend_elem(OP_LIST, |
| 2883 | op_prepend_elem(OP_LIST, iv_op(6), iv_op(7)), a); |
| 2884 | check_op(a, "list[pushmark.list[pushmark.const(6).const(7).]const(5)." |
| 2885 | "list[pushmark.const(3).const(2).const(1).]const(4).]"); |
| 2886 | op_free(a); |
| 2887 | a = op_prepend_elem(OP_LINESEQ, iv_op(2), iv_op(1)); |
| 2888 | check_op(a, "lineseq[const(2).const(1).]"); |
| 2889 | a = op_prepend_elem(OP_LINESEQ, iv_op(3), a); |
| 2890 | check_op(a, "lineseq[const(3).const(2).const(1).]"); |
| 2891 | op_free(a); |
| 2892 | a = op_prepend_elem(OP_LINESEQ, iv_op(3), |
| 2893 | op_prepend_elem(OP_LIST, iv_op(2), iv_op(1))); |
| 2894 | check_op(a, "lineseq[const(3).list[pushmark.const(2).const(1).]]"); |
| 2895 | op_free(a); |
| 2896 | a = op_append_list(OP_LINESEQ, NULL, NULL); |
| 2897 | check_op(a, ""); |
| 2898 | a = op_append_list(OP_LINESEQ, iv_op(1), a); |
| 2899 | check_op(a, "const(1)."); |
| 2900 | a = op_append_list(OP_LINESEQ, NULL, a); |
| 2901 | check_op(a, "const(1)."); |
| 2902 | a = op_append_list(OP_LINESEQ, a, iv_op(2)); |
| 2903 | check_op(a, "lineseq[const(1).const(2).]"); |
| 2904 | a = op_append_list(OP_LINESEQ, a, iv_op(3)); |
| 2905 | check_op(a, "lineseq[const(1).const(2).const(3).]"); |
| 2906 | a = op_append_list(OP_LINESEQ, iv_op(4), a); |
| 2907 | check_op(a, "lineseq[const(4).const(1).const(2).const(3).]"); |
| 2908 | a = op_append_list(OP_LINESEQ, a, NULL); |
| 2909 | check_op(a, "lineseq[const(4).const(1).const(2).const(3).]"); |
| 2910 | a = op_append_list(OP_LINESEQ, NULL, a); |
| 2911 | check_op(a, "lineseq[const(4).const(1).const(2).const(3).]"); |
| 2912 | a = op_append_list(OP_LINESEQ, a, |
| 2913 | op_append_list(OP_LINESEQ, iv_op(5), iv_op(6))); |
| 2914 | check_op(a, "lineseq[const(4).const(1).const(2).const(3)." |
| 2915 | "const(5).const(6).]"); |
| 2916 | op_free(a); |
| 2917 | a = op_append_list(OP_LINESEQ, |
| 2918 | op_append_list(OP_LINESEQ, iv_op(1), iv_op(2)), |
| 2919 | op_append_list(OP_LIST, iv_op(3), iv_op(4))); |
| 2920 | check_op(a, "lineseq[const(1).const(2)." |
| 2921 | "list[pushmark.const(3).const(4).]]"); |
| 2922 | op_free(a); |
| 2923 | a = op_append_list(OP_LINESEQ, |
| 2924 | op_append_list(OP_LIST, iv_op(1), iv_op(2)), |
| 2925 | op_append_list(OP_LINESEQ, iv_op(3), iv_op(4))); |
| 2926 | check_op(a, "lineseq[list[pushmark.const(1).const(2).]" |
| 2927 | "const(3).const(4).]"); |
| 2928 | op_free(a); |
| 2929 | #undef check_op |
| 2930 | |
| 2931 | void |
| 2932 | test_op_linklist () |
| 2933 | PREINIT: |
| 2934 | OP *o; |
| 2935 | CODE: |
| 2936 | #define check_ll(o, expect) \ |
| 2937 | STMT_START { \ |
| 2938 | if (strNE(test_op_linklist_describe(o), (expect))) \ |
| 2939 | croak("fail %s %s", test_op_linklist_describe(o), (expect)); \ |
| 2940 | } STMT_END |
| 2941 | o = iv_op(1); |
| 2942 | check_ll(o, ".const1"); |
| 2943 | op_free(o); |
| 2944 | |
| 2945 | o = mkUNOP(OP_NOT, iv_op(1)); |
| 2946 | check_ll(o, ".const1.not"); |
| 2947 | op_free(o); |
| 2948 | |
| 2949 | o = mkUNOP(OP_NOT, mkUNOP(OP_NEGATE, iv_op(1))); |
| 2950 | check_ll(o, ".const1.negate.not"); |
| 2951 | op_free(o); |
| 2952 | |
| 2953 | o = mkBINOP(OP_ADD, iv_op(1), iv_op(2)); |
| 2954 | check_ll(o, ".const1.const2.add"); |
| 2955 | op_free(o); |
| 2956 | |
| 2957 | o = mkBINOP(OP_ADD, mkUNOP(OP_NOT, iv_op(1)), iv_op(2)); |
| 2958 | check_ll(o, ".const1.not.const2.add"); |
| 2959 | op_free(o); |
| 2960 | |
| 2961 | o = mkUNOP(OP_NOT, mkBINOP(OP_ADD, iv_op(1), iv_op(2))); |
| 2962 | check_ll(o, ".const1.const2.add.not"); |
| 2963 | op_free(o); |
| 2964 | |
| 2965 | o = mkLISTOP(OP_LINESEQ, iv_op(1), iv_op(2), iv_op(3)); |
| 2966 | check_ll(o, ".const1.const2.const3.lineseq"); |
| 2967 | op_free(o); |
| 2968 | |
| 2969 | o = mkLISTOP(OP_LINESEQ, |
| 2970 | mkBINOP(OP_ADD, iv_op(1), iv_op(2)), |
| 2971 | mkUNOP(OP_NOT, iv_op(3)), |
| 2972 | mkLISTOP(OP_SUBSTR, iv_op(4), iv_op(5), iv_op(6))); |
| 2973 | check_ll(o, ".const1.const2.add.const3.not" |
| 2974 | ".const4.const5.const6.substr.lineseq"); |
| 2975 | op_free(o); |
| 2976 | |
| 2977 | o = mkBINOP(OP_ADD, iv_op(1), iv_op(2)); |
| 2978 | LINKLIST(o); |
| 2979 | o = mkBINOP(OP_SUBTRACT, o, iv_op(3)); |
| 2980 | check_ll(o, ".const1.const2.add.const3.subtract"); |
| 2981 | op_free(o); |
| 2982 | #undef check_ll |
| 2983 | #undef iv_op |
| 2984 | |
| 2985 | void |
| 2986 | peep_enable () |
| 2987 | PREINIT: |
| 2988 | dMY_CXT; |
| 2989 | CODE: |
| 2990 | av_clear(MY_CXT.peep_recorder); |
| 2991 | av_clear(MY_CXT.rpeep_recorder); |
| 2992 | MY_CXT.peep_recording = 1; |
| 2993 | |
| 2994 | void |
| 2995 | peep_disable () |
| 2996 | PREINIT: |
| 2997 | dMY_CXT; |
| 2998 | CODE: |
| 2999 | MY_CXT.peep_recording = 0; |
| 3000 | |
| 3001 | SV * |
| 3002 | peep_record () |
| 3003 | PREINIT: |
| 3004 | dMY_CXT; |
| 3005 | CODE: |
| 3006 | RETVAL = newRV_inc((SV *)MY_CXT.peep_recorder); |
| 3007 | OUTPUT: |
| 3008 | RETVAL |
| 3009 | |
| 3010 | SV * |
| 3011 | rpeep_record () |
| 3012 | PREINIT: |
| 3013 | dMY_CXT; |
| 3014 | CODE: |
| 3015 | RETVAL = newRV_inc((SV *)MY_CXT.rpeep_recorder); |
| 3016 | OUTPUT: |
| 3017 | RETVAL |
| 3018 | |
| 3019 | =pod |
| 3020 | |
| 3021 | multicall_each: call a sub for each item in the list. Used to test MULTICALL |
| 3022 | |
| 3023 | =cut |
| 3024 | |
| 3025 | void |
| 3026 | multicall_each(block,...) |
| 3027 | SV * block |
| 3028 | PROTOTYPE: &@ |
| 3029 | CODE: |
| 3030 | { |
| 3031 | dMULTICALL; |
| 3032 | int index; |
| 3033 | GV *gv; |
| 3034 | HV *stash; |
| 3035 | I32 gimme = G_SCALAR; |
| 3036 | SV **args = &PL_stack_base[ax]; |
| 3037 | CV *cv; |
| 3038 | |
| 3039 | if(items <= 1) { |
| 3040 | XSRETURN_UNDEF; |
| 3041 | } |
| 3042 | cv = sv_2cv(block, &stash, &gv, 0); |
| 3043 | if (cv == Nullcv) { |
| 3044 | croak("multicall_each: not a subroutine reference"); |
| 3045 | } |
| 3046 | PUSH_MULTICALL(cv); |
| 3047 | SAVESPTR(GvSV(PL_defgv)); |
| 3048 | |
| 3049 | for(index = 1 ; index < items ; index++) { |
| 3050 | GvSV(PL_defgv) = args[index]; |
| 3051 | MULTICALL; |
| 3052 | } |
| 3053 | POP_MULTICALL; |
| 3054 | XSRETURN_UNDEF; |
| 3055 | } |
| 3056 | |
| 3057 | #ifdef USE_ITHREADS |
| 3058 | |
| 3059 | void |
| 3060 | clone_with_stack() |
| 3061 | CODE: |
| 3062 | { |
| 3063 | PerlInterpreter *interp = aTHX; /* The original interpreter */ |
| 3064 | PerlInterpreter *interp_dup; /* The duplicate interpreter */ |
| 3065 | int oldscope = 1; /* We are responsible for all scopes */ |
| 3066 | |
| 3067 | interp_dup = perl_clone(interp, CLONEf_COPY_STACKS | CLONEf_CLONE_HOST ); |
| 3068 | |
| 3069 | /* destroy old perl */ |
| 3070 | PERL_SET_CONTEXT(interp); |
| 3071 | |
| 3072 | POPSTACK_TO(PL_mainstack); |
| 3073 | dounwind(-1); |
| 3074 | LEAVE_SCOPE(0); |
| 3075 | |
| 3076 | while (interp->Iscopestack_ix > 1) |
| 3077 | LEAVE; |
| 3078 | FREETMPS; |
| 3079 | |
| 3080 | perl_destruct(interp); |
| 3081 | perl_free(interp); |
| 3082 | |
| 3083 | /* switch to new perl */ |
| 3084 | PERL_SET_CONTEXT(interp_dup); |
| 3085 | |
| 3086 | /* continue after 'clone_with_stack' */ |
| 3087 | interp_dup->Iop = interp_dup->Iop->op_next; |
| 3088 | |
| 3089 | /* run with new perl */ |
| 3090 | Perl_runops_standard(interp_dup); |
| 3091 | |
| 3092 | /* We may have additional unclosed scopes if fork() was called |
| 3093 | * from within a BEGIN block. See perlfork.pod for more details. |
| 3094 | * We cannot clean up these other scopes because they belong to a |
| 3095 | * different interpreter, but we also cannot leave PL_scopestack_ix |
| 3096 | * dangling because that can trigger an assertion in perl_destruct(). |
| 3097 | */ |
| 3098 | if (PL_scopestack_ix > oldscope) { |
| 3099 | PL_scopestack[oldscope-1] = PL_scopestack[PL_scopestack_ix-1]; |
| 3100 | PL_scopestack_ix = oldscope; |
| 3101 | } |
| 3102 | |
| 3103 | perl_destruct(interp_dup); |
| 3104 | perl_free(interp_dup); |
| 3105 | |
| 3106 | /* call the real 'exit' not PerlProc_exit */ |
| 3107 | #undef exit |
| 3108 | exit(0); |
| 3109 | } |
| 3110 | |
| 3111 | #endif /* USE_ITHREDS */ |
| 3112 | |
| 3113 | SV* |
| 3114 | take_svref(SVREF sv) |
| 3115 | CODE: |
| 3116 | RETVAL = newRV_inc(sv); |
| 3117 | OUTPUT: |
| 3118 | RETVAL |
| 3119 | |
| 3120 | SV* |
| 3121 | take_avref(AV* av) |
| 3122 | CODE: |
| 3123 | RETVAL = newRV_inc((SV*)av); |
| 3124 | OUTPUT: |
| 3125 | RETVAL |
| 3126 | |
| 3127 | SV* |
| 3128 | take_hvref(HV* hv) |
| 3129 | CODE: |
| 3130 | RETVAL = newRV_inc((SV*)hv); |
| 3131 | OUTPUT: |
| 3132 | RETVAL |
| 3133 | |
| 3134 | |
| 3135 | SV* |
| 3136 | take_cvref(CV* cv) |
| 3137 | CODE: |
| 3138 | RETVAL = newRV_inc((SV*)cv); |
| 3139 | OUTPUT: |
| 3140 | RETVAL |
| 3141 | |
| 3142 | |
| 3143 | BOOT: |
| 3144 | { |
| 3145 | HV* stash; |
| 3146 | SV** meth = NULL; |
| 3147 | CV* cv; |
| 3148 | stash = gv_stashpv("XS::APItest::TempLv", 0); |
| 3149 | if (stash) |
| 3150 | meth = hv_fetchs(stash, "make_temp_mg_lv", 0); |
| 3151 | if (!meth) |
| 3152 | croak("lost method 'make_temp_mg_lv'"); |
| 3153 | cv = GvCV(*meth); |
| 3154 | CvLVALUE_on(cv); |
| 3155 | } |
| 3156 | |
| 3157 | BOOT: |
| 3158 | { |
| 3159 | hintkey_rpn_sv = newSVpvs_share("XS::APItest/rpn"); |
| 3160 | hintkey_calcrpn_sv = newSVpvs_share("XS::APItest/calcrpn"); |
| 3161 | hintkey_stufftest_sv = newSVpvs_share("XS::APItest/stufftest"); |
| 3162 | hintkey_swaptwostmts_sv = newSVpvs_share("XS::APItest/swaptwostmts"); |
| 3163 | hintkey_looprest_sv = newSVpvs_share("XS::APItest/looprest"); |
| 3164 | hintkey_scopelessblock_sv = newSVpvs_share("XS::APItest/scopelessblock"); |
| 3165 | hintkey_stmtasexpr_sv = newSVpvs_share("XS::APItest/stmtasexpr"); |
| 3166 | hintkey_stmtsasexpr_sv = newSVpvs_share("XS::APItest/stmtsasexpr"); |
| 3167 | hintkey_loopblock_sv = newSVpvs_share("XS::APItest/loopblock"); |
| 3168 | hintkey_blockasexpr_sv = newSVpvs_share("XS::APItest/blockasexpr"); |
| 3169 | hintkey_swaplabel_sv = newSVpvs_share("XS::APItest/swaplabel"); |
| 3170 | hintkey_labelconst_sv = newSVpvs_share("XS::APItest/labelconst"); |
| 3171 | hintkey_arrayfullexpr_sv = newSVpvs_share("XS::APItest/arrayfullexpr"); |
| 3172 | hintkey_arraylistexpr_sv = newSVpvs_share("XS::APItest/arraylistexpr"); |
| 3173 | hintkey_arraytermexpr_sv = newSVpvs_share("XS::APItest/arraytermexpr"); |
| 3174 | hintkey_arrayarithexpr_sv = newSVpvs_share("XS::APItest/arrayarithexpr"); |
| 3175 | hintkey_arrayexprflags_sv = newSVpvs_share("XS::APItest/arrayexprflags"); |
| 3176 | next_keyword_plugin = PL_keyword_plugin; |
| 3177 | PL_keyword_plugin = my_keyword_plugin; |
| 3178 | } |
| 3179 | |
| 3180 | void |
| 3181 | establish_cleanup(...) |
| 3182 | PROTOTYPE: $ |
| 3183 | CODE: |
| 3184 | PERL_UNUSED_VAR(items); |
| 3185 | croak("establish_cleanup called as a function"); |
| 3186 | |
| 3187 | BOOT: |
| 3188 | { |
| 3189 | CV *estcv = get_cv("XS::APItest::establish_cleanup", 0); |
| 3190 | cv_set_call_checker(estcv, THX_ck_entersub_establish_cleanup, (SV*)estcv); |
| 3191 | } |
| 3192 | |
| 3193 | void |
| 3194 | postinc(...) |
| 3195 | PROTOTYPE: $ |
| 3196 | CODE: |
| 3197 | PERL_UNUSED_VAR(items); |
| 3198 | croak("postinc called as a function"); |
| 3199 | |
| 3200 | void |
| 3201 | filter() |
| 3202 | CODE: |
| 3203 | filter_add(filter_call, NULL); |
| 3204 | |
| 3205 | BOOT: |
| 3206 | { |
| 3207 | CV *asscv = get_cv("XS::APItest::postinc", 0); |
| 3208 | cv_set_call_checker(asscv, THX_ck_entersub_postinc, (SV*)asscv); |
| 3209 | } |
| 3210 | |
| 3211 | SV * |
| 3212 | lv_temp_object() |
| 3213 | CODE: |
| 3214 | RETVAL = |
| 3215 | sv_bless( |
| 3216 | newRV_noinc(newSV(0)), |
| 3217 | gv_stashpvs("XS::APItest::TempObj",GV_ADD) |
| 3218 | ); /* Package defined in test script */ |
| 3219 | OUTPUT: |
| 3220 | RETVAL |
| 3221 | |
| 3222 | void |
| 3223 | fill_hash_with_nulls(HV *hv) |
| 3224 | PREINIT: |
| 3225 | UV i = 0; |
| 3226 | CODE: |
| 3227 | for(; i < 1000; ++i) { |
| 3228 | HE *entry = hv_fetch_ent(hv, sv_2mortal(newSVuv(i)), 1, 0); |
| 3229 | SvREFCNT_dec(HeVAL(entry)); |
| 3230 | HeVAL(entry) = NULL; |
| 3231 | } |
| 3232 | |
| 3233 | HV * |
| 3234 | newHVhv(HV *hv) |
| 3235 | CODE: |
| 3236 | RETVAL = newHVhv(hv); |
| 3237 | OUTPUT: |
| 3238 | RETVAL |
| 3239 | |
| 3240 | bool |
| 3241 | SvIsCOW(SV *sv) |
| 3242 | CODE: |
| 3243 | RETVAL = SvIsCOW(sv); |
| 3244 | OUTPUT: |
| 3245 | RETVAL |
| 3246 | |
| 3247 | void |
| 3248 | pad_scalar(...) |
| 3249 | PROTOTYPE: $$ |
| 3250 | CODE: |
| 3251 | PERL_UNUSED_VAR(items); |
| 3252 | croak("pad_scalar called as a function"); |
| 3253 | |
| 3254 | BOOT: |
| 3255 | { |
| 3256 | CV *pscv = get_cv("XS::APItest::pad_scalar", 0); |
| 3257 | cv_set_call_checker(pscv, THX_ck_entersub_pad_scalar, (SV*)pscv); |
| 3258 | } |
| 3259 | |
| 3260 | SV* |
| 3261 | fetch_pad_names( cv ) |
| 3262 | CV* cv |
| 3263 | PREINIT: |
| 3264 | I32 i; |
| 3265 | AV *pad_namelist; |
| 3266 | AV *retav = newAV(); |
| 3267 | CODE: |
| 3268 | pad_namelist = (AV*) *av_fetch(CvPADLIST(cv), 0, FALSE); |
| 3269 | |
| 3270 | for ( i = av_len(pad_namelist); i >= 0; i-- ) { |
| 3271 | SV** name_ptr = av_fetch(pad_namelist, i, 0); |
| 3272 | |
| 3273 | if (name_ptr && SvPOKp(*name_ptr)) { |
| 3274 | av_push(retav, newSVsv(*name_ptr)); |
| 3275 | } |
| 3276 | } |
| 3277 | RETVAL = newRV_noinc((SV*)retav); |
| 3278 | OUTPUT: |
| 3279 | RETVAL |
| 3280 | |
| 3281 | STRLEN |
| 3282 | underscore_length() |
| 3283 | PROTOTYPE: |
| 3284 | PREINIT: |
| 3285 | SV *u; |
| 3286 | U8 *pv; |
| 3287 | STRLEN bytelen; |
| 3288 | CODE: |
| 3289 | u = find_rundefsv(); |
| 3290 | pv = (U8*)SvPV(u, bytelen); |
| 3291 | RETVAL = SvUTF8(u) ? utf8_length(pv, pv+bytelen) : bytelen; |
| 3292 | OUTPUT: |
| 3293 | RETVAL |
| 3294 | |
| 3295 | void |
| 3296 | stringify(SV *sv) |
| 3297 | PREINIT: |
| 3298 | const char *pv; |
| 3299 | CODE: |
| 3300 | pv = SvPV_nolen(sv); |
| 3301 | |
| 3302 | SV * |
| 3303 | HvENAME(HV *hv) |
| 3304 | CODE: |
| 3305 | RETVAL = hv && HvENAME(hv) |
| 3306 | ? newSVpvn_flags( |
| 3307 | HvENAME(hv),HvENAMELEN(hv), |
| 3308 | (HvENAMEUTF8(hv) ? SVf_UTF8 : 0) |
| 3309 | ) |
| 3310 | : NULL; |
| 3311 | OUTPUT: |
| 3312 | RETVAL |
| 3313 | |
| 3314 | int |
| 3315 | xs_cmp(int a, int b) |
| 3316 | CODE: |
| 3317 | /* Odd sorting (odd numbers first), to make sure we are actually |
| 3318 | being called */ |
| 3319 | RETVAL = a % 2 != b % 2 |
| 3320 | ? a % 2 ? -1 : 1 |
| 3321 | : a < b ? -1 : a == b ? 0 : 1; |
| 3322 | OUTPUT: |
| 3323 | RETVAL |
| 3324 | |
| 3325 | SV * |
| 3326 | xs_cmp_undef(SV *a, SV *b) |
| 3327 | CODE: |
| 3328 | RETVAL = &PL_sv_undef; |
| 3329 | OUTPUT: |
| 3330 | RETVAL |
| 3331 | |
| 3332 | char * |
| 3333 | SvPVbyte(SV *sv) |
| 3334 | CODE: |
| 3335 | RETVAL = SvPVbyte_nolen(sv); |
| 3336 | OUTPUT: |
| 3337 | RETVAL |
| 3338 | |
| 3339 | char * |
| 3340 | SvPVutf8(SV *sv) |
| 3341 | CODE: |
| 3342 | RETVAL = SvPVutf8_nolen(sv); |
| 3343 | OUTPUT: |
| 3344 | RETVAL |
| 3345 | |
| 3346 | void |
| 3347 | setup_addissub() |
| 3348 | CODE: |
| 3349 | wrap_op_checker(OP_ADD, addissub_myck_add, &addissub_nxck_add); |
| 3350 | |
| 3351 | #ifdef USE_ITHREADS |
| 3352 | |
| 3353 | bool |
| 3354 | test_alloccopstash() |
| 3355 | CODE: |
| 3356 | RETVAL = PL_stashpad[alloccopstash(PL_defstash)] == PL_defstash; |
| 3357 | OUTPUT: |
| 3358 | RETVAL |
| 3359 | |
| 3360 | #endif |
| 3361 | |
| 3362 | MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest |
| 3363 | |
| 3364 | int |
| 3365 | AUTOLOAD(...) |
| 3366 | INIT: |
| 3367 | SV* comms; |
| 3368 | SV* class_and_method; |
| 3369 | SV* tmp; |
| 3370 | CODE: |
| 3371 | class_and_method = GvSV(CvGV(cv)); |
| 3372 | comms = get_sv("main::the_method", 1); |
| 3373 | if (class_and_method == NULL) { |
| 3374 | RETVAL = 1; |
| 3375 | } else if (!SvOK(class_and_method)) { |
| 3376 | RETVAL = 2; |
| 3377 | } else if (!SvPOK(class_and_method)) { |
| 3378 | RETVAL = 3; |
| 3379 | } else { |
| 3380 | sv_setsv(comms, class_and_method); |
| 3381 | RETVAL = 0; |
| 3382 | } |
| 3383 | OUTPUT: RETVAL |
| 3384 | |
| 3385 | |
| 3386 | MODULE = XS::APItest PACKAGE = XS::APItest::Magic |
| 3387 | |
| 3388 | PROTOTYPES: DISABLE |
| 3389 | |
| 3390 | void |
| 3391 | sv_magic_foo(SV *sv, SV *thingy) |
| 3392 | ALIAS: |
| 3393 | sv_magic_bar = 1 |
| 3394 | CODE: |
| 3395 | sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo, (const char *)thingy, 0); |
| 3396 | |
| 3397 | SV * |
| 3398 | mg_find_foo(SV *sv) |
| 3399 | ALIAS: |
| 3400 | mg_find_bar = 1 |
| 3401 | CODE: |
| 3402 | MAGIC *mg = mg_findext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo); |
| 3403 | RETVAL = mg ? SvREFCNT_inc((SV *)mg->mg_ptr) : &PL_sv_undef; |
| 3404 | OUTPUT: |
| 3405 | RETVAL |
| 3406 | |
| 3407 | void |
| 3408 | sv_unmagic_foo(SV *sv) |
| 3409 | ALIAS: |
| 3410 | sv_unmagic_bar = 1 |
| 3411 | CODE: |
| 3412 | sv_unmagicext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo); |
| 3413 | |
| 3414 | UV |
| 3415 | test_get_vtbl() |
| 3416 | PREINIT: |
| 3417 | MGVTBL *have; |
| 3418 | MGVTBL *want; |
| 3419 | CODE: |
| 3420 | #define test_get_this_vtable(name) \ |
| 3421 | want = CAT2(&PL_vtbl_, name); \ |
| 3422 | have = get_vtbl(CAT2(want_vtbl_, name)); \ |
| 3423 | if (have != want) \ |
| 3424 | croak("fail %p!=%p for get_vtbl(want_vtbl_" STRINGIFY(name) ") at " __FILE__ " line %d", have, want, __LINE__) |
| 3425 | |
| 3426 | test_get_this_vtable(sv); |
| 3427 | test_get_this_vtable(env); |
| 3428 | test_get_this_vtable(envelem); |
| 3429 | test_get_this_vtable(sigelem); |
| 3430 | test_get_this_vtable(pack); |
| 3431 | test_get_this_vtable(packelem); |
| 3432 | test_get_this_vtable(dbline); |
| 3433 | test_get_this_vtable(isa); |
| 3434 | test_get_this_vtable(isaelem); |
| 3435 | test_get_this_vtable(arylen); |
| 3436 | test_get_this_vtable(mglob); |
| 3437 | test_get_this_vtable(nkeys); |
| 3438 | test_get_this_vtable(taint); |
| 3439 | test_get_this_vtable(substr); |
| 3440 | test_get_this_vtable(vec); |
| 3441 | test_get_this_vtable(pos); |
| 3442 | test_get_this_vtable(bm); |
| 3443 | test_get_this_vtable(fm); |
| 3444 | test_get_this_vtable(uvar); |
| 3445 | test_get_this_vtable(defelem); |
| 3446 | test_get_this_vtable(regexp); |
| 3447 | test_get_this_vtable(regdata); |
| 3448 | test_get_this_vtable(regdatum); |
| 3449 | #ifdef USE_LOCALE_COLLATE |
| 3450 | test_get_this_vtable(collxfrm); |
| 3451 | #endif |
| 3452 | test_get_this_vtable(backref); |
| 3453 | test_get_this_vtable(utf8); |
| 3454 | |
| 3455 | RETVAL = PTR2UV(get_vtbl(-1)); |
| 3456 | OUTPUT: |
| 3457 | RETVAL |