1 #define PERL_IN_XS_APITEST
3 /* We want to be able to test things that aren't API yet. */
6 /* Do *not* define PERL_NO_GET_CONTEXT. This is the one place where we get
7 to test implicit Perl_get_context(). */
12 #include "fakesdio.h" /* Causes us to use PerlIO below */
15 typedef PTR_TBL_t *XS__APItest__PtrTable;
17 #define croak_fail() croak("fail at " __FILE__ " line %d", __LINE__)
18 #define croak_fail_nep(h, w) croak("fail %p!=%p at " __FILE__ " line %d", (h), (w), __LINE__)
19 #define croak_fail_nei(h, w) croak("fail %d!=%d at " __FILE__ " line %d", (int)(h), (int)(w), __LINE__)
24 cat_utf8a2n(SV* sv, const char * const ascii_utf8, STRLEN len)
26 /* Converts variant UTF-8 text pointed to by 'ascii_utf8' of length 'len',
27 * to UTF-EBCDIC, appending that text to the text already in 'sv'.
28 * Currently doesn't work on invariants, as that is unneeded here, and we
29 * could get double translations if we did.
31 * It has the algorithm for strict UTF-8 hard-coded in to find the code
32 * point it represents, then calls uvchr_to_utf8() to convert to
35 * Note that this uses code points, not characters. Thus if the input is
36 * the UTF-8 for the code point 0xFF, the output will be the UTF-EBCDIC for
37 * 0xFF, even though that code point represents different characters on
38 * ASCII vs EBCDIC platforms. */
41 char * p = (char *) ascii_utf8;
42 const char * const e = p + len;
46 U8 native_utf8[UTF8_MAXBYTES + 1];
50 /* Start bytes are the same in both UTF-8 and I8, therefore we can
51 * treat this ASCII UTF-8 byte as an I8 byte. But PL_utf8skip[] is
52 * indexed by NATIVE_UTF8 bytes, so transform to that */
53 STRLEN char_bytes_len = PL_utf8skip[I8_TO_NATIVE_UTF8(start)];
56 croak("fail: Expecting start byte, instead got 0x%X at %s line %d",
57 (U8) *p, __FILE__, __LINE__);
59 code_point = (start & (((char_bytes_len) >= 7)
61 : (0x1F >> ((char_bytes_len)-2))));
63 while (p < e && ((( (U8) *p) & 0xC0) == 0x80)) {
65 code_point = (code_point << 6) | (( (U8) *p) & 0x3F);
69 char_end = uvchr_to_utf8(native_utf8, code_point);
70 sv_catpvn(sv, (char *) native_utf8, char_end - native_utf8);
76 /* for my_cxt tests */
78 #define MY_CXT_KEY "XS::APItest::_guts" XS_VERSION
98 S_myset_set(pTHX_ SV* sv, MAGIC* mg)
100 SV *isv = (SV*)mg->mg_ptr;
107 MGVTBL vtbl_foo, vtbl_bar;
108 MGVTBL vtbl_myset = { 0, S_myset_set, 0, 0, 0, 0, 0, 0 };
111 /* indirect functions to test the [pa]MY_CXT macros */
114 my_cxt_getint_p(pMY_CXT)
120 my_cxt_setint_p(pMY_CXT_ int i)
126 my_cxt_getsv_interp_context(void)
129 dMY_CXT_INTERP(my_perl);
134 my_cxt_getsv_interp(void)
141 my_cxt_setsv_p(SV* sv _pMY_CXT)
147 /* from exception.c */
148 int apitest_exception(int);
150 /* from core_or_not.inc */
151 bool sv_setsv_cow_hashkey_core(void);
152 bool sv_setsv_cow_hashkey_notcore(void);
154 /* A routine to test hv_delayfree_ent
155 (which itself is tested by testing on hv_free_ent */
157 typedef void (freeent_function)(pTHX_ HV *, HE *);
160 test_freeent(freeent_function *f) {
162 HV *test_hash = newHV();
169 victim = (HE*)safemalloc(sizeof(HE));
171 /* Storing then deleting something should ensure that a hash entry is
173 (void) hv_stores(test_hash, "", &PL_sv_yes);
174 (void) hv_deletes(test_hash, "", 0);
176 /* We need to "inline" new_he here as it's static, and the functions we
177 test expect to be able to call del_HE on the HE */
178 if (!PL_body_roots[HE_SVSLOT])
179 croak("PL_he_root is 0");
180 victim = (HE*) PL_body_roots[HE_SVSLOT];
181 PL_body_roots[HE_SVSLOT] = HeNEXT(victim);
184 victim->hent_hek = Perl_share_hek(aTHX_ "", 0, 0);
186 test_scalar = newSV(0);
187 SvREFCNT_inc(test_scalar);
188 HeVAL(victim) = test_scalar;
190 /* Need this little game else we free the temps on the return stack. */
191 results[0] = SvREFCNT(test_scalar);
193 results[1] = SvREFCNT(test_scalar);
194 f(aTHX_ test_hash, victim);
195 results[2] = SvREFCNT(test_scalar);
197 results[3] = SvREFCNT(test_scalar);
202 } while (++i < (int)(sizeof(results)/sizeof(results[0])));
204 /* Goodbye to our extra reference. */
205 SvREFCNT_dec(test_scalar);
208 /* Not that it matters much, but it's handy for the flipped character to just
209 * be the opposite case (at least for ASCII-range and most Latin1 as well). */
210 #define FLIP_BIT ('A' ^ 'a')
213 bitflip_key(pTHX_ IV action, SV *field) {
214 MAGIC *mg = mg_find(field, PERL_MAGIC_uvar);
216 PERL_UNUSED_ARG(action);
217 if (mg && (keysv = mg->mg_obj)) {
219 const char *p = SvPV(keysv, len);
222 /* Allow for the flipped val to be longer than the original. This
223 * is just for testing, so can afford to have some slop */
224 const STRLEN newlen = len * 2;
226 SV *newkey = newSV(newlen);
227 const char * const new_p_orig = SvPVX(newkey);
228 char *new_p = (char *) new_p_orig;
231 const char *const end = p + len;
234 UV chr = utf8_to_uvchr_buf((U8 *)p, (U8 *) end, &curlen);
236 /* Make sure don't exceed bounds */
237 assert(new_p - new_p_orig + curlen < newlen);
239 new_p = (char *)uvchr_to_utf8((U8 *)new_p, chr ^ FLIP_BIT);
245 *new_p++ = *p++ ^ FLIP_BIT;
248 SvCUR_set(newkey, new_p - new_p_orig);
258 rot13_key(pTHX_ IV action, SV *field) {
259 MAGIC *mg = mg_find(field, PERL_MAGIC_uvar);
261 PERL_UNUSED_ARG(action);
262 if (mg && (keysv = mg->mg_obj)) {
264 const char *p = SvPV(keysv, len);
267 SV *newkey = newSV(len);
268 char *new_p = SvPVX(newkey);
270 /* There's a deliberate fencepost error here to loop len + 1 times
271 to copy the trailing \0 */
274 /* Try doing this cleanly and clearly in EBCDIC another way: */
276 case 'A': new_c = 'N'; break;
277 case 'B': new_c = 'O'; break;
278 case 'C': new_c = 'P'; break;
279 case 'D': new_c = 'Q'; break;
280 case 'E': new_c = 'R'; break;
281 case 'F': new_c = 'S'; break;
282 case 'G': new_c = 'T'; break;
283 case 'H': new_c = 'U'; break;
284 case 'I': new_c = 'V'; break;
285 case 'J': new_c = 'W'; break;
286 case 'K': new_c = 'X'; break;
287 case 'L': new_c = 'Y'; break;
288 case 'M': new_c = 'Z'; break;
289 case 'N': new_c = 'A'; break;
290 case 'O': new_c = 'B'; break;
291 case 'P': new_c = 'C'; break;
292 case 'Q': new_c = 'D'; break;
293 case 'R': new_c = 'E'; break;
294 case 'S': new_c = 'F'; break;
295 case 'T': new_c = 'G'; break;
296 case 'U': new_c = 'H'; break;
297 case 'V': new_c = 'I'; break;
298 case 'W': new_c = 'J'; break;
299 case 'X': new_c = 'K'; break;
300 case 'Y': new_c = 'L'; break;
301 case 'Z': new_c = 'M'; break;
302 case 'a': new_c = 'n'; break;
303 case 'b': new_c = 'o'; break;
304 case 'c': new_c = 'p'; break;
305 case 'd': new_c = 'q'; break;
306 case 'e': new_c = 'r'; break;
307 case 'f': new_c = 's'; break;
308 case 'g': new_c = 't'; break;
309 case 'h': new_c = 'u'; break;
310 case 'i': new_c = 'v'; break;
311 case 'j': new_c = 'w'; break;
312 case 'k': new_c = 'x'; break;
313 case 'l': new_c = 'y'; break;
314 case 'm': new_c = 'z'; break;
315 case 'n': new_c = 'a'; break;
316 case 'o': new_c = 'b'; break;
317 case 'p': new_c = 'c'; break;
318 case 'q': new_c = 'd'; break;
319 case 'r': new_c = 'e'; break;
320 case 's': new_c = 'f'; break;
321 case 't': new_c = 'g'; break;
322 case 'u': new_c = 'h'; break;
323 case 'v': new_c = 'i'; break;
324 case 'w': new_c = 'j'; break;
325 case 'x': new_c = 'k'; break;
326 case 'y': new_c = 'l'; break;
327 case 'z': new_c = 'm'; break;
331 SvCUR_set(newkey, SvCUR(keysv));
343 rmagical_a_dummy(pTHX_ IV idx, SV *sv) {
344 PERL_UNUSED_ARG(idx);
349 /* We could do "= { 0 };" but some versions of gcc do warn
350 * (with -Wextra) about missing initializer, this is probably gcc
351 * being a bit too paranoid. But since this is file-static, we can
352 * just have it without initializer, since it should get
353 * zero-initialized. */
354 STATIC MGVTBL rmagical_b;
357 blockhook_csc_start(pTHX_ int full)
360 AV *const cur = GvAV(MY_CXT.cscgv);
362 PERL_UNUSED_ARG(full);
363 SAVEGENERICSV(GvAV(MY_CXT.cscgv));
367 AV *const new_av = newAV();
369 for (i = 0; i <= av_tindex(cur); i++) {
370 av_store(new_av, i, newSVsv(*av_fetch(cur, i, 0)));
373 GvAV(MY_CXT.cscgv) = new_av;
378 blockhook_csc_pre_end(pTHX_ OP **o)
383 /* if we hit the end of a scope we missed the start of, we need to
384 * unconditionally clear @CSC */
385 if (GvAV(MY_CXT.cscgv) == MY_CXT.cscav && MY_CXT.cscav) {
386 av_clear(MY_CXT.cscav);
392 blockhook_test_start(pTHX_ int full)
397 if (MY_CXT.bhk_record) {
399 av_push(av, newSVpvs("start"));
400 av_push(av, newSViv(full));
401 av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av)));
406 blockhook_test_pre_end(pTHX_ OP **o)
411 if (MY_CXT.bhk_record)
412 av_push(MY_CXT.bhkav, newSVpvs("pre_end"));
416 blockhook_test_post_end(pTHX_ OP **o)
421 if (MY_CXT.bhk_record)
422 av_push(MY_CXT.bhkav, newSVpvs("post_end"));
426 blockhook_test_eval(pTHX_ OP *const o)
431 if (MY_CXT.bhk_record) {
433 av_push(av, newSVpvs("eval"));
434 av_push(av, newSVpv(OP_NAME(o), 0));
435 av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av)));
439 STATIC BHK bhk_csc, bhk_test;
442 my_peep (pTHX_ OP *o)
449 MY_CXT.orig_peep(aTHX_ o);
451 if (!MY_CXT.peep_recording)
454 for (; o; o = o->op_next) {
455 if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
456 av_push(MY_CXT.peep_recorder, newSVsv(cSVOPx_sv(o)));
462 my_rpeep (pTHX_ OP *o)
469 MY_CXT.orig_rpeep(aTHX_ o);
471 if (!MY_CXT.peep_recording)
474 for (; o; o = o->op_next) {
475 if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
476 av_push(MY_CXT.rpeep_recorder, newSVsv(cSVOPx_sv(o)));
482 THX_ck_entersub_args_lists(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
484 PERL_UNUSED_ARG(namegv);
485 PERL_UNUSED_ARG(ckobj);
486 return ck_entersub_args_list(entersubop);
490 THX_ck_entersub_args_scalars(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
492 OP *aop = cUNOPx(entersubop)->op_first;
493 PERL_UNUSED_ARG(namegv);
494 PERL_UNUSED_ARG(ckobj);
495 if (!OpHAS_SIBLING(aop))
496 aop = cUNOPx(aop)->op_first;
497 for (aop = OpSIBLING(aop); OpHAS_SIBLING(aop); aop = OpSIBLING(aop)) {
498 op_contextualize(aop, G_SCALAR);
504 THX_ck_entersub_multi_sum(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
507 OP *parent = entersubop;
508 OP *pushop = cUNOPx(entersubop)->op_first;
509 PERL_UNUSED_ARG(namegv);
510 PERL_UNUSED_ARG(ckobj);
511 if (!OpHAS_SIBLING(pushop)) {
513 pushop = cUNOPx(pushop)->op_first;
516 OP *aop = OpSIBLING(pushop);
517 if (!OpHAS_SIBLING(aop))
519 /* cut out first arg */
520 op_sibling_splice(parent, pushop, 1, NULL);
521 op_contextualize(aop, G_SCALAR);
523 sumop = newBINOP(OP_ADD, 0, sumop, aop);
529 sumop = newSVOP(OP_CONST, 0, newSViv(0));
534 STATIC void test_op_list_describe_part(SV *res, OP *o);
536 test_op_list_describe_part(SV *res, OP *o)
538 sv_catpv(res, PL_op_name[o->op_type]);
539 switch (o->op_type) {
541 sv_catpvf(res, "(%d)", (int)SvIV(cSVOPx(o)->op_sv));
544 if (o->op_flags & OPf_KIDS) {
547 for (k = cUNOPx(o)->op_first; k; k = OpSIBLING(k))
548 test_op_list_describe_part(res, k);
556 test_op_list_describe(OP *o)
558 SV *res = sv_2mortal(newSVpvs(""));
560 test_op_list_describe_part(res, o);
564 /* the real new*OP functions have a tendency to call fold_constants, and
565 * other such unhelpful things, so we need our own versions for testing */
567 #define mkUNOP(t, f) THX_mkUNOP(aTHX_ (t), (f))
569 THX_mkUNOP(pTHX_ U32 type, OP *first)
572 NewOp(1103, unop, 1, UNOP);
573 unop->op_type = (OPCODE)type;
574 op_sibling_splice((OP*)unop, NULL, 0, first);
578 #define mkBINOP(t, f, l) THX_mkBINOP(aTHX_ (t), (f), (l))
580 THX_mkBINOP(pTHX_ U32 type, OP *first, OP *last)
583 NewOp(1103, binop, 1, BINOP);
584 binop->op_type = (OPCODE)type;
585 op_sibling_splice((OP*)binop, NULL, 0, last);
586 op_sibling_splice((OP*)binop, NULL, 0, first);
590 #define mkLISTOP(t, f, s, l) THX_mkLISTOP(aTHX_ (t), (f), (s), (l))
592 THX_mkLISTOP(pTHX_ U32 type, OP *first, OP *sib, OP *last)
595 NewOp(1103, listop, 1, LISTOP);
596 listop->op_type = (OPCODE)type;
597 op_sibling_splice((OP*)listop, NULL, 0, last);
598 op_sibling_splice((OP*)listop, NULL, 0, sib);
599 op_sibling_splice((OP*)listop, NULL, 0, first);
604 test_op_linklist_describe(OP *start)
606 SV *rv = sv_2mortal(newSVpvs(""));
608 o = start = LINKLIST(start);
611 sv_catpv(rv, OP_NAME(o));
612 if (o->op_type == OP_CONST)
613 sv_catsv(rv, cSVOPo->op_sv);
615 } while (o && o != start);
619 /** establish_cleanup operator, ripped off from Scope::Cleanup **/
622 THX_run_cleanup(pTHX_ void *cleanup_code_ref)
629 call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD);
636 THX_pp_establish_cleanup(pTHX)
639 SV *cleanup_code_ref;
640 cleanup_code_ref = newSVsv(POPs);
641 SAVEFREESV(cleanup_code_ref);
642 SAVEDESTRUCTOR_X(THX_run_cleanup, cleanup_code_ref);
643 if(GIMME_V != G_VOID) PUSHs(&PL_sv_undef);
648 THX_ck_entersub_establish_cleanup(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
650 OP *parent, *pushop, *argop, *estop;
651 ck_entersub_args_proto(entersubop, namegv, ckobj);
653 pushop = cUNOPx(entersubop)->op_first;
654 if(!OpHAS_SIBLING(pushop)) {
656 pushop = cUNOPx(pushop)->op_first;
658 /* extract out first arg, then delete the rest of the tree */
659 argop = OpSIBLING(pushop);
660 op_sibling_splice(parent, pushop, 1, NULL);
663 estop = mkUNOP(OP_RAND, argop);
664 estop->op_ppaddr = THX_pp_establish_cleanup;
665 PL_hints |= HINT_BLOCK_SCOPE;
670 THX_ck_entersub_postinc(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
672 OP *parent, *pushop, *argop;
673 ck_entersub_args_proto(entersubop, namegv, ckobj);
675 pushop = cUNOPx(entersubop)->op_first;
676 if(!OpHAS_SIBLING(pushop)) {
678 pushop = cUNOPx(pushop)->op_first;
680 argop = OpSIBLING(pushop);
681 op_sibling_splice(parent, pushop, 1, NULL);
683 return newUNOP(OP_POSTINC, 0,
684 op_lvalue(op_contextualize(argop, G_SCALAR), OP_POSTINC));
688 THX_ck_entersub_pad_scalar(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
691 PADOFFSET padoff = NOT_IN_PAD;
693 ck_entersub_args_proto(entersubop, namegv, ckobj);
694 pushop = cUNOPx(entersubop)->op_first;
695 if(!OpHAS_SIBLING(pushop))
696 pushop = cUNOPx(pushop)->op_first;
697 argop = OpSIBLING(pushop);
698 if(argop->op_type != OP_CONST || OpSIBLING(argop)->op_type != OP_CONST)
699 croak("bad argument expression type for pad_scalar()");
700 a0 = cSVOPx_sv(argop);
701 a1 = cSVOPx_sv(OpSIBLING(argop));
704 SV *namesv = sv_2mortal(newSVpvs("$"));
705 sv_catsv(namesv, a1);
706 padoff = pad_findmy_sv(namesv, 0);
711 SV *namesv = sv_2mortal(newSVpvs("$"));
712 sv_catsv(namesv, a1);
713 namepv = SvPV(namesv, namelen);
714 padoff = pad_findmy_pvn(namepv, namelen, SvUTF8(namesv));
718 SV *namesv = sv_2mortal(newSVpvs("$"));
719 sv_catsv(namesv, a1);
720 namepv = SvPV_nolen(namesv);
721 padoff = pad_findmy_pv(namepv, SvUTF8(namesv));
724 padoff = pad_findmy_pvs("$foo", 0);
726 default: croak("bad type value for pad_scalar()");
729 if(padoff == NOT_IN_PAD) {
730 return newSVOP(OP_CONST, 0, newSVpvs("NOT_IN_PAD"));
731 } else if(PAD_COMPNAME_FLAGS_isOUR(padoff)) {
732 return newSVOP(OP_CONST, 0, newSVpvs("NOT_MY"));
734 OP *padop = newOP(OP_PADSV, 0);
735 padop->op_targ = padoff;
740 /** RPN keyword parser **/
742 #define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV)
743 #define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP)
744 #define sv_is_string(sv) \
745 (!sv_is_glob(sv) && !sv_is_regexp(sv) && \
746 (SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK)))
748 static SV *hintkey_rpn_sv, *hintkey_calcrpn_sv, *hintkey_stufftest_sv;
749 static SV *hintkey_swaptwostmts_sv, *hintkey_looprest_sv;
750 static SV *hintkey_scopelessblock_sv;
751 static SV *hintkey_stmtasexpr_sv, *hintkey_stmtsasexpr_sv;
752 static SV *hintkey_loopblock_sv, *hintkey_blockasexpr_sv;
753 static SV *hintkey_swaplabel_sv, *hintkey_labelconst_sv;
754 static SV *hintkey_arrayfullexpr_sv, *hintkey_arraylistexpr_sv;
755 static SV *hintkey_arraytermexpr_sv, *hintkey_arrayarithexpr_sv;
756 static SV *hintkey_arrayexprflags_sv;
757 static SV *hintkey_DEFSV_sv;
758 static SV *hintkey_with_vars_sv;
759 static SV *hintkey_join_with_space_sv;
760 static int (*next_keyword_plugin)(pTHX_ char *, STRLEN, OP **);
762 /* low-level parser helpers */
764 #define PL_bufptr (PL_parser->bufptr)
765 #define PL_bufend (PL_parser->bufend)
769 #define parse_var() THX_parse_var(aTHX)
770 static OP *THX_parse_var(pTHX)
776 if(*s != '$') croak("RPN syntax error");
779 if(!isALNUM(c)) break;
781 if(s-start < 2) croak("RPN syntax error");
783 varpos = pad_findmy_pvn(start, s-start, 0);
784 if(varpos == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(varpos))
785 croak("RPN only supports \"my\" variables");
786 padop = newOP(OP_PADSV, 0);
787 padop->op_targ = varpos;
791 #define push_rpn_item(o) \
792 op_sibling_splice(parent, NULL, 0, o);
793 #define pop_rpn_item() ( \
794 (tmpop = op_sibling_splice(parent, NULL, 1, NULL)) \
795 ? tmpop : (croak("RPN stack underflow"), (OP*)NULL))
797 #define parse_rpn_expr() THX_parse_rpn_expr(aTHX)
798 static OP *THX_parse_rpn_expr(pTHX)
801 /* fake parent for splice to mess with */
802 OP *parent = mkBINOP(OP_NULL, NULL, NULL);
807 c = lex_peek_unichar(0);
809 case /*(*/')': case /*{*/'}': {
810 OP *result = pop_rpn_item();
811 if(cLISTOPx(parent)->op_first)
812 croak("RPN expression must return a single value");
816 case '0': case '1': case '2': case '3': case '4':
817 case '5': case '6': case '7': case '8': case '9': {
821 val = 10*val + (c - '0');
822 c = lex_peek_unichar(0);
823 } while(c >= '0' && c <= '9');
824 push_rpn_item(newSVOP(OP_CONST, 0, newSVuv(val)));
827 push_rpn_item(parse_var());
830 OP *b = pop_rpn_item();
831 OP *a = pop_rpn_item();
833 push_rpn_item(newBINOP(OP_I_ADD, 0, a, b));
836 OP *b = pop_rpn_item();
837 OP *a = pop_rpn_item();
839 push_rpn_item(newBINOP(OP_I_SUBTRACT, 0, a, b));
842 OP *b = pop_rpn_item();
843 OP *a = pop_rpn_item();
845 push_rpn_item(newBINOP(OP_I_MULTIPLY, 0, a, b));
848 OP *b = pop_rpn_item();
849 OP *a = pop_rpn_item();
851 push_rpn_item(newBINOP(OP_I_DIVIDE, 0, a, b));
854 OP *b = pop_rpn_item();
855 OP *a = pop_rpn_item();
857 push_rpn_item(newBINOP(OP_I_MODULO, 0, a, b));
860 croak("RPN syntax error");
866 #define parse_keyword_rpn() THX_parse_keyword_rpn(aTHX)
867 static OP *THX_parse_keyword_rpn(pTHX)
871 if(lex_peek_unichar(0) != '('/*)*/)
872 croak("RPN expression must be parenthesised");
874 op = parse_rpn_expr();
875 if(lex_peek_unichar(0) != /*(*/')')
876 croak("RPN expression must be parenthesised");
881 #define parse_keyword_calcrpn() THX_parse_keyword_calcrpn(aTHX)
882 static OP *THX_parse_keyword_calcrpn(pTHX)
888 if(lex_peek_unichar(0) != '{'/*}*/)
889 croak("RPN expression must be braced");
891 exprop = parse_rpn_expr();
892 if(lex_peek_unichar(0) != /*{*/'}')
893 croak("RPN expression must be braced");
895 return newASSIGNOP(OPf_STACKED, varop, 0, exprop);
898 #define parse_keyword_stufftest() THX_parse_keyword_stufftest(aTHX)
899 static OP *THX_parse_keyword_stufftest(pTHX)
904 do_stuff = lex_peek_unichar(0) == '+';
909 c = lex_peek_unichar(0);
912 } else if(c != /*{*/'}') {
913 croak("syntax error");
915 if(do_stuff) lex_stuff_pvs(" ", 0);
916 return newOP(OP_NULL, 0);
919 #define parse_keyword_swaptwostmts() THX_parse_keyword_swaptwostmts(aTHX)
920 static OP *THX_parse_keyword_swaptwostmts(pTHX)
923 a = parse_fullstmt(0);
924 b = parse_fullstmt(0);
926 PL_hints |= HINT_BLOCK_SCOPE;
927 return op_append_list(OP_LINESEQ, b, a);
930 #define parse_keyword_looprest() THX_parse_keyword_looprest(aTHX)
931 static OP *THX_parse_keyword_looprest(pTHX)
933 return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes),
934 parse_stmtseq(0), NULL, 1);
937 #define parse_keyword_scopelessblock() THX_parse_keyword_scopelessblock(aTHX)
938 static OP *THX_parse_keyword_scopelessblock(pTHX)
943 if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error");
945 body = parse_stmtseq(0);
946 c = lex_peek_unichar(0);
947 if(c != /*{*/'}' && c != /*[*/']' && c != /*(*/')') croak("syntax error");
952 #define parse_keyword_stmtasexpr() THX_parse_keyword_stmtasexpr(aTHX)
953 static OP *THX_parse_keyword_stmtasexpr(pTHX)
955 OP *o = parse_barestmt(0);
956 if (!o) o = newOP(OP_STUB, 0);
957 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
961 #define parse_keyword_stmtsasexpr() THX_parse_keyword_stmtsasexpr(aTHX)
962 static OP *THX_parse_keyword_stmtsasexpr(pTHX)
966 if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error");
968 o = parse_stmtseq(0);
970 if(lex_peek_unichar(0) != /*{*/'}') croak("syntax error");
972 if (!o) o = newOP(OP_STUB, 0);
973 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
977 #define parse_keyword_loopblock() THX_parse_keyword_loopblock(aTHX)
978 static OP *THX_parse_keyword_loopblock(pTHX)
980 return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes),
981 parse_block(0), NULL, 1);
984 #define parse_keyword_blockasexpr() THX_parse_keyword_blockasexpr(aTHX)
985 static OP *THX_parse_keyword_blockasexpr(pTHX)
987 OP *o = parse_block(0);
988 if (!o) o = newOP(OP_STUB, 0);
989 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
993 #define parse_keyword_swaplabel() THX_parse_keyword_swaplabel(aTHX)
994 static OP *THX_parse_keyword_swaplabel(pTHX)
996 OP *sop = parse_barestmt(0);
997 SV *label = parse_label(PARSE_OPTIONAL);
998 if (label) sv_2mortal(label);
999 return newSTATEOP(label ? SvUTF8(label) : 0,
1000 label ? savepv(SvPVX(label)) : NULL,
1004 #define parse_keyword_labelconst() THX_parse_keyword_labelconst(aTHX)
1005 static OP *THX_parse_keyword_labelconst(pTHX)
1007 return newSVOP(OP_CONST, 0, parse_label(0));
1010 #define parse_keyword_arrayfullexpr() THX_parse_keyword_arrayfullexpr(aTHX)
1011 static OP *THX_parse_keyword_arrayfullexpr(pTHX)
1013 return newANONLIST(parse_fullexpr(0));
1016 #define parse_keyword_arraylistexpr() THX_parse_keyword_arraylistexpr(aTHX)
1017 static OP *THX_parse_keyword_arraylistexpr(pTHX)
1019 return newANONLIST(parse_listexpr(0));
1022 #define parse_keyword_arraytermexpr() THX_parse_keyword_arraytermexpr(aTHX)
1023 static OP *THX_parse_keyword_arraytermexpr(pTHX)
1025 return newANONLIST(parse_termexpr(0));
1028 #define parse_keyword_arrayarithexpr() THX_parse_keyword_arrayarithexpr(aTHX)
1029 static OP *THX_parse_keyword_arrayarithexpr(pTHX)
1031 return newANONLIST(parse_arithexpr(0));
1034 #define parse_keyword_arrayexprflags() THX_parse_keyword_arrayexprflags(aTHX)
1035 static OP *THX_parse_keyword_arrayexprflags(pTHX)
1041 c = lex_peek_unichar(0);
1042 if (c != '!' && c != '?') croak("syntax error");
1043 lex_read_unichar(0);
1044 if (c == '?') flags |= PARSE_OPTIONAL;
1045 o = parse_listexpr(flags);
1046 return o ? newANONLIST(o) : newANONHASH(newOP(OP_STUB, 0));
1049 #define parse_keyword_DEFSV() THX_parse_keyword_DEFSV(aTHX)
1050 static OP *THX_parse_keyword_DEFSV(pTHX)
1052 return newDEFSVOP();
1055 #define sv_cat_c(a,b) THX_sv_cat_c(aTHX_ a, b)
1056 static void THX_sv_cat_c(pTHX_ SV *sv, U32 c) {
1057 char ds[UTF8_MAXBYTES + 1], *d;
1058 d = (char *)uvchr_to_utf8((U8 *)ds, c);
1060 sv_utf8_upgrade(sv);
1062 sv_catpvn(sv, ds, d - ds);
1065 #define parse_keyword_with_vars() THX_parse_keyword_with_vars(aTHX)
1066 static OP *THX_parse_keyword_with_vars(pTHX)
1071 OP *vardeclseq, *body;
1073 save_ix = block_start(TRUE);
1079 c = lex_peek_unichar(0);
1085 croak("unexpected EOF; expecting '{'");
1088 if (!isIDFIRST_uni(c)) {
1089 croak("unexpected '%c'; expecting an identifier", (int)c);
1092 varname = newSVpvs("$");
1093 if (lex_bufutf8()) {
1097 sv_cat_c(varname, c);
1098 lex_read_unichar(0);
1100 while (c = lex_peek_unichar(0), c != -1 && isIDCONT_uni(c)) {
1101 sv_cat_c(varname, c);
1102 lex_read_unichar(0);
1105 padoff = pad_add_name_sv(varname, padadd_NO_DUP_CHECK, NULL, NULL);
1108 OP *my_var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
1109 my_var->op_targ = padoff;
1111 vardeclseq = op_append_list(
1129 c = lex_peek_unichar(0);
1134 body = parse_block(0);
1136 return block_end(save_ix, op_append_list(OP_LINESEQ, vardeclseq, body));
1139 #define parse_join_with_space() THX_parse_join_with_space(aTHX)
1140 static OP *THX_parse_join_with_space(pTHX)
1144 args = parse_listexpr(0);
1145 delim = newSVOP(OP_CONST, 0, newSVpvs(" "));
1146 return op_convert_list(OP_JOIN, 0, op_prepend_elem(OP_LIST, delim, args));
1151 #define keyword_active(hintkey_sv) THX_keyword_active(aTHX_ hintkey_sv)
1152 static int THX_keyword_active(pTHX_ SV *hintkey_sv)
1155 if(!GvHV(PL_hintgv)) return 0;
1156 he = hv_fetch_ent(GvHV(PL_hintgv), hintkey_sv, 0,
1157 SvSHARED_HASH(hintkey_sv));
1158 return he && SvTRUE(HeVAL(he));
1161 static int my_keyword_plugin(pTHX_
1162 char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
1164 if (memEQs(keyword_ptr, keyword_len, "rpn") &&
1165 keyword_active(hintkey_rpn_sv)) {
1166 *op_ptr = parse_keyword_rpn();
1167 return KEYWORD_PLUGIN_EXPR;
1168 } else if (memEQs(keyword_ptr, keyword_len, "calcrpn") &&
1169 keyword_active(hintkey_calcrpn_sv)) {
1170 *op_ptr = parse_keyword_calcrpn();
1171 return KEYWORD_PLUGIN_STMT;
1172 } else if (memEQs(keyword_ptr, keyword_len, "stufftest") &&
1173 keyword_active(hintkey_stufftest_sv)) {
1174 *op_ptr = parse_keyword_stufftest();
1175 return KEYWORD_PLUGIN_STMT;
1176 } else if (memEQs(keyword_ptr, keyword_len, "swaptwostmts") &&
1177 keyword_active(hintkey_swaptwostmts_sv)) {
1178 *op_ptr = parse_keyword_swaptwostmts();
1179 return KEYWORD_PLUGIN_STMT;
1180 } else if (memEQs(keyword_ptr, keyword_len, "looprest") &&
1181 keyword_active(hintkey_looprest_sv)) {
1182 *op_ptr = parse_keyword_looprest();
1183 return KEYWORD_PLUGIN_STMT;
1184 } else if (memEQs(keyword_ptr, keyword_len, "scopelessblock") &&
1185 keyword_active(hintkey_scopelessblock_sv)) {
1186 *op_ptr = parse_keyword_scopelessblock();
1187 return KEYWORD_PLUGIN_STMT;
1188 } else if (memEQs(keyword_ptr, keyword_len, "stmtasexpr") &&
1189 keyword_active(hintkey_stmtasexpr_sv)) {
1190 *op_ptr = parse_keyword_stmtasexpr();
1191 return KEYWORD_PLUGIN_EXPR;
1192 } else if (memEQs(keyword_ptr, keyword_len, "stmtsasexpr") &&
1193 keyword_active(hintkey_stmtsasexpr_sv)) {
1194 *op_ptr = parse_keyword_stmtsasexpr();
1195 return KEYWORD_PLUGIN_EXPR;
1196 } else if (memEQs(keyword_ptr, keyword_len, "loopblock") &&
1197 keyword_active(hintkey_loopblock_sv)) {
1198 *op_ptr = parse_keyword_loopblock();
1199 return KEYWORD_PLUGIN_STMT;
1200 } else if (memEQs(keyword_ptr, keyword_len, "blockasexpr") &&
1201 keyword_active(hintkey_blockasexpr_sv)) {
1202 *op_ptr = parse_keyword_blockasexpr();
1203 return KEYWORD_PLUGIN_EXPR;
1204 } else if (memEQs(keyword_ptr, keyword_len, "swaplabel") &&
1205 keyword_active(hintkey_swaplabel_sv)) {
1206 *op_ptr = parse_keyword_swaplabel();
1207 return KEYWORD_PLUGIN_STMT;
1208 } else if (memEQs(keyword_ptr, keyword_len, "labelconst") &&
1209 keyword_active(hintkey_labelconst_sv)) {
1210 *op_ptr = parse_keyword_labelconst();
1211 return KEYWORD_PLUGIN_EXPR;
1212 } else if (memEQs(keyword_ptr, keyword_len, "arrayfullexpr") &&
1213 keyword_active(hintkey_arrayfullexpr_sv)) {
1214 *op_ptr = parse_keyword_arrayfullexpr();
1215 return KEYWORD_PLUGIN_EXPR;
1216 } else if (memEQs(keyword_ptr, keyword_len, "arraylistexpr") &&
1217 keyword_active(hintkey_arraylistexpr_sv)) {
1218 *op_ptr = parse_keyword_arraylistexpr();
1219 return KEYWORD_PLUGIN_EXPR;
1220 } else if (memEQs(keyword_ptr, keyword_len, "arraytermexpr") &&
1221 keyword_active(hintkey_arraytermexpr_sv)) {
1222 *op_ptr = parse_keyword_arraytermexpr();
1223 return KEYWORD_PLUGIN_EXPR;
1224 } else if (memEQs(keyword_ptr, keyword_len, "arrayarithexpr") &&
1225 keyword_active(hintkey_arrayarithexpr_sv)) {
1226 *op_ptr = parse_keyword_arrayarithexpr();
1227 return KEYWORD_PLUGIN_EXPR;
1228 } else if (memEQs(keyword_ptr, keyword_len, "arrayexprflags") &&
1229 keyword_active(hintkey_arrayexprflags_sv)) {
1230 *op_ptr = parse_keyword_arrayexprflags();
1231 return KEYWORD_PLUGIN_EXPR;
1232 } else if (memEQs(keyword_ptr, keyword_len, "DEFSV") &&
1233 keyword_active(hintkey_DEFSV_sv)) {
1234 *op_ptr = parse_keyword_DEFSV();
1235 return KEYWORD_PLUGIN_EXPR;
1236 } else if (memEQs(keyword_ptr, keyword_len, "with_vars") &&
1237 keyword_active(hintkey_with_vars_sv)) {
1238 *op_ptr = parse_keyword_with_vars();
1239 return KEYWORD_PLUGIN_STMT;
1240 } else if (memEQs(keyword_ptr, keyword_len, "join_with_space") &&
1241 keyword_active(hintkey_join_with_space_sv)) {
1242 *op_ptr = parse_join_with_space();
1243 return KEYWORD_PLUGIN_EXPR;
1245 assert(next_keyword_plugin != my_keyword_plugin);
1246 return next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr);
1255 return PL_op->op_next;
1259 peep_xop(pTHX_ OP *o, OP *oldop)
1262 av_push(MY_CXT.xop_record, newSVpvf("peep:%" UVxf, PTR2UV(o)));
1263 av_push(MY_CXT.xop_record, newSVpvf("oldop:%" UVxf, PTR2UV(oldop)));
1267 filter_call(pTHX_ int idx, SV *buf_sv, int maxlen)
1271 int n = FILTER_READ(idx + 1, buf_sv, maxlen);
1275 p = SvPV_force_nolen(buf_sv);
1276 end = p + SvCUR(buf_sv);
1278 if (*p == 'o') *p = 'e';
1281 return SvCUR(buf_sv);
1285 myget_linear_isa(pTHX_ HV *stash, U32 level) {
1286 GV **gvp = (GV **)hv_fetchs(stash, "ISA", 0);
1287 PERL_UNUSED_ARG(level);
1288 return gvp && *gvp && GvAV(*gvp)
1290 : (AV *)sv_2mortal((SV *)newAV());
1294 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_undef);
1295 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_empty);
1296 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_APIVERSION_invalid);
1298 static struct mro_alg mymro;
1300 static Perl_check_t addissub_nxck_add;
1303 addissub_myck_add(pTHX_ OP *op)
1305 SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addissub", 0);
1308 if (!(flag_svp && SvTRUE(*flag_svp) && (op->op_flags & OPf_KIDS) &&
1309 (aop = cBINOPx(op)->op_first) && (bop = OpSIBLING(aop)) &&
1310 !OpHAS_SIBLING(bop)))
1311 return addissub_nxck_add(aTHX_ op);
1312 flags = op->op_flags;
1313 op_sibling_splice(op, NULL, 1, NULL); /* excise aop */
1314 op_sibling_splice(op, NULL, 1, NULL); /* excise bop */
1315 op_free(op); /* free the empty husk */
1317 return newBINOP(OP_SUBTRACT, flags, aop, bop);
1320 static Perl_check_t old_ck_rv2cv;
1323 my_ck_rv2cv(pTHX_ OP *o)
1326 SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addunder", 0);
1329 if (flag_svp && SvTRUE(*flag_svp) && (o->op_flags & OPf_KIDS)
1330 && (aop = cUNOPx(o)->op_first) && aop->op_type == OP_CONST
1331 && aop->op_private & (OPpCONST_ENTERED|OPpCONST_BARE)
1332 && (ref = cSVOPx(aop)->op_sv) && SvPOK(ref) && SvCUR(ref)
1333 && *(SvEND(ref)-1) == 'o')
1335 SvGROW(ref, SvCUR(ref)+2);
1340 return old_ck_rv2cv(aTHX_ o);
1343 #include "const-c.inc"
1345 MODULE = XS::APItest PACKAGE = XS::APItest
1347 INCLUDE: const-xs.inc
1354 /* this only needs to compile and checks that assert() can be
1355 used this way syntactically */
1356 (void)(assert(x), 1);
1359 MODULE = XS::APItest::utf8 PACKAGE = XS::APItest::utf8
1362 bytes_cmp_utf8(bytes, utf8)
1371 b = (const U8 *)SvPVbyte(bytes, blen);
1372 u = (const U8 *)SvPVbyte(utf8, ulen);
1373 RETVAL = bytes_cmp_utf8(b, blen, u, ulen);
1378 test_utf8n_to_uvchr_error(s, len, flags)
1390 /* Now that utf8n_to_uvchr() is a trivial wrapper for
1391 * utf8n_to_uvchr_error(), call the latter with the inputs. It always
1392 * asks for the actual length to be returned and errors to be returned
1394 * Length to assume <s> is; not checked, so could have buffer overflow
1397 sv_2mortal((SV*)RETVAL);
1399 ret = utf8n_to_uvchr_error((U8*) SvPV(s, slen),
1405 /* Returns the return value in [0]; <retlen> in [1], <errors> in [2] */
1406 av_push(RETVAL, newSVuv(ret));
1407 if (retlen == (STRLEN) -1) {
1408 av_push(RETVAL, newSViv(-1));
1411 av_push(RETVAL, newSVuv(retlen));
1413 av_push(RETVAL, newSVuv(errors));
1419 test_valid_utf8_to_uvchr(s)
1427 /* Call utf8n_to_uvchr() with the inputs. It always asks for the
1428 * actual length to be returned
1430 * Length to assume <s> is; not checked, so could have buffer overflow
1433 sv_2mortal((SV*)RETVAL);
1435 ret = valid_utf8_to_uvchr((U8*) SvPV_nolen(s), &retlen);
1437 /* Returns the return value in [0]; <retlen> in [1] */
1438 av_push(RETVAL, newSVuv(ret));
1439 av_push(RETVAL, newSVuv(retlen));
1445 test_uvchr_to_utf8_flags(uv, flags)
1450 U8 dest[UTF8_MAXBYTES];
1454 /* Call uvchr_to_utf8_flags() with the inputs. */
1455 ret = uvchr_to_utf8_flags(dest, SvUV(uv), SvUV(flags));
1459 RETVAL = newSVpvn((char *) dest, ret - dest);
1464 MODULE = XS::APItest:Overload PACKAGE = XS::APItest::Overload
1467 amagic_deref_call(sv, what)
1471 /* The reference is owned by something else. */
1472 PUSHs(amagic_deref_call(sv, what));
1474 # I'd certainly like to discourage the use of this macro, given that we now
1475 # have amagic_deref_call
1478 tryAMAGICunDEREF_var(sv, what)
1486 tryAMAGICunDEREF(to_av);
1489 tryAMAGICunDEREF(to_cv);
1492 tryAMAGICunDEREF(to_gv);
1495 tryAMAGICunDEREF(to_hv);
1498 tryAMAGICunDEREF(to_sv);
1501 croak("Invalid value %d passed to tryAMAGICunDEREF_var", what);
1504 /* The reference is owned by something else. */
1507 MODULE = XS::APItest PACKAGE = XS::APItest::XSUB
1510 newXS("XS::APItest::XSUB::XS_VERSION_undef", XS_XS__APItest__XSUB_XS_VERSION_undef, __FILE__);
1511 newXS("XS::APItest::XSUB::XS_VERSION_empty", XS_XS__APItest__XSUB_XS_VERSION_empty, __FILE__);
1512 newXS("XS::APItest::XSUB::XS_APIVERSION_invalid", XS_XS__APItest__XSUB_XS_APIVERSION_invalid, __FILE__);
1515 XS_VERSION_defined(...)
1517 XS_VERSION_BOOTCHECK;
1521 XS_APIVERSION_valid(...)
1523 XS_APIVERSION_BOOTCHECK;
1531 for ( ; i < len; i++ ) {
1532 ST(i) = sv_2mortal( newSViv(i) );
1539 XSRETURN_IV(I32_MIN + 1);
1544 XSRETURN_UV( (U32)((1U<<31) + 1) );
1554 XSRETURN_PV("returned");
1559 XSRETURN_PVN("returned too much",8);
1581 MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash
1589 uf.uf_val = rot13_key;
1593 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1602 uf.uf_val = bitflip_key;
1606 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1609 #define UTF8KLEN(sv, len) (SvUTF8(sv) ? -(I32)len : (I32)len)
1612 exists(hash, key_sv)
1620 key = SvPV(key_sv, len);
1621 RETVAL = hv_exists(hash, key, UTF8KLEN(key_sv, len));
1626 exists_ent(hash, key_sv)
1632 RETVAL = hv_exists_ent(hash, key_sv, 0);
1637 delete(hash, key_sv, flags = 0)
1646 key = SvPV(key_sv, len);
1647 /* It's already mortal, so need to increase reference count. */
1649 = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags));
1654 delete_ent(hash, key_sv, flags = 0)
1660 /* It's already mortal, so need to increase reference count. */
1661 RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0));
1666 store_ent(hash, key, value)
1676 result = hv_store_ent(hash, key, copy, 0);
1677 SvSetMagicSV(copy, value);
1682 /* It's about to become mortal, so need to increase reference count.
1684 RETVAL = SvREFCNT_inc(HeVAL(result));
1689 store(hash, key_sv, value)
1700 key = SvPV(key_sv, len);
1702 result = hv_store(hash, key, UTF8KLEN(key_sv, len), copy, 0);
1703 SvSetMagicSV(copy, value);
1708 /* It's about to become mortal, so need to increase reference count.
1710 RETVAL = SvREFCNT_inc(*result);
1715 fetch_ent(hash, key_sv)
1722 result = hv_fetch_ent(hash, key_sv, 0, 0);
1727 RETVAL = newSVsv(HeVAL(result));
1741 key = SvPV(key_sv, len);
1742 result = hv_fetch(hash, key, UTF8KLEN(key_sv, len), 0);
1747 RETVAL = newSVsv(*result);
1751 #if defined (hv_common)
1761 const char *key = NULL;
1769 if ((svp = hv_fetchs(params, "hv", 0))) {
1770 SV *const rv = *svp;
1772 croak("common passed a non-reference for parameter hv");
1773 hv = (HV *)SvRV(rv);
1775 if ((svp = hv_fetchs(params, "keysv", 0)))
1777 if ((svp = hv_fetchs(params, "keypv", 0))) {
1778 key = SvPV_const(*svp, klen);
1782 if ((svp = hv_fetchs(params, "action", 0)))
1783 action = SvIV(*svp);
1784 if ((svp = hv_fetchs(params, "val", 0)))
1785 val = newSVsv(*svp);
1786 if ((svp = hv_fetchs(params, "hash", 0)))
1789 if (hv_fetchs(params, "hash_pv", 0)) {
1791 PERL_HASH(hash, key, klen);
1793 if (hv_fetchs(params, "hash_sv", 0)) {
1797 const char *const p = SvPV(keysv, len);
1798 PERL_HASH(hash, p, len);
1802 result = (HE *)hv_common(hv, keysv, key, klen, flags, action, val, hash);
1807 RETVAL = newSVsv(HeVAL(result));
1816 test_freeent(&Perl_hv_free_ent);
1820 test_hv_delayfree_ent()
1822 test_freeent(&Perl_hv_delayfree_ent);
1826 test_share_unshare_pvn(input)
1835 pvx = SvPV(input, len);
1836 PERL_HASH(hash, pvx, len);
1837 p = sharepvn(pvx, len, hash);
1838 RETVAL = newSVpvn(p, len);
1839 unsharepvn(p, len, hash);
1843 #if PERL_VERSION >= 9
1846 refcounted_he_exists(key, level=0)
1851 croak("level must be zero, not %" IVdf, level);
1853 RETVAL = (cop_hints_fetch_sv(PL_curcop, key, 0, 0) != &PL_sv_placeholder);
1858 refcounted_he_fetch(key, level=0)
1863 croak("level must be zero, not %" IVdf, level);
1865 RETVAL = cop_hints_fetch_sv(PL_curcop, key, 0, 0);
1866 SvREFCNT_inc(RETVAL);
1873 test_force_keys(HV *hv)
1879 he = hv_iternext(hv);
1881 SV *sv = HeSVKEY_force(he);
1884 PUSHs(sv_mortalcopy(sv));
1885 he = hv_iternext(hv);
1890 sub TIEHASH { bless {}, $_[0] }
1891 sub STORE { $_[0]->{$_[1]} = $_[2] }
1892 sub FETCH { $_[0]->{$_[1]} }
1893 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
1894 sub NEXTKEY { each %{$_[0]} }
1895 sub EXISTS { exists $_[0]->{$_[1]} }
1896 sub DELETE { delete $_[0]->{$_[1]} }
1897 sub CLEAR { %{$_[0]} = () }
1901 MODULE = XS::APItest:TempLv PACKAGE = XS::APItest::TempLv
1907 SV * const lv = newSV_type(SVt_PVLV);
1912 sv_magic(lv, NULL, PERL_MAGIC_substr, NULL, 0);
1914 LvTARG(lv) = SvREFCNT_inc_simple(sv);
1915 LvTARGOFF(lv) = len == 0 ? 0 : 1;
1916 LvTARGLEN(lv) = len < 2 ? 0 : len-2;
1919 ST(0) = sv_2mortal(lv);
1923 MODULE = XS::APItest::PtrTable PACKAGE = XS::APItest::PtrTable PREFIX = ptr_table_
1926 ptr_table_new(classname)
1927 const char * classname
1929 PUSHs(sv_setref_pv(sv_newmortal(), classname, (void*)ptr_table_new()));
1933 XS::APItest::PtrTable table
1935 ptr_table_free(table);
1938 ptr_table_store(table, from, to)
1939 XS::APItest::PtrTable table
1943 ptr_table_store(table, from, to);
1946 ptr_table_fetch(table, from)
1947 XS::APItest::PtrTable table
1950 RETVAL = PTR2UV(ptr_table_fetch(table, from));
1955 ptr_table_split(table)
1956 XS::APItest::PtrTable table
1959 ptr_table_clear(table)
1960 XS::APItest::PtrTable table
1962 MODULE = XS::APItest::AutoLoader PACKAGE = XS::APItest::AutoLoader
1967 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
1975 PERL_UNUSED_ARG(items);
1976 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
1981 MODULE = XS::APItest PACKAGE = XS::APItest
1986 mymro.resolve = myget_linear_isa;
1987 mymro.name = "justisa";
1991 Perl_mro_register(aTHX_ &mymro);
1996 RETVAL = PL_custom_ops;
2001 xop_custom_op_names ()
2003 PL_custom_op_names = newHV();
2004 RETVAL = PL_custom_op_names;
2009 xop_custom_op_descs ()
2011 PL_custom_op_descs = newHV();
2012 RETVAL = PL_custom_op_descs;
2019 XopENTRY_set(&my_xop, xop_name, "my_xop");
2020 XopENTRY_set(&my_xop, xop_desc, "XOP for testing");
2021 XopENTRY_set(&my_xop, xop_class, OA_UNOP);
2022 XopENTRY_set(&my_xop, xop_peep, peep_xop);
2023 Perl_custom_op_register(aTHX_ pp_xop, &my_xop);
2028 XopDISABLE(&my_xop, xop_name);
2029 XopDISABLE(&my_xop, xop_desc);
2030 XopDISABLE(&my_xop, xop_class);
2031 XopDISABLE(&my_xop, xop_peep);
2036 RETVAL = PTR2IV(&my_xop);
2043 RETVAL = PTR2IV(pp_xop);
2061 MY_CXT.xop_record = newAV();
2063 kid = newSVOP(OP_CONST, 0, newSViv(42));
2065 unop = (UNOP*)mkUNOP(OP_CUSTOM, kid);
2066 unop->op_ppaddr = pp_xop;
2067 unop->op_private = 0;
2068 unop->op_next = NULL;
2069 kid->op_next = (OP*)unop;
2071 av_push(MY_CXT.xop_record, newSVpvf("unop:%" UVxf, PTR2UV(unop)));
2072 av_push(MY_CXT.xop_record, newSVpvf("kid:%" UVxf, PTR2UV(kid)));
2074 av_push(MY_CXT.xop_record, newSVpvf("NAME:%s", OP_NAME((OP*)unop)));
2075 av_push(MY_CXT.xop_record, newSVpvf("DESC:%s", OP_DESC((OP*)unop)));
2076 av_push(MY_CXT.xop_record, newSVpvf("CLASS:%d", (int)OP_CLASS((OP*)unop)));
2078 PL_rpeepp(aTHX_ kid);
2083 RETVAL = MY_CXT.xop_record;
2084 MY_CXT.xop_record = NULL;
2089 xop_from_custom_op ()
2091 /* author note: this test doesn't imply Perl_custom_op_xop is or isn't public
2092 API or that Perl_custom_op_xop is known to be used outside the core */
2096 unop = (UNOP*)mkUNOP(OP_CUSTOM, NULL);
2097 unop->op_ppaddr = pp_xop;
2098 unop->op_private = 0;
2099 unop->op_next = NULL;
2101 xop = Perl_custom_op_xop(aTHX_ (OP *)unop);
2103 RETVAL = PTR2IV(xop);
2112 MY_CXT.sv = newSVpv("initial",0);
2114 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2115 MY_CXT.bhk_record = 0;
2117 BhkENTRY_set(&bhk_test, bhk_start, blockhook_test_start);
2118 BhkENTRY_set(&bhk_test, bhk_pre_end, blockhook_test_pre_end);
2119 BhkENTRY_set(&bhk_test, bhk_post_end, blockhook_test_post_end);
2120 BhkENTRY_set(&bhk_test, bhk_eval, blockhook_test_eval);
2121 Perl_blockhook_register(aTHX_ &bhk_test);
2123 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2124 GV_ADDMULTI, SVt_PVAV);
2125 MY_CXT.cscav = GvAV(MY_CXT.cscgv);
2127 BhkENTRY_set(&bhk_csc, bhk_start, blockhook_csc_start);
2128 BhkENTRY_set(&bhk_csc, bhk_pre_end, blockhook_csc_pre_end);
2129 Perl_blockhook_register(aTHX_ &bhk_csc);
2131 MY_CXT.peep_recorder = newAV();
2132 MY_CXT.rpeep_recorder = newAV();
2134 MY_CXT.orig_peep = PL_peepp;
2135 MY_CXT.orig_rpeep = PL_rpeepp;
2137 PL_rpeepp = my_rpeep;
2144 PERL_UNUSED_VAR(items);
2145 MY_CXT.sv = newSVpv("initial_clone",0);
2146 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2147 GV_ADDMULTI, SVt_PVAV);
2148 MY_CXT.cscav = NULL;
2149 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2150 MY_CXT.bhk_record = 0;
2151 MY_CXT.peep_recorder = newAV();
2152 MY_CXT.rpeep_recorder = newAV();
2158 printf("%5.3f\n",val);
2163 #ifdef HAS_LONG_DOUBLE
2174 #ifdef HAS_LONG_DOUBLE
2175 # if defined(PERL_PRIfldbl) && (LONG_DOUBLESIZE > DOUBLESIZE)
2176 long double val = 7.0;
2177 printf("%5.3" PERL_PRIfldbl "\n",val);
2180 printf("%5.3f\n",val);
2194 printf("%ld\n",val);
2200 printf("%5.3f\n",val);
2248 mXPUSHp("three", 5);
2276 # test_EXTEND(): excerise the EXTEND() macro.
2277 # After calling EXTEND(), it also does *(p+n) = NULL and
2278 # *PL_stack_max = NULL to allow valgrind etc to spot if the stack hasn't
2279 # actually been extended properly.
2281 # max_offset specifies the SP to use. It is treated as a signed offset
2282 # from PL_stack_max.
2283 # nsv is the SV holding the value of n indicating how many slots
2284 # to extend the stack by.
2285 # use_ss is a boolean indicating that n should be cast to a SSize_t
2288 test_EXTEND(max_offset, nsv, use_ss)
2293 SV **sp = PL_stack_max + max_offset;
2296 SSize_t n = (SSize_t)SvIV(nsv);
2305 *PL_stack_max = NULL;
2317 SV * miscsv = sv_newmortal();
2318 HV * hv = (HV*)sv_2mortal((SV*)newHV());
2320 i_sub = get_cv("i", 0);
2322 /* PUTBACK not needed since this sub was called with 0 args, and is calling
2323 0 args, so global SP doesn't need to be moved before a call_* */
2324 retcnt = call_sv((SV*)i_sub, 0); /* try a CV* */
2326 SP -= retcnt; /* dont care about return count, wipe everything off */
2327 sv_setpvs(miscsv, "i");
2329 retcnt = call_sv(miscsv, 0); /* try a PV */
2332 /* no add and SVt_NULL are intentional, sub i should be defined already */
2333 i_gv = gv_fetchpvn_flags("i", sizeof("i")-1, 0, SVt_NULL);
2335 retcnt = call_sv((SV*)i_gv, 0); /* try a GV* */
2338 /* the tests below are not declaring this being public API behavior,
2339 only current internal behavior, these tests can be changed in the
2340 future if necessery */
2342 retcnt = call_sv(&PL_sv_yes, 0); /* does nothing */
2346 retcnt = call_sv(&PL_sv_no, G_EVAL);
2350 errstr = SvPV(errsv, errlen);
2351 if(memBEGINs(errstr, errlen, "Undefined subroutine &main:: called at")) {
2353 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2358 retcnt = call_sv(&PL_sv_undef, G_EVAL);
2362 errstr = SvPV(errsv, errlen);
2363 if(memBEGINs(errstr, errlen, "Can't use an undefined value as a subroutine reference at")) {
2365 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2370 retcnt = call_sv((SV*)hv, G_EVAL);
2374 errstr = SvPV(errsv, errlen);
2375 if(memBEGINs(errstr, errlen, "Not a CODE reference at")) {
2377 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2383 call_sv(sv, flags, ...)
2389 for (i=0; i<items-2; i++)
2390 ST(i) = ST(i+2); /* pop first two args */
2394 i = call_sv(sv, flags);
2397 PUSHs(sv_2mortal(newSViv(i)));
2400 call_pv(subname, flags, ...)
2406 for (i=0; i<items-2; i++)
2407 ST(i) = ST(i+2); /* pop first two args */
2411 i = call_pv(subname, flags);
2414 PUSHs(sv_2mortal(newSViv(i)));
2417 call_argv(subname, flags, ...)
2424 for (i=0; i<items-2; i++)
2425 tmpary[i] = SvPV_nolen(ST(i+2)); /* ignore first two args */
2428 i = call_argv(subname, flags, tmpary);
2431 PUSHs(sv_2mortal(newSViv(i)));
2434 call_method(methname, flags, ...)
2440 for (i=0; i<items-2; i++)
2441 ST(i) = ST(i+2); /* pop first two args */
2445 i = call_method(methname, flags);
2448 PUSHs(sv_2mortal(newSViv(i)));
2451 newCONSTSUB(stash, name, flags, sv)
2457 newCONSTSUB_flags = 1
2461 const char *pv = SvPV(name, len);
2465 mycv = newCONSTSUB(stash, pv, SvOK(sv) ? SvREFCNT_inc(sv) : NULL);
2468 mycv = newCONSTSUB_flags(
2469 stash, pv, len, flags | SvUTF8(name), SvOK(sv) ? SvREFCNT_inc(sv) : NULL
2475 PUSHs( CvCONST(mycv) ? &PL_sv_yes : &PL_sv_no );
2476 PUSHs((SV*)CvGV(mycv));
2479 gv_init_type(namesv, multi, flags, type)
2486 const char * const name = SvPV_const(namesv, len);
2487 GV *gv = *(GV**)hv_fetch(PL_defstash, name, len, TRUE);
2489 if (SvTYPE(gv) == SVt_PVGV)
2490 Perl_croak(aTHX_ "GV is already a PVGV");
2491 if (multi) flags |= GV_ADDMULTI;
2494 gv_init(gv, PL_defstash, name, len, multi);
2497 gv_init_sv(gv, PL_defstash, namesv, flags);
2500 gv_init_pv(gv, PL_defstash, name, flags | SvUTF8(namesv));
2503 gv_init_pvn(gv, PL_defstash, name, len, flags | SvUTF8(namesv));
2506 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2509 gv_fetchmeth_type(stash, methname, type, level, flags)
2517 const char * const name = SvPV_const(methname, len);
2522 gv = gv_fetchmeth(stash, name, len, level);
2525 gv = gv_fetchmeth_sv(stash, methname, level, flags);
2528 gv = gv_fetchmeth_pv(stash, name, level, flags | SvUTF8(methname));
2531 gv = gv_fetchmeth_pvn(stash, name, len, level, flags | SvUTF8(methname));
2534 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2537 gv_fetchmeth_autoload_type(stash, methname, type, level, flags)
2545 const char * const name = SvPV_const(methname, len);
2550 gv = gv_fetchmeth_autoload(stash, name, len, level);
2553 gv = gv_fetchmeth_sv_autoload(stash, methname, level, flags);
2556 gv = gv_fetchmeth_pv_autoload(stash, name, level, flags | SvUTF8(methname));
2559 gv = gv_fetchmeth_pvn_autoload(stash, name, len, level, flags | SvUTF8(methname));
2562 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2565 gv_fetchmethod_flags_type(stash, methname, type, flags)
2575 gv = gv_fetchmethod_flags(stash, SvPVX_const(methname), flags);
2578 gv = gv_fetchmethod_sv_flags(stash, methname, flags);
2581 gv = gv_fetchmethod_pv_flags(stash, SvPV_nolen(methname), flags | SvUTF8(methname));
2585 const char * const name = SvPV_const(methname, len);
2586 gv = gv_fetchmethod_pvn_flags(stash, name, len, flags | SvUTF8(methname));
2590 gv = gv_fetchmethod_pvn_flags(stash, SvPV_nolen(methname),
2591 flags, SvUTF8(methname));
2593 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2596 gv_autoload_type(stash, methname, type, method)
2603 const char * const name = SvPV_const(methname, len);
2605 I32 flags = method ? GV_AUTOLOAD_ISMETHOD : 0;
2609 gv = gv_autoload4(stash, name, len, method);
2612 gv = gv_autoload_sv(stash, methname, flags);
2615 gv = gv_autoload_pv(stash, name, flags | SvUTF8(methname));
2618 gv = gv_autoload_pvn(stash, name, len, flags | SvUTF8(methname));
2621 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2624 gv_const_sv(SV *name)
2629 HV *stash = gv_stashpv("main",0);
2630 HE *he = hv_fetch_ent(stash, name, 0, 0);
2631 gv = (GV *)HeVAL(he);
2636 RETVAL = gv_const_sv(gv);
2639 RETVAL = newSVsv(RETVAL);
2644 whichsig_type(namesv, type)
2649 const char * const name = SvPV_const(namesv, len);
2657 i = whichsig_sv(namesv);
2660 i = whichsig_pv(name);
2663 i = whichsig_pvn(name, len);
2666 XPUSHs(sv_2mortal(newSViv(i)));
2676 i = eval_sv(sv, flags);
2679 PUSHs(sv_2mortal(newSViv(i)));
2682 eval_pv(p, croak_on_error)
2688 PUSHs(eval_pv(p, croak_on_error));
2698 apitest_exception(throw_e)
2708 Perl_croak(aTHX_ "%s", SvPV_nolen(sv));
2711 Perl_croak(aTHX_ NULL);
2717 RETVAL = newRV_inc((SV*)PL_strtab);
2725 RETVAL = my_cxt_getint_p(aMY_CXT);
2734 my_cxt_setint_p(aMY_CXT_ i);
2741 ST(0) = how ? my_cxt_getsv_interp_context() : my_cxt_getsv_interp();
2749 SvREFCNT_dec(MY_CXT.sv);
2750 my_cxt_setsv_p(sv _aMY_CXT);
2754 sv_setsv_cow_hashkey_core()
2757 sv_setsv_cow_hashkey_notcore()
2760 sv_set_deref(SV *sv, SV *sv2, int which)
2764 const char *pv = SvPV(sv2,len);
2765 if (!SvROK(sv)) croak("Not a ref");
2768 case 0: sv_setsv(sv,sv2); break;
2769 case 1: sv_setpv(sv,pv); break;
2770 case 2: sv_setpvn(sv,pv,len); break;
2775 rmagical_cast(sv, type)
2781 if (!SvOK(sv) || !SvROK(sv) || !SvOK(type)) { XSRETURN_UNDEF; }
2783 if (SvTYPE(sv) != SVt_PVHV) { XSRETURN_UNDEF; }
2784 uf.uf_val = rmagical_a_dummy;
2787 if (SvTRUE(type)) { /* b */
2788 sv_magicext(sv, NULL, PERL_MAGIC_ext, &rmagical_b, NULL, 0);
2790 sv_magic(sv, NULL, PERL_MAGIC_uvar, (char *) &uf, sizeof(uf));
2798 if (!SvOK(sv) || !SvROK(sv)) { XSRETURN_UNDEF; }
2801 mXPUSHu(SvFLAGS(sv) & SVs_GMG);
2802 mXPUSHu(SvFLAGS(sv) & SVs_SMG);
2803 mXPUSHu(SvFLAGS(sv) & SVs_RMG);
2810 const PERL_CONTEXT *cx, *dbcx;
2815 cx = caller_cx(level, &dbcx);
2818 pv = CopSTASHPV(cx->blk_oldcop);
2819 ST(0) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2820 gv = CvGV(cx->blk_sub.cv);
2821 ST(1) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2823 pv = CopSTASHPV(dbcx->blk_oldcop);
2824 ST(2) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2825 gv = CvGV(dbcx->blk_sub.cv);
2826 ST(3) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2828 ST(4) = cop_hints_fetch_pvs(cx->blk_oldcop, "foo", 0);
2829 ST(5) = cop_hints_fetch_pvn(cx->blk_oldcop, "foo", 3, 0, 0);
2830 ST(6) = cop_hints_fetch_sv(cx->blk_oldcop,
2831 sv_2mortal(newSVpvs("foo")), 0, 0);
2833 hv = cop_hints_2hv(cx->blk_oldcop, 0);
2834 ST(7) = hv ? sv_2mortal(newRV_noinc((SV *)hv)) : &PL_sv_undef;
2843 ST (0) = newSVpv (Perl_sv_peek (aTHX_ sv), 0);
2849 sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI));
2854 sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI));
2859 sv_inc(get_sv("XS::APItest::UNITCHECK_called", GV_ADD|GV_ADDMULTI));
2864 sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI));
2869 sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI));
2872 utf16_to_utf8 (sv, ...)
2875 utf16_to_utf8_reversed = 1
2880 I32 got; /* Gah, badly thought out APIs */
2882 if (ix) (void)SvPV_force_nolen(sv);
2883 source = (U8 *)SvPVbyte(sv, len);
2884 /* Optionally only convert part of the buffer. */
2888 /* Mortalise this right now, as we'll be testing croak()s */
2889 dest = sv_2mortal(newSV(len * 2 + 1));
2891 utf16_to_utf8_reversed(source, (U8 *)SvPVX(dest), len, &got);
2893 utf16_to_utf8(source, (U8 *)SvPVX(dest), len, &got);
2895 SvCUR_set(dest, got);
2896 SvPVX(dest)[got] = '\0';
2902 my_exit(int exitcode)
2912 s = SvPVbyte(sv, len);
2920 RETVAL = PL_sv_count;
2928 MY_CXT.bhk_record = on;
2930 av_clear(MY_CXT.bhkav);
2936 MAGIC *callmg, *uvarmg;
2938 sv = sv_2mortal(newSV(0));
2939 if (SvTYPE(sv) >= SVt_PVMG) croak_fail();
2940 if (SvMAGICAL(sv)) croak_fail();
2941 sv_magic(sv, &PL_sv_yes, PERL_MAGIC_checkcall, (char*)&callmg, 0);
2942 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2943 if (!SvMAGICAL(sv)) croak_fail();
2944 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2945 callmg = mg_find(sv, PERL_MAGIC_checkcall);
2946 if (!callmg) croak_fail();
2947 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2949 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
2950 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2951 if (!SvMAGICAL(sv)) croak_fail();
2952 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2953 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
2954 if (!uvarmg) croak_fail();
2955 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2957 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2959 mg_free_type(sv, PERL_MAGIC_vec);
2960 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2961 if (!SvMAGICAL(sv)) croak_fail();
2962 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2963 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
2964 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2966 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2968 mg_free_type(sv, PERL_MAGIC_uvar);
2969 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2970 if (!SvMAGICAL(sv)) croak_fail();
2971 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2972 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2973 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2975 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
2976 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2977 if (!SvMAGICAL(sv)) croak_fail();
2978 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2979 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
2980 if (!uvarmg) croak_fail();
2981 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2983 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2985 mg_free_type(sv, PERL_MAGIC_checkcall);
2986 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2987 if (!SvMAGICAL(sv)) croak_fail();
2988 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
2989 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
2990 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2992 mg_free_type(sv, PERL_MAGIC_uvar);
2993 if (SvMAGICAL(sv)) croak_fail();
2994 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
2995 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2998 test_op_contextualize()
3002 o = newSVOP(OP_CONST, 0, newSViv(0));
3003 o->op_flags &= ~OPf_WANT;
3004 o = op_contextualize(o, G_SCALAR);
3005 if (o->op_type != OP_CONST ||
3006 (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR)
3009 o = newSVOP(OP_CONST, 0, newSViv(0));
3010 o->op_flags &= ~OPf_WANT;
3011 o = op_contextualize(o, G_ARRAY);
3012 if (o->op_type != OP_CONST ||
3013 (o->op_flags & OPf_WANT) != OPf_WANT_LIST)
3016 o = newSVOP(OP_CONST, 0, newSViv(0));
3017 o->op_flags &= ~OPf_WANT;
3018 o = op_contextualize(o, G_VOID);
3019 if (o->op_type != OP_NULL) croak_fail();
3030 troc_gv = gv_fetchpv("XS::APItest::test_rv2cv_op_cv", 0, SVt_PVGV);
3031 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3032 o = newCVREF(0, newGVOP(OP_GV, 0, troc_gv));
3033 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3034 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3036 o->op_private |= OPpENTERSUB_AMPER;
3037 if (rv2cv_op_cv(o, 0)) croak_fail();
3038 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3039 o->op_private &= ~OPpENTERSUB_AMPER;
3040 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3041 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3042 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3044 o = newSVOP(OP_CONST, 0, newSVpv("XS::APItest::test_rv2cv_op_cv", 0));
3045 o->op_private = OPpCONST_BARE;
3047 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3048 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3050 o->op_private |= OPpENTERSUB_AMPER;
3051 if (rv2cv_op_cv(o, 0)) croak_fail();
3052 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3054 o = newCVREF(0, newSVOP(OP_CONST, 0, newRV_inc((SV*)troc_cv)));
3055 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3056 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3058 o->op_private |= OPpENTERSUB_AMPER;
3059 if (rv2cv_op_cv(o, 0)) croak_fail();
3060 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3061 o->op_private &= ~OPpENTERSUB_AMPER;
3062 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3063 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3064 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3066 o = newCVREF(0, newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0))));
3067 if (rv2cv_op_cv(o, 0)) croak_fail();
3068 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3069 o->op_private |= OPpENTERSUB_AMPER;
3070 if (rv2cv_op_cv(o, 0)) croak_fail();
3071 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3072 o->op_private &= ~OPpENTERSUB_AMPER;
3073 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3074 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY)) croak_fail();
3075 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3077 o = newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0)));
3078 if (rv2cv_op_cv(o, 0)) croak_fail();
3079 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3083 test_cv_getset_call_checker()
3085 CV *troc_cv, *tsh_cv;
3086 Perl_call_checker ckfun;
3090 #define check_cc(cv, xckfun, xckobj, xckflags) \
3092 cv_get_call_checker((cv), &ckfun, &ckobj); \
3093 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3094 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3095 cv_get_call_checker_flags((cv), CALL_CHECKER_REQUIRE_GV, &ckfun, &ckobj, &ckflags); \
3096 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3097 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3098 if (ckflags != CALL_CHECKER_REQUIRE_GV) croak_fail_nei(ckflags, CALL_CHECKER_REQUIRE_GV); \
3099 cv_get_call_checker_flags((cv), 0, &ckfun, &ckobj, &ckflags); \
3100 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3101 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3102 if (ckflags != (xckflags)) croak_fail_nei(ckflags, (xckflags)); \
3104 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3105 tsh_cv = get_cv("XS::APItest::test_savehints", 0);
3106 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3107 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3108 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3110 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3111 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3112 cv_set_call_checker(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no);
3113 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no, CALL_CHECKER_REQUIRE_GV);
3114 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3115 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3117 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no, CALL_CHECKER_REQUIRE_GV);
3118 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3119 cv_set_call_checker(troc_cv, Perl_ck_entersub_args_proto_or_list,
3121 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3122 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3123 if (SvMAGICAL((SV*)troc_cv) || SvMAGIC((SV*)troc_cv)) croak_fail();
3124 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3125 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3127 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, 0);
3128 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3129 &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3130 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3131 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3133 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3134 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3135 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3136 &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3137 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3138 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3139 (SV*)tsh_cv, CALL_CHECKER_REQUIRE_GV);
3140 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3141 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3145 cv_set_call_checker_lists(CV *cv)
3147 cv_set_call_checker(cv, THX_ck_entersub_args_lists, &PL_sv_undef);
3150 cv_set_call_checker_scalars(CV *cv)
3152 cv_set_call_checker(cv, THX_ck_entersub_args_scalars, &PL_sv_undef);
3155 cv_set_call_checker_proto(CV *cv, SV *proto)
3158 proto = SvRV(proto);
3159 cv_set_call_checker(cv, Perl_ck_entersub_args_proto, proto);
3162 cv_set_call_checker_proto_or_list(CV *cv, SV *proto)
3165 proto = SvRV(proto);
3166 cv_set_call_checker(cv, Perl_ck_entersub_args_proto_or_list, proto);
3169 cv_set_call_checker_multi_sum(CV *cv)
3171 cv_set_call_checker(cv, THX_ck_entersub_multi_sum, &PL_sv_undef);
3183 #define check_ph(EXPR) \
3184 do { if((EXPR) != &PL_sv_placeholder) croak("fail"); } while(0)
3185 #define check_iv(EXPR, EXPECT) \
3186 do { if(SvIV(EXPR) != (EXPECT)) croak("fail"); } while(0)
3187 #define msvpvs(STR) sv_2mortal(newSVpvs(STR))
3188 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3189 a = cophh_new_empty();
3190 check_ph(cophh_fetch_pvn(a, "foo_1", 5, 0, 0));
3191 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3192 check_ph(cophh_fetch_pv(a, "foo_1", 0, 0));
3193 check_ph(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0));
3194 a = cophh_store_pvn(a, "foo_1abc", 5, 0, msviv(111), 0);
3195 a = cophh_store_pvs(a, "foo_2", msviv(222), 0);
3196 a = cophh_store_pv(a, "foo_3", 0, msviv(333), 0);
3197 a = cophh_store_sv(a, msvpvs("foo_4"), 0, msviv(444), 0);
3198 check_iv(cophh_fetch_pvn(a, "foo_1xyz", 5, 0, 0), 111);
3199 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3200 check_iv(cophh_fetch_pv(a, "foo_1", 0, 0), 111);
3201 check_iv(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0), 111);
3202 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3203 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3204 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3205 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3207 b = cophh_store_pvs(b, "foo_1", msviv(1111), 0);
3208 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3209 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3210 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3211 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3212 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3213 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3214 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3215 check_iv(cophh_fetch_pvs(b, "foo_3", 0), 333);
3216 check_iv(cophh_fetch_pvs(b, "foo_4", 0), 444);
3217 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3218 a = cophh_delete_pvn(a, "foo_1abc", 5, 0, 0);
3219 a = cophh_delete_pvs(a, "foo_2", 0);
3220 b = cophh_delete_pv(b, "foo_3", 0, 0);
3221 b = cophh_delete_sv(b, msvpvs("foo_4"), 0, 0);
3222 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3223 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3224 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3225 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3226 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3227 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3228 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3229 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3230 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3231 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3232 b = cophh_delete_pvs(b, "foo_3", 0);
3233 b = cophh_delete_pvs(b, "foo_5", 0);
3234 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3235 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3236 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3237 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3238 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3240 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3241 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3242 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3243 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3244 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3245 a = cophh_store_pvs(a, "foo_1", msviv(11111), COPHH_KEY_UTF8);
3246 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3248 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3250 /* On EBCDIC, we need to translate the UTF-8 in the ASCII test to the
3251 * equivalent UTF-EBCDIC for the code page. This is done at runtime
3252 * (with the helper function in this file). Therefore we can't use
3253 * cophhh_store_pvs(), as we don't have literal string */
3254 key_sv = sv_2mortal(newSVpvs("foo_"));
3255 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3256 key_name = SvPV(key_sv, key_len);
3257 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3260 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3262 sv_setpvs(key_sv, "foo_");
3263 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3264 key_name = SvPV(key_sv, key_len);
3265 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3268 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3270 sv_setpvs(key_sv, "foo_");
3271 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3272 key_name = SvPV(key_sv, key_len);
3273 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3275 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 11111);
3276 check_iv(cophh_fetch_pvs(a, "foo_1", COPHH_KEY_UTF8), 11111);
3277 check_iv(cophh_fetch_pvs(a, "foo_\xaa", 0), 123);
3279 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xaa", COPHH_KEY_UTF8), 123);
3280 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xaa", 0));
3282 sv_setpvs(key_sv, "foo_");
3283 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xaa"));
3284 key_name = SvPV(key_sv, key_len);
3285 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 123);
3286 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3288 check_iv(cophh_fetch_pvs(a, "foo_\xbb", 0), 456);
3290 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xbb", COPHH_KEY_UTF8), 456);
3291 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xbb", 0));
3293 sv_setpvs(key_sv, "foo_");
3294 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3295 key_name = SvPV(key_sv, key_len);
3296 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 456);
3297 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3299 check_iv(cophh_fetch_pvs(a, "foo_\xcc", 0), 789);
3301 check_iv(cophh_fetch_pvs(a, "foo_\xc3\x8c", COPHH_KEY_UTF8), 789);
3302 check_ph(cophh_fetch_pvs(a, "foo_\xc2\x8c", 0));
3304 sv_setpvs(key_sv, "foo_");
3305 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3306 key_name = SvPV(key_sv, key_len);
3307 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 789);
3308 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3311 check_iv(cophh_fetch_pvs(a, "foo_\xd9\xa6", COPHH_KEY_UTF8), 666);
3312 check_ph(cophh_fetch_pvs(a, "foo_\xd9\xa6", 0));
3314 sv_setpvs(key_sv, "foo_");
3315 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3316 key_name = SvPV(key_sv, key_len);
3317 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 666);
3318 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3336 cop = &PL_compiling;
3337 Perl_cop_store_label(aTHX_ cop, "foo", 3, 0);
3338 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3339 if (strNE(label,"foo")) croak("fail # cop_fetch_label label");
3340 if (len != 3) croak("fail # cop_fetch_label len");
3341 if (utf8) croak("fail # cop_fetch_label utf8");
3342 /* SMALL GERMAN UMLAUT A */
3343 Perl_cop_store_label(aTHX_ cop, "fo\xc3\xa4", 4, SVf_UTF8);
3344 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3345 if (strNE(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label");
3346 if (len != 4) croak("fail # cop_fetch_label len");
3347 if (!utf8) croak("fail # cop_fetch_label utf8");
3360 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3361 a = cophh_new_empty();
3362 a = cophh_store_pvs(a, "foo_0", msviv(999), 0);
3363 a = cophh_store_pvs(a, "foo_1", msviv(111), 0);
3364 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3366 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3368 key_sv = sv_2mortal(newSVpvs("foo_"));
3369 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3370 key_name = SvPV(key_sv, key_len);
3371 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3374 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3376 sv_setpvs(key_sv, "foo_");
3377 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3378 key_name = SvPV(key_sv, key_len);
3379 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3382 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3384 sv_setpvs(key_sv, "foo_");
3385 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3386 key_name = SvPV(key_sv, key_len);
3387 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3389 a = cophh_delete_pvs(a, "foo_0", 0);
3390 a = cophh_delete_pvs(a, "foo_2", 0);
3391 RETVAL = cophh_2hv(a, 0);
3402 #define store_hint(KEY, VALUE) \
3403 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), KEY, 1), (VALUE))
3404 #define hint_ok(KEY, EXPECT) \
3405 ((svp = hv_fetchs(GvHV(PL_hintgv), KEY, 0)) && \
3406 (sv = *svp) && SvIV(sv) == (EXPECT) && \
3407 (sv = cop_hints_fetch_pvs(&PL_compiling, KEY, 0)) && \
3408 SvIV(sv) == (EXPECT))
3409 #define check_hint(KEY, EXPECT) \
3410 do { if (!hint_ok(KEY, EXPECT)) croak_fail(); } while(0)
3411 PL_hints |= HINT_LOCALIZE_HH;
3414 PL_hints &= HINT_INTEGER;
3415 store_hint("t0", 123);
3416 store_hint("t1", 456);
3417 if (PL_hints & HINT_INTEGER) croak_fail();
3418 check_hint("t0", 123); check_hint("t1", 456);
3421 if (PL_hints & HINT_INTEGER) croak_fail();
3422 check_hint("t0", 123); check_hint("t1", 456);
3423 PL_hints |= HINT_INTEGER;
3424 store_hint("t0", 321);
3425 if (!(PL_hints & HINT_INTEGER)) croak_fail();
3426 check_hint("t0", 321); check_hint("t1", 456);
3428 if (PL_hints & HINT_INTEGER) croak_fail();
3429 check_hint("t0", 123); check_hint("t1", 456);
3432 if (PL_hints & HINT_INTEGER) croak_fail();
3433 check_hint("t0", 123); check_hint("t1", 456);
3434 store_hint("t1", 654);
3435 if (PL_hints & HINT_INTEGER) croak_fail();
3436 check_hint("t0", 123); check_hint("t1", 654);
3438 if (PL_hints & HINT_INTEGER) croak_fail();
3439 check_hint("t0", 123); check_hint("t1", 456);
3450 PL_hints |= HINT_LOCALIZE_HH;
3453 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), "t0", 1), 123);
3454 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3456 a = newHVhv(GvHV(PL_hintgv));
3458 sv_setiv_mg(*hv_fetchs(a, "t0", 1), 456);
3459 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3461 b = hv_copy_hints_hv(a);
3463 sv_setiv_mg(*hv_fetchs(b, "t0", 1), 789);
3464 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 789)
3473 #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv))
3474 #define check_op(o, expect) \
3476 if (strNE(test_op_list_describe(o), (expect))) \
3477 croak("fail %s %s", test_op_list_describe(o), (expect)); \
3479 a = op_append_elem(OP_LIST, NULL, NULL);
3481 a = op_append_elem(OP_LIST, iv_op(1), a);
3482 check_op(a, "const(1).");
3483 a = op_append_elem(OP_LIST, NULL, a);
3484 check_op(a, "const(1).");
3485 a = op_append_elem(OP_LIST, a, iv_op(2));
3486 check_op(a, "list[pushmark.const(1).const(2).]");
3487 a = op_append_elem(OP_LIST, a, iv_op(3));
3488 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3489 a = op_append_elem(OP_LIST, a, NULL);
3490 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3491 a = op_append_elem(OP_LIST, NULL, a);
3492 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3493 a = op_append_elem(OP_LIST, iv_op(4), a);
3494 check_op(a, "list[pushmark.const(4)."
3495 "list[pushmark.const(1).const(2).const(3).]]");
3496 a = op_append_elem(OP_LIST, a, iv_op(5));
3497 check_op(a, "list[pushmark.const(4)."
3498 "list[pushmark.const(1).const(2).const(3).]const(5).]");
3499 a = op_append_elem(OP_LIST, a,
3500 op_append_elem(OP_LIST, iv_op(7), iv_op(6)));
3501 check_op(a, "list[pushmark.const(4)."
3502 "list[pushmark.const(1).const(2).const(3).]const(5)."
3503 "list[pushmark.const(7).const(6).]]");
3505 a = op_append_elem(OP_LINESEQ, iv_op(1), iv_op(2));
3506 check_op(a, "lineseq[const(1).const(2).]");
3507 a = op_append_elem(OP_LINESEQ, a, iv_op(3));
3508 check_op(a, "lineseq[const(1).const(2).const(3).]");
3510 a = op_append_elem(OP_LINESEQ,
3511 op_append_elem(OP_LIST, iv_op(1), iv_op(2)),
3513 check_op(a, "lineseq[list[pushmark.const(1).const(2).]const(3).]");
3515 a = op_prepend_elem(OP_LIST, NULL, NULL);
3517 a = op_prepend_elem(OP_LIST, a, iv_op(1));
3518 check_op(a, "const(1).");
3519 a = op_prepend_elem(OP_LIST, a, NULL);
3520 check_op(a, "const(1).");
3521 a = op_prepend_elem(OP_LIST, iv_op(2), a);
3522 check_op(a, "list[pushmark.const(2).const(1).]");
3523 a = op_prepend_elem(OP_LIST, iv_op(3), a);
3524 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3525 a = op_prepend_elem(OP_LIST, NULL, a);
3526 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3527 a = op_prepend_elem(OP_LIST, a, NULL);
3528 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3529 a = op_prepend_elem(OP_LIST, a, iv_op(4));
3530 check_op(a, "list[pushmark."
3531 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3532 a = op_prepend_elem(OP_LIST, iv_op(5), a);
3533 check_op(a, "list[pushmark.const(5)."
3534 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3535 a = op_prepend_elem(OP_LIST,
3536 op_prepend_elem(OP_LIST, iv_op(6), iv_op(7)), a);
3537 check_op(a, "list[pushmark.list[pushmark.const(6).const(7).]const(5)."
3538 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3540 a = op_prepend_elem(OP_LINESEQ, iv_op(2), iv_op(1));
3541 check_op(a, "lineseq[const(2).const(1).]");
3542 a = op_prepend_elem(OP_LINESEQ, iv_op(3), a);
3543 check_op(a, "lineseq[const(3).const(2).const(1).]");
3545 a = op_prepend_elem(OP_LINESEQ, iv_op(3),
3546 op_prepend_elem(OP_LIST, iv_op(2), iv_op(1)));
3547 check_op(a, "lineseq[const(3).list[pushmark.const(2).const(1).]]");
3549 a = op_append_list(OP_LINESEQ, NULL, NULL);
3551 a = op_append_list(OP_LINESEQ, iv_op(1), a);
3552 check_op(a, "const(1).");
3553 a = op_append_list(OP_LINESEQ, NULL, a);
3554 check_op(a, "const(1).");
3555 a = op_append_list(OP_LINESEQ, a, iv_op(2));
3556 check_op(a, "lineseq[const(1).const(2).]");
3557 a = op_append_list(OP_LINESEQ, a, iv_op(3));
3558 check_op(a, "lineseq[const(1).const(2).const(3).]");
3559 a = op_append_list(OP_LINESEQ, iv_op(4), a);
3560 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3561 a = op_append_list(OP_LINESEQ, a, NULL);
3562 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3563 a = op_append_list(OP_LINESEQ, NULL, a);
3564 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3565 a = op_append_list(OP_LINESEQ, a,
3566 op_append_list(OP_LINESEQ, iv_op(5), iv_op(6)));
3567 check_op(a, "lineseq[const(4).const(1).const(2).const(3)."
3568 "const(5).const(6).]");
3570 a = op_append_list(OP_LINESEQ,
3571 op_append_list(OP_LINESEQ, iv_op(1), iv_op(2)),
3572 op_append_list(OP_LIST, iv_op(3), iv_op(4)));
3573 check_op(a, "lineseq[const(1).const(2)."
3574 "list[pushmark.const(3).const(4).]]");
3576 a = op_append_list(OP_LINESEQ,
3577 op_append_list(OP_LIST, iv_op(1), iv_op(2)),
3578 op_append_list(OP_LINESEQ, iv_op(3), iv_op(4)));
3579 check_op(a, "lineseq[list[pushmark.const(1).const(2).]"
3580 "const(3).const(4).]");
3589 #define check_ll(o, expect) \
3591 if (strNE(test_op_linklist_describe(o), (expect))) \
3592 croak("fail %s %s", test_op_linklist_describe(o), (expect)); \
3595 check_ll(o, ".const1");
3598 o = mkUNOP(OP_NOT, iv_op(1));
3599 check_ll(o, ".const1.not");
3602 o = mkUNOP(OP_NOT, mkUNOP(OP_NEGATE, iv_op(1)));
3603 check_ll(o, ".const1.negate.not");
3606 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3607 check_ll(o, ".const1.const2.add");
3610 o = mkBINOP(OP_ADD, mkUNOP(OP_NOT, iv_op(1)), iv_op(2));
3611 check_ll(o, ".const1.not.const2.add");
3614 o = mkUNOP(OP_NOT, mkBINOP(OP_ADD, iv_op(1), iv_op(2)));
3615 check_ll(o, ".const1.const2.add.not");
3618 o = mkLISTOP(OP_LINESEQ, iv_op(1), iv_op(2), iv_op(3));
3619 check_ll(o, ".const1.const2.const3.lineseq");
3622 o = mkLISTOP(OP_LINESEQ,
3623 mkBINOP(OP_ADD, iv_op(1), iv_op(2)),
3624 mkUNOP(OP_NOT, iv_op(3)),
3625 mkLISTOP(OP_SUBSTR, iv_op(4), iv_op(5), iv_op(6)));
3626 check_ll(o, ".const1.const2.add.const3.not"
3627 ".const4.const5.const6.substr.lineseq");
3630 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3632 o = mkBINOP(OP_SUBTRACT, o, iv_op(3));
3633 check_ll(o, ".const1.const2.add.const3.subtract");
3643 av_clear(MY_CXT.peep_recorder);
3644 av_clear(MY_CXT.rpeep_recorder);
3645 MY_CXT.peep_recording = 1;
3652 MY_CXT.peep_recording = 0;
3659 RETVAL = newRV_inc((SV *)MY_CXT.peep_recorder);
3668 RETVAL = newRV_inc((SV *)MY_CXT.rpeep_recorder);
3674 multicall_each: call a sub for each item in the list. Used to test MULTICALL
3679 multicall_each(block,...)
3688 I32 gimme = G_SCALAR;
3689 SV **args = &PL_stack_base[ax];
3695 cv = sv_2cv(block, &stash, &gv, 0);
3697 croak("multicall_each: not a subroutine reference");
3700 SAVESPTR(GvSV(PL_defgv));
3702 for(index = 1 ; index < items ; index++) {
3703 GvSV(PL_defgv) = args[index];
3712 multicall_return(): call the passed sub once in the specificed context
3713 and return whatever it returns
3718 multicall_return(block, context)
3728 I32 gimme = context;
3734 cv = sv_2cv(block, &stash, &gv, 0);
3736 croak("multicall_return not a subroutine reference");
3742 /* copy returned values into an array so they're not freed during
3753 av_push(av, SvREFCNT_inc(TOPs));
3757 for (p = PL_stack_base + 1; p <= SP; p++)
3758 av_push(av, SvREFCNT_inc(*p));
3764 size = AvFILLp(av) + 1;
3766 for (i = 0; i < size; i++)
3767 ST(i) = *av_fetch(av, i, FALSE);
3768 sv_2mortal((SV*)av);
3779 PerlInterpreter *interp = aTHX; /* The original interpreter */
3780 PerlInterpreter *interp_dup; /* The duplicate interpreter */
3781 int oldscope = 1; /* We are responsible for all scopes */
3783 interp_dup = perl_clone(interp, CLONEf_COPY_STACKS | CLONEf_CLONE_HOST );
3785 /* destroy old perl */
3786 PERL_SET_CONTEXT(interp);
3788 POPSTACK_TO(PL_mainstack);
3789 if (cxstack_ix >= 0) {
3791 cx_popblock(cxstack);
3794 PL_scopestack_ix = oldscope;
3797 perl_destruct(interp);
3800 /* switch to new perl */
3801 PERL_SET_CONTEXT(interp_dup);
3803 /* continue after 'clone_with_stack' */
3804 if (interp_dup->Iop)
3805 interp_dup->Iop = interp_dup->Iop->op_next;
3807 /* run with new perl */
3808 Perl_runops_standard(interp_dup);
3810 /* We may have additional unclosed scopes if fork() was called
3811 * from within a BEGIN block. See perlfork.pod for more details.
3812 * We cannot clean up these other scopes because they belong to a
3813 * different interpreter, but we also cannot leave PL_scopestack_ix
3814 * dangling because that can trigger an assertion in perl_destruct().
3816 if (PL_scopestack_ix > oldscope) {
3817 PL_scopestack[oldscope-1] = PL_scopestack[PL_scopestack_ix-1];
3818 PL_scopestack_ix = oldscope;
3821 perl_destruct(interp_dup);
3822 perl_free(interp_dup);
3824 /* call the real 'exit' not PerlProc_exit */
3829 #endif /* USE_ITHREDS */
3832 take_svref(SVREF sv)
3834 RETVAL = newRV_inc(sv);
3841 RETVAL = newRV_inc((SV*)av);
3848 RETVAL = newRV_inc((SV*)hv);
3856 RETVAL = newRV_inc((SV*)cv);
3866 stash = gv_stashpv("XS::APItest::TempLv", 0);
3868 meth = hv_fetchs(stash, "make_temp_mg_lv", 0);
3870 croak("lost method 'make_temp_mg_lv'");
3877 hintkey_rpn_sv = newSVpvs_share("XS::APItest/rpn");
3878 hintkey_calcrpn_sv = newSVpvs_share("XS::APItest/calcrpn");
3879 hintkey_stufftest_sv = newSVpvs_share("XS::APItest/stufftest");
3880 hintkey_swaptwostmts_sv = newSVpvs_share("XS::APItest/swaptwostmts");
3881 hintkey_looprest_sv = newSVpvs_share("XS::APItest/looprest");
3882 hintkey_scopelessblock_sv = newSVpvs_share("XS::APItest/scopelessblock");
3883 hintkey_stmtasexpr_sv = newSVpvs_share("XS::APItest/stmtasexpr");
3884 hintkey_stmtsasexpr_sv = newSVpvs_share("XS::APItest/stmtsasexpr");
3885 hintkey_loopblock_sv = newSVpvs_share("XS::APItest/loopblock");
3886 hintkey_blockasexpr_sv = newSVpvs_share("XS::APItest/blockasexpr");
3887 hintkey_swaplabel_sv = newSVpvs_share("XS::APItest/swaplabel");
3888 hintkey_labelconst_sv = newSVpvs_share("XS::APItest/labelconst");
3889 hintkey_arrayfullexpr_sv = newSVpvs_share("XS::APItest/arrayfullexpr");
3890 hintkey_arraylistexpr_sv = newSVpvs_share("XS::APItest/arraylistexpr");
3891 hintkey_arraytermexpr_sv = newSVpvs_share("XS::APItest/arraytermexpr");
3892 hintkey_arrayarithexpr_sv = newSVpvs_share("XS::APItest/arrayarithexpr");
3893 hintkey_arrayexprflags_sv = newSVpvs_share("XS::APItest/arrayexprflags");
3894 hintkey_DEFSV_sv = newSVpvs_share("XS::APItest/DEFSV");
3895 hintkey_with_vars_sv = newSVpvs_share("XS::APItest/with_vars");
3896 hintkey_join_with_space_sv = newSVpvs_share("XS::APItest/join_with_space");
3897 wrap_keyword_plugin(my_keyword_plugin, &next_keyword_plugin);
3901 establish_cleanup(...)
3904 PERL_UNUSED_VAR(items);
3905 croak("establish_cleanup called as a function");
3909 CV *estcv = get_cv("XS::APItest::establish_cleanup", 0);
3910 cv_set_call_checker(estcv, THX_ck_entersub_establish_cleanup, (SV*)estcv);
3917 PERL_UNUSED_VAR(items);
3918 croak("postinc called as a function");
3923 filter_add(filter_call, NULL);
3927 CV *asscv = get_cv("XS::APItest::postinc", 0);
3928 cv_set_call_checker(asscv, THX_ck_entersub_postinc, (SV*)asscv);
3936 newRV_noinc(newSV(0)),
3937 gv_stashpvs("XS::APItest::TempObj",GV_ADD)
3938 ); /* Package defined in test script */
3943 fill_hash_with_nulls(HV *hv)
3947 for(; i < 1000; ++i) {
3948 HE *entry = hv_fetch_ent(hv, sv_2mortal(newSVuv(i)), 1, 0);
3949 SvREFCNT_dec(HeVAL(entry));
3950 HeVAL(entry) = NULL;
3956 RETVAL = newHVhv(hv);
3963 RETVAL = SvIsCOW(sv);
3971 PERL_UNUSED_VAR(items);
3972 croak("pad_scalar called as a function");
3976 CV *pscv = get_cv("XS::APItest::pad_scalar", 0);
3977 cv_set_call_checker(pscv, THX_ck_entersub_pad_scalar, (SV*)pscv);
3981 fetch_pad_names( cv )
3985 PADNAMELIST *pad_namelist;
3986 AV *retav = newAV();
3988 pad_namelist = PadlistNAMES(CvPADLIST(cv));
3990 for ( i = PadnamelistMAX(pad_namelist); i >= 0; i-- ) {
3991 PADNAME* name = PadnamelistARRAY(pad_namelist)[i];
3993 if (PadnameLEN(name)) {
3994 av_push(retav, newSVpadname(name));
3997 RETVAL = newRV_noinc((SV*)retav);
4009 u = find_rundefsv();
4010 pv = (U8*)SvPV(u, bytelen);
4011 RETVAL = SvUTF8(u) ? utf8_length(pv, pv+bytelen) : bytelen;
4018 (void)SvPV_nolen(sv);
4023 RETVAL = hv && HvENAME(hv)
4025 HvENAME(hv),HvENAMELEN(hv),
4026 (HvENAMEUTF8(hv) ? SVf_UTF8 : 0)
4033 xs_cmp(int a, int b)
4035 /* Odd sorting (odd numbers first), to make sure we are actually
4037 RETVAL = a % 2 != b % 2
4039 : a < b ? -1 : a == b ? 0 : 1;
4044 xs_cmp_undef(SV *a, SV *b)
4048 RETVAL = &PL_sv_undef;
4055 RETVAL = SvPVbyte_nolen(sv);
4062 RETVAL = SvPVutf8_nolen(sv);
4069 wrap_op_checker(OP_ADD, addissub_myck_add, &addissub_nxck_add);
4072 setup_rv2cv_addunderbar()
4074 wrap_op_checker(OP_RV2CV, my_ck_rv2cv, &old_ck_rv2cv);
4079 test_alloccopstash()
4081 RETVAL = PL_stashpad[alloccopstash(PL_defstash)] == PL_defstash;
4088 test_newFOROP_without_slab()
4091 const I32 floor = start_subparse(0,0);
4093 /* The slab allocator does not like CvROOT being set. */
4094 CvROOT(PL_compcv) = (OP *)1;
4095 o = newFOROP(0, 0, newOP(OP_PUSHMARK, 0), 0, 0);
4096 #ifdef PERL_OP_PARENT
4097 if (cLOOPx(cUNOPo->op_first)->op_last->op_sibparent
4098 != cUNOPo->op_first)
4100 Perl_warn(aTHX_ "Op parent pointer is stale");
4105 /* If we do not crash before returning, the test passes. */
4108 CvROOT(PL_compcv) = NULL;
4109 SvREFCNT_dec(PL_compcv);
4115 # provide access to CALLREGEXEC, except replace pointers within the
4116 # string with offsets from the start of the string
4119 callregexec(SV *prog, STRLEN stringarg, STRLEN strend, I32 minend, SV *sv, U32 nosave)
4126 strbeg = SvPV_force(sv, len);
4127 RETVAL = CALLREGEXEC((REGEXP *)prog,
4140 lexical_import(SV *name, CV *cv)
4147 "lexical_import can only be called at compile time");
4148 pl = CvPADLIST(PL_compcv);
4150 SAVESPTR(PL_comppad_name); PL_comppad_name = PadlistNAMES(pl);
4151 SAVESPTR(PL_comppad); PL_comppad = PadlistARRAY(pl)[1];
4152 SAVESPTR(PL_curpad); PL_curpad = PadARRAY(PL_comppad);
4153 off = pad_add_name_sv(sv_2mortal(newSVpvf("&%" SVf,name)),
4154 padadd_STATE, 0, 0);
4155 SvREFCNT_dec(PL_curpad[off]);
4156 PL_curpad[off] = SvREFCNT_inc(cv);
4162 sv_mortalcopy(SV *sv)
4164 RETVAL = SvREFCNT_inc(sv_mortalcopy(sv));
4172 alias_av(AV *av, IV ix, SV *sv)
4174 av_store(av, ix, SvREFCNT_inc(sv));
4177 cv_name(SVREF ref, ...)
4179 RETVAL = SvREFCNT_inc(cv_name((CV *)ref,
4180 items>1 && ST(1) != &PL_sv_undef
4183 items>2 ? SvUV(ST(2)) : 0));
4188 sv_catpvn(SV *sv, SV *sv2)
4192 const char *s = SvPV(sv2,len);
4193 sv_catpvn_flags(sv,s,len, SvUTF8(sv2) ? SV_CATUTF8 : SV_CATBYTES);
4200 OP *o = newLISTOP(OP_CUSTOM, 0, NULL, NULL);
4202 o = newOP(OP_CUSTOM, 0);
4204 o = newUNOP(OP_CUSTOM, 0, NULL);
4206 o = newUNOP_AUX(OP_CUSTOM, 0, NULL, NULL);
4208 o = newMETHOP(OP_CUSTOM, 0, newOP(OP_NULL,0));
4210 o = newMETHOP_named(OP_CUSTOM, 0, newSV(0));
4212 o = newBINOP(OP_CUSTOM, 0, NULL, NULL);
4214 o = newPMOP(OP_CUSTOM, 0);
4216 o = newSVOP(OP_CUSTOM, 0, newSV(0));
4220 lex_start(NULL, NULL, 0);
4222 I32 ix = start_subparse(FALSE,0);
4223 o = newPADOP(OP_CUSTOM, 0, newSV(0));
4229 o = newPVOP(OP_CUSTOM, 0, NULL);
4231 o = newLOGOP(OP_CUSTOM, 0, newOP(OP_NULL,0), newOP(OP_NULL,0));
4233 o = newLOOPEX(OP_CUSTOM, newOP(OP_NULL,0));
4241 test_sv_catpvf(SV *fmtsv)
4246 fmt = SvPV_nolen(fmtsv);
4247 sv = sv_2mortal(newSVpvn("", 0));
4248 sv_catpvf(sv, fmt, 5, 6, 7, 8);
4251 load_module(flags, name, ...)
4256 Perl_load_module(aTHX_ flags, SvREFCNT_inc(name), NULL);
4257 } else if (items == 3) {
4258 Perl_load_module(aTHX_ flags, SvREFCNT_inc(name), SvREFCNT_inc(ST(2)));
4260 Perl_croak(aTHX_ "load_module can't yet support %" IVdf " items",
4264 string_without_null(SV *sv)
4268 const char *s = SvPV(sv, len);
4269 RETVAL = newSVpvn_flags(s, len, SvUTF8(sv));
4270 *SvEND(RETVAL) = 0xff;
4280 const char *s = SvPV(sv, len);
4281 RETVAL = get_cvn_flags(s, len, 0);
4287 get_cv_flags(SV *sv, UV flags)
4291 const char *s = SvPV(sv, len);
4292 RETVAL = get_cvn_flags(s, len, flags);
4297 MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest
4303 SV* class_and_method;
4305 PERL_UNUSED_ARG(items);
4306 class_and_method = GvSV(CvGV(cv));
4307 comms = get_sv("main::the_method", 1);
4308 if (class_and_method == NULL) {
4310 } else if (!SvOK(class_and_method)) {
4312 } else if (!SvPOK(class_and_method)) {
4315 sv_setsv(comms, class_and_method);
4321 MODULE = XS::APItest PACKAGE = XS::APItest::Magic
4326 sv_magic_foo(SV *sv, SV *thingy)
4330 sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo, (const char *)thingy, 0);
4337 MAGIC *mg = mg_findext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4338 RETVAL = mg ? SvREFCNT_inc((SV *)mg->mg_ptr) : &PL_sv_undef;
4343 sv_unmagic_foo(SV *sv)
4347 sv_unmagicext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4350 sv_magic(SV *sv, SV *thingy)
4352 sv_magic(SvRV(sv), NULL, PERL_MAGIC_ext, (const char *)thingy, 0);
4360 #define test_get_this_vtable(name) \
4361 want = (MGVTBL*)CAT2(&PL_vtbl_, name); \
4362 have = get_vtbl(CAT2(want_vtbl_, name)); \
4364 croak("fail %p!=%p for get_vtbl(want_vtbl_" STRINGIFY(name) ") at " __FILE__ " line %d", have, want, __LINE__)
4366 test_get_this_vtable(sv);
4367 test_get_this_vtable(env);
4368 test_get_this_vtable(envelem);
4369 test_get_this_vtable(sigelem);
4370 test_get_this_vtable(pack);
4371 test_get_this_vtable(packelem);
4372 test_get_this_vtable(dbline);
4373 test_get_this_vtable(isa);
4374 test_get_this_vtable(isaelem);
4375 test_get_this_vtable(arylen);
4376 test_get_this_vtable(mglob);
4377 test_get_this_vtable(nkeys);
4378 test_get_this_vtable(taint);
4379 test_get_this_vtable(substr);
4380 test_get_this_vtable(vec);
4381 test_get_this_vtable(pos);
4382 test_get_this_vtable(bm);
4383 test_get_this_vtable(fm);
4384 test_get_this_vtable(uvar);
4385 test_get_this_vtable(defelem);
4386 test_get_this_vtable(regexp);
4387 test_get_this_vtable(regdata);
4388 test_get_this_vtable(regdatum);
4389 #ifdef USE_LOCALE_COLLATE
4390 test_get_this_vtable(collxfrm);
4392 test_get_this_vtable(backref);
4393 test_get_this_vtable(utf8);
4395 RETVAL = PTR2UV(get_vtbl(-1));
4400 # attach ext magic to the SV pointed to by rsv that only has set magic,
4401 # where that magic's job is to increment thingy
4404 sv_magic_myset(SV *rsv, SV *thingy)
4406 sv_magicext(SvRV(rsv), NULL, PERL_MAGIC_ext, &vtbl_myset,
4407 (const char *)thingy, 0);
4412 test_isBLANK_uni(UV ord)
4414 RETVAL = isBLANK_uni(ord);
4419 test_isBLANK_uvchr(UV ord)
4421 RETVAL = isBLANK_uvchr(ord);
4426 test_isBLANK_LC_uvchr(UV ord)
4428 RETVAL = isBLANK_LC_uvchr(ord);
4433 test_isBLANK(UV ord)
4435 RETVAL = isBLANK(ord);
4440 test_isBLANK_A(UV ord)
4442 RETVAL = isBLANK_A(ord);
4447 test_isBLANK_L1(UV ord)
4449 RETVAL = isBLANK_L1(ord);
4454 test_isBLANK_LC(UV ord)
4456 RETVAL = isBLANK_LC(ord);
4461 test_isBLANK_utf8(unsigned char * p, int type)
4463 const unsigned char * e;
4466 /* In this function and those that follow, the boolean 'type'
4467 * indicates if to pass a malformed UTF-8 string to the tested macro
4468 * (malformed by making it too short) */
4470 e = p + UTF8SKIP(p) - type;
4471 RETVAL = isBLANK_utf8_safe(p, e);
4474 RETVAL = isBLANK_utf8(p);
4480 test_isBLANK_LC_utf8(unsigned char * p, int type)
4482 const unsigned char * e;
4485 e = p + UTF8SKIP(p) - type;
4486 RETVAL = isBLANK_LC_utf8_safe(p, e);
4489 RETVAL = isBLANK_LC_utf8(p);
4495 test_isVERTWS_uni(UV ord)
4497 RETVAL = isVERTWS_uni(ord);
4502 test_isVERTWS_uvchr(UV ord)
4504 RETVAL = isVERTWS_uvchr(ord);
4509 test_isVERTWS_utf8(unsigned char * p, int type)
4511 const unsigned char * e;
4514 e = p + UTF8SKIP(p) - type;
4515 RETVAL = isVERTWS_utf8_safe(p, e);
4518 RETVAL = isVERTWS_utf8(p);
4524 test_isUPPER_uni(UV ord)
4526 RETVAL = isUPPER_uni(ord);
4531 test_isUPPER_uvchr(UV ord)
4533 RETVAL = isUPPER_uvchr(ord);
4538 test_isUPPER_LC_uvchr(UV ord)
4540 RETVAL = isUPPER_LC_uvchr(ord);
4545 test_isUPPER(UV ord)
4547 RETVAL = isUPPER(ord);
4552 test_isUPPER_A(UV ord)
4554 RETVAL = isUPPER_A(ord);
4559 test_isUPPER_L1(UV ord)
4561 RETVAL = isUPPER_L1(ord);
4566 test_isUPPER_LC(UV ord)
4568 RETVAL = isUPPER_LC(ord);
4573 test_isUPPER_utf8(unsigned char * p, int type)
4575 const unsigned char * e;
4578 e = p + UTF8SKIP(p) - type;
4579 RETVAL = isUPPER_utf8_safe(p, e);
4582 RETVAL = isUPPER_utf8(p);
4588 test_isUPPER_LC_utf8(unsigned char * p, int type)
4590 const unsigned char * e;
4593 e = p + UTF8SKIP(p) - type;
4594 RETVAL = isUPPER_LC_utf8_safe(p, e);
4597 RETVAL = isUPPER_LC_utf8(p);
4603 test_isLOWER_uni(UV ord)
4605 RETVAL = isLOWER_uni(ord);
4610 test_isLOWER_uvchr(UV ord)
4612 RETVAL = isLOWER_uvchr(ord);
4617 test_isLOWER_LC_uvchr(UV ord)
4619 RETVAL = isLOWER_LC_uvchr(ord);
4624 test_isLOWER(UV ord)
4626 RETVAL = isLOWER(ord);
4631 test_isLOWER_A(UV ord)
4633 RETVAL = isLOWER_A(ord);
4638 test_isLOWER_L1(UV ord)
4640 RETVAL = isLOWER_L1(ord);
4645 test_isLOWER_LC(UV ord)
4647 RETVAL = isLOWER_LC(ord);
4652 test_isLOWER_utf8(unsigned char * p, int type)
4654 const unsigned char * e;
4657 e = p + UTF8SKIP(p) - type;
4658 RETVAL = isLOWER_utf8_safe(p, e);
4661 RETVAL = isLOWER_utf8(p);
4667 test_isLOWER_LC_utf8(unsigned char * p, int type)
4669 const unsigned char * e;
4672 e = p + UTF8SKIP(p) - type;
4673 RETVAL = isLOWER_LC_utf8_safe(p, e);
4676 RETVAL = isLOWER_LC_utf8(p);
4682 test_isALPHA_uni(UV ord)
4684 RETVAL = isALPHA_uni(ord);
4689 test_isALPHA_uvchr(UV ord)
4691 RETVAL = isALPHA_uvchr(ord);
4696 test_isALPHA_LC_uvchr(UV ord)
4698 RETVAL = isALPHA_LC_uvchr(ord);
4703 test_isALPHA(UV ord)
4705 RETVAL = isALPHA(ord);
4710 test_isALPHA_A(UV ord)
4712 RETVAL = isALPHA_A(ord);
4717 test_isALPHA_L1(UV ord)
4719 RETVAL = isALPHA_L1(ord);
4724 test_isALPHA_LC(UV ord)
4726 RETVAL = isALPHA_LC(ord);
4731 test_isALPHA_utf8(unsigned char * p, int type)
4733 const unsigned char * e;
4736 e = p + UTF8SKIP(p) - type;
4737 RETVAL = isALPHA_utf8_safe(p, e);
4740 RETVAL = isALPHA_utf8(p);
4746 test_isALPHA_LC_utf8(unsigned char * p, int type)
4748 const unsigned char * e;
4751 e = p + UTF8SKIP(p) - type;
4752 RETVAL = isALPHA_LC_utf8_safe(p, e);
4755 RETVAL = isALPHA_LC_utf8(p);
4761 test_isWORDCHAR_uni(UV ord)
4763 RETVAL = isWORDCHAR_uni(ord);
4768 test_isWORDCHAR_uvchr(UV ord)
4770 RETVAL = isWORDCHAR_uvchr(ord);
4775 test_isWORDCHAR_LC_uvchr(UV ord)
4777 RETVAL = isWORDCHAR_LC_uvchr(ord);
4782 test_isWORDCHAR(UV ord)
4784 RETVAL = isWORDCHAR(ord);
4789 test_isWORDCHAR_A(UV ord)
4791 RETVAL = isWORDCHAR_A(ord);
4796 test_isWORDCHAR_L1(UV ord)
4798 RETVAL = isWORDCHAR_L1(ord);
4803 test_isWORDCHAR_LC(UV ord)
4805 RETVAL = isWORDCHAR_LC(ord);
4810 test_isWORDCHAR_utf8(unsigned char * p, int type)
4812 const unsigned char * e;
4815 e = p + UTF8SKIP(p) - type;
4816 RETVAL = isWORDCHAR_utf8_safe(p, e);
4819 RETVAL = isWORDCHAR_utf8(p);
4825 test_isWORDCHAR_LC_utf8(unsigned char * p, int type)
4827 const unsigned char * e;
4830 e = p + UTF8SKIP(p) - type;
4831 RETVAL = isWORDCHAR_LC_utf8_safe(p, e);
4834 RETVAL = isWORDCHAR_LC_utf8(p);
4840 test_isALPHANUMERIC_uni(UV ord)
4842 RETVAL = isALPHANUMERIC_uni(ord);
4847 test_isALPHANUMERIC_uvchr(UV ord)
4849 RETVAL = isALPHANUMERIC_uvchr(ord);
4854 test_isALPHANUMERIC_LC_uvchr(UV ord)
4856 RETVAL = isALPHANUMERIC_LC_uvchr(ord);
4861 test_isALPHANUMERIC(UV ord)
4863 RETVAL = isALPHANUMERIC(ord);
4868 test_isALPHANUMERIC_A(UV ord)
4870 RETVAL = isALPHANUMERIC_A(ord);
4875 test_isALPHANUMERIC_L1(UV ord)
4877 RETVAL = isALPHANUMERIC_L1(ord);
4882 test_isALPHANUMERIC_LC(UV ord)
4884 RETVAL = isALPHANUMERIC_LC(ord);
4889 test_isALPHANUMERIC_utf8(unsigned char * p, int type)
4891 const unsigned char * e;
4894 e = p + UTF8SKIP(p) - type;
4895 RETVAL = isALPHANUMERIC_utf8_safe(p, e);
4898 RETVAL = isALPHANUMERIC_utf8(p);
4904 test_isALPHANUMERIC_LC_utf8(unsigned char * p, int type)
4906 const unsigned char * e;
4909 e = p + UTF8SKIP(p) - type;
4910 RETVAL = isALPHANUMERIC_LC_utf8_safe(p, e);
4913 RETVAL = isALPHANUMERIC_LC_utf8(p);
4919 test_isALNUM(UV ord)
4921 RETVAL = isALNUM(ord);
4926 test_isALNUM_uni(UV ord)
4928 RETVAL = isALNUM_uni(ord);
4933 test_isALNUM_LC_uvchr(UV ord)
4935 RETVAL = isALNUM_LC_uvchr(ord);
4940 test_isALNUM_LC(UV ord)
4942 RETVAL = isALNUM_LC(ord);
4947 test_isALNUM_utf8(unsigned char * p, int type)
4949 const unsigned char * e;
4952 e = p + UTF8SKIP(p) - type;
4953 RETVAL = isWORDCHAR_utf8_safe(p, e);
4956 RETVAL = isWORDCHAR_utf8(p);
4962 test_isALNUM_LC_utf8(unsigned char * p, int type)
4964 const unsigned char * e;
4967 e = p + UTF8SKIP(p) - type;
4968 RETVAL = isWORDCHAR_LC_utf8_safe(p, e);
4971 RETVAL = isWORDCHAR_LC_utf8(p);
4977 test_isDIGIT_uni(UV ord)
4979 RETVAL = isDIGIT_uni(ord);
4984 test_isDIGIT_uvchr(UV ord)
4986 RETVAL = isDIGIT_uvchr(ord);
4991 test_isDIGIT_LC_uvchr(UV ord)
4993 RETVAL = isDIGIT_LC_uvchr(ord);
4998 test_isDIGIT_utf8(unsigned char * p, int type)
5000 const unsigned char * e;
5003 e = p + UTF8SKIP(p) - type;
5004 RETVAL = isDIGIT_utf8_safe(p, e);
5007 RETVAL = isDIGIT_utf8(p);
5013 test_isDIGIT_LC_utf8(unsigned char * p, int type)
5015 const unsigned char * e;
5018 e = p + UTF8SKIP(p) - type;
5019 RETVAL = isDIGIT_LC_utf8_safe(p, e);
5022 RETVAL = isDIGIT_LC_utf8(p);
5028 test_isDIGIT(UV ord)
5030 RETVAL = isDIGIT(ord);
5035 test_isDIGIT_A(UV ord)
5037 RETVAL = isDIGIT_A(ord);
5042 test_isDIGIT_L1(UV ord)
5044 RETVAL = isDIGIT_L1(ord);
5049 test_isDIGIT_LC(UV ord)
5051 RETVAL = isDIGIT_LC(ord);
5056 test_isOCTAL(UV ord)
5058 RETVAL = isOCTAL(ord);
5063 test_isOCTAL_A(UV ord)
5065 RETVAL = isOCTAL_A(ord);
5070 test_isOCTAL_L1(UV ord)
5072 RETVAL = isOCTAL_L1(ord);
5077 test_isIDFIRST_uni(UV ord)
5079 RETVAL = isIDFIRST_uni(ord);
5084 test_isIDFIRST_uvchr(UV ord)
5086 RETVAL = isIDFIRST_uvchr(ord);
5091 test_isIDFIRST_LC_uvchr(UV ord)
5093 RETVAL = isIDFIRST_LC_uvchr(ord);
5098 test_isIDFIRST(UV ord)
5100 RETVAL = isIDFIRST(ord);
5105 test_isIDFIRST_A(UV ord)
5107 RETVAL = isIDFIRST_A(ord);
5112 test_isIDFIRST_L1(UV ord)
5114 RETVAL = isIDFIRST_L1(ord);
5119 test_isIDFIRST_LC(UV ord)
5121 RETVAL = isIDFIRST_LC(ord);
5126 test_isIDFIRST_utf8(unsigned char * p, int type)
5128 const unsigned char * e;
5131 e = p + UTF8SKIP(p) - type;
5132 RETVAL = isIDFIRST_utf8_safe(p, e);
5135 RETVAL = isIDFIRST_utf8(p);
5141 test_isIDFIRST_LC_utf8(unsigned char * p, int type)
5143 const unsigned char * e;
5146 e = p + UTF8SKIP(p) - type;
5147 RETVAL = isIDFIRST_LC_utf8_safe(p, e);
5150 RETVAL = isIDFIRST_LC_utf8(p);
5156 test_isIDCONT_uni(UV ord)
5158 RETVAL = isIDCONT_uni(ord);
5163 test_isIDCONT_uvchr(UV ord)
5165 RETVAL = isIDCONT_uvchr(ord);
5170 test_isIDCONT_LC_uvchr(UV ord)
5172 RETVAL = isIDCONT_LC_uvchr(ord);
5177 test_isIDCONT(UV ord)
5179 RETVAL = isIDCONT(ord);
5184 test_isIDCONT_A(UV ord)
5186 RETVAL = isIDCONT_A(ord);
5191 test_isIDCONT_L1(UV ord)
5193 RETVAL = isIDCONT_L1(ord);
5198 test_isIDCONT_LC(UV ord)
5200 RETVAL = isIDCONT_LC(ord);
5205 test_isIDCONT_utf8(unsigned char * p, int type)
5207 const unsigned char * e;
5210 e = p + UTF8SKIP(p) - type;
5211 RETVAL = isIDCONT_utf8_safe(p, e);
5214 RETVAL = isIDCONT_utf8(p);
5220 test_isIDCONT_LC_utf8(unsigned char * p, int type)
5222 const unsigned char * e;
5225 e = p + UTF8SKIP(p) - type;
5226 RETVAL = isIDCONT_LC_utf8_safe(p, e);
5229 RETVAL = isIDCONT_LC_utf8(p);
5235 test_isSPACE_uni(UV ord)
5237 RETVAL = isSPACE_uni(ord);
5242 test_isSPACE_uvchr(UV ord)
5244 RETVAL = isSPACE_uvchr(ord);
5249 test_isSPACE_LC_uvchr(UV ord)
5251 RETVAL = isSPACE_LC_uvchr(ord);
5256 test_isSPACE(UV ord)
5258 RETVAL = isSPACE(ord);
5263 test_isSPACE_A(UV ord)
5265 RETVAL = isSPACE_A(ord);
5270 test_isSPACE_L1(UV ord)
5272 RETVAL = isSPACE_L1(ord);
5277 test_isSPACE_LC(UV ord)
5279 RETVAL = isSPACE_LC(ord);
5284 test_isSPACE_utf8(unsigned char * p, int type)
5286 const unsigned char * e;
5289 e = p + UTF8SKIP(p) - type;
5290 RETVAL = isSPACE_utf8_safe(p, e);
5293 RETVAL = isSPACE_utf8(p);
5299 test_isSPACE_LC_utf8(unsigned char * p, int type)
5301 const unsigned char * e;
5304 e = p + UTF8SKIP(p) - type;
5305 RETVAL = isSPACE_LC_utf8_safe(p, e);
5308 RETVAL = isSPACE_LC_utf8(p);
5314 test_isASCII_uni(UV ord)
5316 RETVAL = isASCII_uni(ord);
5321 test_isASCII_uvchr(UV ord)
5323 RETVAL = isASCII_uvchr(ord);
5328 test_isASCII_LC_uvchr(UV ord)
5330 RETVAL = isASCII_LC_uvchr(ord);
5335 test_isASCII(UV ord)
5337 RETVAL = isASCII(ord);
5342 test_isASCII_A(UV ord)
5344 RETVAL = isASCII_A(ord);
5349 test_isASCII_L1(UV ord)
5351 RETVAL = isASCII_L1(ord);
5356 test_isASCII_LC(UV ord)
5358 RETVAL = isASCII_LC(ord);
5363 test_isASCII_utf8(unsigned char * p, int type)
5365 const unsigned char * e;
5371 e = p + UTF8SKIP(p) - type;
5372 RETVAL = isASCII_utf8_safe(p, e);
5375 RETVAL = isASCII_utf8(p);
5381 test_isASCII_LC_utf8(unsigned char * p, int type)
5383 const unsigned char * e;
5389 e = p + UTF8SKIP(p) - type;
5390 RETVAL = isASCII_LC_utf8_safe(p, e);
5393 RETVAL = isASCII_LC_utf8(p);
5399 test_isCNTRL_uni(UV ord)
5401 RETVAL = isCNTRL_uni(ord);
5406 test_isCNTRL_uvchr(UV ord)
5408 RETVAL = isCNTRL_uvchr(ord);
5413 test_isCNTRL_LC_uvchr(UV ord)
5415 RETVAL = isCNTRL_LC_uvchr(ord);
5420 test_isCNTRL(UV ord)
5422 RETVAL = isCNTRL(ord);
5427 test_isCNTRL_A(UV ord)
5429 RETVAL = isCNTRL_A(ord);
5434 test_isCNTRL_L1(UV ord)
5436 RETVAL = isCNTRL_L1(ord);
5441 test_isCNTRL_LC(UV ord)
5443 RETVAL = isCNTRL_LC(ord);
5448 test_isCNTRL_utf8(unsigned char * p, int type)
5450 const unsigned char * e;
5453 e = p + UTF8SKIP(p) - type;
5454 RETVAL = isCNTRL_utf8_safe(p, e);
5457 RETVAL = isCNTRL_utf8(p);
5463 test_isCNTRL_LC_utf8(unsigned char * p, int type)
5465 const unsigned char * e;
5468 e = p + UTF8SKIP(p) - type;
5469 RETVAL = isCNTRL_LC_utf8_safe(p, e);
5472 RETVAL = isCNTRL_LC_utf8(p);
5478 test_isPRINT_uni(UV ord)
5480 RETVAL = isPRINT_uni(ord);
5485 test_isPRINT_uvchr(UV ord)
5487 RETVAL = isPRINT_uvchr(ord);
5492 test_isPRINT_LC_uvchr(UV ord)
5494 RETVAL = isPRINT_LC_uvchr(ord);
5499 test_isPRINT(UV ord)
5501 RETVAL = isPRINT(ord);
5506 test_isPRINT_A(UV ord)
5508 RETVAL = isPRINT_A(ord);
5513 test_isPRINT_L1(UV ord)
5515 RETVAL = isPRINT_L1(ord);
5520 test_isPRINT_LC(UV ord)
5522 RETVAL = isPRINT_LC(ord);
5527 test_isPRINT_utf8(unsigned char * p, int type)
5529 const unsigned char * e;
5532 e = p + UTF8SKIP(p) - type;
5533 RETVAL = isPRINT_utf8_safe(p, e);
5536 RETVAL = isPRINT_utf8(p);
5542 test_isPRINT_LC_utf8(unsigned char * p, int type)
5544 const unsigned char * e;
5547 e = p + UTF8SKIP(p) - type;
5548 RETVAL = isPRINT_LC_utf8_safe(p, e);
5551 RETVAL = isPRINT_LC_utf8(p);
5557 test_isGRAPH_uni(UV ord)
5559 RETVAL = isGRAPH_uni(ord);
5564 test_isGRAPH_uvchr(UV ord)
5566 RETVAL = isGRAPH_uvchr(ord);
5571 test_isGRAPH_LC_uvchr(UV ord)
5573 RETVAL = isGRAPH_LC_uvchr(ord);
5578 test_isGRAPH(UV ord)
5580 RETVAL = isGRAPH(ord);
5585 test_isGRAPH_A(UV ord)
5587 RETVAL = isGRAPH_A(ord);
5592 test_isGRAPH_L1(UV ord)
5594 RETVAL = isGRAPH_L1(ord);
5599 test_isGRAPH_LC(UV ord)
5601 RETVAL = isGRAPH_LC(ord);
5606 test_isGRAPH_utf8(unsigned char * p, int type)
5608 const unsigned char * e;
5611 e = p + UTF8SKIP(p) - type;
5612 RETVAL = isGRAPH_utf8_safe(p, e);
5615 RETVAL = isGRAPH_utf8(p);
5621 test_isGRAPH_LC_utf8(unsigned char * p, int type)
5623 const unsigned char * e;
5626 e = p + UTF8SKIP(p) - type;
5627 RETVAL = isGRAPH_LC_utf8_safe(p, e);
5630 RETVAL = isGRAPH_LC_utf8(p);
5636 test_isPUNCT_uni(UV ord)
5638 RETVAL = isPUNCT_uni(ord);
5643 test_isPUNCT_uvchr(UV ord)
5645 RETVAL = isPUNCT_uvchr(ord);
5650 test_isPUNCT_LC_uvchr(UV ord)
5652 RETVAL = isPUNCT_LC_uvchr(ord);
5657 test_isPUNCT(UV ord)
5659 RETVAL = isPUNCT(ord);
5664 test_isPUNCT_A(UV ord)
5666 RETVAL = isPUNCT_A(ord);
5671 test_isPUNCT_L1(UV ord)
5673 RETVAL = isPUNCT_L1(ord);
5678 test_isPUNCT_LC(UV ord)
5680 RETVAL = isPUNCT_LC(ord);
5685 test_isPUNCT_utf8(unsigned char * p, int type)
5687 const unsigned char * e;
5690 e = p + UTF8SKIP(p) - type;
5691 RETVAL = isPUNCT_utf8_safe(p, e);
5694 RETVAL = isPUNCT_utf8(p);
5700 test_isPUNCT_LC_utf8(unsigned char * p, int type)
5702 const unsigned char * e;
5705 e = p + UTF8SKIP(p) - type;
5706 RETVAL = isPUNCT_LC_utf8_safe(p, e);
5709 RETVAL = isPUNCT_LC_utf8(p);
5715 test_isXDIGIT_uni(UV ord)
5717 RETVAL = isXDIGIT_uni(ord);
5722 test_isXDIGIT_uvchr(UV ord)
5724 RETVAL = isXDIGIT_uvchr(ord);
5729 test_isXDIGIT_LC_uvchr(UV ord)
5731 RETVAL = isXDIGIT_LC_uvchr(ord);
5736 test_isXDIGIT(UV ord)
5738 RETVAL = isXDIGIT(ord);
5743 test_isXDIGIT_A(UV ord)
5745 RETVAL = isXDIGIT_A(ord);
5750 test_isXDIGIT_L1(UV ord)
5752 RETVAL = isXDIGIT_L1(ord);
5757 test_isXDIGIT_LC(UV ord)
5759 RETVAL = isXDIGIT_LC(ord);
5764 test_isXDIGIT_utf8(unsigned char * p, int type)
5766 const unsigned char * e;
5769 e = p + UTF8SKIP(p) - type;
5770 RETVAL = isXDIGIT_utf8_safe(p, e);
5773 RETVAL = isXDIGIT_utf8(p);
5779 test_isXDIGIT_LC_utf8(unsigned char * p, int type)
5781 const unsigned char * e;
5784 e = p + UTF8SKIP(p) - type;
5785 RETVAL = isXDIGIT_LC_utf8_safe(p, e);
5788 RETVAL = isXDIGIT_LC_utf8(p);
5794 test_isPSXSPC_uni(UV ord)
5796 RETVAL = isPSXSPC_uni(ord);
5801 test_isPSXSPC_uvchr(UV ord)
5803 RETVAL = isPSXSPC_uvchr(ord);
5808 test_isPSXSPC_LC_uvchr(UV ord)
5810 RETVAL = isPSXSPC_LC_uvchr(ord);
5815 test_isPSXSPC(UV ord)
5817 RETVAL = isPSXSPC(ord);
5822 test_isPSXSPC_A(UV ord)
5824 RETVAL = isPSXSPC_A(ord);
5829 test_isPSXSPC_L1(UV ord)
5831 RETVAL = isPSXSPC_L1(ord);
5836 test_isPSXSPC_LC(UV ord)
5838 RETVAL = isPSXSPC_LC(ord);
5843 test_isPSXSPC_utf8(unsigned char * p, int type)
5845 const unsigned char * e;
5848 e = p + UTF8SKIP(p) - type;
5849 RETVAL = isPSXSPC_utf8_safe(p, e);
5852 RETVAL = isPSXSPC_utf8(p);
5858 test_isPSXSPC_LC_utf8(unsigned char * p, int type)
5860 const unsigned char * e;
5863 e = p + UTF8SKIP(p) - type;
5864 RETVAL = isPSXSPC_LC_utf8_safe(p, e);
5867 RETVAL = isPSXSPC_LC_utf8(p);
5873 test_isQUOTEMETA(UV ord)
5875 RETVAL = _isQUOTEMETA(ord);
5880 test_OFFUNISKIP(UV ord)
5882 RETVAL = OFFUNISKIP(ord);
5887 test_OFFUNI_IS_INVARIANT(UV ord)
5889 RETVAL = OFFUNI_IS_INVARIANT(ord);
5894 test_UVCHR_IS_INVARIANT(UV ord)
5896 RETVAL = UVCHR_IS_INVARIANT(ord);
5901 test_UTF8_IS_INVARIANT(char ch)
5903 RETVAL = UTF8_IS_INVARIANT(ch);
5908 test_UVCHR_SKIP(UV ord)
5910 RETVAL = UVCHR_SKIP(ord);
5915 test_UTF8_SKIP(char * ch)
5917 RETVAL = UTF8_SKIP(ch);
5922 test_UTF8_IS_START(char ch)
5924 RETVAL = UTF8_IS_START(ch);
5929 test_UTF8_IS_CONTINUATION(char ch)
5931 RETVAL = UTF8_IS_CONTINUATION(ch);
5936 test_UTF8_IS_CONTINUED(char ch)
5938 RETVAL = UTF8_IS_CONTINUED(ch);
5943 test_UTF8_IS_DOWNGRADEABLE_START(char ch)
5945 RETVAL = UTF8_IS_DOWNGRADEABLE_START(ch);
5950 test_UTF8_IS_ABOVE_LATIN1(char ch)
5952 RETVAL = UTF8_IS_ABOVE_LATIN1(ch);
5957 test_isUTF8_POSSIBLY_PROBLEMATIC(char ch)
5959 RETVAL = isUTF8_POSSIBLY_PROBLEMATIC(ch);
5964 test_isUTF8_CHAR(char *s, STRLEN len)
5966 RETVAL = isUTF8_CHAR((U8 *) s, (U8 *) s + len);
5971 test_isUTF8_CHAR_flags(char *s, STRLEN len, U32 flags)
5973 RETVAL = isUTF8_CHAR_flags((U8 *) s, (U8 *) s + len, flags);
5978 test_isSTRICT_UTF8_CHAR(char *s, STRLEN len)
5980 RETVAL = isSTRICT_UTF8_CHAR((U8 *) s, (U8 *) s + len);
5985 test_isC9_STRICT_UTF8_CHAR(char *s, STRLEN len)
5987 RETVAL = isC9_STRICT_UTF8_CHAR((U8 *) s, (U8 *) s + len);
5992 test_is_utf8_valid_partial_char_flags(char *s, STRLEN len, U32 flags)
5994 /* RETVAL should be bool (here and in tests below), but making it IV
5995 * allows us to test it returning 0 or 1 */
5996 RETVAL = is_utf8_valid_partial_char_flags((U8 *) s, (U8 *) s + len, flags);
6001 test_is_utf8_string(char *s, STRLEN len)
6003 RETVAL = is_utf8_string((U8 *) s, len);
6008 test_is_utf8_invariant_string_loc(char *s, STRLEN offset, STRLEN len)
6011 const U8 * ep = NULL;
6014 av_push(av, newSViv(is_utf8_invariant_string_loc((U8 *) s + offset, len, &ep)));
6015 av_push(av, newSViv(ep - ((U8 *) s + offset)));
6021 test_utf8_length(unsigned char *s, STRLEN offset, STRLEN len)
6023 RETVAL = utf8_length(s + offset, s + len);
6028 test_is_utf8_string_loc(char *s, STRLEN len)
6034 av_push(av, newSViv(is_utf8_string_loc((U8 *) s, len, &ep)));
6035 av_push(av, newSViv(ep - (U8 *) s));
6041 test_is_utf8_string_loclen(char *s, STRLEN len)
6048 av_push(av, newSViv(is_utf8_string_loclen((U8 *) s, len, &ep, &ret_len)));
6049 av_push(av, newSViv(ep - (U8 *) s));
6050 av_push(av, newSVuv(ret_len));
6056 test_is_utf8_string_flags(char *s, STRLEN len, U32 flags)
6058 RETVAL = is_utf8_string_flags((U8 *) s, len, flags);
6063 test_is_utf8_string_loc_flags(char *s, STRLEN len, U32 flags)
6069 av_push(av, newSViv(is_utf8_string_loc_flags((U8 *) s, len, &ep, flags)));
6070 av_push(av, newSViv(ep - (U8 *) s));
6076 test_is_utf8_string_loclen_flags(char *s, STRLEN len, U32 flags)
6083 av_push(av, newSViv(is_utf8_string_loclen_flags((U8 *) s, len, &ep, &ret_len, flags)));
6084 av_push(av, newSViv(ep - (U8 *) s));
6085 av_push(av, newSVuv(ret_len));
6091 test_is_strict_utf8_string(char *s, STRLEN len)
6093 RETVAL = is_strict_utf8_string((U8 *) s, len);
6098 test_is_strict_utf8_string_loc(char *s, STRLEN len)
6104 av_push(av, newSViv(is_strict_utf8_string_loc((U8 *) s, len, &ep)));
6105 av_push(av, newSViv(ep - (U8 *) s));
6111 test_is_strict_utf8_string_loclen(char *s, STRLEN len)
6118 av_push(av, newSViv(is_strict_utf8_string_loclen((U8 *) s, len, &ep, &ret_len)));
6119 av_push(av, newSViv(ep - (U8 *) s));
6120 av_push(av, newSVuv(ret_len));
6126 test_is_c9strict_utf8_string(char *s, STRLEN len)
6128 RETVAL = is_c9strict_utf8_string((U8 *) s, len);
6133 test_is_c9strict_utf8_string_loc(char *s, STRLEN len)
6139 av_push(av, newSViv(is_c9strict_utf8_string_loc((U8 *) s, len, &ep)));
6140 av_push(av, newSViv(ep - (U8 *) s));
6146 test_is_c9strict_utf8_string_loclen(char *s, STRLEN len)
6153 av_push(av, newSViv(is_c9strict_utf8_string_loclen((U8 *) s, len, &ep, &ret_len)));
6154 av_push(av, newSViv(ep - (U8 *) s));
6155 av_push(av, newSVuv(ret_len));
6161 test_is_utf8_fixed_width_buf_flags(char *s, STRLEN len, U32 flags)
6163 RETVAL = is_utf8_fixed_width_buf_flags((U8 *) s, len, flags);
6168 test_is_utf8_fixed_width_buf_loc_flags(char *s, STRLEN len, U32 flags)
6174 av_push(av, newSViv(is_utf8_fixed_width_buf_loc_flags((U8 *) s, len, &ep, flags)));
6175 av_push(av, newSViv(ep - (U8 *) s));
6181 test_is_utf8_fixed_width_buf_loclen_flags(char *s, STRLEN len, U32 flags)
6188 av_push(av, newSViv(is_utf8_fixed_width_buf_loclen_flags((U8 *) s, len, &ep, &ret_len, flags)));
6189 av_push(av, newSViv(ep - (U8 *) s));
6190 av_push(av, newSVuv(ret_len));
6196 test_utf8_hop_safe(SV *s_sv, STRLEN s_off, IV off)
6202 p = (U8 *)SvPV(s_sv, len);
6203 r = utf8_hop_safe(p + s_off, off, p, p + len);
6209 test_toLOWER(UV ord)
6211 RETVAL = toLOWER(ord);
6216 test_toLOWER_L1(UV ord)
6218 RETVAL = toLOWER_L1(ord);
6223 test_toLOWER_LC(UV ord)
6225 RETVAL = toLOWER_LC(ord);
6230 test_toLOWER_uni(UV ord)
6232 U8 s[UTF8_MAXBYTES_CASE + 1];
6238 av_push(av, newSVuv(toLOWER_uni(ord, s, &len)));
6240 utf8 = newSVpvn((char *) s, len);
6244 av_push(av, newSVuv(len));
6250 test_toLOWER_uvchr(UV ord)
6252 U8 s[UTF8_MAXBYTES_CASE + 1];
6258 av_push(av, newSVuv(toLOWER_uvchr(ord, s, &len)));
6260 utf8 = newSVpvn((char *) s, len);
6264 av_push(av, newSVuv(len));
6270 test_toLOWER_utf8(SV * p, int type)
6273 U8 s[UTF8_MAXBYTES_CASE + 1];
6277 const unsigned char * e;
6278 UV resultant_cp = UV_MAX; /* Initialized because of dumb compilers */
6280 input = (U8 *) SvPV(p, len);
6283 e = input + UTF8SKIP(input) - type;
6284 resultant_cp = toLOWER_utf8_safe(input, e, s, &len);
6286 else if (type == -1) {
6287 resultant_cp = toLOWER_utf8(input, s, &len);
6291 resultant_cp = Perl_to_utf8_lower(aTHX_ input, s, &len);
6294 av_push(av, newSVuv(resultant_cp));
6296 utf8 = newSVpvn((char *) s, len);
6300 av_push(av, newSVuv(len));
6308 RETVAL = toFOLD(ord);
6313 test_toFOLD_LC(UV ord)
6315 RETVAL = toFOLD_LC(ord);
6320 test_toFOLD_uni(UV ord)
6322 U8 s[UTF8_MAXBYTES_CASE + 1];
6328 av_push(av, newSVuv(toFOLD_uni(ord, s, &len)));
6330 utf8 = newSVpvn((char *) s, len);
6334 av_push(av, newSVuv(len));
6340 test_toFOLD_uvchr(UV ord)
6342 U8 s[UTF8_MAXBYTES_CASE + 1];
6348 av_push(av, newSVuv(toFOLD_uvchr(ord, s, &len)));
6350 utf8 = newSVpvn((char *) s, len);
6354 av_push(av, newSVuv(len));
6360 test_toFOLD_utf8(SV * p, int type)
6363 U8 s[UTF8_MAXBYTES_CASE + 1];
6367 const unsigned char * e;
6368 UV resultant_cp = UV_MAX;
6370 input = (U8 *) SvPV(p, len);
6373 e = input + UTF8SKIP(input) - type;
6374 resultant_cp = toFOLD_utf8_safe(input, e, s, &len);
6376 else if (type == -1) {
6377 resultant_cp = toFOLD_utf8(input, s, &len);
6381 resultant_cp = Perl_to_utf8_fold(aTHX_ input, s, &len);
6384 av_push(av, newSVuv(resultant_cp));
6386 utf8 = newSVpvn((char *) s, len);
6390 av_push(av, newSVuv(len));
6396 test_toUPPER(UV ord)
6398 RETVAL = toUPPER(ord);
6403 test_toUPPER_LC(UV ord)
6405 RETVAL = toUPPER_LC(ord);
6410 test_toUPPER_uni(UV ord)
6412 U8 s[UTF8_MAXBYTES_CASE + 1];
6418 av_push(av, newSVuv(toUPPER_uni(ord, s, &len)));
6420 utf8 = newSVpvn((char *) s, len);
6424 av_push(av, newSVuv(len));
6430 test_toUPPER_uvchr(UV ord)
6432 U8 s[UTF8_MAXBYTES_CASE + 1];
6438 av_push(av, newSVuv(toUPPER_uvchr(ord, s, &len)));
6440 utf8 = newSVpvn((char *) s, len);
6444 av_push(av, newSVuv(len));
6450 test_toUPPER_utf8(SV * p, int type)
6453 U8 s[UTF8_MAXBYTES_CASE + 1];
6457 const unsigned char * e;
6458 UV resultant_cp = UV_MAX;
6460 input = (U8 *) SvPV(p, len);
6463 e = input + UTF8SKIP(input) - type;
6464 resultant_cp = toUPPER_utf8_safe(input, e, s, &len);
6466 else if (type == -1) {
6467 resultant_cp = toUPPER_utf8(input, s, &len);
6471 resultant_cp = Perl_to_utf8_upper(aTHX_ input, s, &len);
6474 av_push(av, newSVuv(resultant_cp));
6476 utf8 = newSVpvn((char *) s, len);
6480 av_push(av, newSVuv(len));
6486 test_toTITLE(UV ord)
6488 RETVAL = toTITLE(ord);
6493 test_toTITLE_uni(UV ord)
6495 U8 s[UTF8_MAXBYTES_CASE + 1];
6501 av_push(av, newSVuv(toTITLE_uni(ord, s, &len)));
6503 utf8 = newSVpvn((char *) s, len);
6507 av_push(av, newSVuv(len));
6513 test_toTITLE_uvchr(UV ord)
6515 U8 s[UTF8_MAXBYTES_CASE + 1];
6521 av_push(av, newSVuv(toTITLE_uvchr(ord, s, &len)));
6523 utf8 = newSVpvn((char *) s, len);
6527 av_push(av, newSVuv(len));
6533 test_toTITLE_utf8(SV * p, int type)
6536 U8 s[UTF8_MAXBYTES_CASE + 1];
6540 const unsigned char * e;
6541 UV resultant_cp = UV_MAX;
6543 input = (U8 *) SvPV(p, len);
6546 e = input + UTF8SKIP(input) - type;
6547 resultant_cp = toTITLE_utf8_safe(input, e, s, &len);
6549 else if (type == -1) {
6550 resultant_cp = toTITLE_utf8(input, s, &len);
6554 resultant_cp = Perl_to_utf8_title(aTHX_ input, s, &len);
6557 av_push(av, newSVuv(resultant_cp));
6559 utf8 = newSVpvn((char *) s, len);
6563 av_push(av, newSVuv(len));
6569 test_Gconvert(SV * number, SV * num_digits)
6574 len = (int) SvIV(num_digits);
6575 if (len > 99) croak("Too long a number for test_Gconvert");
6576 if (len < 0) croak("Too short a number for test_Gconvert");
6577 PERL_UNUSED_RESULT(Gconvert(SvNV(number), len,
6578 0, /* No trailing zeroes */
6580 RETVAL = newSVpv(buffer, 0);
6585 test_Perl_langinfo(SV * item)
6587 RETVAL = newSVpv(Perl_langinfo(SvIV(item)), 0);
6591 MODULE = XS::APItest PACKAGE = XS::APItest::Backrefs
6594 apitest_weaken(SV *sv)
6600 has_backrefs(SV *sv)
6602 if (SvROK(sv) && sv_get_backrefs(SvRV(sv)))
6603 RETVAL = &PL_sv_yes;
6610 #ifdef PERL_IMPLICIT_SYS
6613 PerlDir_mapA(const char *path)
6616 PerlDir_mapW(const WCHAR *wpath)
6624 VS_FIXEDFILEINFO *info;
6630 dll = GetModuleHandle("comctl32.dll"); /* must already be in proc */
6632 croak("Comctl32Version: comctl32.dll not in process???");
6633 hrsc = FindResource(dll, MAKEINTRESOURCE(VS_VERSION_INFO),
6634 MAKEINTRESOURCE(VS_FILE_INFO));
6636 croak("Comctl32Version: comctl32.dll no version???");
6637 ver = LoadResource(dll, hrsc);
6638 len = SizeofResource(dll, hrsc);
6639 vercopy = _alloca(len);
6640 memcpy(vercopy, ver, len);
6641 if (VerQueryValue(vercopy, "\\", (void**)&info, &len)) {
6642 int dwValueMS1 = (info->dwFileVersionMS>>16);
6643 int dwValueMS2 = (info->dwFileVersionMS&0xffff);
6644 int dwValueLS1 = (info->dwFileVersionLS>>16);
6645 int dwValueLS2 = (info->dwFileVersionLS&0xffff);