1 #define PERL_IN_XS_APITEST
3 /* We want to be able to test things that aren't API yet. */
9 #include "fakesdio.h" /* Causes us to use PerlIO below */
12 typedef PTR_TBL_t *XS__APItest__PtrTable;
14 #define croak_fail() croak("fail at " __FILE__ " line %d", __LINE__)
15 #define croak_fail_ne(h, w) croak("fail %p!=%p at " __FILE__ " line %d", (h), (w), __LINE__)
20 cat_utf8a2n(SV* sv, const char * const ascii_utf8, STRLEN len)
22 /* Converts variant UTF-8 text pointed to by 'ascii_utf8' of length 'len',
23 * to UTF-EBCDIC, appending that text to the text already in 'sv'.
24 * Currently doesn't work on invariants, as that is unneeded here, and we
25 * could get double translations if we did.
27 * It has the algorithm for strict UTF-8 hard-coded in to find the code
28 * point it represents, then calls uvchr_to_utf8() to convert to
31 * Note that this uses code points, not characters. Thus if the input is
32 * the UTF-8 for the code point 0xFF, the output will be the UTF-EBCDIC for
33 * 0xFF, even though that code point represents different characters on
34 * ASCII vs EBCDIC platforms. */
37 char * p = (char *) ascii_utf8;
38 const char * const e = p + len;
42 U8 native_utf8[UTF8_MAXBYTES + 1];
46 /* Start bytes are the same in both UTF-8 and I8, therefore we can
47 * treat this ASCII UTF-8 byte as an I8 byte. But PL_utf8skip[] is
48 * indexed by NATIVE_UTF8 bytes, so transform to that */
49 STRLEN char_bytes_len = PL_utf8skip[I8_TO_NATIVE_UTF8(start)];
52 croak("fail: Expecting start byte, instead got 0x%X at %s line %d",
53 (U8) *p, __FILE__, __LINE__);
55 code_point = (start & (((char_bytes_len) >= 7)
57 : (0x1F >> ((char_bytes_len)-2))));
59 while (p < e && ((( (U8) *p) & 0xC0) == 0x80)) {
61 code_point = (code_point << 6) | (( (U8) *p) & 0x3F);
65 char_end = uvchr_to_utf8(native_utf8, code_point);
66 sv_catpvn(sv, (char *) native_utf8, char_end - native_utf8);
72 /* for my_cxt tests */
74 #define MY_CXT_KEY "XS::APItest::_guts" XS_VERSION
93 MGVTBL vtbl_foo, vtbl_bar;
95 /* indirect functions to test the [pa]MY_CXT macros */
98 my_cxt_getint_p(pMY_CXT)
104 my_cxt_setint_p(pMY_CXT_ int i)
110 my_cxt_getsv_interp_context(void)
113 dMY_CXT_INTERP(my_perl);
118 my_cxt_getsv_interp(void)
125 my_cxt_setsv_p(SV* sv _pMY_CXT)
131 /* from exception.c */
132 int apitest_exception(int);
134 /* from core_or_not.inc */
135 bool sv_setsv_cow_hashkey_core(void);
136 bool sv_setsv_cow_hashkey_notcore(void);
138 /* A routine to test hv_delayfree_ent
139 (which itself is tested by testing on hv_free_ent */
141 typedef void (freeent_function)(pTHX_ HV *, HE *);
144 test_freeent(freeent_function *f) {
146 HV *test_hash = newHV();
153 victim = (HE*)safemalloc(sizeof(HE));
155 /* Storing then deleting something should ensure that a hash entry is
157 (void) hv_store(test_hash, "", 0, &PL_sv_yes, 0);
158 (void) hv_delete(test_hash, "", 0, 0);
160 /* We need to "inline" new_he here as it's static, and the functions we
161 test expect to be able to call del_HE on the HE */
162 if (!PL_body_roots[HE_SVSLOT])
163 croak("PL_he_root is 0");
164 victim = (HE*) PL_body_roots[HE_SVSLOT];
165 PL_body_roots[HE_SVSLOT] = HeNEXT(victim);
168 victim->hent_hek = Perl_share_hek(aTHX_ "", 0, 0);
170 test_scalar = newSV(0);
171 SvREFCNT_inc(test_scalar);
172 HeVAL(victim) = test_scalar;
174 /* Need this little game else we free the temps on the return stack. */
175 results[0] = SvREFCNT(test_scalar);
177 results[1] = SvREFCNT(test_scalar);
178 f(aTHX_ test_hash, victim);
179 results[2] = SvREFCNT(test_scalar);
181 results[3] = SvREFCNT(test_scalar);
186 } while (++i < (int)(sizeof(results)/sizeof(results[0])));
188 /* Goodbye to our extra reference. */
189 SvREFCNT_dec(test_scalar);
192 /* Not that it matters much, but it's handy for the flipped character to just
193 * be the opposite case (at least for ASCII-range and most Latin1 as well). */
194 #define FLIP_BIT ('A' ^ 'a')
197 bitflip_key(pTHX_ IV action, SV *field) {
198 MAGIC *mg = mg_find(field, PERL_MAGIC_uvar);
200 PERL_UNUSED_ARG(action);
201 if (mg && (keysv = mg->mg_obj)) {
203 const char *p = SvPV(keysv, len);
206 /* Allow for the flipped val to be longer than the original. This
207 * is just for testing, so can afford to have some slop */
208 const STRLEN newlen = len * 2;
210 SV *newkey = newSV(newlen);
211 const char * const new_p_orig = SvPVX(newkey);
212 char *new_p = (char *) new_p_orig;
215 const char *const end = p + len;
218 UV chr = utf8_to_uvchr_buf((U8 *)p, (U8 *) end, &curlen);
220 /* Make sure don't exceed bounds */
221 assert(new_p - new_p_orig + curlen < newlen);
223 new_p = (char *)uvchr_to_utf8((U8 *)new_p, chr ^ FLIP_BIT);
229 *new_p++ = *p++ ^ FLIP_BIT;
232 SvCUR_set(newkey, new_p - new_p_orig);
242 rot13_key(pTHX_ IV action, SV *field) {
243 MAGIC *mg = mg_find(field, PERL_MAGIC_uvar);
245 PERL_UNUSED_ARG(action);
246 if (mg && (keysv = mg->mg_obj)) {
248 const char *p = SvPV(keysv, len);
251 SV *newkey = newSV(len);
252 char *new_p = SvPVX(newkey);
254 /* There's a deliberate fencepost error here to loop len + 1 times
255 to copy the trailing \0 */
258 /* Try doing this cleanly and clearly in EBCDIC another way: */
260 case 'A': new_c = 'N'; break;
261 case 'B': new_c = 'O'; break;
262 case 'C': new_c = 'P'; break;
263 case 'D': new_c = 'Q'; break;
264 case 'E': new_c = 'R'; break;
265 case 'F': new_c = 'S'; break;
266 case 'G': new_c = 'T'; break;
267 case 'H': new_c = 'U'; break;
268 case 'I': new_c = 'V'; break;
269 case 'J': new_c = 'W'; break;
270 case 'K': new_c = 'X'; break;
271 case 'L': new_c = 'Y'; break;
272 case 'M': new_c = 'Z'; break;
273 case 'N': new_c = 'A'; break;
274 case 'O': new_c = 'B'; break;
275 case 'P': new_c = 'C'; break;
276 case 'Q': new_c = 'D'; break;
277 case 'R': new_c = 'E'; break;
278 case 'S': new_c = 'F'; break;
279 case 'T': new_c = 'G'; break;
280 case 'U': new_c = 'H'; break;
281 case 'V': new_c = 'I'; break;
282 case 'W': new_c = 'J'; break;
283 case 'X': new_c = 'K'; break;
284 case 'Y': new_c = 'L'; break;
285 case 'Z': new_c = 'M'; break;
286 case 'a': new_c = 'n'; break;
287 case 'b': new_c = 'o'; break;
288 case 'c': new_c = 'p'; break;
289 case 'd': new_c = 'q'; break;
290 case 'e': new_c = 'r'; break;
291 case 'f': new_c = 's'; break;
292 case 'g': new_c = 't'; break;
293 case 'h': new_c = 'u'; break;
294 case 'i': new_c = 'v'; break;
295 case 'j': new_c = 'w'; break;
296 case 'k': new_c = 'x'; break;
297 case 'l': new_c = 'y'; break;
298 case 'm': new_c = 'z'; break;
299 case 'n': new_c = 'a'; break;
300 case 'o': new_c = 'b'; break;
301 case 'p': new_c = 'c'; break;
302 case 'q': new_c = 'd'; break;
303 case 'r': new_c = 'e'; break;
304 case 's': new_c = 'f'; break;
305 case 't': new_c = 'g'; break;
306 case 'u': new_c = 'h'; break;
307 case 'v': new_c = 'i'; break;
308 case 'w': new_c = 'j'; break;
309 case 'x': new_c = 'k'; break;
310 case 'y': new_c = 'l'; break;
311 case 'z': new_c = 'm'; break;
315 SvCUR_set(newkey, SvCUR(keysv));
327 rmagical_a_dummy(pTHX_ IV idx, SV *sv) {
328 PERL_UNUSED_ARG(idx);
333 /* We could do "= { 0 };" but some versions of gcc do warn
334 * (with -Wextra) about missing initializer, this is probably gcc
335 * being a bit too paranoid. But since this is file-static, we can
336 * just have it without initializer, since it should get
337 * zero-initialized. */
338 STATIC MGVTBL rmagical_b;
341 blockhook_csc_start(pTHX_ int full)
344 AV *const cur = GvAV(MY_CXT.cscgv);
346 PERL_UNUSED_ARG(full);
347 SAVEGENERICSV(GvAV(MY_CXT.cscgv));
351 AV *const new_av = newAV();
353 for (i = 0; i <= av_tindex(cur); i++) {
354 av_store(new_av, i, newSVsv(*av_fetch(cur, i, 0)));
357 GvAV(MY_CXT.cscgv) = new_av;
362 blockhook_csc_pre_end(pTHX_ OP **o)
367 /* if we hit the end of a scope we missed the start of, we need to
368 * unconditionally clear @CSC */
369 if (GvAV(MY_CXT.cscgv) == MY_CXT.cscav && MY_CXT.cscav) {
370 av_clear(MY_CXT.cscav);
376 blockhook_test_start(pTHX_ int full)
381 if (MY_CXT.bhk_record) {
383 av_push(av, newSVpvs("start"));
384 av_push(av, newSViv(full));
385 av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av)));
390 blockhook_test_pre_end(pTHX_ OP **o)
395 if (MY_CXT.bhk_record)
396 av_push(MY_CXT.bhkav, newSVpvs("pre_end"));
400 blockhook_test_post_end(pTHX_ OP **o)
405 if (MY_CXT.bhk_record)
406 av_push(MY_CXT.bhkav, newSVpvs("post_end"));
410 blockhook_test_eval(pTHX_ OP *const o)
415 if (MY_CXT.bhk_record) {
417 av_push(av, newSVpvs("eval"));
418 av_push(av, newSVpv(OP_NAME(o), 0));
419 av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av)));
423 STATIC BHK bhk_csc, bhk_test;
426 my_peep (pTHX_ OP *o)
433 MY_CXT.orig_peep(aTHX_ o);
435 if (!MY_CXT.peep_recording)
438 for (; o; o = o->op_next) {
439 if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
440 av_push(MY_CXT.peep_recorder, newSVsv(cSVOPx_sv(o)));
446 my_rpeep (pTHX_ OP *o)
453 MY_CXT.orig_rpeep(aTHX_ o);
455 if (!MY_CXT.peep_recording)
458 for (; o; o = o->op_next) {
459 if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
460 av_push(MY_CXT.rpeep_recorder, newSVsv(cSVOPx_sv(o)));
466 THX_ck_entersub_args_lists(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
468 PERL_UNUSED_ARG(namegv);
469 PERL_UNUSED_ARG(ckobj);
470 return ck_entersub_args_list(entersubop);
474 THX_ck_entersub_args_scalars(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
476 OP *aop = cUNOPx(entersubop)->op_first;
477 PERL_UNUSED_ARG(namegv);
478 PERL_UNUSED_ARG(ckobj);
479 if (!OpHAS_SIBLING(aop))
480 aop = cUNOPx(aop)->op_first;
481 for (aop = OpSIBLING(aop); OpHAS_SIBLING(aop); aop = OpSIBLING(aop)) {
482 op_contextualize(aop, G_SCALAR);
488 THX_ck_entersub_multi_sum(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
491 OP *parent = entersubop;
492 OP *pushop = cUNOPx(entersubop)->op_first;
493 PERL_UNUSED_ARG(namegv);
494 PERL_UNUSED_ARG(ckobj);
495 if (!OpHAS_SIBLING(pushop)) {
497 pushop = cUNOPx(pushop)->op_first;
500 OP *aop = OpSIBLING(pushop);
501 if (!OpHAS_SIBLING(aop))
503 /* cut out first arg */
504 op_sibling_splice(parent, pushop, 1, NULL);
505 op_contextualize(aop, G_SCALAR);
507 sumop = newBINOP(OP_ADD, 0, sumop, aop);
513 sumop = newSVOP(OP_CONST, 0, newSViv(0));
518 STATIC void test_op_list_describe_part(SV *res, OP *o);
520 test_op_list_describe_part(SV *res, OP *o)
522 sv_catpv(res, PL_op_name[o->op_type]);
523 switch (o->op_type) {
525 sv_catpvf(res, "(%d)", (int)SvIV(cSVOPx(o)->op_sv));
528 if (o->op_flags & OPf_KIDS) {
531 for (k = cUNOPx(o)->op_first; k; k = OpSIBLING(k))
532 test_op_list_describe_part(res, k);
540 test_op_list_describe(OP *o)
542 SV *res = sv_2mortal(newSVpvs(""));
544 test_op_list_describe_part(res, o);
548 /* the real new*OP functions have a tendency to call fold_constants, and
549 * other such unhelpful things, so we need our own versions for testing */
551 #define mkUNOP(t, f) THX_mkUNOP(aTHX_ (t), (f))
553 THX_mkUNOP(pTHX_ U32 type, OP *first)
556 NewOp(1103, unop, 1, UNOP);
557 unop->op_type = (OPCODE)type;
558 op_sibling_splice((OP*)unop, NULL, 0, first);
562 #define mkBINOP(t, f, l) THX_mkBINOP(aTHX_ (t), (f), (l))
564 THX_mkBINOP(pTHX_ U32 type, OP *first, OP *last)
567 NewOp(1103, binop, 1, BINOP);
568 binop->op_type = (OPCODE)type;
569 op_sibling_splice((OP*)binop, NULL, 0, last);
570 op_sibling_splice((OP*)binop, NULL, 0, first);
574 #define mkLISTOP(t, f, s, l) THX_mkLISTOP(aTHX_ (t), (f), (s), (l))
576 THX_mkLISTOP(pTHX_ U32 type, OP *first, OP *sib, OP *last)
579 NewOp(1103, listop, 1, LISTOP);
580 listop->op_type = (OPCODE)type;
581 op_sibling_splice((OP*)listop, NULL, 0, last);
582 op_sibling_splice((OP*)listop, NULL, 0, sib);
583 op_sibling_splice((OP*)listop, NULL, 0, first);
588 test_op_linklist_describe(OP *start)
590 SV *rv = sv_2mortal(newSVpvs(""));
592 o = start = LINKLIST(start);
595 sv_catpv(rv, OP_NAME(o));
596 if (o->op_type == OP_CONST)
597 sv_catsv(rv, cSVOPo->op_sv);
599 } while (o && o != start);
603 /** establish_cleanup operator, ripped off from Scope::Cleanup **/
606 THX_run_cleanup(pTHX_ void *cleanup_code_ref)
613 call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD);
620 THX_pp_establish_cleanup(pTHX)
623 SV *cleanup_code_ref;
624 cleanup_code_ref = newSVsv(POPs);
625 SAVEFREESV(cleanup_code_ref);
626 SAVEDESTRUCTOR_X(THX_run_cleanup, cleanup_code_ref);
627 if(GIMME_V != G_VOID) PUSHs(&PL_sv_undef);
632 THX_ck_entersub_establish_cleanup(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
634 OP *parent, *pushop, *argop, *estop;
635 ck_entersub_args_proto(entersubop, namegv, ckobj);
637 pushop = cUNOPx(entersubop)->op_first;
638 if(!OpHAS_SIBLING(pushop)) {
640 pushop = cUNOPx(pushop)->op_first;
642 /* extract out first arg, then delete the rest of the tree */
643 argop = OpSIBLING(pushop);
644 op_sibling_splice(parent, pushop, 1, NULL);
647 estop = mkUNOP(OP_RAND, argop);
648 estop->op_ppaddr = THX_pp_establish_cleanup;
649 PL_hints |= HINT_BLOCK_SCOPE;
654 THX_ck_entersub_postinc(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
656 OP *parent, *pushop, *argop;
657 ck_entersub_args_proto(entersubop, namegv, ckobj);
659 pushop = cUNOPx(entersubop)->op_first;
660 if(!OpHAS_SIBLING(pushop)) {
662 pushop = cUNOPx(pushop)->op_first;
664 argop = OpSIBLING(pushop);
665 op_sibling_splice(parent, pushop, 1, NULL);
667 return newUNOP(OP_POSTINC, 0,
668 op_lvalue(op_contextualize(argop, G_SCALAR), OP_POSTINC));
672 THX_ck_entersub_pad_scalar(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
675 PADOFFSET padoff = NOT_IN_PAD;
677 ck_entersub_args_proto(entersubop, namegv, ckobj);
678 pushop = cUNOPx(entersubop)->op_first;
679 if(!OpHAS_SIBLING(pushop))
680 pushop = cUNOPx(pushop)->op_first;
681 argop = OpSIBLING(pushop);
682 if(argop->op_type != OP_CONST || OpSIBLING(argop)->op_type != OP_CONST)
683 croak("bad argument expression type for pad_scalar()");
684 a0 = cSVOPx_sv(argop);
685 a1 = cSVOPx_sv(OpSIBLING(argop));
688 SV *namesv = sv_2mortal(newSVpvs("$"));
689 sv_catsv(namesv, a1);
690 padoff = pad_findmy_sv(namesv, 0);
695 SV *namesv = sv_2mortal(newSVpvs("$"));
696 sv_catsv(namesv, a1);
697 namepv = SvPV(namesv, namelen);
698 padoff = pad_findmy_pvn(namepv, namelen, SvUTF8(namesv));
702 SV *namesv = sv_2mortal(newSVpvs("$"));
703 sv_catsv(namesv, a1);
704 namepv = SvPV_nolen(namesv);
705 padoff = pad_findmy_pv(namepv, SvUTF8(namesv));
708 padoff = pad_findmy_pvs("$foo", 0);
710 default: croak("bad type value for pad_scalar()");
713 if(padoff == NOT_IN_PAD) {
714 return newSVOP(OP_CONST, 0, newSVpvs("NOT_IN_PAD"));
715 } else if(PAD_COMPNAME_FLAGS_isOUR(padoff)) {
716 return newSVOP(OP_CONST, 0, newSVpvs("NOT_MY"));
718 OP *padop = newOP(OP_PADSV, 0);
719 padop->op_targ = padoff;
724 /** RPN keyword parser **/
726 #define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV)
727 #define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP)
728 #define sv_is_string(sv) \
729 (!sv_is_glob(sv) && !sv_is_regexp(sv) && \
730 (SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK)))
732 static SV *hintkey_rpn_sv, *hintkey_calcrpn_sv, *hintkey_stufftest_sv;
733 static SV *hintkey_swaptwostmts_sv, *hintkey_looprest_sv;
734 static SV *hintkey_scopelessblock_sv;
735 static SV *hintkey_stmtasexpr_sv, *hintkey_stmtsasexpr_sv;
736 static SV *hintkey_loopblock_sv, *hintkey_blockasexpr_sv;
737 static SV *hintkey_swaplabel_sv, *hintkey_labelconst_sv;
738 static SV *hintkey_arrayfullexpr_sv, *hintkey_arraylistexpr_sv;
739 static SV *hintkey_arraytermexpr_sv, *hintkey_arrayarithexpr_sv;
740 static SV *hintkey_arrayexprflags_sv;
741 static SV *hintkey_DEFSV_sv;
742 static SV *hintkey_with_vars_sv;
743 static SV *hintkey_join_with_space_sv;
744 static int (*next_keyword_plugin)(pTHX_ char *, STRLEN, OP **);
746 /* low-level parser helpers */
748 #define PL_bufptr (PL_parser->bufptr)
749 #define PL_bufend (PL_parser->bufend)
753 #define parse_var() THX_parse_var(aTHX)
754 static OP *THX_parse_var(pTHX)
760 if(*s != '$') croak("RPN syntax error");
763 if(!isALNUM(c)) break;
765 if(s-start < 2) croak("RPN syntax error");
767 varpos = pad_findmy_pvn(start, s-start, 0);
768 if(varpos == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(varpos))
769 croak("RPN only supports \"my\" variables");
770 padop = newOP(OP_PADSV, 0);
771 padop->op_targ = varpos;
775 #define push_rpn_item(o) \
776 op_sibling_splice(parent, NULL, 0, o);
777 #define pop_rpn_item() ( \
778 (tmpop = op_sibling_splice(parent, NULL, 1, NULL)) \
779 ? tmpop : (croak("RPN stack underflow"), (OP*)NULL))
781 #define parse_rpn_expr() THX_parse_rpn_expr(aTHX)
782 static OP *THX_parse_rpn_expr(pTHX)
785 /* fake parent for splice to mess with */
786 OP *parent = mkBINOP(OP_NULL, NULL, NULL);
791 c = lex_peek_unichar(0);
793 case /*(*/')': case /*{*/'}': {
794 OP *result = pop_rpn_item();
795 if(cLISTOPx(parent)->op_first)
796 croak("RPN expression must return a single value");
800 case '0': case '1': case '2': case '3': case '4':
801 case '5': case '6': case '7': case '8': case '9': {
805 val = 10*val + (c - '0');
806 c = lex_peek_unichar(0);
807 } while(c >= '0' && c <= '9');
808 push_rpn_item(newSVOP(OP_CONST, 0, newSVuv(val)));
811 push_rpn_item(parse_var());
814 OP *b = pop_rpn_item();
815 OP *a = pop_rpn_item();
817 push_rpn_item(newBINOP(OP_I_ADD, 0, a, b));
820 OP *b = pop_rpn_item();
821 OP *a = pop_rpn_item();
823 push_rpn_item(newBINOP(OP_I_SUBTRACT, 0, a, b));
826 OP *b = pop_rpn_item();
827 OP *a = pop_rpn_item();
829 push_rpn_item(newBINOP(OP_I_MULTIPLY, 0, a, b));
832 OP *b = pop_rpn_item();
833 OP *a = pop_rpn_item();
835 push_rpn_item(newBINOP(OP_I_DIVIDE, 0, a, b));
838 OP *b = pop_rpn_item();
839 OP *a = pop_rpn_item();
841 push_rpn_item(newBINOP(OP_I_MODULO, 0, a, b));
844 croak("RPN syntax error");
850 #define parse_keyword_rpn() THX_parse_keyword_rpn(aTHX)
851 static OP *THX_parse_keyword_rpn(pTHX)
855 if(lex_peek_unichar(0) != '('/*)*/)
856 croak("RPN expression must be parenthesised");
858 op = parse_rpn_expr();
859 if(lex_peek_unichar(0) != /*(*/')')
860 croak("RPN expression must be parenthesised");
865 #define parse_keyword_calcrpn() THX_parse_keyword_calcrpn(aTHX)
866 static OP *THX_parse_keyword_calcrpn(pTHX)
872 if(lex_peek_unichar(0) != '{'/*}*/)
873 croak("RPN expression must be braced");
875 exprop = parse_rpn_expr();
876 if(lex_peek_unichar(0) != /*{*/'}')
877 croak("RPN expression must be braced");
879 return newASSIGNOP(OPf_STACKED, varop, 0, exprop);
882 #define parse_keyword_stufftest() THX_parse_keyword_stufftest(aTHX)
883 static OP *THX_parse_keyword_stufftest(pTHX)
888 do_stuff = lex_peek_unichar(0) == '+';
893 c = lex_peek_unichar(0);
896 } else if(c != /*{*/'}') {
897 croak("syntax error");
899 if(do_stuff) lex_stuff_pvs(" ", 0);
900 return newOP(OP_NULL, 0);
903 #define parse_keyword_swaptwostmts() THX_parse_keyword_swaptwostmts(aTHX)
904 static OP *THX_parse_keyword_swaptwostmts(pTHX)
907 a = parse_fullstmt(0);
908 b = parse_fullstmt(0);
910 PL_hints |= HINT_BLOCK_SCOPE;
911 return op_append_list(OP_LINESEQ, b, a);
914 #define parse_keyword_looprest() THX_parse_keyword_looprest(aTHX)
915 static OP *THX_parse_keyword_looprest(pTHX)
917 return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes),
918 parse_stmtseq(0), NULL, 1);
921 #define parse_keyword_scopelessblock() THX_parse_keyword_scopelessblock(aTHX)
922 static OP *THX_parse_keyword_scopelessblock(pTHX)
927 if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error");
929 body = parse_stmtseq(0);
930 c = lex_peek_unichar(0);
931 if(c != /*{*/'}' && c != /*[*/']' && c != /*(*/')') croak("syntax error");
936 #define parse_keyword_stmtasexpr() THX_parse_keyword_stmtasexpr(aTHX)
937 static OP *THX_parse_keyword_stmtasexpr(pTHX)
939 OP *o = parse_barestmt(0);
940 if (!o) o = newOP(OP_STUB, 0);
941 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
945 #define parse_keyword_stmtsasexpr() THX_parse_keyword_stmtsasexpr(aTHX)
946 static OP *THX_parse_keyword_stmtsasexpr(pTHX)
950 if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error");
952 o = parse_stmtseq(0);
954 if(lex_peek_unichar(0) != /*{*/'}') croak("syntax error");
956 if (!o) o = newOP(OP_STUB, 0);
957 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
961 #define parse_keyword_loopblock() THX_parse_keyword_loopblock(aTHX)
962 static OP *THX_parse_keyword_loopblock(pTHX)
964 return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes),
965 parse_block(0), NULL, 1);
968 #define parse_keyword_blockasexpr() THX_parse_keyword_blockasexpr(aTHX)
969 static OP *THX_parse_keyword_blockasexpr(pTHX)
971 OP *o = parse_block(0);
972 if (!o) o = newOP(OP_STUB, 0);
973 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
977 #define parse_keyword_swaplabel() THX_parse_keyword_swaplabel(aTHX)
978 static OP *THX_parse_keyword_swaplabel(pTHX)
980 OP *sop = parse_barestmt(0);
981 SV *label = parse_label(PARSE_OPTIONAL);
982 if (label) sv_2mortal(label);
983 return newSTATEOP(label ? SvUTF8(label) : 0,
984 label ? savepv(SvPVX(label)) : NULL,
988 #define parse_keyword_labelconst() THX_parse_keyword_labelconst(aTHX)
989 static OP *THX_parse_keyword_labelconst(pTHX)
991 return newSVOP(OP_CONST, 0, parse_label(0));
994 #define parse_keyword_arrayfullexpr() THX_parse_keyword_arrayfullexpr(aTHX)
995 static OP *THX_parse_keyword_arrayfullexpr(pTHX)
997 return newANONLIST(parse_fullexpr(0));
1000 #define parse_keyword_arraylistexpr() THX_parse_keyword_arraylistexpr(aTHX)
1001 static OP *THX_parse_keyword_arraylistexpr(pTHX)
1003 return newANONLIST(parse_listexpr(0));
1006 #define parse_keyword_arraytermexpr() THX_parse_keyword_arraytermexpr(aTHX)
1007 static OP *THX_parse_keyword_arraytermexpr(pTHX)
1009 return newANONLIST(parse_termexpr(0));
1012 #define parse_keyword_arrayarithexpr() THX_parse_keyword_arrayarithexpr(aTHX)
1013 static OP *THX_parse_keyword_arrayarithexpr(pTHX)
1015 return newANONLIST(parse_arithexpr(0));
1018 #define parse_keyword_arrayexprflags() THX_parse_keyword_arrayexprflags(aTHX)
1019 static OP *THX_parse_keyword_arrayexprflags(pTHX)
1025 c = lex_peek_unichar(0);
1026 if (c != '!' && c != '?') croak("syntax error");
1027 lex_read_unichar(0);
1028 if (c == '?') flags |= PARSE_OPTIONAL;
1029 o = parse_listexpr(flags);
1030 return o ? newANONLIST(o) : newANONHASH(newOP(OP_STUB, 0));
1033 #define parse_keyword_DEFSV() THX_parse_keyword_DEFSV(aTHX)
1034 static OP *THX_parse_keyword_DEFSV(pTHX)
1036 return newDEFSVOP();
1039 #define sv_cat_c(a,b) THX_sv_cat_c(aTHX_ a, b)
1040 static void THX_sv_cat_c(pTHX_ SV *sv, U32 c) {
1041 char ds[UTF8_MAXBYTES + 1], *d;
1042 d = (char *)uvchr_to_utf8((U8 *)ds, c);
1044 sv_utf8_upgrade(sv);
1046 sv_catpvn(sv, ds, d - ds);
1049 #define parse_keyword_with_vars() THX_parse_keyword_with_vars(aTHX)
1050 static OP *THX_parse_keyword_with_vars(pTHX)
1055 OP *vardeclseq, *body;
1057 save_ix = block_start(TRUE);
1063 c = lex_peek_unichar(0);
1069 croak("unexpected EOF; expecting '{'");
1072 if (!isIDFIRST_uni(c)) {
1073 croak("unexpected '%c'; expecting an identifier", (int)c);
1076 varname = newSVpvs("$");
1077 if (lex_bufutf8()) {
1081 sv_cat_c(varname, c);
1082 lex_read_unichar(0);
1084 while (c = lex_peek_unichar(0), c != -1 && isIDCONT_uni(c)) {
1085 sv_cat_c(varname, c);
1086 lex_read_unichar(0);
1089 padoff = pad_add_name_sv(varname, padadd_NO_DUP_CHECK, NULL, NULL);
1092 OP *my_var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
1093 my_var->op_targ = padoff;
1095 vardeclseq = op_append_list(
1113 c = lex_peek_unichar(0);
1118 body = parse_block(0);
1120 return block_end(save_ix, op_append_list(OP_LINESEQ, vardeclseq, body));
1123 #define parse_join_with_space() THX_parse_join_with_space(aTHX)
1124 static OP *THX_parse_join_with_space(pTHX)
1128 args = parse_listexpr(0);
1129 delim = newSVOP(OP_CONST, 0, newSVpvs(" "));
1130 return op_convert_list(OP_JOIN, 0, op_prepend_elem(OP_LIST, delim, args));
1135 #define keyword_active(hintkey_sv) THX_keyword_active(aTHX_ hintkey_sv)
1136 static int THX_keyword_active(pTHX_ SV *hintkey_sv)
1139 if(!GvHV(PL_hintgv)) return 0;
1140 he = hv_fetch_ent(GvHV(PL_hintgv), hintkey_sv, 0,
1141 SvSHARED_HASH(hintkey_sv));
1142 return he && SvTRUE(HeVAL(he));
1145 static int my_keyword_plugin(pTHX_
1146 char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
1148 if(keyword_len == 3 && strnEQ(keyword_ptr, "rpn", 3) &&
1149 keyword_active(hintkey_rpn_sv)) {
1150 *op_ptr = parse_keyword_rpn();
1151 return KEYWORD_PLUGIN_EXPR;
1152 } else if(keyword_len == 7 && strnEQ(keyword_ptr, "calcrpn", 7) &&
1153 keyword_active(hintkey_calcrpn_sv)) {
1154 *op_ptr = parse_keyword_calcrpn();
1155 return KEYWORD_PLUGIN_STMT;
1156 } else if(keyword_len == 9 && strnEQ(keyword_ptr, "stufftest", 9) &&
1157 keyword_active(hintkey_stufftest_sv)) {
1158 *op_ptr = parse_keyword_stufftest();
1159 return KEYWORD_PLUGIN_STMT;
1160 } else if(keyword_len == 12 &&
1161 strnEQ(keyword_ptr, "swaptwostmts", 12) &&
1162 keyword_active(hintkey_swaptwostmts_sv)) {
1163 *op_ptr = parse_keyword_swaptwostmts();
1164 return KEYWORD_PLUGIN_STMT;
1165 } else if(keyword_len == 8 && strnEQ(keyword_ptr, "looprest", 8) &&
1166 keyword_active(hintkey_looprest_sv)) {
1167 *op_ptr = parse_keyword_looprest();
1168 return KEYWORD_PLUGIN_STMT;
1169 } else if(keyword_len == 14 && strnEQ(keyword_ptr, "scopelessblock", 14) &&
1170 keyword_active(hintkey_scopelessblock_sv)) {
1171 *op_ptr = parse_keyword_scopelessblock();
1172 return KEYWORD_PLUGIN_STMT;
1173 } else if(keyword_len == 10 && strnEQ(keyword_ptr, "stmtasexpr", 10) &&
1174 keyword_active(hintkey_stmtasexpr_sv)) {
1175 *op_ptr = parse_keyword_stmtasexpr();
1176 return KEYWORD_PLUGIN_EXPR;
1177 } else if(keyword_len == 11 && strnEQ(keyword_ptr, "stmtsasexpr", 11) &&
1178 keyword_active(hintkey_stmtsasexpr_sv)) {
1179 *op_ptr = parse_keyword_stmtsasexpr();
1180 return KEYWORD_PLUGIN_EXPR;
1181 } else if(keyword_len == 9 && strnEQ(keyword_ptr, "loopblock", 9) &&
1182 keyword_active(hintkey_loopblock_sv)) {
1183 *op_ptr = parse_keyword_loopblock();
1184 return KEYWORD_PLUGIN_STMT;
1185 } else if(keyword_len == 11 && strnEQ(keyword_ptr, "blockasexpr", 11) &&
1186 keyword_active(hintkey_blockasexpr_sv)) {
1187 *op_ptr = parse_keyword_blockasexpr();
1188 return KEYWORD_PLUGIN_EXPR;
1189 } else if(keyword_len == 9 && strnEQ(keyword_ptr, "swaplabel", 9) &&
1190 keyword_active(hintkey_swaplabel_sv)) {
1191 *op_ptr = parse_keyword_swaplabel();
1192 return KEYWORD_PLUGIN_STMT;
1193 } else if(keyword_len == 10 && strnEQ(keyword_ptr, "labelconst", 10) &&
1194 keyword_active(hintkey_labelconst_sv)) {
1195 *op_ptr = parse_keyword_labelconst();
1196 return KEYWORD_PLUGIN_EXPR;
1197 } else if(keyword_len == 13 && strnEQ(keyword_ptr, "arrayfullexpr", 13) &&
1198 keyword_active(hintkey_arrayfullexpr_sv)) {
1199 *op_ptr = parse_keyword_arrayfullexpr();
1200 return KEYWORD_PLUGIN_EXPR;
1201 } else if(keyword_len == 13 && strnEQ(keyword_ptr, "arraylistexpr", 13) &&
1202 keyword_active(hintkey_arraylistexpr_sv)) {
1203 *op_ptr = parse_keyword_arraylistexpr();
1204 return KEYWORD_PLUGIN_EXPR;
1205 } else if(keyword_len == 13 && strnEQ(keyword_ptr, "arraytermexpr", 13) &&
1206 keyword_active(hintkey_arraytermexpr_sv)) {
1207 *op_ptr = parse_keyword_arraytermexpr();
1208 return KEYWORD_PLUGIN_EXPR;
1209 } else if(keyword_len == 14 && strnEQ(keyword_ptr, "arrayarithexpr", 14) &&
1210 keyword_active(hintkey_arrayarithexpr_sv)) {
1211 *op_ptr = parse_keyword_arrayarithexpr();
1212 return KEYWORD_PLUGIN_EXPR;
1213 } else if(keyword_len == 14 && strnEQ(keyword_ptr, "arrayexprflags", 14) &&
1214 keyword_active(hintkey_arrayexprflags_sv)) {
1215 *op_ptr = parse_keyword_arrayexprflags();
1216 return KEYWORD_PLUGIN_EXPR;
1217 } else if(keyword_len == 5 && strnEQ(keyword_ptr, "DEFSV", 5) &&
1218 keyword_active(hintkey_DEFSV_sv)) {
1219 *op_ptr = parse_keyword_DEFSV();
1220 return KEYWORD_PLUGIN_EXPR;
1221 } else if(keyword_len == 9 && strnEQ(keyword_ptr, "with_vars", 9) &&
1222 keyword_active(hintkey_with_vars_sv)) {
1223 *op_ptr = parse_keyword_with_vars();
1224 return KEYWORD_PLUGIN_STMT;
1225 } else if(keyword_len == 15 && strnEQ(keyword_ptr, "join_with_space", 15) &&
1226 keyword_active(hintkey_join_with_space_sv)) {
1227 *op_ptr = parse_join_with_space();
1228 return KEYWORD_PLUGIN_EXPR;
1230 return next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr);
1239 return PL_op->op_next;
1243 peep_xop(pTHX_ OP *o, OP *oldop)
1246 av_push(MY_CXT.xop_record, newSVpvf("peep:%"UVxf, PTR2UV(o)));
1247 av_push(MY_CXT.xop_record, newSVpvf("oldop:%"UVxf, PTR2UV(oldop)));
1251 filter_call(pTHX_ int idx, SV *buf_sv, int maxlen)
1255 int n = FILTER_READ(idx + 1, buf_sv, maxlen);
1259 p = SvPV_force_nolen(buf_sv);
1260 end = p + SvCUR(buf_sv);
1262 if (*p == 'o') *p = 'e';
1265 return SvCUR(buf_sv);
1269 myget_linear_isa(pTHX_ HV *stash, U32 level) {
1270 GV **gvp = (GV **)hv_fetchs(stash, "ISA", 0);
1271 PERL_UNUSED_ARG(level);
1272 return gvp && *gvp && GvAV(*gvp)
1274 : (AV *)sv_2mortal((SV *)newAV());
1278 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_undef);
1279 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_empty);
1280 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_APIVERSION_invalid);
1282 static struct mro_alg mymro;
1284 static Perl_check_t addissub_nxck_add;
1287 addissub_myck_add(pTHX_ OP *op)
1289 SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addissub", 0);
1292 if (!(flag_svp && SvTRUE(*flag_svp) && (op->op_flags & OPf_KIDS) &&
1293 (aop = cBINOPx(op)->op_first) && (bop = OpSIBLING(aop)) &&
1294 !OpHAS_SIBLING(bop)))
1295 return addissub_nxck_add(aTHX_ op);
1296 flags = op->op_flags;
1297 op_sibling_splice(op, NULL, 1, NULL); /* excise aop */
1298 op_sibling_splice(op, NULL, 1, NULL); /* excise bop */
1299 op_free(op); /* free the empty husk */
1301 return newBINOP(OP_SUBTRACT, flags, aop, bop);
1304 static Perl_check_t old_ck_rv2cv;
1307 my_ck_rv2cv(pTHX_ OP *o)
1310 SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addunder", 0);
1313 if (flag_svp && SvTRUE(*flag_svp) && (o->op_flags & OPf_KIDS)
1314 && (aop = cUNOPx(o)->op_first) && aop->op_type == OP_CONST
1315 && aop->op_private & (OPpCONST_ENTERED|OPpCONST_BARE)
1316 && (ref = cSVOPx(aop)->op_sv) && SvPOK(ref) && SvCUR(ref)
1317 && *(SvEND(ref)-1) == 'o')
1319 SvGROW(ref, SvCUR(ref)+2);
1324 return old_ck_rv2cv(aTHX_ o);
1327 #include "const-c.inc"
1329 MODULE = XS::APItest PACKAGE = XS::APItest
1331 INCLUDE: const-xs.inc
1338 /* this only needs to compile and checks that assert() can be
1339 used this way syntactically */
1340 (void)(assert(x), 1);
1343 MODULE = XS::APItest::utf8 PACKAGE = XS::APItest::utf8
1346 bytes_cmp_utf8(bytes, utf8)
1355 b = (const U8 *)SvPVbyte(bytes, blen);
1356 u = (const U8 *)SvPVbyte(utf8, ulen);
1357 RETVAL = bytes_cmp_utf8(b, blen, u, ulen);
1362 test_utf8n_to_uvchr(s, len, flags)
1373 /* Call utf8n_to_uvchr() with the inputs. It always asks for the
1374 * actual length to be returned
1376 * Length to assume <s> is; not checked, so could have buffer overflow
1379 sv_2mortal((SV*)RETVAL);
1382 = utf8n_to_uvchr((U8*) SvPV(s, slen), SvUV(len), &retlen, SvUV(flags));
1384 /* Returns the return value in [0]; <retlen> in [1] */
1385 av_push(RETVAL, newSVuv(ret));
1386 if (retlen == (STRLEN) -1) {
1387 av_push(RETVAL, newSViv(-1));
1390 av_push(RETVAL, newSVuv(retlen));
1397 test_valid_utf8_to_uvchr(s)
1406 /* Call utf8n_to_uvchr() with the inputs. It always asks for the
1407 * actual length to be returned
1409 * Length to assume <s> is; not checked, so could have buffer overflow
1412 sv_2mortal((SV*)RETVAL);
1415 = valid_utf8_to_uvchr((U8*) SvPV(s, slen), &retlen);
1417 /* Returns the return value in [0]; <retlen> in [1] */
1418 av_push(RETVAL, newSVuv(ret));
1419 av_push(RETVAL, newSVuv(retlen));
1425 test_uvchr_to_utf8_flags(uv, flags)
1430 U8 dest[UTF8_MAXBYTES];
1434 /* Call uvchr_to_utf8_flags() with the inputs. */
1435 ret = uvchr_to_utf8_flags(dest, SvUV(uv), SvUV(flags));
1439 RETVAL = newSVpvn((char *) dest, ret - dest);
1444 MODULE = XS::APItest:Overload PACKAGE = XS::APItest::Overload
1447 amagic_deref_call(sv, what)
1451 /* The reference is owned by something else. */
1452 PUSHs(amagic_deref_call(sv, what));
1454 # I'd certainly like to discourage the use of this macro, given that we now
1455 # have amagic_deref_call
1458 tryAMAGICunDEREF_var(sv, what)
1466 tryAMAGICunDEREF(to_av);
1469 tryAMAGICunDEREF(to_cv);
1472 tryAMAGICunDEREF(to_gv);
1475 tryAMAGICunDEREF(to_hv);
1478 tryAMAGICunDEREF(to_sv);
1481 croak("Invalid value %d passed to tryAMAGICunDEREF_var", what);
1484 /* The reference is owned by something else. */
1487 MODULE = XS::APItest PACKAGE = XS::APItest::XSUB
1490 newXS("XS::APItest::XSUB::XS_VERSION_undef", XS_XS__APItest__XSUB_XS_VERSION_undef, __FILE__);
1491 newXS("XS::APItest::XSUB::XS_VERSION_empty", XS_XS__APItest__XSUB_XS_VERSION_empty, __FILE__);
1492 newXS("XS::APItest::XSUB::XS_APIVERSION_invalid", XS_XS__APItest__XSUB_XS_APIVERSION_invalid, __FILE__);
1495 XS_VERSION_defined(...)
1497 XS_VERSION_BOOTCHECK;
1501 XS_APIVERSION_valid(...)
1503 XS_APIVERSION_BOOTCHECK;
1511 for ( ; i < len; i++ ) {
1512 ST(i) = sv_2mortal( newSViv(i) );
1519 XSRETURN_IV( (1<<31) + 1 );
1524 XSRETURN_UV( (U32)((1U<<31) + 1) );
1534 XSRETURN_PV("returned");
1539 XSRETURN_PVN("returned too much",8);
1561 MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash
1569 uf.uf_val = rot13_key;
1573 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1582 uf.uf_val = bitflip_key;
1586 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1589 #define UTF8KLEN(sv, len) (SvUTF8(sv) ? -(I32)len : (I32)len)
1592 exists(hash, key_sv)
1600 key = SvPV(key_sv, len);
1601 RETVAL = hv_exists(hash, key, UTF8KLEN(key_sv, len));
1606 exists_ent(hash, key_sv)
1612 RETVAL = hv_exists_ent(hash, key_sv, 0);
1617 delete(hash, key_sv, flags = 0)
1626 key = SvPV(key_sv, len);
1627 /* It's already mortal, so need to increase reference count. */
1629 = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags));
1634 delete_ent(hash, key_sv, flags = 0)
1640 /* It's already mortal, so need to increase reference count. */
1641 RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0));
1646 store_ent(hash, key, value)
1656 result = hv_store_ent(hash, key, copy, 0);
1657 SvSetMagicSV(copy, value);
1662 /* It's about to become mortal, so need to increase reference count.
1664 RETVAL = SvREFCNT_inc(HeVAL(result));
1669 store(hash, key_sv, value)
1680 key = SvPV(key_sv, len);
1682 result = hv_store(hash, key, UTF8KLEN(key_sv, len), copy, 0);
1683 SvSetMagicSV(copy, value);
1688 /* It's about to become mortal, so need to increase reference count.
1690 RETVAL = SvREFCNT_inc(*result);
1695 fetch_ent(hash, key_sv)
1702 result = hv_fetch_ent(hash, key_sv, 0, 0);
1707 RETVAL = newSVsv(HeVAL(result));
1721 key = SvPV(key_sv, len);
1722 result = hv_fetch(hash, key, UTF8KLEN(key_sv, len), 0);
1727 RETVAL = newSVsv(*result);
1731 #if defined (hv_common)
1741 const char *key = NULL;
1749 if ((svp = hv_fetchs(params, "hv", 0))) {
1750 SV *const rv = *svp;
1752 croak("common passed a non-reference for parameter hv");
1753 hv = (HV *)SvRV(rv);
1755 if ((svp = hv_fetchs(params, "keysv", 0)))
1757 if ((svp = hv_fetchs(params, "keypv", 0))) {
1758 key = SvPV_const(*svp, klen);
1762 if ((svp = hv_fetchs(params, "action", 0)))
1763 action = SvIV(*svp);
1764 if ((svp = hv_fetchs(params, "val", 0)))
1765 val = newSVsv(*svp);
1766 if ((svp = hv_fetchs(params, "hash", 0)))
1769 if (hv_fetchs(params, "hash_pv", 0)) {
1771 PERL_HASH(hash, key, klen);
1773 if (hv_fetchs(params, "hash_sv", 0)) {
1777 const char *const p = SvPV(keysv, len);
1778 PERL_HASH(hash, p, len);
1782 result = (HE *)hv_common(hv, keysv, key, klen, flags, action, val, hash);
1787 RETVAL = newSVsv(HeVAL(result));
1796 test_freeent(&Perl_hv_free_ent);
1800 test_hv_delayfree_ent()
1802 test_freeent(&Perl_hv_delayfree_ent);
1806 test_share_unshare_pvn(input)
1815 pvx = SvPV(input, len);
1816 PERL_HASH(hash, pvx, len);
1817 p = sharepvn(pvx, len, hash);
1818 RETVAL = newSVpvn(p, len);
1819 unsharepvn(p, len, hash);
1823 #if PERL_VERSION >= 9
1826 refcounted_he_exists(key, level=0)
1831 croak("level must be zero, not %"IVdf, level);
1833 RETVAL = (cop_hints_fetch_sv(PL_curcop, key, 0, 0) != &PL_sv_placeholder);
1838 refcounted_he_fetch(key, level=0)
1843 croak("level must be zero, not %"IVdf, level);
1845 RETVAL = cop_hints_fetch_sv(PL_curcop, key, 0, 0);
1846 SvREFCNT_inc(RETVAL);
1853 test_force_keys(HV *hv)
1859 he = hv_iternext(hv);
1861 SV *sv = HeSVKEY_force(he);
1864 PUSHs(sv_mortalcopy(sv));
1865 he = hv_iternext(hv);
1870 sub TIEHASH { bless {}, $_[0] }
1871 sub STORE { $_[0]->{$_[1]} = $_[2] }
1872 sub FETCH { $_[0]->{$_[1]} }
1873 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
1874 sub NEXTKEY { each %{$_[0]} }
1875 sub EXISTS { exists $_[0]->{$_[1]} }
1876 sub DELETE { delete $_[0]->{$_[1]} }
1877 sub CLEAR { %{$_[0]} = () }
1881 MODULE = XS::APItest:TempLv PACKAGE = XS::APItest::TempLv
1887 SV * const lv = newSV_type(SVt_PVLV);
1892 sv_magic(lv, NULL, PERL_MAGIC_substr, NULL, 0);
1894 LvTARG(lv) = SvREFCNT_inc_simple(sv);
1895 LvTARGOFF(lv) = len == 0 ? 0 : 1;
1896 LvTARGLEN(lv) = len < 2 ? 0 : len-2;
1899 ST(0) = sv_2mortal(lv);
1903 MODULE = XS::APItest::PtrTable PACKAGE = XS::APItest::PtrTable PREFIX = ptr_table_
1906 ptr_table_new(classname)
1907 const char * classname
1909 PUSHs(sv_setref_pv(sv_newmortal(), classname, (void*)ptr_table_new()));
1913 XS::APItest::PtrTable table
1915 ptr_table_free(table);
1918 ptr_table_store(table, from, to)
1919 XS::APItest::PtrTable table
1923 ptr_table_store(table, from, to);
1926 ptr_table_fetch(table, from)
1927 XS::APItest::PtrTable table
1930 RETVAL = PTR2UV(ptr_table_fetch(table, from));
1935 ptr_table_split(table)
1936 XS::APItest::PtrTable table
1939 ptr_table_clear(table)
1940 XS::APItest::PtrTable table
1942 MODULE = XS::APItest::AutoLoader PACKAGE = XS::APItest::AutoLoader
1947 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
1955 PERL_UNUSED_ARG(items);
1956 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
1961 MODULE = XS::APItest PACKAGE = XS::APItest
1966 mymro.resolve = myget_linear_isa;
1967 mymro.name = "justisa";
1971 Perl_mro_register(aTHX_ &mymro);
1976 RETVAL = PL_custom_ops;
1981 xop_custom_op_names ()
1983 PL_custom_op_names = newHV();
1984 RETVAL = PL_custom_op_names;
1989 xop_custom_op_descs ()
1991 PL_custom_op_descs = newHV();
1992 RETVAL = PL_custom_op_descs;
1999 XopENTRY_set(&my_xop, xop_name, "my_xop");
2000 XopENTRY_set(&my_xop, xop_desc, "XOP for testing");
2001 XopENTRY_set(&my_xop, xop_class, OA_UNOP);
2002 XopENTRY_set(&my_xop, xop_peep, peep_xop);
2003 Perl_custom_op_register(aTHX_ pp_xop, &my_xop);
2008 XopDISABLE(&my_xop, xop_name);
2009 XopDISABLE(&my_xop, xop_desc);
2010 XopDISABLE(&my_xop, xop_class);
2011 XopDISABLE(&my_xop, xop_peep);
2016 RETVAL = PTR2IV(&my_xop);
2023 RETVAL = PTR2IV(pp_xop);
2041 MY_CXT.xop_record = newAV();
2043 kid = newSVOP(OP_CONST, 0, newSViv(42));
2045 unop = (UNOP*)mkUNOP(OP_CUSTOM, kid);
2046 unop->op_ppaddr = pp_xop;
2047 unop->op_private = 0;
2048 unop->op_next = NULL;
2049 kid->op_next = (OP*)unop;
2051 av_push(MY_CXT.xop_record, newSVpvf("unop:%"UVxf, PTR2UV(unop)));
2052 av_push(MY_CXT.xop_record, newSVpvf("kid:%"UVxf, PTR2UV(kid)));
2054 av_push(MY_CXT.xop_record, newSVpvf("NAME:%s", OP_NAME((OP*)unop)));
2055 av_push(MY_CXT.xop_record, newSVpvf("DESC:%s", OP_DESC((OP*)unop)));
2056 av_push(MY_CXT.xop_record, newSVpvf("CLASS:%d", (int)OP_CLASS((OP*)unop)));
2058 PL_rpeepp(aTHX_ kid);
2063 RETVAL = MY_CXT.xop_record;
2064 MY_CXT.xop_record = NULL;
2069 xop_from_custom_op ()
2071 /* author note: this test doesn't imply Perl_custom_op_xop is or isn't public
2072 API or that Perl_custom_op_xop is known to be used outside the core */
2076 unop = (UNOP*)mkUNOP(OP_CUSTOM, NULL);
2077 unop->op_ppaddr = pp_xop;
2078 unop->op_private = 0;
2079 unop->op_next = NULL;
2081 xop = Perl_custom_op_xop(aTHX_ (OP *)unop);
2083 RETVAL = PTR2IV(xop);
2092 MY_CXT.sv = newSVpv("initial",0);
2094 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2095 MY_CXT.bhk_record = 0;
2097 BhkENTRY_set(&bhk_test, bhk_start, blockhook_test_start);
2098 BhkENTRY_set(&bhk_test, bhk_pre_end, blockhook_test_pre_end);
2099 BhkENTRY_set(&bhk_test, bhk_post_end, blockhook_test_post_end);
2100 BhkENTRY_set(&bhk_test, bhk_eval, blockhook_test_eval);
2101 Perl_blockhook_register(aTHX_ &bhk_test);
2103 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2104 GV_ADDMULTI, SVt_PVAV);
2105 MY_CXT.cscav = GvAV(MY_CXT.cscgv);
2107 BhkENTRY_set(&bhk_csc, bhk_start, blockhook_csc_start);
2108 BhkENTRY_set(&bhk_csc, bhk_pre_end, blockhook_csc_pre_end);
2109 Perl_blockhook_register(aTHX_ &bhk_csc);
2111 MY_CXT.peep_recorder = newAV();
2112 MY_CXT.rpeep_recorder = newAV();
2114 MY_CXT.orig_peep = PL_peepp;
2115 MY_CXT.orig_rpeep = PL_rpeepp;
2117 PL_rpeepp = my_rpeep;
2124 PERL_UNUSED_VAR(items);
2125 MY_CXT.sv = newSVpv("initial_clone",0);
2126 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2127 GV_ADDMULTI, SVt_PVAV);
2128 MY_CXT.cscav = NULL;
2129 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2130 MY_CXT.bhk_record = 0;
2131 MY_CXT.peep_recorder = newAV();
2132 MY_CXT.rpeep_recorder = newAV();
2138 printf("%5.3f\n",val);
2143 #ifdef HAS_LONG_DOUBLE
2154 #ifdef HAS_LONG_DOUBLE
2155 # if defined(PERL_PRIfldbl) && (LONG_DOUBLESIZE > DOUBLESIZE)
2156 long double val = 7.0;
2157 printf("%5.3" PERL_PRIfldbl "\n",val);
2160 printf("%5.3f\n",val);
2174 printf("%ld\n",val);
2180 printf("%5.3f\n",val);
2228 mXPUSHp("three", 5);
2256 # test_EXTEND(): excerise the EXTEND() macro.
2257 # After calling EXTEND(), it also does *(p+n) = NULL and
2258 # *PL_stack_max = NULL to allow valgrind etc to spot if the stack hasn't
2259 # actually been extended properly.
2261 # max_offset specifies the SP to use. It is treated as a signed offset
2262 # from PL_stack_max.
2263 # nsv is the SV holding the value of n indicating how many slots
2264 # to extend the stack by.
2265 # use_ss is a boolean indicating that n should be cast to a SSize_t
2268 test_EXTEND(max_offset, nsv, use_ss)
2273 SV **sp = PL_stack_max + max_offset;
2276 SSize_t n = (SSize_t)SvIV(nsv);
2285 *PL_stack_max = NULL;
2296 SV * miscsv = sv_newmortal();
2297 HV * hv = (HV*)sv_2mortal((SV*)newHV());
2299 i_sub = get_cv("i", 0);
2301 /* PUTBACK not needed since this sub was called with 0 args, and is calling
2302 0 args, so global SP doesn't need to be moved before a call_* */
2303 retcnt = call_sv((SV*)i_sub, 0); /* try a CV* */
2305 SP -= retcnt; /* dont care about return count, wipe everything off */
2306 sv_setpvs(miscsv, "i");
2308 retcnt = call_sv(miscsv, 0); /* try a PV */
2311 /* no add and SVt_NULL are intentional, sub i should be defined already */
2312 i_gv = gv_fetchpvn_flags("i", sizeof("i")-1, 0, SVt_NULL);
2314 retcnt = call_sv((SV*)i_gv, 0); /* try a GV* */
2317 /* the tests below are not declaring this being public API behavior,
2318 only current internal behavior, these tests can be changed in the
2319 future if necessery */
2321 retcnt = call_sv(&PL_sv_yes, 0); /* does nothing */
2325 retcnt = call_sv(&PL_sv_no, G_EVAL);
2329 errstr = SvPV_nolen(errsv);
2330 if(strnEQ(errstr, "Undefined subroutine &main:: called at",
2331 sizeof("Undefined subroutine &main:: called at") - 1)) {
2333 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2338 retcnt = call_sv(&PL_sv_undef, G_EVAL);
2342 errstr = SvPV_nolen(errsv);
2343 if(strnEQ(errstr, "Can't use an undefined value as a subroutine reference at",
2344 sizeof("Can't use an undefined value as a subroutine reference at") - 1)) {
2346 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2351 retcnt = call_sv((SV*)hv, G_EVAL);
2355 errstr = SvPV_nolen(errsv);
2356 if(strnEQ(errstr, "Not a CODE reference at",
2357 sizeof("Not a CODE reference at") - 1)) {
2359 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2365 call_sv(sv, flags, ...)
2371 for (i=0; i<items-2; i++)
2372 ST(i) = ST(i+2); /* pop first two args */
2376 i = call_sv(sv, flags);
2379 PUSHs(sv_2mortal(newSViv(i)));
2382 call_pv(subname, flags, ...)
2388 for (i=0; i<items-2; i++)
2389 ST(i) = ST(i+2); /* pop first two args */
2393 i = call_pv(subname, flags);
2396 PUSHs(sv_2mortal(newSViv(i)));
2399 call_method(methname, flags, ...)
2405 for (i=0; i<items-2; i++)
2406 ST(i) = ST(i+2); /* pop first two args */
2410 i = call_method(methname, flags);
2413 PUSHs(sv_2mortal(newSViv(i)));
2416 newCONSTSUB(stash, name, flags, sv)
2422 newCONSTSUB_flags = 1
2426 const char *pv = SvPV(name, len);
2430 mycv = newCONSTSUB(stash, pv, SvOK(sv) ? SvREFCNT_inc(sv) : NULL);
2433 mycv = newCONSTSUB_flags(
2434 stash, pv, len, flags | SvUTF8(name), SvOK(sv) ? SvREFCNT_inc(sv) : NULL
2440 PUSHs( CvCONST(mycv) ? &PL_sv_yes : &PL_sv_no );
2441 PUSHs((SV*)CvGV(mycv));
2444 gv_init_type(namesv, multi, flags, type)
2451 const char * const name = SvPV_const(namesv, len);
2452 GV *gv = *(GV**)hv_fetch(PL_defstash, name, len, TRUE);
2454 if (SvTYPE(gv) == SVt_PVGV)
2455 Perl_croak(aTHX_ "GV is already a PVGV");
2456 if (multi) flags |= GV_ADDMULTI;
2459 gv_init(gv, PL_defstash, name, len, multi);
2462 gv_init_sv(gv, PL_defstash, namesv, flags);
2465 gv_init_pv(gv, PL_defstash, name, flags | SvUTF8(namesv));
2468 gv_init_pvn(gv, PL_defstash, name, len, flags | SvUTF8(namesv));
2471 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2474 gv_fetchmeth_type(stash, methname, type, level, flags)
2482 const char * const name = SvPV_const(methname, len);
2487 gv = gv_fetchmeth(stash, name, len, level);
2490 gv = gv_fetchmeth_sv(stash, methname, level, flags);
2493 gv = gv_fetchmeth_pv(stash, name, level, flags | SvUTF8(methname));
2496 gv = gv_fetchmeth_pvn(stash, name, len, level, flags | SvUTF8(methname));
2499 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2502 gv_fetchmeth_autoload_type(stash, methname, type, level, flags)
2510 const char * const name = SvPV_const(methname, len);
2515 gv = gv_fetchmeth_autoload(stash, name, len, level);
2518 gv = gv_fetchmeth_sv_autoload(stash, methname, level, flags);
2521 gv = gv_fetchmeth_pv_autoload(stash, name, level, flags | SvUTF8(methname));
2524 gv = gv_fetchmeth_pvn_autoload(stash, name, len, level, flags | SvUTF8(methname));
2527 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2530 gv_fetchmethod_flags_type(stash, methname, type, flags)
2540 gv = gv_fetchmethod_flags(stash, SvPVX_const(methname), flags);
2543 gv = gv_fetchmethod_sv_flags(stash, methname, flags);
2546 gv = gv_fetchmethod_pv_flags(stash, SvPV_nolen(methname), flags | SvUTF8(methname));
2550 const char * const name = SvPV_const(methname, len);
2551 gv = gv_fetchmethod_pvn_flags(stash, name, len, flags | SvUTF8(methname));
2555 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2558 gv_autoload_type(stash, methname, type, method)
2565 const char * const name = SvPV_const(methname, len);
2567 I32 flags = method ? GV_AUTOLOAD_ISMETHOD : 0;
2571 gv = gv_autoload4(stash, name, len, method);
2574 gv = gv_autoload_sv(stash, methname, flags);
2577 gv = gv_autoload_pv(stash, name, flags | SvUTF8(methname));
2580 gv = gv_autoload_pvn(stash, name, len, flags | SvUTF8(methname));
2583 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2586 gv_const_sv(SV *name)
2591 HV *stash = gv_stashpv("main",0);
2592 HE *he = hv_fetch_ent(stash, name, 0, 0);
2593 gv = (GV *)HeVAL(he);
2598 RETVAL = gv_const_sv(gv);
2601 RETVAL = newSVsv(RETVAL);
2606 whichsig_type(namesv, type)
2611 const char * const name = SvPV_const(namesv, len);
2619 i = whichsig_sv(namesv);
2622 i = whichsig_pv(name);
2625 i = whichsig_pvn(name, len);
2628 XPUSHs(sv_2mortal(newSViv(i)));
2638 i = eval_sv(sv, flags);
2641 PUSHs(sv_2mortal(newSViv(i)));
2644 eval_pv(p, croak_on_error)
2650 PUSHs(eval_pv(p, croak_on_error));
2660 apitest_exception(throw_e)
2670 Perl_croak(aTHX_ "%s", SvPV_nolen(sv));
2673 Perl_croak(aTHX_ NULL);
2679 RETVAL = newRV_inc((SV*)PL_strtab);
2687 RETVAL = my_cxt_getint_p(aMY_CXT);
2696 my_cxt_setint_p(aMY_CXT_ i);
2703 ST(0) = how ? my_cxt_getsv_interp_context() : my_cxt_getsv_interp();
2711 SvREFCNT_dec(MY_CXT.sv);
2712 my_cxt_setsv_p(sv _aMY_CXT);
2716 sv_setsv_cow_hashkey_core()
2719 sv_setsv_cow_hashkey_notcore()
2722 sv_set_deref(SV *sv, SV *sv2, int which)
2726 const char *pv = SvPV(sv2,len);
2727 if (!SvROK(sv)) croak("Not a ref");
2730 case 0: sv_setsv(sv,sv2); break;
2731 case 1: sv_setpv(sv,pv); break;
2732 case 2: sv_setpvn(sv,pv,len); break;
2737 rmagical_cast(sv, type)
2743 if (!SvOK(sv) || !SvROK(sv) || !SvOK(type)) { XSRETURN_UNDEF; }
2745 if (SvTYPE(sv) != SVt_PVHV) { XSRETURN_UNDEF; }
2746 uf.uf_val = rmagical_a_dummy;
2749 if (SvTRUE(type)) { /* b */
2750 sv_magicext(sv, NULL, PERL_MAGIC_ext, &rmagical_b, NULL, 0);
2752 sv_magic(sv, NULL, PERL_MAGIC_uvar, (char *) &uf, sizeof(uf));
2760 if (!SvOK(sv) || !SvROK(sv)) { XSRETURN_UNDEF; }
2763 mXPUSHu(SvFLAGS(sv) & SVs_GMG);
2764 mXPUSHu(SvFLAGS(sv) & SVs_SMG);
2765 mXPUSHu(SvFLAGS(sv) & SVs_RMG);
2772 const PERL_CONTEXT *cx, *dbcx;
2777 cx = caller_cx(level, &dbcx);
2780 pv = CopSTASHPV(cx->blk_oldcop);
2781 ST(0) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2782 gv = CvGV(cx->blk_sub.cv);
2783 ST(1) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2785 pv = CopSTASHPV(dbcx->blk_oldcop);
2786 ST(2) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2787 gv = CvGV(dbcx->blk_sub.cv);
2788 ST(3) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2790 ST(4) = cop_hints_fetch_pvs(cx->blk_oldcop, "foo", 0);
2791 ST(5) = cop_hints_fetch_pvn(cx->blk_oldcop, "foo", 3, 0, 0);
2792 ST(6) = cop_hints_fetch_sv(cx->blk_oldcop,
2793 sv_2mortal(newSVpvs("foo")), 0, 0);
2795 hv = cop_hints_2hv(cx->blk_oldcop, 0);
2796 ST(7) = hv ? sv_2mortal(newRV_noinc((SV *)hv)) : &PL_sv_undef;
2805 ST (0) = newSVpv (Perl_sv_peek (aTHX_ sv), 0);
2811 sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI));
2816 sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI));
2821 sv_inc(get_sv("XS::APItest::UNITCHECK_called", GV_ADD|GV_ADDMULTI));
2826 sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI));
2831 sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI));
2834 utf16_to_utf8 (sv, ...)
2837 utf16_to_utf8_reversed = 1
2842 I32 got; /* Gah, badly thought out APIs */
2844 if (ix) (void)SvPV_force_nolen(sv);
2845 source = (U8 *)SvPVbyte(sv, len);
2846 /* Optionally only convert part of the buffer. */
2850 /* Mortalise this right now, as we'll be testing croak()s */
2851 dest = sv_2mortal(newSV(len * 3 / 2 + 1));
2853 utf16_to_utf8_reversed(source, (U8 *)SvPVX(dest), len, &got);
2855 utf16_to_utf8(source, (U8 *)SvPVX(dest), len, &got);
2857 SvCUR_set(dest, got);
2858 SvPVX(dest)[got] = '\0';
2864 my_exit(int exitcode)
2874 s = SvPVbyte(sv, len);
2882 RETVAL = PL_sv_count;
2890 MY_CXT.bhk_record = on;
2892 av_clear(MY_CXT.bhkav);
2898 MAGIC *callmg, *uvarmg;
2900 sv = sv_2mortal(newSV(0));
2901 if (SvTYPE(sv) >= SVt_PVMG) croak_fail();
2902 if (SvMAGICAL(sv)) croak_fail();
2903 sv_magic(sv, &PL_sv_yes, PERL_MAGIC_checkcall, (char*)&callmg, 0);
2904 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2905 if (!SvMAGICAL(sv)) croak_fail();
2906 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2907 callmg = mg_find(sv, PERL_MAGIC_checkcall);
2908 if (!callmg) croak_fail();
2909 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2911 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
2912 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2913 if (!SvMAGICAL(sv)) croak_fail();
2914 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2915 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
2916 if (!uvarmg) croak_fail();
2917 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2919 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2921 mg_free_type(sv, PERL_MAGIC_vec);
2922 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2923 if (!SvMAGICAL(sv)) croak_fail();
2924 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2925 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
2926 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2928 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2930 mg_free_type(sv, PERL_MAGIC_uvar);
2931 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2932 if (!SvMAGICAL(sv)) croak_fail();
2933 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2934 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2935 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2937 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
2938 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2939 if (!SvMAGICAL(sv)) croak_fail();
2940 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2941 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
2942 if (!uvarmg) croak_fail();
2943 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2945 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2947 mg_free_type(sv, PERL_MAGIC_checkcall);
2948 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2949 if (!SvMAGICAL(sv)) croak_fail();
2950 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
2951 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
2952 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2954 mg_free_type(sv, PERL_MAGIC_uvar);
2955 if (SvMAGICAL(sv)) croak_fail();
2956 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
2957 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2960 test_op_contextualize()
2964 o = newSVOP(OP_CONST, 0, newSViv(0));
2965 o->op_flags &= ~OPf_WANT;
2966 o = op_contextualize(o, G_SCALAR);
2967 if (o->op_type != OP_CONST ||
2968 (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR)
2971 o = newSVOP(OP_CONST, 0, newSViv(0));
2972 o->op_flags &= ~OPf_WANT;
2973 o = op_contextualize(o, G_ARRAY);
2974 if (o->op_type != OP_CONST ||
2975 (o->op_flags & OPf_WANT) != OPf_WANT_LIST)
2978 o = newSVOP(OP_CONST, 0, newSViv(0));
2979 o->op_flags &= ~OPf_WANT;
2980 o = op_contextualize(o, G_VOID);
2981 if (o->op_type != OP_NULL) croak_fail();
2992 troc_gv = gv_fetchpv("XS::APItest::test_rv2cv_op_cv", 0, SVt_PVGV);
2993 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
2994 o = newCVREF(0, newGVOP(OP_GV, 0, troc_gv));
2995 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
2996 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
2998 o->op_private |= OPpENTERSUB_AMPER;
2999 if (rv2cv_op_cv(o, 0)) croak_fail();
3000 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3001 o->op_private &= ~OPpENTERSUB_AMPER;
3002 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3003 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3004 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3006 o = newSVOP(OP_CONST, 0, newSVpv("XS::APItest::test_rv2cv_op_cv", 0));
3007 o->op_private = OPpCONST_BARE;
3009 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3010 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3012 o->op_private |= OPpENTERSUB_AMPER;
3013 if (rv2cv_op_cv(o, 0)) croak_fail();
3014 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3016 o = newCVREF(0, newSVOP(OP_CONST, 0, newRV_inc((SV*)troc_cv)));
3017 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3018 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3020 o->op_private |= OPpENTERSUB_AMPER;
3021 if (rv2cv_op_cv(o, 0)) croak_fail();
3022 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3023 o->op_private &= ~OPpENTERSUB_AMPER;
3024 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3025 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3026 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3028 o = newCVREF(0, newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0))));
3029 if (rv2cv_op_cv(o, 0)) croak_fail();
3030 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3031 o->op_private |= OPpENTERSUB_AMPER;
3032 if (rv2cv_op_cv(o, 0)) croak_fail();
3033 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3034 o->op_private &= ~OPpENTERSUB_AMPER;
3035 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3036 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY)) croak_fail();
3037 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3039 o = newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0)));
3040 if (rv2cv_op_cv(o, 0)) croak_fail();
3041 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3045 test_cv_getset_call_checker()
3047 CV *troc_cv, *tsh_cv;
3048 Perl_call_checker ckfun;
3051 #define check_cc(cv, xckfun, xckobj) \
3053 cv_get_call_checker((cv), &ckfun, &ckobj); \
3054 if (ckfun != (xckfun)) croak_fail_ne(FPTR2DPTR(void *, ckfun), xckfun); \
3055 if (ckobj != (xckobj)) croak_fail_ne(FPTR2DPTR(void *, ckobj), xckobj); \
3057 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3058 tsh_cv = get_cv("XS::APItest::test_savehints", 0);
3059 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv);
3060 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv);
3061 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3063 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv);
3064 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes);
3065 cv_set_call_checker(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no);
3066 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no);
3067 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes);
3068 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3070 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no);
3071 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv);
3072 cv_set_call_checker(troc_cv, Perl_ck_entersub_args_proto_or_list,
3074 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv);
3075 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv);
3076 if (SvMAGICAL((SV*)troc_cv) || SvMAGIC((SV*)troc_cv)) croak_fail();
3077 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3081 cv_set_call_checker_lists(CV *cv)
3083 cv_set_call_checker(cv, THX_ck_entersub_args_lists, &PL_sv_undef);
3086 cv_set_call_checker_scalars(CV *cv)
3088 cv_set_call_checker(cv, THX_ck_entersub_args_scalars, &PL_sv_undef);
3091 cv_set_call_checker_proto(CV *cv, SV *proto)
3094 proto = SvRV(proto);
3095 cv_set_call_checker(cv, Perl_ck_entersub_args_proto, proto);
3098 cv_set_call_checker_proto_or_list(CV *cv, SV *proto)
3101 proto = SvRV(proto);
3102 cv_set_call_checker(cv, Perl_ck_entersub_args_proto_or_list, proto);
3105 cv_set_call_checker_multi_sum(CV *cv)
3107 cv_set_call_checker(cv, THX_ck_entersub_multi_sum, &PL_sv_undef);
3119 #define check_ph(EXPR) \
3120 do { if((EXPR) != &PL_sv_placeholder) croak("fail"); } while(0)
3121 #define check_iv(EXPR, EXPECT) \
3122 do { if(SvIV(EXPR) != (EXPECT)) croak("fail"); } while(0)
3123 #define msvpvs(STR) sv_2mortal(newSVpvs(STR))
3124 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3125 a = cophh_new_empty();
3126 check_ph(cophh_fetch_pvn(a, "foo_1", 5, 0, 0));
3127 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3128 check_ph(cophh_fetch_pv(a, "foo_1", 0, 0));
3129 check_ph(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0));
3130 a = cophh_store_pvn(a, "foo_1abc", 5, 0, msviv(111), 0);
3131 a = cophh_store_pvs(a, "foo_2", msviv(222), 0);
3132 a = cophh_store_pv(a, "foo_3", 0, msviv(333), 0);
3133 a = cophh_store_sv(a, msvpvs("foo_4"), 0, msviv(444), 0);
3134 check_iv(cophh_fetch_pvn(a, "foo_1xyz", 5, 0, 0), 111);
3135 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3136 check_iv(cophh_fetch_pv(a, "foo_1", 0, 0), 111);
3137 check_iv(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0), 111);
3138 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3139 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3140 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3141 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3143 b = cophh_store_pvs(b, "foo_1", msviv(1111), 0);
3144 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3145 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3146 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3147 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3148 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3149 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3150 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3151 check_iv(cophh_fetch_pvs(b, "foo_3", 0), 333);
3152 check_iv(cophh_fetch_pvs(b, "foo_4", 0), 444);
3153 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3154 a = cophh_delete_pvn(a, "foo_1abc", 5, 0, 0);
3155 a = cophh_delete_pvs(a, "foo_2", 0);
3156 b = cophh_delete_pv(b, "foo_3", 0, 0);
3157 b = cophh_delete_sv(b, msvpvs("foo_4"), 0, 0);
3158 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3159 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3160 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3161 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3162 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3163 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3164 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3165 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3166 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3167 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3168 b = cophh_delete_pvs(b, "foo_3", 0);
3169 b = cophh_delete_pvs(b, "foo_5", 0);
3170 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3171 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3172 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3173 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3174 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3176 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3177 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3178 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3179 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3180 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3181 a = cophh_store_pvs(a, "foo_1", msviv(11111), COPHH_KEY_UTF8);
3182 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3184 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3186 /* On EBCDIC, we need to translate the UTF-8 in the ASCII test to the
3187 * equivalent UTF-EBCDIC for the code page. This is done at runtime
3188 * (with the helper function in this file). Therefore we can't use
3189 * cophhh_store_pvs(), as we don't have literal string */
3190 key_sv = sv_2mortal(newSVpvs("foo_"));
3191 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3192 key_name = SvPV(key_sv, key_len);
3193 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3196 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3198 sv_setpvs(key_sv, "foo_");
3199 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3200 key_name = SvPV(key_sv, key_len);
3201 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3204 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3206 sv_setpvs(key_sv, "foo_");
3207 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3208 key_name = SvPV(key_sv, key_len);
3209 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3211 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 11111);
3212 check_iv(cophh_fetch_pvs(a, "foo_1", COPHH_KEY_UTF8), 11111);
3213 check_iv(cophh_fetch_pvs(a, "foo_\xaa", 0), 123);
3215 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xaa", COPHH_KEY_UTF8), 123);
3216 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xaa", 0));
3218 sv_setpvs(key_sv, "foo_");
3219 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xaa"));
3220 key_name = SvPV(key_sv, key_len);
3221 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 123);
3222 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3224 check_iv(cophh_fetch_pvs(a, "foo_\xbb", 0), 456);
3226 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xbb", COPHH_KEY_UTF8), 456);
3227 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xbb", 0));
3229 sv_setpvs(key_sv, "foo_");
3230 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3231 key_name = SvPV(key_sv, key_len);
3232 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 456);
3233 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3235 check_iv(cophh_fetch_pvs(a, "foo_\xcc", 0), 789);
3237 check_iv(cophh_fetch_pvs(a, "foo_\xc3\x8c", COPHH_KEY_UTF8), 789);
3238 check_ph(cophh_fetch_pvs(a, "foo_\xc2\x8c", 0));
3240 sv_setpvs(key_sv, "foo_");
3241 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3242 key_name = SvPV(key_sv, key_len);
3243 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 789);
3244 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3247 check_iv(cophh_fetch_pvs(a, "foo_\xd9\xa6", COPHH_KEY_UTF8), 666);
3248 check_ph(cophh_fetch_pvs(a, "foo_\xd9\xa6", 0));
3250 sv_setpvs(key_sv, "foo_");
3251 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3252 key_name = SvPV(key_sv, key_len);
3253 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 666);
3254 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3272 cop = &PL_compiling;
3273 Perl_cop_store_label(aTHX_ cop, "foo", 3, 0);
3274 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3275 if (strcmp(label,"foo")) croak("fail # cop_fetch_label label");
3276 if (len != 3) croak("fail # cop_fetch_label len");
3277 if (utf8) croak("fail # cop_fetch_label utf8");
3278 /* SMALL GERMAN UMLAUT A */
3279 Perl_cop_store_label(aTHX_ cop, "fo\xc3\xa4", 4, SVf_UTF8);
3280 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3281 if (strcmp(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label");
3282 if (len != 4) croak("fail # cop_fetch_label len");
3283 if (!utf8) croak("fail # cop_fetch_label utf8");
3296 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3297 a = cophh_new_empty();
3298 a = cophh_store_pvs(a, "foo_0", msviv(999), 0);
3299 a = cophh_store_pvs(a, "foo_1", msviv(111), 0);
3300 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3302 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3304 key_sv = sv_2mortal(newSVpvs("foo_"));
3305 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3306 key_name = SvPV(key_sv, key_len);
3307 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3310 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3312 sv_setpvs(key_sv, "foo_");
3313 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3314 key_name = SvPV(key_sv, key_len);
3315 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3318 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3320 sv_setpvs(key_sv, "foo_");
3321 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3322 key_name = SvPV(key_sv, key_len);
3323 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3325 a = cophh_delete_pvs(a, "foo_0", 0);
3326 a = cophh_delete_pvs(a, "foo_2", 0);
3327 RETVAL = cophh_2hv(a, 0);
3338 #define store_hint(KEY, VALUE) \
3339 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), KEY, 1), (VALUE))
3340 #define hint_ok(KEY, EXPECT) \
3341 ((svp = hv_fetchs(GvHV(PL_hintgv), KEY, 0)) && \
3342 (sv = *svp) && SvIV(sv) == (EXPECT) && \
3343 (sv = cop_hints_fetch_pvs(&PL_compiling, KEY, 0)) && \
3344 SvIV(sv) == (EXPECT))
3345 #define check_hint(KEY, EXPECT) \
3346 do { if (!hint_ok(KEY, EXPECT)) croak_fail(); } while(0)
3347 PL_hints |= HINT_LOCALIZE_HH;
3350 PL_hints &= HINT_INTEGER;
3351 store_hint("t0", 123);
3352 store_hint("t1", 456);
3353 if (PL_hints & HINT_INTEGER) croak_fail();
3354 check_hint("t0", 123); check_hint("t1", 456);
3357 if (PL_hints & HINT_INTEGER) croak_fail();
3358 check_hint("t0", 123); check_hint("t1", 456);
3359 PL_hints |= HINT_INTEGER;
3360 store_hint("t0", 321);
3361 if (!(PL_hints & HINT_INTEGER)) croak_fail();
3362 check_hint("t0", 321); check_hint("t1", 456);
3364 if (PL_hints & HINT_INTEGER) croak_fail();
3365 check_hint("t0", 123); check_hint("t1", 456);
3368 if (PL_hints & HINT_INTEGER) croak_fail();
3369 check_hint("t0", 123); check_hint("t1", 456);
3370 store_hint("t1", 654);
3371 if (PL_hints & HINT_INTEGER) croak_fail();
3372 check_hint("t0", 123); check_hint("t1", 654);
3374 if (PL_hints & HINT_INTEGER) croak_fail();
3375 check_hint("t0", 123); check_hint("t1", 456);
3386 PL_hints |= HINT_LOCALIZE_HH;
3389 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), "t0", 1), 123);
3390 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3392 a = newHVhv(GvHV(PL_hintgv));
3394 sv_setiv_mg(*hv_fetchs(a, "t0", 1), 456);
3395 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3397 b = hv_copy_hints_hv(a);
3399 sv_setiv_mg(*hv_fetchs(b, "t0", 1), 789);
3400 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 789)
3409 #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv))
3410 #define check_op(o, expect) \
3412 if (strcmp(test_op_list_describe(o), (expect))) \
3413 croak("fail %s %s", test_op_list_describe(o), (expect)); \
3415 a = op_append_elem(OP_LIST, NULL, NULL);
3417 a = op_append_elem(OP_LIST, iv_op(1), a);
3418 check_op(a, "const(1).");
3419 a = op_append_elem(OP_LIST, NULL, a);
3420 check_op(a, "const(1).");
3421 a = op_append_elem(OP_LIST, a, iv_op(2));
3422 check_op(a, "list[pushmark.const(1).const(2).]");
3423 a = op_append_elem(OP_LIST, a, iv_op(3));
3424 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3425 a = op_append_elem(OP_LIST, a, NULL);
3426 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3427 a = op_append_elem(OP_LIST, NULL, a);
3428 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3429 a = op_append_elem(OP_LIST, iv_op(4), a);
3430 check_op(a, "list[pushmark.const(4)."
3431 "list[pushmark.const(1).const(2).const(3).]]");
3432 a = op_append_elem(OP_LIST, a, iv_op(5));
3433 check_op(a, "list[pushmark.const(4)."
3434 "list[pushmark.const(1).const(2).const(3).]const(5).]");
3435 a = op_append_elem(OP_LIST, a,
3436 op_append_elem(OP_LIST, iv_op(7), iv_op(6)));
3437 check_op(a, "list[pushmark.const(4)."
3438 "list[pushmark.const(1).const(2).const(3).]const(5)."
3439 "list[pushmark.const(7).const(6).]]");
3441 a = op_append_elem(OP_LINESEQ, iv_op(1), iv_op(2));
3442 check_op(a, "lineseq[const(1).const(2).]");
3443 a = op_append_elem(OP_LINESEQ, a, iv_op(3));
3444 check_op(a, "lineseq[const(1).const(2).const(3).]");
3446 a = op_append_elem(OP_LINESEQ,
3447 op_append_elem(OP_LIST, iv_op(1), iv_op(2)),
3449 check_op(a, "lineseq[list[pushmark.const(1).const(2).]const(3).]");
3451 a = op_prepend_elem(OP_LIST, NULL, NULL);
3453 a = op_prepend_elem(OP_LIST, a, iv_op(1));
3454 check_op(a, "const(1).");
3455 a = op_prepend_elem(OP_LIST, a, NULL);
3456 check_op(a, "const(1).");
3457 a = op_prepend_elem(OP_LIST, iv_op(2), a);
3458 check_op(a, "list[pushmark.const(2).const(1).]");
3459 a = op_prepend_elem(OP_LIST, iv_op(3), a);
3460 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3461 a = op_prepend_elem(OP_LIST, NULL, a);
3462 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3463 a = op_prepend_elem(OP_LIST, a, NULL);
3464 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3465 a = op_prepend_elem(OP_LIST, a, iv_op(4));
3466 check_op(a, "list[pushmark."
3467 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3468 a = op_prepend_elem(OP_LIST, iv_op(5), a);
3469 check_op(a, "list[pushmark.const(5)."
3470 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3471 a = op_prepend_elem(OP_LIST,
3472 op_prepend_elem(OP_LIST, iv_op(6), iv_op(7)), a);
3473 check_op(a, "list[pushmark.list[pushmark.const(6).const(7).]const(5)."
3474 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3476 a = op_prepend_elem(OP_LINESEQ, iv_op(2), iv_op(1));
3477 check_op(a, "lineseq[const(2).const(1).]");
3478 a = op_prepend_elem(OP_LINESEQ, iv_op(3), a);
3479 check_op(a, "lineseq[const(3).const(2).const(1).]");
3481 a = op_prepend_elem(OP_LINESEQ, iv_op(3),
3482 op_prepend_elem(OP_LIST, iv_op(2), iv_op(1)));
3483 check_op(a, "lineseq[const(3).list[pushmark.const(2).const(1).]]");
3485 a = op_append_list(OP_LINESEQ, NULL, NULL);
3487 a = op_append_list(OP_LINESEQ, iv_op(1), a);
3488 check_op(a, "const(1).");
3489 a = op_append_list(OP_LINESEQ, NULL, a);
3490 check_op(a, "const(1).");
3491 a = op_append_list(OP_LINESEQ, a, iv_op(2));
3492 check_op(a, "lineseq[const(1).const(2).]");
3493 a = op_append_list(OP_LINESEQ, a, iv_op(3));
3494 check_op(a, "lineseq[const(1).const(2).const(3).]");
3495 a = op_append_list(OP_LINESEQ, iv_op(4), a);
3496 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3497 a = op_append_list(OP_LINESEQ, a, NULL);
3498 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3499 a = op_append_list(OP_LINESEQ, NULL, a);
3500 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3501 a = op_append_list(OP_LINESEQ, a,
3502 op_append_list(OP_LINESEQ, iv_op(5), iv_op(6)));
3503 check_op(a, "lineseq[const(4).const(1).const(2).const(3)."
3504 "const(5).const(6).]");
3506 a = op_append_list(OP_LINESEQ,
3507 op_append_list(OP_LINESEQ, iv_op(1), iv_op(2)),
3508 op_append_list(OP_LIST, iv_op(3), iv_op(4)));
3509 check_op(a, "lineseq[const(1).const(2)."
3510 "list[pushmark.const(3).const(4).]]");
3512 a = op_append_list(OP_LINESEQ,
3513 op_append_list(OP_LIST, iv_op(1), iv_op(2)),
3514 op_append_list(OP_LINESEQ, iv_op(3), iv_op(4)));
3515 check_op(a, "lineseq[list[pushmark.const(1).const(2).]"
3516 "const(3).const(4).]");
3525 #define check_ll(o, expect) \
3527 if (strNE(test_op_linklist_describe(o), (expect))) \
3528 croak("fail %s %s", test_op_linklist_describe(o), (expect)); \
3531 check_ll(o, ".const1");
3534 o = mkUNOP(OP_NOT, iv_op(1));
3535 check_ll(o, ".const1.not");
3538 o = mkUNOP(OP_NOT, mkUNOP(OP_NEGATE, iv_op(1)));
3539 check_ll(o, ".const1.negate.not");
3542 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3543 check_ll(o, ".const1.const2.add");
3546 o = mkBINOP(OP_ADD, mkUNOP(OP_NOT, iv_op(1)), iv_op(2));
3547 check_ll(o, ".const1.not.const2.add");
3550 o = mkUNOP(OP_NOT, mkBINOP(OP_ADD, iv_op(1), iv_op(2)));
3551 check_ll(o, ".const1.const2.add.not");
3554 o = mkLISTOP(OP_LINESEQ, iv_op(1), iv_op(2), iv_op(3));
3555 check_ll(o, ".const1.const2.const3.lineseq");
3558 o = mkLISTOP(OP_LINESEQ,
3559 mkBINOP(OP_ADD, iv_op(1), iv_op(2)),
3560 mkUNOP(OP_NOT, iv_op(3)),
3561 mkLISTOP(OP_SUBSTR, iv_op(4), iv_op(5), iv_op(6)));
3562 check_ll(o, ".const1.const2.add.const3.not"
3563 ".const4.const5.const6.substr.lineseq");
3566 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3568 o = mkBINOP(OP_SUBTRACT, o, iv_op(3));
3569 check_ll(o, ".const1.const2.add.const3.subtract");
3579 av_clear(MY_CXT.peep_recorder);
3580 av_clear(MY_CXT.rpeep_recorder);
3581 MY_CXT.peep_recording = 1;
3588 MY_CXT.peep_recording = 0;
3595 RETVAL = newRV_inc((SV *)MY_CXT.peep_recorder);
3604 RETVAL = newRV_inc((SV *)MY_CXT.rpeep_recorder);
3610 multicall_each: call a sub for each item in the list. Used to test MULTICALL
3615 multicall_each(block,...)
3624 I32 gimme = G_SCALAR;
3625 SV **args = &PL_stack_base[ax];
3631 cv = sv_2cv(block, &stash, &gv, 0);
3633 croak("multicall_each: not a subroutine reference");
3636 SAVESPTR(GvSV(PL_defgv));
3638 for(index = 1 ; index < items ; index++) {
3639 GvSV(PL_defgv) = args[index];
3648 multicall_return(): call the passed sub once in the specificed context
3649 and return whatever it returns
3654 multicall_return(block, context)
3664 I32 gimme = context;
3670 cv = sv_2cv(block, &stash, &gv, 0);
3672 croak("multicall_return not a subroutine reference");
3678 /* copy returned values into an array so they're not freed during
3689 av_push(av, SvREFCNT_inc(TOPs));
3693 for (p = PL_stack_base + 1; p <= SP; p++)
3694 av_push(av, SvREFCNT_inc(*p));
3700 size = AvFILLp(av) + 1;
3702 for (i = 0; i < size; i++)
3703 ST(i) = *av_fetch(av, i, FALSE);
3704 sv_2mortal((SV*)av);
3715 PerlInterpreter *interp = aTHX; /* The original interpreter */
3716 PerlInterpreter *interp_dup; /* The duplicate interpreter */
3717 int oldscope = 1; /* We are responsible for all scopes */
3719 interp_dup = perl_clone(interp, CLONEf_COPY_STACKS | CLONEf_CLONE_HOST );
3721 /* destroy old perl */
3722 PERL_SET_CONTEXT(interp);
3724 POPSTACK_TO(PL_mainstack);
3725 if (cxstack_ix >= 0) {
3727 cx_popblock(cxstack);
3730 PL_scopestack_ix = oldscope;
3733 perl_destruct(interp);
3736 /* switch to new perl */
3737 PERL_SET_CONTEXT(interp_dup);
3739 /* continue after 'clone_with_stack' */
3740 if (interp_dup->Iop)
3741 interp_dup->Iop = interp_dup->Iop->op_next;
3743 /* run with new perl */
3744 Perl_runops_standard(interp_dup);
3746 /* We may have additional unclosed scopes if fork() was called
3747 * from within a BEGIN block. See perlfork.pod for more details.
3748 * We cannot clean up these other scopes because they belong to a
3749 * different interpreter, but we also cannot leave PL_scopestack_ix
3750 * dangling because that can trigger an assertion in perl_destruct().
3752 if (PL_scopestack_ix > oldscope) {
3753 PL_scopestack[oldscope-1] = PL_scopestack[PL_scopestack_ix-1];
3754 PL_scopestack_ix = oldscope;
3757 perl_destruct(interp_dup);
3758 perl_free(interp_dup);
3760 /* call the real 'exit' not PerlProc_exit */
3765 #endif /* USE_ITHREDS */
3768 take_svref(SVREF sv)
3770 RETVAL = newRV_inc(sv);
3777 RETVAL = newRV_inc((SV*)av);
3784 RETVAL = newRV_inc((SV*)hv);
3792 RETVAL = newRV_inc((SV*)cv);
3802 stash = gv_stashpv("XS::APItest::TempLv", 0);
3804 meth = hv_fetchs(stash, "make_temp_mg_lv", 0);
3806 croak("lost method 'make_temp_mg_lv'");
3813 hintkey_rpn_sv = newSVpvs_share("XS::APItest/rpn");
3814 hintkey_calcrpn_sv = newSVpvs_share("XS::APItest/calcrpn");
3815 hintkey_stufftest_sv = newSVpvs_share("XS::APItest/stufftest");
3816 hintkey_swaptwostmts_sv = newSVpvs_share("XS::APItest/swaptwostmts");
3817 hintkey_looprest_sv = newSVpvs_share("XS::APItest/looprest");
3818 hintkey_scopelessblock_sv = newSVpvs_share("XS::APItest/scopelessblock");
3819 hintkey_stmtasexpr_sv = newSVpvs_share("XS::APItest/stmtasexpr");
3820 hintkey_stmtsasexpr_sv = newSVpvs_share("XS::APItest/stmtsasexpr");
3821 hintkey_loopblock_sv = newSVpvs_share("XS::APItest/loopblock");
3822 hintkey_blockasexpr_sv = newSVpvs_share("XS::APItest/blockasexpr");
3823 hintkey_swaplabel_sv = newSVpvs_share("XS::APItest/swaplabel");
3824 hintkey_labelconst_sv = newSVpvs_share("XS::APItest/labelconst");
3825 hintkey_arrayfullexpr_sv = newSVpvs_share("XS::APItest/arrayfullexpr");
3826 hintkey_arraylistexpr_sv = newSVpvs_share("XS::APItest/arraylistexpr");
3827 hintkey_arraytermexpr_sv = newSVpvs_share("XS::APItest/arraytermexpr");
3828 hintkey_arrayarithexpr_sv = newSVpvs_share("XS::APItest/arrayarithexpr");
3829 hintkey_arrayexprflags_sv = newSVpvs_share("XS::APItest/arrayexprflags");
3830 hintkey_DEFSV_sv = newSVpvs_share("XS::APItest/DEFSV");
3831 hintkey_with_vars_sv = newSVpvs_share("XS::APItest/with_vars");
3832 hintkey_join_with_space_sv = newSVpvs_share("XS::APItest/join_with_space");
3833 next_keyword_plugin = PL_keyword_plugin;
3834 PL_keyword_plugin = my_keyword_plugin;
3838 establish_cleanup(...)
3841 PERL_UNUSED_VAR(items);
3842 croak("establish_cleanup called as a function");
3846 CV *estcv = get_cv("XS::APItest::establish_cleanup", 0);
3847 cv_set_call_checker(estcv, THX_ck_entersub_establish_cleanup, (SV*)estcv);
3854 PERL_UNUSED_VAR(items);
3855 croak("postinc called as a function");
3860 filter_add(filter_call, NULL);
3864 CV *asscv = get_cv("XS::APItest::postinc", 0);
3865 cv_set_call_checker(asscv, THX_ck_entersub_postinc, (SV*)asscv);
3873 newRV_noinc(newSV(0)),
3874 gv_stashpvs("XS::APItest::TempObj",GV_ADD)
3875 ); /* Package defined in test script */
3880 fill_hash_with_nulls(HV *hv)
3884 for(; i < 1000; ++i) {
3885 HE *entry = hv_fetch_ent(hv, sv_2mortal(newSVuv(i)), 1, 0);
3886 SvREFCNT_dec(HeVAL(entry));
3887 HeVAL(entry) = NULL;
3893 RETVAL = newHVhv(hv);
3900 RETVAL = SvIsCOW(sv);
3908 PERL_UNUSED_VAR(items);
3909 croak("pad_scalar called as a function");
3913 CV *pscv = get_cv("XS::APItest::pad_scalar", 0);
3914 cv_set_call_checker(pscv, THX_ck_entersub_pad_scalar, (SV*)pscv);
3918 fetch_pad_names( cv )
3922 PADNAMELIST *pad_namelist;
3923 AV *retav = newAV();
3925 pad_namelist = PadlistNAMES(CvPADLIST(cv));
3927 for ( i = PadnamelistMAX(pad_namelist); i >= 0; i-- ) {
3928 PADNAME* name = PadnamelistARRAY(pad_namelist)[i];
3930 if (PadnameLEN(name)) {
3931 av_push(retav, newSVpadname(name));
3934 RETVAL = newRV_noinc((SV*)retav);
3946 u = find_rundefsv();
3947 pv = (U8*)SvPV(u, bytelen);
3948 RETVAL = SvUTF8(u) ? utf8_length(pv, pv+bytelen) : bytelen;
3955 (void)SvPV_nolen(sv);
3960 RETVAL = hv && HvENAME(hv)
3962 HvENAME(hv),HvENAMELEN(hv),
3963 (HvENAMEUTF8(hv) ? SVf_UTF8 : 0)
3970 xs_cmp(int a, int b)
3972 /* Odd sorting (odd numbers first), to make sure we are actually
3974 RETVAL = a % 2 != b % 2
3976 : a < b ? -1 : a == b ? 0 : 1;
3981 xs_cmp_undef(SV *a, SV *b)
3985 RETVAL = &PL_sv_undef;
3992 RETVAL = SvPVbyte_nolen(sv);
3999 RETVAL = SvPVutf8_nolen(sv);
4006 wrap_op_checker(OP_ADD, addissub_myck_add, &addissub_nxck_add);
4009 setup_rv2cv_addunderbar()
4011 wrap_op_checker(OP_RV2CV, my_ck_rv2cv, &old_ck_rv2cv);
4016 test_alloccopstash()
4018 RETVAL = PL_stashpad[alloccopstash(PL_defstash)] == PL_defstash;
4025 test_newFOROP_without_slab()
4028 const I32 floor = start_subparse(0,0);
4030 /* The slab allocator does not like CvROOT being set. */
4031 CvROOT(PL_compcv) = (OP *)1;
4032 o = newFOROP(0, 0, newOP(OP_PUSHMARK, 0), 0, 0);
4033 #ifdef PERL_OP_PARENT
4034 if (cLOOPx(cUNOPo->op_first)->op_last->op_sibparent
4035 != cUNOPo->op_first)
4037 Perl_warn(aTHX_ "Op parent pointer is stale");
4042 /* If we do not crash before returning, the test passes. */
4045 CvROOT(PL_compcv) = NULL;
4046 SvREFCNT_dec(PL_compcv);
4052 # provide access to CALLREGEXEC, except replace pointers within the
4053 # string with offsets from the start of the string
4056 callregexec(SV *prog, STRLEN stringarg, STRLEN strend, I32 minend, SV *sv, U32 nosave)
4063 strbeg = SvPV_force(sv, len);
4064 RETVAL = CALLREGEXEC((REGEXP *)prog,
4077 lexical_import(SV *name, CV *cv)
4084 "lexical_import can only be called at compile time");
4085 pl = CvPADLIST(PL_compcv);
4087 SAVESPTR(PL_comppad_name); PL_comppad_name = PadlistNAMES(pl);
4088 SAVESPTR(PL_comppad); PL_comppad = PadlistARRAY(pl)[1];
4089 SAVESPTR(PL_curpad); PL_curpad = PadARRAY(PL_comppad);
4090 off = pad_add_name_sv(sv_2mortal(newSVpvf("&%"SVf,name)),
4091 padadd_STATE, 0, 0);
4092 SvREFCNT_dec(PL_curpad[off]);
4093 PL_curpad[off] = SvREFCNT_inc(cv);
4098 sv_mortalcopy(SV *sv)
4100 RETVAL = SvREFCNT_inc(sv_mortalcopy(sv));
4108 alias_av(AV *av, IV ix, SV *sv)
4110 av_store(av, ix, SvREFCNT_inc(sv));
4113 cv_name(SVREF ref, ...)
4115 RETVAL = SvREFCNT_inc(cv_name((CV *)ref,
4116 items>1 && ST(1) != &PL_sv_undef
4119 items>2 ? SvUV(ST(2)) : 0));
4124 sv_catpvn(SV *sv, SV *sv2)
4128 const char *s = SvPV(sv2,len);
4129 sv_catpvn_flags(sv,s,len, SvUTF8(sv2) ? SV_CATUTF8 : SV_CATBYTES);
4136 OP *o = newLISTOP(OP_CUSTOM, 0, NULL, NULL);
4138 o = newOP(OP_CUSTOM, 0);
4140 o = newUNOP(OP_CUSTOM, 0, NULL);
4142 o = newUNOP_AUX(OP_CUSTOM, 0, NULL, NULL);
4144 o = newMETHOP(OP_CUSTOM, 0, newOP(OP_NULL,0));
4146 o = newMETHOP_named(OP_CUSTOM, 0, newSV(0));
4148 o = newBINOP(OP_CUSTOM, 0, NULL, NULL);
4150 o = newPMOP(OP_CUSTOM, 0);
4152 o = newSVOP(OP_CUSTOM, 0, newSV(0));
4156 lex_start(NULL, NULL, 0);
4158 I32 ix = start_subparse(FALSE,0);
4159 o = newPADOP(OP_CUSTOM, 0, newSV(0));
4165 o = newPVOP(OP_CUSTOM, 0, NULL);
4167 o = newLOGOP(OP_CUSTOM, 0, newOP(OP_NULL,0), newOP(OP_NULL,0));
4169 o = newLOOPEX(OP_CUSTOM, newOP(OP_NULL,0));
4177 test_sv_catpvf(SV *fmtsv)
4182 fmt = SvPV_nolen(fmtsv);
4183 sv = sv_2mortal(newSVpvn("", 0));
4184 sv_catpvf(sv, fmt, 5, 6, 7, 8);
4186 MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest
4192 SV* class_and_method;
4194 PERL_UNUSED_ARG(items);
4195 class_and_method = GvSV(CvGV(cv));
4196 comms = get_sv("main::the_method", 1);
4197 if (class_and_method == NULL) {
4199 } else if (!SvOK(class_and_method)) {
4201 } else if (!SvPOK(class_and_method)) {
4204 sv_setsv(comms, class_and_method);
4210 MODULE = XS::APItest PACKAGE = XS::APItest::Magic
4215 sv_magic_foo(SV *sv, SV *thingy)
4219 sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo, (const char *)thingy, 0);
4226 MAGIC *mg = mg_findext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4227 RETVAL = mg ? SvREFCNT_inc((SV *)mg->mg_ptr) : &PL_sv_undef;
4232 sv_unmagic_foo(SV *sv)
4236 sv_unmagicext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4239 sv_magic(SV *sv, SV *thingy)
4241 sv_magic(SvRV(sv), NULL, PERL_MAGIC_ext, (const char *)thingy, 0);
4249 #define test_get_this_vtable(name) \
4250 want = (MGVTBL*)CAT2(&PL_vtbl_, name); \
4251 have = get_vtbl(CAT2(want_vtbl_, name)); \
4253 croak("fail %p!=%p for get_vtbl(want_vtbl_" STRINGIFY(name) ") at " __FILE__ " line %d", have, want, __LINE__)
4255 test_get_this_vtable(sv);
4256 test_get_this_vtable(env);
4257 test_get_this_vtable(envelem);
4258 test_get_this_vtable(sigelem);
4259 test_get_this_vtable(pack);
4260 test_get_this_vtable(packelem);
4261 test_get_this_vtable(dbline);
4262 test_get_this_vtable(isa);
4263 test_get_this_vtable(isaelem);
4264 test_get_this_vtable(arylen);
4265 test_get_this_vtable(mglob);
4266 test_get_this_vtable(nkeys);
4267 test_get_this_vtable(taint);
4268 test_get_this_vtable(substr);
4269 test_get_this_vtable(vec);
4270 test_get_this_vtable(pos);
4271 test_get_this_vtable(bm);
4272 test_get_this_vtable(fm);
4273 test_get_this_vtable(uvar);
4274 test_get_this_vtable(defelem);
4275 test_get_this_vtable(regexp);
4276 test_get_this_vtable(regdata);
4277 test_get_this_vtable(regdatum);
4278 #ifdef USE_LOCALE_COLLATE
4279 test_get_this_vtable(collxfrm);
4281 test_get_this_vtable(backref);
4282 test_get_this_vtable(utf8);
4284 RETVAL = PTR2UV(get_vtbl(-1));
4289 test_isBLANK_uni(UV ord)
4291 RETVAL = isBLANK_uni(ord);
4296 test_isBLANK_LC_uvchr(UV ord)
4298 RETVAL = isBLANK_LC_uvchr(ord);
4303 test_isBLANK_A(UV ord)
4305 RETVAL = isBLANK_A(ord);
4310 test_isBLANK_L1(UV ord)
4312 RETVAL = isBLANK_L1(ord);
4317 test_isBLANK_LC(UV ord)
4319 RETVAL = isBLANK_LC(ord);
4324 test_isBLANK_utf8(unsigned char * p)
4326 RETVAL = isBLANK_utf8(p);
4331 test_isBLANK_LC_utf8(unsigned char * p)
4333 RETVAL = isBLANK_LC_utf8(p);
4338 test_isVERTWS_uni(UV ord)
4340 RETVAL = isVERTWS_uni(ord);
4345 test_isVERTWS_utf8(unsigned char * p)
4347 RETVAL = isVERTWS_utf8(p);
4352 test_isUPPER_uni(UV ord)
4354 RETVAL = isUPPER_uni(ord);
4359 test_isUPPER_LC_uvchr(UV ord)
4361 RETVAL = isUPPER_LC_uvchr(ord);
4366 test_isUPPER_A(UV ord)
4368 RETVAL = isUPPER_A(ord);
4373 test_isUPPER_L1(UV ord)
4375 RETVAL = isUPPER_L1(ord);
4380 test_isUPPER_LC(UV ord)
4382 RETVAL = isUPPER_LC(ord);
4387 test_isUPPER_utf8(unsigned char * p)
4389 RETVAL = isUPPER_utf8( p);
4394 test_isUPPER_LC_utf8(unsigned char * p)
4396 RETVAL = isUPPER_LC_utf8( p);
4401 test_isLOWER_uni(UV ord)
4403 RETVAL = isLOWER_uni(ord);
4408 test_isLOWER_LC_uvchr(UV ord)
4410 RETVAL = isLOWER_LC_uvchr(ord);
4415 test_isLOWER_A(UV ord)
4417 RETVAL = isLOWER_A(ord);
4422 test_isLOWER_L1(UV ord)
4424 RETVAL = isLOWER_L1(ord);
4429 test_isLOWER_LC(UV ord)
4431 RETVAL = isLOWER_LC(ord);
4436 test_isLOWER_utf8(unsigned char * p)
4438 RETVAL = isLOWER_utf8( p);
4443 test_isLOWER_LC_utf8(unsigned char * p)
4445 RETVAL = isLOWER_LC_utf8( p);
4450 test_isALPHA_uni(UV ord)
4452 RETVAL = isALPHA_uni(ord);
4457 test_isALPHA_LC_uvchr(UV ord)
4459 RETVAL = isALPHA_LC_uvchr(ord);
4464 test_isALPHA_A(UV ord)
4466 RETVAL = isALPHA_A(ord);
4471 test_isALPHA_L1(UV ord)
4473 RETVAL = isALPHA_L1(ord);
4478 test_isALPHA_LC(UV ord)
4480 RETVAL = isALPHA_LC(ord);
4485 test_isALPHA_utf8(unsigned char * p)
4487 RETVAL = isALPHA_utf8( p);
4492 test_isALPHA_LC_utf8(unsigned char * p)
4494 RETVAL = isALPHA_LC_utf8( p);
4499 test_isWORDCHAR_uni(UV ord)
4501 RETVAL = isWORDCHAR_uni(ord);
4506 test_isWORDCHAR_LC_uvchr(UV ord)
4508 RETVAL = isWORDCHAR_LC_uvchr(ord);
4513 test_isWORDCHAR_A(UV ord)
4515 RETVAL = isWORDCHAR_A(ord);
4520 test_isWORDCHAR_L1(UV ord)
4522 RETVAL = isWORDCHAR_L1(ord);
4527 test_isWORDCHAR_LC(UV ord)
4529 RETVAL = isWORDCHAR_LC(ord);
4534 test_isWORDCHAR_utf8(unsigned char * p)
4536 RETVAL = isWORDCHAR_utf8( p);
4541 test_isWORDCHAR_LC_utf8(unsigned char * p)
4543 RETVAL = isWORDCHAR_LC_utf8( p);
4548 test_isALPHANUMERIC_uni(UV ord)
4550 RETVAL = isALPHANUMERIC_uni(ord);
4555 test_isALPHANUMERIC_LC_uvchr(UV ord)
4557 RETVAL = isALPHANUMERIC_LC_uvchr(ord);
4562 test_isALPHANUMERIC_A(UV ord)
4564 RETVAL = isALPHANUMERIC_A(ord);
4569 test_isALPHANUMERIC_L1(UV ord)
4571 RETVAL = isALPHANUMERIC_L1(ord);
4576 test_isALPHANUMERIC_LC(UV ord)
4578 RETVAL = isALPHANUMERIC_LC(ord);
4583 test_isALPHANUMERIC_utf8(unsigned char * p)
4585 RETVAL = isALPHANUMERIC_utf8( p);
4590 test_isALPHANUMERIC_LC_utf8(unsigned char * p)
4592 RETVAL = isALPHANUMERIC_LC_utf8( p);
4597 test_isALNUM_uni(UV ord)
4599 RETVAL = isALNUM_uni(ord);
4604 test_isALNUM_LC_uvchr(UV ord)
4606 RETVAL = isALNUM_LC_uvchr(ord);
4611 test_isALNUM_LC(UV ord)
4613 RETVAL = isALNUM_LC(ord);
4618 test_isALNUM_utf8(unsigned char * p)
4620 RETVAL = isALNUM_utf8( p);
4625 test_isALNUM_LC_utf8(unsigned char * p)
4627 RETVAL = isALNUM_LC_utf8( p);
4632 test_isDIGIT_uni(UV ord)
4634 RETVAL = isDIGIT_uni(ord);
4639 test_isDIGIT_LC_uvchr(UV ord)
4641 RETVAL = isDIGIT_LC_uvchr(ord);
4646 test_isDIGIT_utf8(unsigned char * p)
4648 RETVAL = isDIGIT_utf8( p);
4653 test_isDIGIT_LC_utf8(unsigned char * p)
4655 RETVAL = isDIGIT_LC_utf8( p);
4660 test_isDIGIT_A(UV ord)
4662 RETVAL = isDIGIT_A(ord);
4667 test_isDIGIT_L1(UV ord)
4669 RETVAL = isDIGIT_L1(ord);
4674 test_isDIGIT_LC(UV ord)
4676 RETVAL = isDIGIT_LC(ord);
4681 test_isIDFIRST_uni(UV ord)
4683 RETVAL = isIDFIRST_uni(ord);
4688 test_isIDFIRST_LC_uvchr(UV ord)
4690 RETVAL = isIDFIRST_LC_uvchr(ord);
4695 test_isIDFIRST_A(UV ord)
4697 RETVAL = isIDFIRST_A(ord);
4702 test_isIDFIRST_L1(UV ord)
4704 RETVAL = isIDFIRST_L1(ord);
4709 test_isIDFIRST_LC(UV ord)
4711 RETVAL = isIDFIRST_LC(ord);
4716 test_isIDFIRST_utf8(unsigned char * p)
4718 RETVAL = isIDFIRST_utf8( p);
4723 test_isIDFIRST_LC_utf8(unsigned char * p)
4725 RETVAL = isIDFIRST_LC_utf8( p);
4730 test_isIDCONT_uni(UV ord)
4732 RETVAL = isIDCONT_uni(ord);
4737 test_isIDCONT_LC_uvchr(UV ord)
4739 RETVAL = isIDCONT_LC_uvchr(ord);
4744 test_isIDCONT_A(UV ord)
4746 RETVAL = isIDCONT_A(ord);
4751 test_isIDCONT_L1(UV ord)
4753 RETVAL = isIDCONT_L1(ord);
4758 test_isIDCONT_LC(UV ord)
4760 RETVAL = isIDCONT_LC(ord);
4765 test_isIDCONT_utf8(unsigned char * p)
4767 RETVAL = isIDCONT_utf8( p);
4772 test_isIDCONT_LC_utf8(unsigned char * p)
4774 RETVAL = isIDCONT_LC_utf8( p);
4779 test_isSPACE_uni(UV ord)
4781 RETVAL = isSPACE_uni(ord);
4786 test_isSPACE_LC_uvchr(UV ord)
4788 RETVAL = isSPACE_LC_uvchr(ord);
4793 test_isSPACE_A(UV ord)
4795 RETVAL = isSPACE_A(ord);
4800 test_isSPACE_L1(UV ord)
4802 RETVAL = isSPACE_L1(ord);
4807 test_isSPACE_LC(UV ord)
4809 RETVAL = isSPACE_LC(ord);
4814 test_isSPACE_utf8(unsigned char * p)
4816 RETVAL = isSPACE_utf8( p);
4821 test_isSPACE_LC_utf8(unsigned char * p)
4823 RETVAL = isSPACE_LC_utf8( p);
4828 test_isASCII_uni(UV ord)
4830 RETVAL = isASCII_uni(ord);
4835 test_isASCII_LC_uvchr(UV ord)
4837 RETVAL = isASCII_LC_uvchr(ord);
4842 test_isASCII_A(UV ord)
4844 RETVAL = isASCII_A(ord);
4849 test_isASCII_L1(UV ord)
4851 RETVAL = isASCII_L1(ord);
4856 test_isASCII_LC(UV ord)
4858 RETVAL = isASCII_LC(ord);
4863 test_isASCII_utf8(unsigned char * p)
4865 RETVAL = isASCII_utf8( p);
4870 test_isASCII_LC_utf8(unsigned char * p)
4872 RETVAL = isASCII_LC_utf8( p);
4877 test_isCNTRL_uni(UV ord)
4879 RETVAL = isCNTRL_uni(ord);
4884 test_isCNTRL_LC_uvchr(UV ord)
4886 RETVAL = isCNTRL_LC_uvchr(ord);
4891 test_isCNTRL_A(UV ord)
4893 RETVAL = isCNTRL_A(ord);
4898 test_isCNTRL_L1(UV ord)
4900 RETVAL = isCNTRL_L1(ord);
4905 test_isCNTRL_LC(UV ord)
4907 RETVAL = isCNTRL_LC(ord);
4912 test_isCNTRL_utf8(unsigned char * p)
4914 RETVAL = isCNTRL_utf8( p);
4919 test_isCNTRL_LC_utf8(unsigned char * p)
4921 RETVAL = isCNTRL_LC_utf8( p);
4926 test_isPRINT_uni(UV ord)
4928 RETVAL = isPRINT_uni(ord);
4933 test_isPRINT_LC_uvchr(UV ord)
4935 RETVAL = isPRINT_LC_uvchr(ord);
4940 test_isPRINT_A(UV ord)
4942 RETVAL = isPRINT_A(ord);
4947 test_isPRINT_L1(UV ord)
4949 RETVAL = isPRINT_L1(ord);
4954 test_isPRINT_LC(UV ord)
4956 RETVAL = isPRINT_LC(ord);
4961 test_isPRINT_utf8(unsigned char * p)
4963 RETVAL = isPRINT_utf8( p);
4968 test_isPRINT_LC_utf8(unsigned char * p)
4970 RETVAL = isPRINT_LC_utf8( p);
4975 test_isGRAPH_uni(UV ord)
4977 RETVAL = isGRAPH_uni(ord);
4982 test_isGRAPH_LC_uvchr(UV ord)
4984 RETVAL = isGRAPH_LC_uvchr(ord);
4989 test_isGRAPH_A(UV ord)
4991 RETVAL = isGRAPH_A(ord);
4996 test_isGRAPH_L1(UV ord)
4998 RETVAL = isGRAPH_L1(ord);
5003 test_isGRAPH_LC(UV ord)
5005 RETVAL = isGRAPH_LC(ord);
5010 test_isGRAPH_utf8(unsigned char * p)
5012 RETVAL = isGRAPH_utf8( p);
5017 test_isGRAPH_LC_utf8(unsigned char * p)
5019 RETVAL = isGRAPH_LC_utf8( p);
5024 test_isPUNCT_uni(UV ord)
5026 RETVAL = isPUNCT_uni(ord);
5031 test_isPUNCT_LC_uvchr(UV ord)
5033 RETVAL = isPUNCT_LC_uvchr(ord);
5038 test_isPUNCT_A(UV ord)
5040 RETVAL = isPUNCT_A(ord);
5045 test_isPUNCT_L1(UV ord)
5047 RETVAL = isPUNCT_L1(ord);
5052 test_isPUNCT_LC(UV ord)
5054 RETVAL = isPUNCT_LC(ord);
5059 test_isPUNCT_utf8(unsigned char * p)
5061 RETVAL = isPUNCT_utf8( p);
5066 test_isPUNCT_LC_utf8(unsigned char * p)
5068 RETVAL = isPUNCT_LC_utf8( p);
5073 test_isXDIGIT_uni(UV ord)
5075 RETVAL = isXDIGIT_uni(ord);
5080 test_isXDIGIT_LC_uvchr(UV ord)
5082 RETVAL = isXDIGIT_LC_uvchr(ord);
5087 test_isXDIGIT_A(UV ord)
5089 RETVAL = isXDIGIT_A(ord);
5094 test_isXDIGIT_L1(UV ord)
5096 RETVAL = isXDIGIT_L1(ord);
5101 test_isXDIGIT_LC(UV ord)
5103 RETVAL = isXDIGIT_LC(ord);
5108 test_isXDIGIT_utf8(unsigned char * p)
5110 RETVAL = isXDIGIT_utf8( p);
5115 test_isXDIGIT_LC_utf8(unsigned char * p)
5117 RETVAL = isXDIGIT_LC_utf8( p);
5122 test_isPSXSPC_uni(UV ord)
5124 RETVAL = isPSXSPC_uni(ord);
5129 test_isPSXSPC_LC_uvchr(UV ord)
5131 RETVAL = isPSXSPC_LC_uvchr(ord);
5136 test_isPSXSPC_A(UV ord)
5138 RETVAL = isPSXSPC_A(ord);
5143 test_isPSXSPC_L1(UV ord)
5145 RETVAL = isPSXSPC_L1(ord);
5150 test_isPSXSPC_LC(UV ord)
5152 RETVAL = isPSXSPC_LC(ord);
5157 test_isPSXSPC_utf8(unsigned char * p)
5159 RETVAL = isPSXSPC_utf8( p);
5164 test_isPSXSPC_LC_utf8(unsigned char * p)
5166 RETVAL = isPSXSPC_LC_utf8( p);
5171 test_isQUOTEMETA(UV ord)
5173 RETVAL = _isQUOTEMETA(ord);
5178 test_OFFUNISKIP(UV ord)
5180 RETVAL = OFFUNISKIP(ord);
5185 test_OFFUNI_IS_INVARIANT(UV ord)
5187 RETVAL = OFFUNI_IS_INVARIANT(ord);
5192 test_UVCHR_IS_INVARIANT(UV ord)
5194 RETVAL = UVCHR_IS_INVARIANT(ord);
5199 test_UTF8_IS_INVARIANT(char ch)
5201 RETVAL = UTF8_IS_INVARIANT(ch);
5206 test_UVCHR_SKIP(UV ord)
5208 RETVAL = UVCHR_SKIP(ord);
5213 test_UTF8_SKIP(char * ch)
5215 RETVAL = UTF8_SKIP(ch);
5220 test_UTF8_IS_START(char ch)
5222 RETVAL = UTF8_IS_START(ch);
5227 test_UTF8_IS_CONTINUATION(char ch)
5229 RETVAL = UTF8_IS_CONTINUATION(ch);
5234 test_UTF8_IS_CONTINUED(char ch)
5236 RETVAL = UTF8_IS_CONTINUED(ch);
5241 test_UTF8_IS_DOWNGRADEABLE_START(char ch)
5243 RETVAL = UTF8_IS_DOWNGRADEABLE_START(ch);
5248 test_UTF8_IS_ABOVE_LATIN1(char ch)
5250 RETVAL = UTF8_IS_ABOVE_LATIN1(ch);
5255 test_isUTF8_POSSIBLY_PROBLEMATIC(char ch)
5257 RETVAL = isUTF8_POSSIBLY_PROBLEMATIC(ch);
5262 test_toLOWER(UV ord)
5264 RETVAL = toLOWER(ord);
5269 test_toLOWER_L1(UV ord)
5271 RETVAL = toLOWER_L1(ord);
5276 test_toLOWER_LC(UV ord)
5278 RETVAL = toLOWER_LC(ord);
5283 test_toLOWER_uni(UV ord)
5285 U8 s[UTF8_MAXBYTES_CASE + 1];
5291 av_push(av, newSVuv(toLOWER_uni(ord, s, &len)));
5293 utf8 = newSVpvn((char *) s, len);
5297 av_push(av, newSVuv(len));
5303 test_toLOWER_utf8(SV * p)
5306 U8 s[UTF8_MAXBYTES_CASE + 1];
5311 input = (U8 *) SvPV(p, len);
5313 av_push(av, newSVuv(toLOWER_utf8(input, s, &len)));
5315 utf8 = newSVpvn((char *) s, len);
5319 av_push(av, newSVuv(len));
5327 RETVAL = toFOLD(ord);
5332 test_toFOLD_LC(UV ord)
5334 RETVAL = toFOLD_LC(ord);
5339 test_toFOLD_uni(UV ord)
5341 U8 s[UTF8_MAXBYTES_CASE + 1];
5347 av_push(av, newSVuv(toFOLD_uni(ord, s, &len)));
5349 utf8 = newSVpvn((char *) s, len);
5353 av_push(av, newSVuv(len));
5359 test_toFOLD_utf8(SV * p)
5362 U8 s[UTF8_MAXBYTES_CASE + 1];
5367 input = (U8 *) SvPV(p, len);
5369 av_push(av, newSVuv(toFOLD_utf8(input, s, &len)));
5371 utf8 = newSVpvn((char *) s, len);
5375 av_push(av, newSVuv(len));
5381 test_toUPPER(UV ord)
5383 RETVAL = toUPPER(ord);
5388 test_toUPPER_LC(UV ord)
5390 RETVAL = toUPPER_LC(ord);
5395 test_toUPPER_uni(UV ord)
5397 U8 s[UTF8_MAXBYTES_CASE + 1];
5403 av_push(av, newSVuv(toUPPER_uni(ord, s, &len)));
5405 utf8 = newSVpvn((char *) s, len);
5409 av_push(av, newSVuv(len));
5415 test_toUPPER_utf8(SV * p)
5418 U8 s[UTF8_MAXBYTES_CASE + 1];
5423 input = (U8 *) SvPV(p, len);
5425 av_push(av, newSVuv(toUPPER_utf8(input, s, &len)));
5427 utf8 = newSVpvn((char *) s, len);
5431 av_push(av, newSVuv(len));
5437 test_toTITLE(UV ord)
5439 RETVAL = toTITLE(ord);
5444 test_toTITLE_uni(UV ord)
5446 U8 s[UTF8_MAXBYTES_CASE + 1];
5452 av_push(av, newSVuv(toTITLE_uni(ord, s, &len)));
5454 utf8 = newSVpvn((char *) s, len);
5458 av_push(av, newSVuv(len));
5464 test_toTITLE_utf8(SV * p)
5467 U8 s[UTF8_MAXBYTES_CASE + 1];
5472 input = (U8 *) SvPV(p, len);
5474 av_push(av, newSVuv(toTITLE_utf8(input, s, &len)));
5476 utf8 = newSVpvn((char *) s, len);
5480 av_push(av, newSVuv(len));
5486 test_Gconvert(SV * number, SV * num_digits)
5491 len = (int) SvIV(num_digits);
5492 if (len > 99) croak("Too long a number for test_Gconvert");
5493 if (len < 0) croak("Too short a number for test_Gconvert");
5494 PERL_UNUSED_RESULT(Gconvert(SvNV(number), len,
5495 0, /* No trailing zeroes */
5497 RETVAL = newSVpv(buffer, 0);
5501 MODULE = XS::APItest PACKAGE = XS::APItest::Backrefs
5504 apitest_weaken(SV *sv)
5510 has_backrefs(SV *sv)
5512 if (SvROK(sv) && sv_get_backrefs(SvRV(sv)))
5513 RETVAL = &PL_sv_yes;
5520 #ifdef PERL_IMPLICIT_SYS
5523 PerlDir_mapA(const char *path)
5526 PerlDir_mapW(const WCHAR *wpath)
5534 VS_FIXEDFILEINFO *info;
5540 dll = GetModuleHandle("comctl32.dll"); /* must already be in proc */
5542 croak("Comctl32Version: comctl32.dll not in process???");
5543 hrsc = FindResource(dll, MAKEINTRESOURCE(VS_VERSION_INFO),
5544 MAKEINTRESOURCE(VS_FILE_INFO));
5546 croak("Comctl32Version: comctl32.dll no version???");
5547 ver = LoadResource(dll, hrsc);
5548 len = SizeofResource(dll, hrsc);
5549 vercopy = _alloca(len);
5550 memcpy(vercopy, ver, len);
5551 if (VerQueryValue(vercopy, "\\", (void**)&info, &len)) {
5552 int dwValueMS1 = (info->dwFileVersionMS>>16);
5553 int dwValueMS2 = (info->dwFileVersionMS&0xffff);
5554 int dwValueLS1 = (info->dwFileVersionLS>>16);
5555 int dwValueLS2 = (info->dwFileVersionLS&0xffff);