1 #define PERL_IN_XS_APITEST
3 /* We want to be able to test things that aren't API yet. */
6 /* Do *not* define PERL_NO_GET_CONTEXT. This is the one place where we get
7 to test implicit Perl_get_context(). */
13 typedef FILE NativeFile;
15 #include "fakesdio.h" /* Causes us to use PerlIO below */
18 typedef PTR_TBL_t *XS__APItest__PtrTable;
19 typedef PerlIO * InputStream;
20 typedef PerlIO * OutputStream;
22 #define croak_fail() croak("fail at " __FILE__ " line %d", __LINE__)
23 #define croak_fail_nep(h, w) croak("fail %p!=%p at " __FILE__ " line %d", (h), (w), __LINE__)
24 #define croak_fail_nei(h, w) croak("fail %d!=%d at " __FILE__ " line %d", (int)(h), (int)(w), __LINE__)
29 cat_utf8a2n(SV* sv, const char * const ascii_utf8, STRLEN len)
31 /* Converts variant UTF-8 text pointed to by 'ascii_utf8' of length 'len',
32 * to UTF-EBCDIC, appending that text to the text already in 'sv'.
33 * Currently doesn't work on invariants, as that is unneeded here, and we
34 * could get double translations if we did.
36 * It has the algorithm for strict UTF-8 hard-coded in to find the code
37 * point it represents, then calls uvchr_to_utf8() to convert to
40 * Note that this uses code points, not characters. Thus if the input is
41 * the UTF-8 for the code point 0xFF, the output will be the UTF-EBCDIC for
42 * 0xFF, even though that code point represents different characters on
43 * ASCII vs EBCDIC platforms. */
46 char * p = (char *) ascii_utf8;
47 const char * const e = p + len;
51 U8 native_utf8[UTF8_MAXBYTES + 1];
55 /* Start bytes are the same in both UTF-8 and I8, therefore we can
56 * treat this ASCII UTF-8 byte as an I8 byte. But PL_utf8skip[] is
57 * indexed by NATIVE_UTF8 bytes, so transform to that */
58 STRLEN char_bytes_len = PL_utf8skip[I8_TO_NATIVE_UTF8(start)];
61 croak("fail: Expecting start byte, instead got 0x%X at %s line %d",
62 (U8) *p, __FILE__, __LINE__);
64 code_point = (start & (((char_bytes_len) >= 7)
66 : (0x1F >> ((char_bytes_len)-2))));
68 while (p < e && ((( (U8) *p) & 0xC0) == 0x80)) {
70 code_point = (code_point << 6) | (( (U8) *p) & 0x3F);
74 char_end = uvchr_to_utf8(native_utf8, code_point);
75 sv_catpvn(sv, (char *) native_utf8, char_end - native_utf8);
81 /* for my_cxt tests */
83 #define MY_CXT_KEY "XS::APItest::_guts" XS_VERSION
103 S_myset_set(pTHX_ SV* sv, MAGIC* mg)
105 SV *isv = (SV*)mg->mg_ptr;
112 MGVTBL vtbl_foo, vtbl_bar;
113 MGVTBL vtbl_myset = { 0, S_myset_set, 0, 0, 0, 0, 0, 0 };
116 /* indirect functions to test the [pa]MY_CXT macros */
119 my_cxt_getint_p(pMY_CXT)
125 my_cxt_setint_p(pMY_CXT_ int i)
131 my_cxt_getsv_interp_context(void)
134 dMY_CXT_INTERP(my_perl);
139 my_cxt_getsv_interp(void)
146 my_cxt_setsv_p(SV* sv _pMY_CXT)
152 /* from exception.c */
153 int apitest_exception(int);
155 /* from core_or_not.inc */
156 bool sv_setsv_cow_hashkey_core(void);
157 bool sv_setsv_cow_hashkey_notcore(void);
159 /* A routine to test hv_delayfree_ent
160 (which itself is tested by testing on hv_free_ent */
162 typedef void (freeent_function)(pTHX_ HV *, HE *);
165 test_freeent(freeent_function *f) {
167 HV *test_hash = newHV();
174 victim = (HE*)safemalloc(sizeof(HE));
176 /* Storing then deleting something should ensure that a hash entry is
178 (void) hv_stores(test_hash, "", &PL_sv_yes);
179 (void) hv_deletes(test_hash, "", 0);
181 /* We need to "inline" new_he here as it's static, and the functions we
182 test expect to be able to call del_HE on the HE */
183 if (!PL_body_roots[HE_SVSLOT])
184 croak("PL_he_root is 0");
185 victim = (HE*) PL_body_roots[HE_SVSLOT];
186 PL_body_roots[HE_SVSLOT] = HeNEXT(victim);
189 victim->hent_hek = Perl_share_hek(aTHX_ "", 0, 0);
191 test_scalar = newSV(0);
192 SvREFCNT_inc(test_scalar);
193 HeVAL(victim) = test_scalar;
195 /* Need this little game else we free the temps on the return stack. */
196 results[0] = SvREFCNT(test_scalar);
198 results[1] = SvREFCNT(test_scalar);
199 f(aTHX_ test_hash, victim);
200 results[2] = SvREFCNT(test_scalar);
202 results[3] = SvREFCNT(test_scalar);
207 } while (++i < (int)(sizeof(results)/sizeof(results[0])));
209 /* Goodbye to our extra reference. */
210 SvREFCNT_dec(test_scalar);
213 /* Not that it matters much, but it's handy for the flipped character to just
214 * be the opposite case (at least for ASCII-range and most Latin1 as well). */
215 #define FLIP_BIT ('A' ^ 'a')
218 bitflip_key(pTHX_ IV action, SV *field) {
219 MAGIC *mg = mg_find(field, PERL_MAGIC_uvar);
221 PERL_UNUSED_ARG(action);
222 if (mg && (keysv = mg->mg_obj)) {
224 const char *p = SvPV(keysv, len);
227 /* Allow for the flipped val to be longer than the original. This
228 * is just for testing, so can afford to have some slop */
229 const STRLEN newlen = len * 2;
231 SV *newkey = newSV(newlen);
232 const char * const new_p_orig = SvPVX(newkey);
233 char *new_p = (char *) new_p_orig;
236 const char *const end = p + len;
239 UV chr = utf8_to_uvchr_buf((U8 *)p, (U8 *) end, &curlen);
241 /* Make sure don't exceed bounds */
242 assert(new_p - new_p_orig + curlen < newlen);
244 new_p = (char *)uvchr_to_utf8((U8 *)new_p, chr ^ FLIP_BIT);
250 *new_p++ = *p++ ^ FLIP_BIT;
253 SvCUR_set(newkey, new_p - new_p_orig);
263 rot13_key(pTHX_ IV action, SV *field) {
264 MAGIC *mg = mg_find(field, PERL_MAGIC_uvar);
266 PERL_UNUSED_ARG(action);
267 if (mg && (keysv = mg->mg_obj)) {
269 const char *p = SvPV(keysv, len);
272 SV *newkey = newSV(len);
273 char *new_p = SvPVX(newkey);
275 /* There's a deliberate fencepost error here to loop len + 1 times
276 to copy the trailing \0 */
279 /* Try doing this cleanly and clearly in EBCDIC another way: */
281 case 'A': new_c = 'N'; break;
282 case 'B': new_c = 'O'; break;
283 case 'C': new_c = 'P'; break;
284 case 'D': new_c = 'Q'; break;
285 case 'E': new_c = 'R'; break;
286 case 'F': new_c = 'S'; break;
287 case 'G': new_c = 'T'; break;
288 case 'H': new_c = 'U'; break;
289 case 'I': new_c = 'V'; break;
290 case 'J': new_c = 'W'; break;
291 case 'K': new_c = 'X'; break;
292 case 'L': new_c = 'Y'; break;
293 case 'M': new_c = 'Z'; break;
294 case 'N': new_c = 'A'; break;
295 case 'O': new_c = 'B'; break;
296 case 'P': new_c = 'C'; break;
297 case 'Q': new_c = 'D'; break;
298 case 'R': new_c = 'E'; break;
299 case 'S': new_c = 'F'; break;
300 case 'T': new_c = 'G'; break;
301 case 'U': new_c = 'H'; break;
302 case 'V': new_c = 'I'; break;
303 case 'W': new_c = 'J'; break;
304 case 'X': new_c = 'K'; break;
305 case 'Y': new_c = 'L'; break;
306 case 'Z': new_c = 'M'; break;
307 case 'a': new_c = 'n'; break;
308 case 'b': new_c = 'o'; break;
309 case 'c': new_c = 'p'; break;
310 case 'd': new_c = 'q'; break;
311 case 'e': new_c = 'r'; break;
312 case 'f': new_c = 's'; break;
313 case 'g': new_c = 't'; break;
314 case 'h': new_c = 'u'; break;
315 case 'i': new_c = 'v'; break;
316 case 'j': new_c = 'w'; break;
317 case 'k': new_c = 'x'; break;
318 case 'l': new_c = 'y'; break;
319 case 'm': new_c = 'z'; break;
320 case 'n': new_c = 'a'; break;
321 case 'o': new_c = 'b'; break;
322 case 'p': new_c = 'c'; break;
323 case 'q': new_c = 'd'; break;
324 case 'r': new_c = 'e'; break;
325 case 's': new_c = 'f'; break;
326 case 't': new_c = 'g'; break;
327 case 'u': new_c = 'h'; break;
328 case 'v': new_c = 'i'; break;
329 case 'w': new_c = 'j'; break;
330 case 'x': new_c = 'k'; break;
331 case 'y': new_c = 'l'; break;
332 case 'z': new_c = 'm'; break;
336 SvCUR_set(newkey, SvCUR(keysv));
348 rmagical_a_dummy(pTHX_ IV idx, SV *sv) {
349 PERL_UNUSED_ARG(idx);
354 /* We could do "= { 0 };" but some versions of gcc do warn
355 * (with -Wextra) about missing initializer, this is probably gcc
356 * being a bit too paranoid. But since this is file-static, we can
357 * just have it without initializer, since it should get
358 * zero-initialized. */
359 STATIC MGVTBL rmagical_b;
362 blockhook_csc_start(pTHX_ int full)
365 AV *const cur = GvAV(MY_CXT.cscgv);
367 PERL_UNUSED_ARG(full);
368 SAVEGENERICSV(GvAV(MY_CXT.cscgv));
372 AV *const new_av = newAV();
374 for (i = 0; i <= av_tindex(cur); i++) {
375 av_store(new_av, i, newSVsv(*av_fetch(cur, i, 0)));
378 GvAV(MY_CXT.cscgv) = new_av;
383 blockhook_csc_pre_end(pTHX_ OP **o)
388 /* if we hit the end of a scope we missed the start of, we need to
389 * unconditionally clear @CSC */
390 if (GvAV(MY_CXT.cscgv) == MY_CXT.cscav && MY_CXT.cscav) {
391 av_clear(MY_CXT.cscav);
397 blockhook_test_start(pTHX_ int full)
402 if (MY_CXT.bhk_record) {
404 av_push(av, newSVpvs("start"));
405 av_push(av, newSViv(full));
406 av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av)));
411 blockhook_test_pre_end(pTHX_ OP **o)
416 if (MY_CXT.bhk_record)
417 av_push(MY_CXT.bhkav, newSVpvs("pre_end"));
421 blockhook_test_post_end(pTHX_ OP **o)
426 if (MY_CXT.bhk_record)
427 av_push(MY_CXT.bhkav, newSVpvs("post_end"));
431 blockhook_test_eval(pTHX_ OP *const o)
436 if (MY_CXT.bhk_record) {
438 av_push(av, newSVpvs("eval"));
439 av_push(av, newSVpv(OP_NAME(o), 0));
440 av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av)));
444 STATIC BHK bhk_csc, bhk_test;
447 my_peep (pTHX_ OP *o)
454 MY_CXT.orig_peep(aTHX_ o);
456 if (!MY_CXT.peep_recording)
459 for (; o; o = o->op_next) {
460 if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
461 av_push(MY_CXT.peep_recorder, newSVsv(cSVOPx_sv(o)));
467 my_rpeep (pTHX_ OP *o)
474 MY_CXT.orig_rpeep(aTHX_ o);
476 if (!MY_CXT.peep_recording)
479 for (; o; o = o->op_next) {
480 if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) {
481 av_push(MY_CXT.rpeep_recorder, newSVsv(cSVOPx_sv(o)));
487 THX_ck_entersub_args_lists(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
489 PERL_UNUSED_ARG(namegv);
490 PERL_UNUSED_ARG(ckobj);
491 return ck_entersub_args_list(entersubop);
495 THX_ck_entersub_args_scalars(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
497 OP *aop = cUNOPx(entersubop)->op_first;
498 PERL_UNUSED_ARG(namegv);
499 PERL_UNUSED_ARG(ckobj);
500 if (!OpHAS_SIBLING(aop))
501 aop = cUNOPx(aop)->op_first;
502 for (aop = OpSIBLING(aop); OpHAS_SIBLING(aop); aop = OpSIBLING(aop)) {
503 op_contextualize(aop, G_SCALAR);
509 THX_ck_entersub_multi_sum(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
512 OP *parent = entersubop;
513 OP *pushop = cUNOPx(entersubop)->op_first;
514 PERL_UNUSED_ARG(namegv);
515 PERL_UNUSED_ARG(ckobj);
516 if (!OpHAS_SIBLING(pushop)) {
518 pushop = cUNOPx(pushop)->op_first;
521 OP *aop = OpSIBLING(pushop);
522 if (!OpHAS_SIBLING(aop))
524 /* cut out first arg */
525 op_sibling_splice(parent, pushop, 1, NULL);
526 op_contextualize(aop, G_SCALAR);
528 sumop = newBINOP(OP_ADD, 0, sumop, aop);
534 sumop = newSVOP(OP_CONST, 0, newSViv(0));
539 STATIC void test_op_list_describe_part(SV *res, OP *o);
541 test_op_list_describe_part(SV *res, OP *o)
543 sv_catpv(res, PL_op_name[o->op_type]);
544 switch (o->op_type) {
546 sv_catpvf(res, "(%d)", (int)SvIV(cSVOPx(o)->op_sv));
549 if (o->op_flags & OPf_KIDS) {
552 for (k = cUNOPx(o)->op_first; k; k = OpSIBLING(k))
553 test_op_list_describe_part(res, k);
561 test_op_list_describe(OP *o)
563 SV *res = sv_2mortal(newSVpvs(""));
565 test_op_list_describe_part(res, o);
569 /* the real new*OP functions have a tendency to call fold_constants, and
570 * other such unhelpful things, so we need our own versions for testing */
572 #define mkUNOP(t, f) THX_mkUNOP(aTHX_ (t), (f))
574 THX_mkUNOP(pTHX_ U32 type, OP *first)
577 NewOp(1103, unop, 1, UNOP);
578 unop->op_type = (OPCODE)type;
579 op_sibling_splice((OP*)unop, NULL, 0, first);
583 #define mkBINOP(t, f, l) THX_mkBINOP(aTHX_ (t), (f), (l))
585 THX_mkBINOP(pTHX_ U32 type, OP *first, OP *last)
588 NewOp(1103, binop, 1, BINOP);
589 binop->op_type = (OPCODE)type;
590 op_sibling_splice((OP*)binop, NULL, 0, last);
591 op_sibling_splice((OP*)binop, NULL, 0, first);
595 #define mkLISTOP(t, f, s, l) THX_mkLISTOP(aTHX_ (t), (f), (s), (l))
597 THX_mkLISTOP(pTHX_ U32 type, OP *first, OP *sib, OP *last)
600 NewOp(1103, listop, 1, LISTOP);
601 listop->op_type = (OPCODE)type;
602 op_sibling_splice((OP*)listop, NULL, 0, last);
603 op_sibling_splice((OP*)listop, NULL, 0, sib);
604 op_sibling_splice((OP*)listop, NULL, 0, first);
609 test_op_linklist_describe(OP *start)
611 SV *rv = sv_2mortal(newSVpvs(""));
613 o = start = LINKLIST(start);
616 sv_catpv(rv, OP_NAME(o));
617 if (o->op_type == OP_CONST)
618 sv_catsv(rv, cSVOPo->op_sv);
620 } while (o && o != start);
624 /** establish_cleanup operator, ripped off from Scope::Cleanup **/
627 THX_run_cleanup(pTHX_ void *cleanup_code_ref)
634 call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD);
641 THX_pp_establish_cleanup(pTHX)
644 SV *cleanup_code_ref;
645 cleanup_code_ref = newSVsv(POPs);
646 SAVEFREESV(cleanup_code_ref);
647 SAVEDESTRUCTOR_X(THX_run_cleanup, cleanup_code_ref);
648 if(GIMME_V != G_VOID) PUSHs(&PL_sv_undef);
653 THX_ck_entersub_establish_cleanup(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
655 OP *parent, *pushop, *argop, *estop;
656 ck_entersub_args_proto(entersubop, namegv, ckobj);
658 pushop = cUNOPx(entersubop)->op_first;
659 if(!OpHAS_SIBLING(pushop)) {
661 pushop = cUNOPx(pushop)->op_first;
663 /* extract out first arg, then delete the rest of the tree */
664 argop = OpSIBLING(pushop);
665 op_sibling_splice(parent, pushop, 1, NULL);
668 estop = mkUNOP(OP_RAND, argop);
669 estop->op_ppaddr = THX_pp_establish_cleanup;
670 PL_hints |= HINT_BLOCK_SCOPE;
675 THX_ck_entersub_postinc(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
677 OP *parent, *pushop, *argop;
678 ck_entersub_args_proto(entersubop, namegv, ckobj);
680 pushop = cUNOPx(entersubop)->op_first;
681 if(!OpHAS_SIBLING(pushop)) {
683 pushop = cUNOPx(pushop)->op_first;
685 argop = OpSIBLING(pushop);
686 op_sibling_splice(parent, pushop, 1, NULL);
688 return newUNOP(OP_POSTINC, 0,
689 op_lvalue(op_contextualize(argop, G_SCALAR), OP_POSTINC));
693 THX_ck_entersub_pad_scalar(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
696 PADOFFSET padoff = NOT_IN_PAD;
698 ck_entersub_args_proto(entersubop, namegv, ckobj);
699 pushop = cUNOPx(entersubop)->op_first;
700 if(!OpHAS_SIBLING(pushop))
701 pushop = cUNOPx(pushop)->op_first;
702 argop = OpSIBLING(pushop);
703 if(argop->op_type != OP_CONST || OpSIBLING(argop)->op_type != OP_CONST)
704 croak("bad argument expression type for pad_scalar()");
705 a0 = cSVOPx_sv(argop);
706 a1 = cSVOPx_sv(OpSIBLING(argop));
709 SV *namesv = sv_2mortal(newSVpvs("$"));
710 sv_catsv(namesv, a1);
711 padoff = pad_findmy_sv(namesv, 0);
716 SV *namesv = sv_2mortal(newSVpvs("$"));
717 sv_catsv(namesv, a1);
718 namepv = SvPV(namesv, namelen);
719 padoff = pad_findmy_pvn(namepv, namelen, SvUTF8(namesv));
723 SV *namesv = sv_2mortal(newSVpvs("$"));
724 sv_catsv(namesv, a1);
725 namepv = SvPV_nolen(namesv);
726 padoff = pad_findmy_pv(namepv, SvUTF8(namesv));
729 padoff = pad_findmy_pvs("$foo", 0);
731 default: croak("bad type value for pad_scalar()");
734 if(padoff == NOT_IN_PAD) {
735 return newSVOP(OP_CONST, 0, newSVpvs("NOT_IN_PAD"));
736 } else if(PAD_COMPNAME_FLAGS_isOUR(padoff)) {
737 return newSVOP(OP_CONST, 0, newSVpvs("NOT_MY"));
739 OP *padop = newOP(OP_PADSV, 0);
740 padop->op_targ = padoff;
745 /** RPN keyword parser **/
747 #define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV)
748 #define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP)
749 #define sv_is_string(sv) \
750 (!sv_is_glob(sv) && !sv_is_regexp(sv) && \
751 (SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK)))
753 static SV *hintkey_rpn_sv, *hintkey_calcrpn_sv, *hintkey_stufftest_sv;
754 static SV *hintkey_swaptwostmts_sv, *hintkey_looprest_sv;
755 static SV *hintkey_scopelessblock_sv;
756 static SV *hintkey_stmtasexpr_sv, *hintkey_stmtsasexpr_sv;
757 static SV *hintkey_loopblock_sv, *hintkey_blockasexpr_sv;
758 static SV *hintkey_swaplabel_sv, *hintkey_labelconst_sv;
759 static SV *hintkey_arrayfullexpr_sv, *hintkey_arraylistexpr_sv;
760 static SV *hintkey_arraytermexpr_sv, *hintkey_arrayarithexpr_sv;
761 static SV *hintkey_arrayexprflags_sv;
762 static SV *hintkey_DEFSV_sv;
763 static SV *hintkey_with_vars_sv;
764 static SV *hintkey_join_with_space_sv;
765 static int (*next_keyword_plugin)(pTHX_ char *, STRLEN, OP **);
767 /* low-level parser helpers */
769 #define PL_bufptr (PL_parser->bufptr)
770 #define PL_bufend (PL_parser->bufend)
774 #define parse_var() THX_parse_var(aTHX)
775 static OP *THX_parse_var(pTHX)
781 if(*s != '$') croak("RPN syntax error");
784 if(!isALNUM(c)) break;
786 if(s-start < 2) croak("RPN syntax error");
788 varpos = pad_findmy_pvn(start, s-start, 0);
789 if(varpos == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(varpos))
790 croak("RPN only supports \"my\" variables");
791 padop = newOP(OP_PADSV, 0);
792 padop->op_targ = varpos;
796 #define push_rpn_item(o) \
797 op_sibling_splice(parent, NULL, 0, o);
798 #define pop_rpn_item() ( \
799 (tmpop = op_sibling_splice(parent, NULL, 1, NULL)) \
800 ? tmpop : (croak("RPN stack underflow"), (OP*)NULL))
802 #define parse_rpn_expr() THX_parse_rpn_expr(aTHX)
803 static OP *THX_parse_rpn_expr(pTHX)
806 /* fake parent for splice to mess with */
807 OP *parent = mkBINOP(OP_NULL, NULL, NULL);
812 c = lex_peek_unichar(0);
814 case /*(*/')': case /*{*/'}': {
815 OP *result = pop_rpn_item();
816 if(cLISTOPx(parent)->op_first)
817 croak("RPN expression must return a single value");
821 case '0': case '1': case '2': case '3': case '4':
822 case '5': case '6': case '7': case '8': case '9': {
826 val = 10*val + (c - '0');
827 c = lex_peek_unichar(0);
828 } while(c >= '0' && c <= '9');
829 push_rpn_item(newSVOP(OP_CONST, 0, newSVuv(val)));
832 push_rpn_item(parse_var());
835 OP *b = pop_rpn_item();
836 OP *a = pop_rpn_item();
838 push_rpn_item(newBINOP(OP_I_ADD, 0, a, b));
841 OP *b = pop_rpn_item();
842 OP *a = pop_rpn_item();
844 push_rpn_item(newBINOP(OP_I_SUBTRACT, 0, a, b));
847 OP *b = pop_rpn_item();
848 OP *a = pop_rpn_item();
850 push_rpn_item(newBINOP(OP_I_MULTIPLY, 0, a, b));
853 OP *b = pop_rpn_item();
854 OP *a = pop_rpn_item();
856 push_rpn_item(newBINOP(OP_I_DIVIDE, 0, a, b));
859 OP *b = pop_rpn_item();
860 OP *a = pop_rpn_item();
862 push_rpn_item(newBINOP(OP_I_MODULO, 0, a, b));
865 croak("RPN syntax error");
871 #define parse_keyword_rpn() THX_parse_keyword_rpn(aTHX)
872 static OP *THX_parse_keyword_rpn(pTHX)
876 if(lex_peek_unichar(0) != '('/*)*/)
877 croak("RPN expression must be parenthesised");
879 op = parse_rpn_expr();
880 if(lex_peek_unichar(0) != /*(*/')')
881 croak("RPN expression must be parenthesised");
886 #define parse_keyword_calcrpn() THX_parse_keyword_calcrpn(aTHX)
887 static OP *THX_parse_keyword_calcrpn(pTHX)
893 if(lex_peek_unichar(0) != '{'/*}*/)
894 croak("RPN expression must be braced");
896 exprop = parse_rpn_expr();
897 if(lex_peek_unichar(0) != /*{*/'}')
898 croak("RPN expression must be braced");
900 return newASSIGNOP(OPf_STACKED, varop, 0, exprop);
903 #define parse_keyword_stufftest() THX_parse_keyword_stufftest(aTHX)
904 static OP *THX_parse_keyword_stufftest(pTHX)
909 do_stuff = lex_peek_unichar(0) == '+';
914 c = lex_peek_unichar(0);
917 } else if(c != /*{*/'}') {
918 croak("syntax error");
920 if(do_stuff) lex_stuff_pvs(" ", 0);
921 return newOP(OP_NULL, 0);
924 #define parse_keyword_swaptwostmts() THX_parse_keyword_swaptwostmts(aTHX)
925 static OP *THX_parse_keyword_swaptwostmts(pTHX)
928 a = parse_fullstmt(0);
929 b = parse_fullstmt(0);
931 PL_hints |= HINT_BLOCK_SCOPE;
932 return op_append_list(OP_LINESEQ, b, a);
935 #define parse_keyword_looprest() THX_parse_keyword_looprest(aTHX)
936 static OP *THX_parse_keyword_looprest(pTHX)
938 return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes),
939 parse_stmtseq(0), NULL, 1);
942 #define parse_keyword_scopelessblock() THX_parse_keyword_scopelessblock(aTHX)
943 static OP *THX_parse_keyword_scopelessblock(pTHX)
948 if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error");
950 body = parse_stmtseq(0);
951 c = lex_peek_unichar(0);
952 if(c != /*{*/'}' && c != /*[*/']' && c != /*(*/')') croak("syntax error");
957 #define parse_keyword_stmtasexpr() THX_parse_keyword_stmtasexpr(aTHX)
958 static OP *THX_parse_keyword_stmtasexpr(pTHX)
960 OP *o = parse_barestmt(0);
961 if (!o) o = newOP(OP_STUB, 0);
962 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
966 #define parse_keyword_stmtsasexpr() THX_parse_keyword_stmtsasexpr(aTHX)
967 static OP *THX_parse_keyword_stmtsasexpr(pTHX)
971 if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error");
973 o = parse_stmtseq(0);
975 if(lex_peek_unichar(0) != /*{*/'}') croak("syntax error");
977 if (!o) o = newOP(OP_STUB, 0);
978 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
982 #define parse_keyword_loopblock() THX_parse_keyword_loopblock(aTHX)
983 static OP *THX_parse_keyword_loopblock(pTHX)
985 return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes),
986 parse_block(0), NULL, 1);
989 #define parse_keyword_blockasexpr() THX_parse_keyword_blockasexpr(aTHX)
990 static OP *THX_parse_keyword_blockasexpr(pTHX)
992 OP *o = parse_block(0);
993 if (!o) o = newOP(OP_STUB, 0);
994 if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS;
998 #define parse_keyword_swaplabel() THX_parse_keyword_swaplabel(aTHX)
999 static OP *THX_parse_keyword_swaplabel(pTHX)
1001 OP *sop = parse_barestmt(0);
1002 SV *label = parse_label(PARSE_OPTIONAL);
1003 if (label) sv_2mortal(label);
1004 return newSTATEOP(label ? SvUTF8(label) : 0,
1005 label ? savepv(SvPVX(label)) : NULL,
1009 #define parse_keyword_labelconst() THX_parse_keyword_labelconst(aTHX)
1010 static OP *THX_parse_keyword_labelconst(pTHX)
1012 return newSVOP(OP_CONST, 0, parse_label(0));
1015 #define parse_keyword_arrayfullexpr() THX_parse_keyword_arrayfullexpr(aTHX)
1016 static OP *THX_parse_keyword_arrayfullexpr(pTHX)
1018 return newANONLIST(parse_fullexpr(0));
1021 #define parse_keyword_arraylistexpr() THX_parse_keyword_arraylistexpr(aTHX)
1022 static OP *THX_parse_keyword_arraylistexpr(pTHX)
1024 return newANONLIST(parse_listexpr(0));
1027 #define parse_keyword_arraytermexpr() THX_parse_keyword_arraytermexpr(aTHX)
1028 static OP *THX_parse_keyword_arraytermexpr(pTHX)
1030 return newANONLIST(parse_termexpr(0));
1033 #define parse_keyword_arrayarithexpr() THX_parse_keyword_arrayarithexpr(aTHX)
1034 static OP *THX_parse_keyword_arrayarithexpr(pTHX)
1036 return newANONLIST(parse_arithexpr(0));
1039 #define parse_keyword_arrayexprflags() THX_parse_keyword_arrayexprflags(aTHX)
1040 static OP *THX_parse_keyword_arrayexprflags(pTHX)
1046 c = lex_peek_unichar(0);
1047 if (c != '!' && c != '?') croak("syntax error");
1048 lex_read_unichar(0);
1049 if (c == '?') flags |= PARSE_OPTIONAL;
1050 o = parse_listexpr(flags);
1051 return o ? newANONLIST(o) : newANONHASH(newOP(OP_STUB, 0));
1054 #define parse_keyword_DEFSV() THX_parse_keyword_DEFSV(aTHX)
1055 static OP *THX_parse_keyword_DEFSV(pTHX)
1057 return newDEFSVOP();
1060 #define sv_cat_c(a,b) THX_sv_cat_c(aTHX_ a, b)
1061 static void THX_sv_cat_c(pTHX_ SV *sv, U32 c) {
1062 char ds[UTF8_MAXBYTES + 1], *d;
1063 d = (char *)uvchr_to_utf8((U8 *)ds, c);
1065 sv_utf8_upgrade(sv);
1067 sv_catpvn(sv, ds, d - ds);
1070 #define parse_keyword_with_vars() THX_parse_keyword_with_vars(aTHX)
1071 static OP *THX_parse_keyword_with_vars(pTHX)
1076 OP *vardeclseq, *body;
1078 save_ix = block_start(TRUE);
1084 c = lex_peek_unichar(0);
1090 croak("unexpected EOF; expecting '{'");
1093 if (!isIDFIRST_uni(c)) {
1094 croak("unexpected '%c'; expecting an identifier", (int)c);
1097 varname = newSVpvs("$");
1098 if (lex_bufutf8()) {
1102 sv_cat_c(varname, c);
1103 lex_read_unichar(0);
1105 while (c = lex_peek_unichar(0), c != -1 && isIDCONT_uni(c)) {
1106 sv_cat_c(varname, c);
1107 lex_read_unichar(0);
1110 padoff = pad_add_name_sv(varname, padadd_NO_DUP_CHECK, NULL, NULL);
1113 OP *my_var = newOP(OP_PADSV, OPf_MOD | (OPpLVAL_INTRO << 8));
1114 my_var->op_targ = padoff;
1116 vardeclseq = op_append_list(
1134 c = lex_peek_unichar(0);
1139 body = parse_block(0);
1141 return block_end(save_ix, op_append_list(OP_LINESEQ, vardeclseq, body));
1144 #define parse_join_with_space() THX_parse_join_with_space(aTHX)
1145 static OP *THX_parse_join_with_space(pTHX)
1149 args = parse_listexpr(0);
1150 delim = newSVOP(OP_CONST, 0, newSVpvs(" "));
1151 return op_convert_list(OP_JOIN, 0, op_prepend_elem(OP_LIST, delim, args));
1156 #define keyword_active(hintkey_sv) THX_keyword_active(aTHX_ hintkey_sv)
1157 static int THX_keyword_active(pTHX_ SV *hintkey_sv)
1160 if(!GvHV(PL_hintgv)) return 0;
1161 he = hv_fetch_ent(GvHV(PL_hintgv), hintkey_sv, 0,
1162 SvSHARED_HASH(hintkey_sv));
1163 return he && SvTRUE(HeVAL(he));
1166 static int my_keyword_plugin(pTHX_
1167 char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
1169 if (memEQs(keyword_ptr, keyword_len, "rpn") &&
1170 keyword_active(hintkey_rpn_sv)) {
1171 *op_ptr = parse_keyword_rpn();
1172 return KEYWORD_PLUGIN_EXPR;
1173 } else if (memEQs(keyword_ptr, keyword_len, "calcrpn") &&
1174 keyword_active(hintkey_calcrpn_sv)) {
1175 *op_ptr = parse_keyword_calcrpn();
1176 return KEYWORD_PLUGIN_STMT;
1177 } else if (memEQs(keyword_ptr, keyword_len, "stufftest") &&
1178 keyword_active(hintkey_stufftest_sv)) {
1179 *op_ptr = parse_keyword_stufftest();
1180 return KEYWORD_PLUGIN_STMT;
1181 } else if (memEQs(keyword_ptr, keyword_len, "swaptwostmts") &&
1182 keyword_active(hintkey_swaptwostmts_sv)) {
1183 *op_ptr = parse_keyword_swaptwostmts();
1184 return KEYWORD_PLUGIN_STMT;
1185 } else if (memEQs(keyword_ptr, keyword_len, "looprest") &&
1186 keyword_active(hintkey_looprest_sv)) {
1187 *op_ptr = parse_keyword_looprest();
1188 return KEYWORD_PLUGIN_STMT;
1189 } else if (memEQs(keyword_ptr, keyword_len, "scopelessblock") &&
1190 keyword_active(hintkey_scopelessblock_sv)) {
1191 *op_ptr = parse_keyword_scopelessblock();
1192 return KEYWORD_PLUGIN_STMT;
1193 } else if (memEQs(keyword_ptr, keyword_len, "stmtasexpr") &&
1194 keyword_active(hintkey_stmtasexpr_sv)) {
1195 *op_ptr = parse_keyword_stmtasexpr();
1196 return KEYWORD_PLUGIN_EXPR;
1197 } else if (memEQs(keyword_ptr, keyword_len, "stmtsasexpr") &&
1198 keyword_active(hintkey_stmtsasexpr_sv)) {
1199 *op_ptr = parse_keyword_stmtsasexpr();
1200 return KEYWORD_PLUGIN_EXPR;
1201 } else if (memEQs(keyword_ptr, keyword_len, "loopblock") &&
1202 keyword_active(hintkey_loopblock_sv)) {
1203 *op_ptr = parse_keyword_loopblock();
1204 return KEYWORD_PLUGIN_STMT;
1205 } else if (memEQs(keyword_ptr, keyword_len, "blockasexpr") &&
1206 keyword_active(hintkey_blockasexpr_sv)) {
1207 *op_ptr = parse_keyword_blockasexpr();
1208 return KEYWORD_PLUGIN_EXPR;
1209 } else if (memEQs(keyword_ptr, keyword_len, "swaplabel") &&
1210 keyword_active(hintkey_swaplabel_sv)) {
1211 *op_ptr = parse_keyword_swaplabel();
1212 return KEYWORD_PLUGIN_STMT;
1213 } else if (memEQs(keyword_ptr, keyword_len, "labelconst") &&
1214 keyword_active(hintkey_labelconst_sv)) {
1215 *op_ptr = parse_keyword_labelconst();
1216 return KEYWORD_PLUGIN_EXPR;
1217 } else if (memEQs(keyword_ptr, keyword_len, "arrayfullexpr") &&
1218 keyword_active(hintkey_arrayfullexpr_sv)) {
1219 *op_ptr = parse_keyword_arrayfullexpr();
1220 return KEYWORD_PLUGIN_EXPR;
1221 } else if (memEQs(keyword_ptr, keyword_len, "arraylistexpr") &&
1222 keyword_active(hintkey_arraylistexpr_sv)) {
1223 *op_ptr = parse_keyword_arraylistexpr();
1224 return KEYWORD_PLUGIN_EXPR;
1225 } else if (memEQs(keyword_ptr, keyword_len, "arraytermexpr") &&
1226 keyword_active(hintkey_arraytermexpr_sv)) {
1227 *op_ptr = parse_keyword_arraytermexpr();
1228 return KEYWORD_PLUGIN_EXPR;
1229 } else if (memEQs(keyword_ptr, keyword_len, "arrayarithexpr") &&
1230 keyword_active(hintkey_arrayarithexpr_sv)) {
1231 *op_ptr = parse_keyword_arrayarithexpr();
1232 return KEYWORD_PLUGIN_EXPR;
1233 } else if (memEQs(keyword_ptr, keyword_len, "arrayexprflags") &&
1234 keyword_active(hintkey_arrayexprflags_sv)) {
1235 *op_ptr = parse_keyword_arrayexprflags();
1236 return KEYWORD_PLUGIN_EXPR;
1237 } else if (memEQs(keyword_ptr, keyword_len, "DEFSV") &&
1238 keyword_active(hintkey_DEFSV_sv)) {
1239 *op_ptr = parse_keyword_DEFSV();
1240 return KEYWORD_PLUGIN_EXPR;
1241 } else if (memEQs(keyword_ptr, keyword_len, "with_vars") &&
1242 keyword_active(hintkey_with_vars_sv)) {
1243 *op_ptr = parse_keyword_with_vars();
1244 return KEYWORD_PLUGIN_STMT;
1245 } else if (memEQs(keyword_ptr, keyword_len, "join_with_space") &&
1246 keyword_active(hintkey_join_with_space_sv)) {
1247 *op_ptr = parse_join_with_space();
1248 return KEYWORD_PLUGIN_EXPR;
1250 assert(next_keyword_plugin != my_keyword_plugin);
1251 return next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr);
1260 return PL_op->op_next;
1264 peep_xop(pTHX_ OP *o, OP *oldop)
1267 av_push(MY_CXT.xop_record, newSVpvf("peep:%" UVxf, PTR2UV(o)));
1268 av_push(MY_CXT.xop_record, newSVpvf("oldop:%" UVxf, PTR2UV(oldop)));
1272 filter_call(pTHX_ int idx, SV *buf_sv, int maxlen)
1276 int n = FILTER_READ(idx + 1, buf_sv, maxlen);
1280 p = SvPV_force_nolen(buf_sv);
1281 end = p + SvCUR(buf_sv);
1283 if (*p == 'o') *p = 'e';
1286 return SvCUR(buf_sv);
1290 myget_linear_isa(pTHX_ HV *stash, U32 level) {
1291 GV **gvp = (GV **)hv_fetchs(stash, "ISA", 0);
1292 PERL_UNUSED_ARG(level);
1293 return gvp && *gvp && GvAV(*gvp)
1295 : (AV *)sv_2mortal((SV *)newAV());
1299 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_undef);
1300 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_VERSION_empty);
1301 XS_EXTERNAL(XS_XS__APItest__XSUB_XS_APIVERSION_invalid);
1303 static struct mro_alg mymro;
1305 static Perl_check_t addissub_nxck_add;
1308 addissub_myck_add(pTHX_ OP *op)
1310 SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addissub", 0);
1313 if (!(flag_svp && SvTRUE(*flag_svp) && (op->op_flags & OPf_KIDS) &&
1314 (aop = cBINOPx(op)->op_first) && (bop = OpSIBLING(aop)) &&
1315 !OpHAS_SIBLING(bop)))
1316 return addissub_nxck_add(aTHX_ op);
1317 flags = op->op_flags;
1318 op_sibling_splice(op, NULL, 1, NULL); /* excise aop */
1319 op_sibling_splice(op, NULL, 1, NULL); /* excise bop */
1320 op_free(op); /* free the empty husk */
1322 return newBINOP(OP_SUBTRACT, flags, aop, bop);
1325 static Perl_check_t old_ck_rv2cv;
1328 my_ck_rv2cv(pTHX_ OP *o)
1331 SV **flag_svp = hv_fetchs(GvHV(PL_hintgv), "XS::APItest/addunder", 0);
1334 if (flag_svp && SvTRUE(*flag_svp) && (o->op_flags & OPf_KIDS)
1335 && (aop = cUNOPx(o)->op_first) && aop->op_type == OP_CONST
1336 && aop->op_private & (OPpCONST_ENTERED|OPpCONST_BARE)
1337 && (ref = cSVOPx(aop)->op_sv) && SvPOK(ref) && SvCUR(ref)
1338 && *(SvEND(ref)-1) == 'o')
1340 SvGROW(ref, SvCUR(ref)+2);
1345 return old_ck_rv2cv(aTHX_ o);
1348 #include "const-c.inc"
1350 MODULE = XS::APItest PACKAGE = XS::APItest
1352 INCLUDE: const-xs.inc
1359 /* this only needs to compile and checks that assert() can be
1360 used this way syntactically */
1361 (void)(assert(x), 1);
1364 MODULE = XS::APItest::utf8 PACKAGE = XS::APItest::utf8
1367 bytes_cmp_utf8(bytes, utf8)
1376 b = (const U8 *)SvPVbyte(bytes, blen);
1377 u = (const U8 *)SvPVbyte(utf8, ulen);
1378 RETVAL = bytes_cmp_utf8(b, blen, u, ulen);
1383 test_utf8n_to_uvchr_error(s, len, flags)
1395 /* Now that utf8n_to_uvchr() is a trivial wrapper for
1396 * utf8n_to_uvchr_error(), call the latter with the inputs. It always
1397 * asks for the actual length to be returned and errors to be returned
1399 * Length to assume <s> is; not checked, so could have buffer overflow
1402 sv_2mortal((SV*)RETVAL);
1404 ret = utf8n_to_uvchr_error((U8*) SvPV(s, slen),
1410 /* Returns the return value in [0]; <retlen> in [1], <errors> in [2] */
1411 av_push(RETVAL, newSVuv(ret));
1412 if (retlen == (STRLEN) -1) {
1413 av_push(RETVAL, newSViv(-1));
1416 av_push(RETVAL, newSVuv(retlen));
1418 av_push(RETVAL, newSVuv(errors));
1424 test_valid_utf8_to_uvchr(s)
1432 /* Call utf8n_to_uvchr() with the inputs. It always asks for the
1433 * actual length to be returned
1435 * Length to assume <s> is; not checked, so could have buffer overflow
1438 sv_2mortal((SV*)RETVAL);
1440 ret = valid_utf8_to_uvchr((U8*) SvPV_nolen(s), &retlen);
1442 /* Returns the return value in [0]; <retlen> in [1] */
1443 av_push(RETVAL, newSVuv(ret));
1444 av_push(RETVAL, newSVuv(retlen));
1450 test_uvchr_to_utf8_flags(uv, flags)
1455 U8 dest[UTF8_MAXBYTES + 1];
1459 /* Call uvchr_to_utf8_flags() with the inputs. */
1460 ret = uvchr_to_utf8_flags(dest, SvUV(uv), SvUV(flags));
1464 RETVAL = newSVpvn((char *) dest, ret - dest);
1469 MODULE = XS::APItest:Overload PACKAGE = XS::APItest::Overload
1472 amagic_deref_call(sv, what)
1476 /* The reference is owned by something else. */
1477 PUSHs(amagic_deref_call(sv, what));
1479 # I'd certainly like to discourage the use of this macro, given that we now
1480 # have amagic_deref_call
1483 tryAMAGICunDEREF_var(sv, what)
1491 tryAMAGICunDEREF(to_av);
1494 tryAMAGICunDEREF(to_cv);
1497 tryAMAGICunDEREF(to_gv);
1500 tryAMAGICunDEREF(to_hv);
1503 tryAMAGICunDEREF(to_sv);
1506 croak("Invalid value %d passed to tryAMAGICunDEREF_var", what);
1509 /* The reference is owned by something else. */
1512 MODULE = XS::APItest PACKAGE = XS::APItest::XSUB
1515 newXS("XS::APItest::XSUB::XS_VERSION_undef", XS_XS__APItest__XSUB_XS_VERSION_undef, __FILE__);
1516 newXS("XS::APItest::XSUB::XS_VERSION_empty", XS_XS__APItest__XSUB_XS_VERSION_empty, __FILE__);
1517 newXS("XS::APItest::XSUB::XS_APIVERSION_invalid", XS_XS__APItest__XSUB_XS_APIVERSION_invalid, __FILE__);
1520 XS_VERSION_defined(...)
1522 XS_VERSION_BOOTCHECK;
1526 XS_APIVERSION_valid(...)
1528 XS_APIVERSION_BOOTCHECK;
1536 for ( ; i < len; i++ ) {
1537 ST(i) = sv_2mortal( newSViv(i) );
1544 XSRETURN_IV(I32_MIN + 1);
1549 XSRETURN_UV( (U32)((1U<<31) + 1) );
1559 XSRETURN_PV("returned");
1564 XSRETURN_PVN("returned too much",8);
1586 MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash
1594 uf.uf_val = rot13_key;
1598 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1607 uf.uf_val = bitflip_key;
1611 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1614 #define UTF8KLEN(sv, len) (SvUTF8(sv) ? -(I32)len : (I32)len)
1617 exists(hash, key_sv)
1625 key = SvPV(key_sv, len);
1626 RETVAL = hv_exists(hash, key, UTF8KLEN(key_sv, len));
1631 exists_ent(hash, key_sv)
1637 RETVAL = hv_exists_ent(hash, key_sv, 0);
1642 delete(hash, key_sv, flags = 0)
1651 key = SvPV(key_sv, len);
1652 /* It's already mortal, so need to increase reference count. */
1654 = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags));
1659 delete_ent(hash, key_sv, flags = 0)
1665 /* It's already mortal, so need to increase reference count. */
1666 RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0));
1671 store_ent(hash, key, value)
1681 result = hv_store_ent(hash, key, copy, 0);
1682 SvSetMagicSV(copy, value);
1687 /* It's about to become mortal, so need to increase reference count.
1689 RETVAL = SvREFCNT_inc(HeVAL(result));
1694 store(hash, key_sv, value)
1705 key = SvPV(key_sv, len);
1707 result = hv_store(hash, key, UTF8KLEN(key_sv, len), copy, 0);
1708 SvSetMagicSV(copy, value);
1713 /* It's about to become mortal, so need to increase reference count.
1715 RETVAL = SvREFCNT_inc(*result);
1720 fetch_ent(hash, key_sv)
1727 result = hv_fetch_ent(hash, key_sv, 0, 0);
1732 RETVAL = newSVsv(HeVAL(result));
1746 key = SvPV(key_sv, len);
1747 result = hv_fetch(hash, key, UTF8KLEN(key_sv, len), 0);
1752 RETVAL = newSVsv(*result);
1756 #if defined (hv_common)
1766 const char *key = NULL;
1774 if ((svp = hv_fetchs(params, "hv", 0))) {
1775 SV *const rv = *svp;
1777 croak("common passed a non-reference for parameter hv");
1778 hv = (HV *)SvRV(rv);
1780 if ((svp = hv_fetchs(params, "keysv", 0)))
1782 if ((svp = hv_fetchs(params, "keypv", 0))) {
1783 key = SvPV_const(*svp, klen);
1787 if ((svp = hv_fetchs(params, "action", 0)))
1788 action = SvIV(*svp);
1789 if ((svp = hv_fetchs(params, "val", 0)))
1790 val = newSVsv(*svp);
1791 if ((svp = hv_fetchs(params, "hash", 0)))
1794 if (hv_fetchs(params, "hash_pv", 0)) {
1796 PERL_HASH(hash, key, klen);
1798 if (hv_fetchs(params, "hash_sv", 0)) {
1802 const char *const p = SvPV(keysv, len);
1803 PERL_HASH(hash, p, len);
1807 result = (HE *)hv_common(hv, keysv, key, klen, flags, action, val, hash);
1812 RETVAL = newSVsv(HeVAL(result));
1821 test_freeent(&Perl_hv_free_ent);
1825 test_hv_delayfree_ent()
1827 test_freeent(&Perl_hv_delayfree_ent);
1831 test_share_unshare_pvn(input)
1840 pvx = SvPV(input, len);
1841 PERL_HASH(hash, pvx, len);
1842 p = sharepvn(pvx, len, hash);
1843 RETVAL = newSVpvn(p, len);
1844 unsharepvn(p, len, hash);
1848 #if PERL_VERSION >= 9
1851 refcounted_he_exists(key, level=0)
1856 croak("level must be zero, not %" IVdf, level);
1858 RETVAL = (cop_hints_fetch_sv(PL_curcop, key, 0, 0) != &PL_sv_placeholder);
1863 refcounted_he_fetch(key, level=0)
1868 croak("level must be zero, not %" IVdf, level);
1870 RETVAL = cop_hints_fetch_sv(PL_curcop, key, 0, 0);
1871 SvREFCNT_inc(RETVAL);
1878 test_force_keys(HV *hv)
1884 he = hv_iternext(hv);
1886 SV *sv = HeSVKEY_force(he);
1889 PUSHs(sv_mortalcopy(sv));
1890 he = hv_iternext(hv);
1895 sub TIEHASH { bless {}, $_[0] }
1896 sub STORE { $_[0]->{$_[1]} = $_[2] }
1897 sub FETCH { $_[0]->{$_[1]} }
1898 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
1899 sub NEXTKEY { each %{$_[0]} }
1900 sub EXISTS { exists $_[0]->{$_[1]} }
1901 sub DELETE { delete $_[0]->{$_[1]} }
1902 sub CLEAR { %{$_[0]} = () }
1906 MODULE = XS::APItest:TempLv PACKAGE = XS::APItest::TempLv
1912 SV * const lv = newSV_type(SVt_PVLV);
1917 sv_magic(lv, NULL, PERL_MAGIC_substr, NULL, 0);
1919 LvTARG(lv) = SvREFCNT_inc_simple(sv);
1920 LvTARGOFF(lv) = len == 0 ? 0 : 1;
1921 LvTARGLEN(lv) = len < 2 ? 0 : len-2;
1924 ST(0) = sv_2mortal(lv);
1928 MODULE = XS::APItest::PtrTable PACKAGE = XS::APItest::PtrTable PREFIX = ptr_table_
1931 ptr_table_new(classname)
1932 const char * classname
1934 PUSHs(sv_setref_pv(sv_newmortal(), classname, (void*)ptr_table_new()));
1938 XS::APItest::PtrTable table
1940 ptr_table_free(table);
1943 ptr_table_store(table, from, to)
1944 XS::APItest::PtrTable table
1948 ptr_table_store(table, from, to);
1951 ptr_table_fetch(table, from)
1952 XS::APItest::PtrTable table
1955 RETVAL = PTR2UV(ptr_table_fetch(table, from));
1960 ptr_table_split(table)
1961 XS::APItest::PtrTable table
1964 ptr_table_clear(table)
1965 XS::APItest::PtrTable table
1967 MODULE = XS::APItest::AutoLoader PACKAGE = XS::APItest::AutoLoader
1972 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
1980 PERL_UNUSED_ARG(items);
1981 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
1986 MODULE = XS::APItest PACKAGE = XS::APItest
1991 mymro.resolve = myget_linear_isa;
1992 mymro.name = "justisa";
1996 Perl_mro_register(aTHX_ &mymro);
2001 RETVAL = PL_custom_ops;
2006 xop_custom_op_names ()
2008 PL_custom_op_names = newHV();
2009 RETVAL = PL_custom_op_names;
2014 xop_custom_op_descs ()
2016 PL_custom_op_descs = newHV();
2017 RETVAL = PL_custom_op_descs;
2024 XopENTRY_set(&my_xop, xop_name, "my_xop");
2025 XopENTRY_set(&my_xop, xop_desc, "XOP for testing");
2026 XopENTRY_set(&my_xop, xop_class, OA_UNOP);
2027 XopENTRY_set(&my_xop, xop_peep, peep_xop);
2028 Perl_custom_op_register(aTHX_ pp_xop, &my_xop);
2033 XopDISABLE(&my_xop, xop_name);
2034 XopDISABLE(&my_xop, xop_desc);
2035 XopDISABLE(&my_xop, xop_class);
2036 XopDISABLE(&my_xop, xop_peep);
2041 RETVAL = PTR2IV(&my_xop);
2048 RETVAL = PTR2IV(pp_xop);
2066 MY_CXT.xop_record = newAV();
2068 kid = newSVOP(OP_CONST, 0, newSViv(42));
2070 unop = (UNOP*)mkUNOP(OP_CUSTOM, kid);
2071 unop->op_ppaddr = pp_xop;
2072 unop->op_private = 0;
2073 unop->op_next = NULL;
2074 kid->op_next = (OP*)unop;
2076 av_push(MY_CXT.xop_record, newSVpvf("unop:%" UVxf, PTR2UV(unop)));
2077 av_push(MY_CXT.xop_record, newSVpvf("kid:%" UVxf, PTR2UV(kid)));
2079 av_push(MY_CXT.xop_record, newSVpvf("NAME:%s", OP_NAME((OP*)unop)));
2080 av_push(MY_CXT.xop_record, newSVpvf("DESC:%s", OP_DESC((OP*)unop)));
2081 av_push(MY_CXT.xop_record, newSVpvf("CLASS:%d", (int)OP_CLASS((OP*)unop)));
2083 PL_rpeepp(aTHX_ kid);
2088 RETVAL = MY_CXT.xop_record;
2089 MY_CXT.xop_record = NULL;
2094 xop_from_custom_op ()
2096 /* author note: this test doesn't imply Perl_custom_op_xop is or isn't public
2097 API or that Perl_custom_op_xop is known to be used outside the core */
2101 unop = (UNOP*)mkUNOP(OP_CUSTOM, NULL);
2102 unop->op_ppaddr = pp_xop;
2103 unop->op_private = 0;
2104 unop->op_next = NULL;
2106 xop = Perl_custom_op_xop(aTHX_ (OP *)unop);
2108 RETVAL = PTR2IV(xop);
2117 MY_CXT.sv = newSVpv("initial",0);
2119 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2120 MY_CXT.bhk_record = 0;
2122 BhkENTRY_set(&bhk_test, bhk_start, blockhook_test_start);
2123 BhkENTRY_set(&bhk_test, bhk_pre_end, blockhook_test_pre_end);
2124 BhkENTRY_set(&bhk_test, bhk_post_end, blockhook_test_post_end);
2125 BhkENTRY_set(&bhk_test, bhk_eval, blockhook_test_eval);
2126 Perl_blockhook_register(aTHX_ &bhk_test);
2128 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2129 GV_ADDMULTI, SVt_PVAV);
2130 MY_CXT.cscav = GvAV(MY_CXT.cscgv);
2132 BhkENTRY_set(&bhk_csc, bhk_start, blockhook_csc_start);
2133 BhkENTRY_set(&bhk_csc, bhk_pre_end, blockhook_csc_pre_end);
2134 Perl_blockhook_register(aTHX_ &bhk_csc);
2136 MY_CXT.peep_recorder = newAV();
2137 MY_CXT.rpeep_recorder = newAV();
2139 MY_CXT.orig_peep = PL_peepp;
2140 MY_CXT.orig_rpeep = PL_rpeepp;
2142 PL_rpeepp = my_rpeep;
2149 PERL_UNUSED_VAR(items);
2150 MY_CXT.sv = newSVpv("initial_clone",0);
2151 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2152 GV_ADDMULTI, SVt_PVAV);
2153 MY_CXT.cscav = NULL;
2154 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2155 MY_CXT.bhk_record = 0;
2156 MY_CXT.peep_recorder = newAV();
2157 MY_CXT.rpeep_recorder = newAV();
2163 printf("%5.3f\n",val);
2168 #ifdef HAS_LONG_DOUBLE
2179 #ifdef HAS_LONG_DOUBLE
2180 # if defined(PERL_PRIfldbl) && (LONG_DOUBLESIZE > DOUBLESIZE)
2181 long double val = 7.0;
2182 printf("%5.3" PERL_PRIfldbl "\n",val);
2185 printf("%5.3f\n",val);
2199 printf("%ld\n",val);
2205 printf("%5.3f\n",val);
2253 mXPUSHp("three", 5);
2281 # test_EXTEND(): excerise the EXTEND() macro.
2282 # After calling EXTEND(), it also does *(p+n) = NULL and
2283 # *PL_stack_max = NULL to allow valgrind etc to spot if the stack hasn't
2284 # actually been extended properly.
2286 # max_offset specifies the SP to use. It is treated as a signed offset
2287 # from PL_stack_max.
2288 # nsv is the SV holding the value of n indicating how many slots
2289 # to extend the stack by.
2290 # use_ss is a boolean indicating that n should be cast to a SSize_t
2293 test_EXTEND(max_offset, nsv, use_ss)
2298 SV **sp = PL_stack_max + max_offset;
2301 SSize_t n = (SSize_t)SvIV(nsv);
2310 *PL_stack_max = NULL;
2322 SV * miscsv = sv_newmortal();
2323 HV * hv = (HV*)sv_2mortal((SV*)newHV());
2325 i_sub = get_cv("i", 0);
2327 /* PUTBACK not needed since this sub was called with 0 args, and is calling
2328 0 args, so global SP doesn't need to be moved before a call_* */
2329 retcnt = call_sv((SV*)i_sub, 0); /* try a CV* */
2331 SP -= retcnt; /* dont care about return count, wipe everything off */
2332 sv_setpvs(miscsv, "i");
2334 retcnt = call_sv(miscsv, 0); /* try a PV */
2337 /* no add and SVt_NULL are intentional, sub i should be defined already */
2338 i_gv = gv_fetchpvn_flags("i", sizeof("i")-1, 0, SVt_NULL);
2340 retcnt = call_sv((SV*)i_gv, 0); /* try a GV* */
2343 /* the tests below are not declaring this being public API behavior,
2344 only current internal behavior, these tests can be changed in the
2345 future if necessery */
2347 retcnt = call_sv(&PL_sv_yes, G_EVAL);
2351 errstr = SvPV(errsv, errlen);
2352 if(memBEGINs(errstr, errlen, "Undefined subroutine &main::1 called at")) {
2354 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2359 retcnt = call_sv(&PL_sv_no, G_EVAL);
2363 errstr = SvPV(errsv, errlen);
2364 if(memBEGINs(errstr, errlen, "Undefined subroutine &main:: called at")) {
2366 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2371 retcnt = call_sv(&PL_sv_undef, G_EVAL);
2375 errstr = SvPV(errsv, errlen);
2376 if(memBEGINs(errstr, errlen, "Can't use an undefined value as a subroutine reference at")) {
2378 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2383 retcnt = call_sv((SV*)hv, G_EVAL);
2387 errstr = SvPV(errsv, errlen);
2388 if(memBEGINs(errstr, errlen, "Not a CODE reference at")) {
2390 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2396 call_sv(sv, flags, ...)
2402 for (i=0; i<items-2; i++)
2403 ST(i) = ST(i+2); /* pop first two args */
2407 i = call_sv(sv, flags);
2410 PUSHs(sv_2mortal(newSViv(i)));
2413 call_pv(subname, flags, ...)
2419 for (i=0; i<items-2; i++)
2420 ST(i) = ST(i+2); /* pop first two args */
2424 i = call_pv(subname, flags);
2427 PUSHs(sv_2mortal(newSViv(i)));
2430 call_argv(subname, flags, ...)
2437 for (i=0; i<items-2; i++)
2438 tmpary[i] = SvPV_nolen(ST(i+2)); /* ignore first two args */
2441 i = call_argv(subname, flags, tmpary);
2444 PUSHs(sv_2mortal(newSViv(i)));
2447 call_method(methname, flags, ...)
2453 for (i=0; i<items-2; i++)
2454 ST(i) = ST(i+2); /* pop first two args */
2458 i = call_method(methname, flags);
2461 PUSHs(sv_2mortal(newSViv(i)));
2464 newCONSTSUB(stash, name, flags, sv)
2470 newCONSTSUB_flags = 1
2474 const char *pv = SvPV(name, len);
2478 mycv = newCONSTSUB(stash, pv, SvOK(sv) ? SvREFCNT_inc(sv) : NULL);
2481 mycv = newCONSTSUB_flags(
2482 stash, pv, len, flags | SvUTF8(name), SvOK(sv) ? SvREFCNT_inc(sv) : NULL
2488 PUSHs( CvCONST(mycv) ? &PL_sv_yes : &PL_sv_no );
2489 PUSHs((SV*)CvGV(mycv));
2492 gv_init_type(namesv, multi, flags, type)
2499 const char * const name = SvPV_const(namesv, len);
2500 GV *gv = *(GV**)hv_fetch(PL_defstash, name, len, TRUE);
2502 if (SvTYPE(gv) == SVt_PVGV)
2503 Perl_croak(aTHX_ "GV is already a PVGV");
2504 if (multi) flags |= GV_ADDMULTI;
2507 gv_init(gv, PL_defstash, name, len, multi);
2510 gv_init_sv(gv, PL_defstash, namesv, flags);
2513 gv_init_pv(gv, PL_defstash, name, flags | SvUTF8(namesv));
2516 gv_init_pvn(gv, PL_defstash, name, len, flags | SvUTF8(namesv));
2519 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2522 gv_fetchmeth_type(stash, methname, type, level, flags)
2530 const char * const name = SvPV_const(methname, len);
2535 gv = gv_fetchmeth(stash, name, len, level);
2538 gv = gv_fetchmeth_sv(stash, methname, level, flags);
2541 gv = gv_fetchmeth_pv(stash, name, level, flags | SvUTF8(methname));
2544 gv = gv_fetchmeth_pvn(stash, name, len, level, flags | SvUTF8(methname));
2547 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2550 gv_fetchmeth_autoload_type(stash, methname, type, level, flags)
2558 const char * const name = SvPV_const(methname, len);
2563 gv = gv_fetchmeth_autoload(stash, name, len, level);
2566 gv = gv_fetchmeth_sv_autoload(stash, methname, level, flags);
2569 gv = gv_fetchmeth_pv_autoload(stash, name, level, flags | SvUTF8(methname));
2572 gv = gv_fetchmeth_pvn_autoload(stash, name, len, level, flags | SvUTF8(methname));
2575 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2578 gv_fetchmethod_flags_type(stash, methname, type, flags)
2588 gv = gv_fetchmethod_flags(stash, SvPVX_const(methname), flags);
2591 gv = gv_fetchmethod_sv_flags(stash, methname, flags);
2594 gv = gv_fetchmethod_pv_flags(stash, SvPV_nolen(methname), flags | SvUTF8(methname));
2598 const char * const name = SvPV_const(methname, len);
2599 gv = gv_fetchmethod_pvn_flags(stash, name, len, flags | SvUTF8(methname));
2603 gv = gv_fetchmethod_pvn_flags(stash, SvPV_nolen(methname),
2604 flags, SvUTF8(methname));
2606 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2609 gv_autoload_type(stash, methname, type, method)
2616 const char * const name = SvPV_const(methname, len);
2618 I32 flags = method ? GV_AUTOLOAD_ISMETHOD : 0;
2622 gv = gv_autoload4(stash, name, len, method);
2625 gv = gv_autoload_sv(stash, methname, flags);
2628 gv = gv_autoload_pv(stash, name, flags | SvUTF8(methname));
2631 gv = gv_autoload_pvn(stash, name, len, flags | SvUTF8(methname));
2634 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2637 gv_const_sv(SV *name)
2642 HV *stash = gv_stashpv("main",0);
2643 HE *he = hv_fetch_ent(stash, name, 0, 0);
2644 gv = (GV *)HeVAL(he);
2649 RETVAL = gv_const_sv(gv);
2652 RETVAL = newSVsv(RETVAL);
2657 whichsig_type(namesv, type)
2662 const char * const name = SvPV_const(namesv, len);
2670 i = whichsig_sv(namesv);
2673 i = whichsig_pv(name);
2676 i = whichsig_pvn(name, len);
2679 XPUSHs(sv_2mortal(newSViv(i)));
2689 i = eval_sv(sv, flags);
2692 PUSHs(sv_2mortal(newSViv(i)));
2695 eval_pv(p, croak_on_error)
2701 PUSHs(eval_pv(p, croak_on_error));
2711 apitest_exception(throw_e)
2721 Perl_croak(aTHX_ "%s", SvPV_nolen(sv));
2724 Perl_croak(aTHX_ NULL);
2730 RETVAL = newRV_inc((SV*)PL_strtab);
2738 RETVAL = my_cxt_getint_p(aMY_CXT);
2747 my_cxt_setint_p(aMY_CXT_ i);
2754 ST(0) = how ? my_cxt_getsv_interp_context() : my_cxt_getsv_interp();
2762 SvREFCNT_dec(MY_CXT.sv);
2763 my_cxt_setsv_p(sv _aMY_CXT);
2767 sv_setsv_cow_hashkey_core()
2770 sv_setsv_cow_hashkey_notcore()
2773 sv_set_deref(SV *sv, SV *sv2, int which)
2777 const char *pv = SvPV(sv2,len);
2778 if (!SvROK(sv)) croak("Not a ref");
2781 case 0: sv_setsv(sv,sv2); break;
2782 case 1: sv_setpv(sv,pv); break;
2783 case 2: sv_setpvn(sv,pv,len); break;
2788 rmagical_cast(sv, type)
2794 if (!SvOK(sv) || !SvROK(sv) || !SvOK(type)) { XSRETURN_UNDEF; }
2796 if (SvTYPE(sv) != SVt_PVHV) { XSRETURN_UNDEF; }
2797 uf.uf_val = rmagical_a_dummy;
2800 if (SvTRUE(type)) { /* b */
2801 sv_magicext(sv, NULL, PERL_MAGIC_ext, &rmagical_b, NULL, 0);
2803 sv_magic(sv, NULL, PERL_MAGIC_uvar, (char *) &uf, sizeof(uf));
2811 if (!SvOK(sv) || !SvROK(sv)) { XSRETURN_UNDEF; }
2814 mXPUSHu(SvFLAGS(sv) & SVs_GMG);
2815 mXPUSHu(SvFLAGS(sv) & SVs_SMG);
2816 mXPUSHu(SvFLAGS(sv) & SVs_RMG);
2823 const PERL_CONTEXT *cx, *dbcx;
2828 cx = caller_cx(level, &dbcx);
2831 pv = CopSTASHPV(cx->blk_oldcop);
2832 ST(0) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2833 gv = CvGV(cx->blk_sub.cv);
2834 ST(1) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2836 pv = CopSTASHPV(dbcx->blk_oldcop);
2837 ST(2) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2838 gv = CvGV(dbcx->blk_sub.cv);
2839 ST(3) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2841 ST(4) = cop_hints_fetch_pvs(cx->blk_oldcop, "foo", 0);
2842 ST(5) = cop_hints_fetch_pvn(cx->blk_oldcop, "foo", 3, 0, 0);
2843 ST(6) = cop_hints_fetch_sv(cx->blk_oldcop,
2844 sv_2mortal(newSVpvs("foo")), 0, 0);
2846 hv = cop_hints_2hv(cx->blk_oldcop, 0);
2847 ST(7) = hv ? sv_2mortal(newRV_noinc((SV *)hv)) : &PL_sv_undef;
2856 ST (0) = newSVpv (Perl_sv_peek (aTHX_ sv), 0);
2862 sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI));
2867 sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI));
2872 sv_inc(get_sv("XS::APItest::UNITCHECK_called", GV_ADD|GV_ADDMULTI));
2877 sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI));
2882 sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI));
2885 utf16_to_utf8 (sv, ...)
2888 utf16_to_utf8_reversed = 1
2893 I32 got; /* Gah, badly thought out APIs */
2895 if (ix) (void)SvPV_force_nolen(sv);
2896 source = (U8 *)SvPVbyte(sv, len);
2897 /* Optionally only convert part of the buffer. */
2901 /* Mortalise this right now, as we'll be testing croak()s */
2902 dest = sv_2mortal(newSV(len * 2 + 1));
2904 utf16_to_utf8_reversed(source, (U8 *)SvPVX(dest), len, &got);
2906 utf16_to_utf8(source, (U8 *)SvPVX(dest), len, &got);
2908 SvCUR_set(dest, got);
2909 SvPVX(dest)[got] = '\0';
2915 my_exit(int exitcode)
2925 s = SvPVbyte(sv, len);
2933 RETVAL = PL_sv_count;
2941 MY_CXT.bhk_record = on;
2943 av_clear(MY_CXT.bhkav);
2949 MAGIC *callmg, *uvarmg;
2951 sv = sv_2mortal(newSV(0));
2952 if (SvTYPE(sv) >= SVt_PVMG) croak_fail();
2953 if (SvMAGICAL(sv)) croak_fail();
2954 sv_magic(sv, &PL_sv_yes, PERL_MAGIC_checkcall, (char*)&callmg, 0);
2955 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2956 if (!SvMAGICAL(sv)) croak_fail();
2957 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2958 callmg = mg_find(sv, PERL_MAGIC_checkcall);
2959 if (!callmg) croak_fail();
2960 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2962 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
2963 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2964 if (!SvMAGICAL(sv)) croak_fail();
2965 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2966 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
2967 if (!uvarmg) croak_fail();
2968 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2970 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2972 mg_free_type(sv, PERL_MAGIC_vec);
2973 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2974 if (!SvMAGICAL(sv)) croak_fail();
2975 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2976 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
2977 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2979 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2981 mg_free_type(sv, PERL_MAGIC_uvar);
2982 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2983 if (!SvMAGICAL(sv)) croak_fail();
2984 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2985 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
2986 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2988 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
2989 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
2990 if (!SvMAGICAL(sv)) croak_fail();
2991 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
2992 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
2993 if (!uvarmg) croak_fail();
2994 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
2996 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
2998 mg_free_type(sv, PERL_MAGIC_checkcall);
2999 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3000 if (!SvMAGICAL(sv)) croak_fail();
3001 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
3002 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
3003 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
3005 mg_free_type(sv, PERL_MAGIC_uvar);
3006 if (SvMAGICAL(sv)) croak_fail();
3007 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
3008 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
3011 test_op_contextualize()
3015 o = newSVOP(OP_CONST, 0, newSViv(0));
3016 o->op_flags &= ~OPf_WANT;
3017 o = op_contextualize(o, G_SCALAR);
3018 if (o->op_type != OP_CONST ||
3019 (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR)
3022 o = newSVOP(OP_CONST, 0, newSViv(0));
3023 o->op_flags &= ~OPf_WANT;
3024 o = op_contextualize(o, G_ARRAY);
3025 if (o->op_type != OP_CONST ||
3026 (o->op_flags & OPf_WANT) != OPf_WANT_LIST)
3029 o = newSVOP(OP_CONST, 0, newSViv(0));
3030 o->op_flags &= ~OPf_WANT;
3031 o = op_contextualize(o, G_VOID);
3032 if (o->op_type != OP_NULL) croak_fail();
3043 troc_gv = gv_fetchpv("XS::APItest::test_rv2cv_op_cv", 0, SVt_PVGV);
3044 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3045 o = newCVREF(0, newGVOP(OP_GV, 0, troc_gv));
3046 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3047 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3049 o->op_private |= OPpENTERSUB_AMPER;
3050 if (rv2cv_op_cv(o, 0)) croak_fail();
3051 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3052 o->op_private &= ~OPpENTERSUB_AMPER;
3053 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3054 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3055 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3057 o = newSVOP(OP_CONST, 0, newSVpv("XS::APItest::test_rv2cv_op_cv", 0));
3058 o->op_private = OPpCONST_BARE;
3060 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3061 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3063 o->op_private |= OPpENTERSUB_AMPER;
3064 if (rv2cv_op_cv(o, 0)) croak_fail();
3065 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3067 o = newCVREF(0, newSVOP(OP_CONST, 0, newRV_inc((SV*)troc_cv)));
3068 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3069 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3071 o->op_private |= OPpENTERSUB_AMPER;
3072 if (rv2cv_op_cv(o, 0)) croak_fail();
3073 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3074 o->op_private &= ~OPpENTERSUB_AMPER;
3075 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3076 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3077 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3079 o = newCVREF(0, newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0))));
3080 if (rv2cv_op_cv(o, 0)) croak_fail();
3081 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3082 o->op_private |= OPpENTERSUB_AMPER;
3083 if (rv2cv_op_cv(o, 0)) croak_fail();
3084 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3085 o->op_private &= ~OPpENTERSUB_AMPER;
3086 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3087 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY)) croak_fail();
3088 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3090 o = newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0)));
3091 if (rv2cv_op_cv(o, 0)) croak_fail();
3092 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3096 test_cv_getset_call_checker()
3098 CV *troc_cv, *tsh_cv;
3099 Perl_call_checker ckfun;
3103 #define check_cc(cv, xckfun, xckobj, xckflags) \
3105 cv_get_call_checker((cv), &ckfun, &ckobj); \
3106 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3107 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3108 cv_get_call_checker_flags((cv), CALL_CHECKER_REQUIRE_GV, &ckfun, &ckobj, &ckflags); \
3109 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3110 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3111 if (ckflags != CALL_CHECKER_REQUIRE_GV) croak_fail_nei(ckflags, CALL_CHECKER_REQUIRE_GV); \
3112 cv_get_call_checker_flags((cv), 0, &ckfun, &ckobj, &ckflags); \
3113 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3114 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3115 if (ckflags != (xckflags)) croak_fail_nei(ckflags, (xckflags)); \
3117 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3118 tsh_cv = get_cv("XS::APItest::test_savehints", 0);
3119 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3120 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3121 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3123 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3124 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3125 cv_set_call_checker(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no);
3126 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no, CALL_CHECKER_REQUIRE_GV);
3127 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3128 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3130 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no, CALL_CHECKER_REQUIRE_GV);
3131 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3132 cv_set_call_checker(troc_cv, Perl_ck_entersub_args_proto_or_list,
3134 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3135 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3136 if (SvMAGICAL((SV*)troc_cv) || SvMAGIC((SV*)troc_cv)) croak_fail();
3137 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3138 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3140 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, 0);
3141 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3142 &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3143 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3144 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3146 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3147 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3148 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3149 &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3150 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3151 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3152 (SV*)tsh_cv, CALL_CHECKER_REQUIRE_GV);
3153 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3154 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3158 cv_set_call_checker_lists(CV *cv)
3160 cv_set_call_checker(cv, THX_ck_entersub_args_lists, &PL_sv_undef);
3163 cv_set_call_checker_scalars(CV *cv)
3165 cv_set_call_checker(cv, THX_ck_entersub_args_scalars, &PL_sv_undef);
3168 cv_set_call_checker_proto(CV *cv, SV *proto)
3171 proto = SvRV(proto);
3172 cv_set_call_checker(cv, Perl_ck_entersub_args_proto, proto);
3175 cv_set_call_checker_proto_or_list(CV *cv, SV *proto)
3178 proto = SvRV(proto);
3179 cv_set_call_checker(cv, Perl_ck_entersub_args_proto_or_list, proto);
3182 cv_set_call_checker_multi_sum(CV *cv)
3184 cv_set_call_checker(cv, THX_ck_entersub_multi_sum, &PL_sv_undef);
3196 #define check_ph(EXPR) \
3197 do { if((EXPR) != &PL_sv_placeholder) croak("fail"); } while(0)
3198 #define check_iv(EXPR, EXPECT) \
3199 do { if(SvIV(EXPR) != (EXPECT)) croak("fail"); } while(0)
3200 #define msvpvs(STR) sv_2mortal(newSVpvs(STR))
3201 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3202 a = cophh_new_empty();
3203 check_ph(cophh_fetch_pvn(a, "foo_1", 5, 0, 0));
3204 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3205 check_ph(cophh_fetch_pv(a, "foo_1", 0, 0));
3206 check_ph(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0));
3207 a = cophh_store_pvn(a, "foo_1abc", 5, 0, msviv(111), 0);
3208 a = cophh_store_pvs(a, "foo_2", msviv(222), 0);
3209 a = cophh_store_pv(a, "foo_3", 0, msviv(333), 0);
3210 a = cophh_store_sv(a, msvpvs("foo_4"), 0, msviv(444), 0);
3211 check_iv(cophh_fetch_pvn(a, "foo_1xyz", 5, 0, 0), 111);
3212 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3213 check_iv(cophh_fetch_pv(a, "foo_1", 0, 0), 111);
3214 check_iv(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0), 111);
3215 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3216 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3217 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3218 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3220 b = cophh_store_pvs(b, "foo_1", msviv(1111), 0);
3221 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3222 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3223 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3224 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3225 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3226 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3227 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3228 check_iv(cophh_fetch_pvs(b, "foo_3", 0), 333);
3229 check_iv(cophh_fetch_pvs(b, "foo_4", 0), 444);
3230 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3231 a = cophh_delete_pvn(a, "foo_1abc", 5, 0, 0);
3232 a = cophh_delete_pvs(a, "foo_2", 0);
3233 b = cophh_delete_pv(b, "foo_3", 0, 0);
3234 b = cophh_delete_sv(b, msvpvs("foo_4"), 0, 0);
3235 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3236 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3237 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3238 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3239 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3240 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3241 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3242 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3243 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3244 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3245 b = cophh_delete_pvs(b, "foo_3", 0);
3246 b = cophh_delete_pvs(b, "foo_5", 0);
3247 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3248 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3249 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3250 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3251 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3253 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3254 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3255 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3256 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3257 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3258 a = cophh_store_pvs(a, "foo_1", msviv(11111), COPHH_KEY_UTF8);
3259 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3261 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3263 /* On EBCDIC, we need to translate the UTF-8 in the ASCII test to the
3264 * equivalent UTF-EBCDIC for the code page. This is done at runtime
3265 * (with the helper function in this file). Therefore we can't use
3266 * cophhh_store_pvs(), as we don't have literal string */
3267 key_sv = sv_2mortal(newSVpvs("foo_"));
3268 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3269 key_name = SvPV(key_sv, key_len);
3270 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3273 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3275 sv_setpvs(key_sv, "foo_");
3276 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3277 key_name = SvPV(key_sv, key_len);
3278 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3281 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3283 sv_setpvs(key_sv, "foo_");
3284 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3285 key_name = SvPV(key_sv, key_len);
3286 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3288 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 11111);
3289 check_iv(cophh_fetch_pvs(a, "foo_1", COPHH_KEY_UTF8), 11111);
3290 check_iv(cophh_fetch_pvs(a, "foo_\xaa", 0), 123);
3292 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xaa", COPHH_KEY_UTF8), 123);
3293 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xaa", 0));
3295 sv_setpvs(key_sv, "foo_");
3296 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xaa"));
3297 key_name = SvPV(key_sv, key_len);
3298 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 123);
3299 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3301 check_iv(cophh_fetch_pvs(a, "foo_\xbb", 0), 456);
3303 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xbb", COPHH_KEY_UTF8), 456);
3304 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xbb", 0));
3306 sv_setpvs(key_sv, "foo_");
3307 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3308 key_name = SvPV(key_sv, key_len);
3309 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 456);
3310 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3312 check_iv(cophh_fetch_pvs(a, "foo_\xcc", 0), 789);
3314 check_iv(cophh_fetch_pvs(a, "foo_\xc3\x8c", COPHH_KEY_UTF8), 789);
3315 check_ph(cophh_fetch_pvs(a, "foo_\xc2\x8c", 0));
3317 sv_setpvs(key_sv, "foo_");
3318 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3319 key_name = SvPV(key_sv, key_len);
3320 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 789);
3321 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3324 check_iv(cophh_fetch_pvs(a, "foo_\xd9\xa6", COPHH_KEY_UTF8), 666);
3325 check_ph(cophh_fetch_pvs(a, "foo_\xd9\xa6", 0));
3327 sv_setpvs(key_sv, "foo_");
3328 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3329 key_name = SvPV(key_sv, key_len);
3330 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 666);
3331 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3349 cop = &PL_compiling;
3350 Perl_cop_store_label(aTHX_ cop, "foo", 3, 0);
3351 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3352 if (strNE(label,"foo")) croak("fail # cop_fetch_label label");
3353 if (len != 3) croak("fail # cop_fetch_label len");
3354 if (utf8) croak("fail # cop_fetch_label utf8");
3355 /* SMALL GERMAN UMLAUT A */
3356 Perl_cop_store_label(aTHX_ cop, "fo\xc3\xa4", 4, SVf_UTF8);
3357 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3358 if (strNE(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label");
3359 if (len != 4) croak("fail # cop_fetch_label len");
3360 if (!utf8) croak("fail # cop_fetch_label utf8");
3373 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3374 a = cophh_new_empty();
3375 a = cophh_store_pvs(a, "foo_0", msviv(999), 0);
3376 a = cophh_store_pvs(a, "foo_1", msviv(111), 0);
3377 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3379 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3381 key_sv = sv_2mortal(newSVpvs("foo_"));
3382 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3383 key_name = SvPV(key_sv, key_len);
3384 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3387 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3389 sv_setpvs(key_sv, "foo_");
3390 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3391 key_name = SvPV(key_sv, key_len);
3392 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3395 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3397 sv_setpvs(key_sv, "foo_");
3398 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3399 key_name = SvPV(key_sv, key_len);
3400 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3402 a = cophh_delete_pvs(a, "foo_0", 0);
3403 a = cophh_delete_pvs(a, "foo_2", 0);
3404 RETVAL = cophh_2hv(a, 0);
3415 #define store_hint(KEY, VALUE) \
3416 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), KEY, 1), (VALUE))
3417 #define hint_ok(KEY, EXPECT) \
3418 ((svp = hv_fetchs(GvHV(PL_hintgv), KEY, 0)) && \
3419 (sv = *svp) && SvIV(sv) == (EXPECT) && \
3420 (sv = cop_hints_fetch_pvs(&PL_compiling, KEY, 0)) && \
3421 SvIV(sv) == (EXPECT))
3422 #define check_hint(KEY, EXPECT) \
3423 do { if (!hint_ok(KEY, EXPECT)) croak_fail(); } while(0)
3424 PL_hints |= HINT_LOCALIZE_HH;
3427 PL_hints &= HINT_INTEGER;
3428 store_hint("t0", 123);
3429 store_hint("t1", 456);
3430 if (PL_hints & HINT_INTEGER) croak_fail();
3431 check_hint("t0", 123); check_hint("t1", 456);
3434 if (PL_hints & HINT_INTEGER) croak_fail();
3435 check_hint("t0", 123); check_hint("t1", 456);
3436 PL_hints |= HINT_INTEGER;
3437 store_hint("t0", 321);
3438 if (!(PL_hints & HINT_INTEGER)) croak_fail();
3439 check_hint("t0", 321); check_hint("t1", 456);
3441 if (PL_hints & HINT_INTEGER) croak_fail();
3442 check_hint("t0", 123); check_hint("t1", 456);
3445 if (PL_hints & HINT_INTEGER) croak_fail();
3446 check_hint("t0", 123); check_hint("t1", 456);
3447 store_hint("t1", 654);
3448 if (PL_hints & HINT_INTEGER) croak_fail();
3449 check_hint("t0", 123); check_hint("t1", 654);
3451 if (PL_hints & HINT_INTEGER) croak_fail();
3452 check_hint("t0", 123); check_hint("t1", 456);
3463 PL_hints |= HINT_LOCALIZE_HH;
3466 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), "t0", 1), 123);
3467 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3469 a = newHVhv(GvHV(PL_hintgv));
3471 sv_setiv_mg(*hv_fetchs(a, "t0", 1), 456);
3472 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3474 b = hv_copy_hints_hv(a);
3476 sv_setiv_mg(*hv_fetchs(b, "t0", 1), 789);
3477 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 789)
3486 #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv))
3487 #define check_op(o, expect) \
3489 if (strNE(test_op_list_describe(o), (expect))) \
3490 croak("fail %s %s", test_op_list_describe(o), (expect)); \
3492 a = op_append_elem(OP_LIST, NULL, NULL);
3494 a = op_append_elem(OP_LIST, iv_op(1), a);
3495 check_op(a, "const(1).");
3496 a = op_append_elem(OP_LIST, NULL, a);
3497 check_op(a, "const(1).");
3498 a = op_append_elem(OP_LIST, a, iv_op(2));
3499 check_op(a, "list[pushmark.const(1).const(2).]");
3500 a = op_append_elem(OP_LIST, a, iv_op(3));
3501 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3502 a = op_append_elem(OP_LIST, a, NULL);
3503 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3504 a = op_append_elem(OP_LIST, NULL, a);
3505 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3506 a = op_append_elem(OP_LIST, iv_op(4), a);
3507 check_op(a, "list[pushmark.const(4)."
3508 "list[pushmark.const(1).const(2).const(3).]]");
3509 a = op_append_elem(OP_LIST, a, iv_op(5));
3510 check_op(a, "list[pushmark.const(4)."
3511 "list[pushmark.const(1).const(2).const(3).]const(5).]");
3512 a = op_append_elem(OP_LIST, a,
3513 op_append_elem(OP_LIST, iv_op(7), iv_op(6)));
3514 check_op(a, "list[pushmark.const(4)."
3515 "list[pushmark.const(1).const(2).const(3).]const(5)."
3516 "list[pushmark.const(7).const(6).]]");
3518 a = op_append_elem(OP_LINESEQ, iv_op(1), iv_op(2));
3519 check_op(a, "lineseq[const(1).const(2).]");
3520 a = op_append_elem(OP_LINESEQ, a, iv_op(3));
3521 check_op(a, "lineseq[const(1).const(2).const(3).]");
3523 a = op_append_elem(OP_LINESEQ,
3524 op_append_elem(OP_LIST, iv_op(1), iv_op(2)),
3526 check_op(a, "lineseq[list[pushmark.const(1).const(2).]const(3).]");
3528 a = op_prepend_elem(OP_LIST, NULL, NULL);
3530 a = op_prepend_elem(OP_LIST, a, iv_op(1));
3531 check_op(a, "const(1).");
3532 a = op_prepend_elem(OP_LIST, a, NULL);
3533 check_op(a, "const(1).");
3534 a = op_prepend_elem(OP_LIST, iv_op(2), a);
3535 check_op(a, "list[pushmark.const(2).const(1).]");
3536 a = op_prepend_elem(OP_LIST, iv_op(3), a);
3537 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3538 a = op_prepend_elem(OP_LIST, NULL, a);
3539 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3540 a = op_prepend_elem(OP_LIST, a, NULL);
3541 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3542 a = op_prepend_elem(OP_LIST, a, iv_op(4));
3543 check_op(a, "list[pushmark."
3544 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3545 a = op_prepend_elem(OP_LIST, iv_op(5), a);
3546 check_op(a, "list[pushmark.const(5)."
3547 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3548 a = op_prepend_elem(OP_LIST,
3549 op_prepend_elem(OP_LIST, iv_op(6), iv_op(7)), a);
3550 check_op(a, "list[pushmark.list[pushmark.const(6).const(7).]const(5)."
3551 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3553 a = op_prepend_elem(OP_LINESEQ, iv_op(2), iv_op(1));
3554 check_op(a, "lineseq[const(2).const(1).]");
3555 a = op_prepend_elem(OP_LINESEQ, iv_op(3), a);
3556 check_op(a, "lineseq[const(3).const(2).const(1).]");
3558 a = op_prepend_elem(OP_LINESEQ, iv_op(3),
3559 op_prepend_elem(OP_LIST, iv_op(2), iv_op(1)));
3560 check_op(a, "lineseq[const(3).list[pushmark.const(2).const(1).]]");
3562 a = op_append_list(OP_LINESEQ, NULL, NULL);
3564 a = op_append_list(OP_LINESEQ, iv_op(1), a);
3565 check_op(a, "const(1).");
3566 a = op_append_list(OP_LINESEQ, NULL, a);
3567 check_op(a, "const(1).");
3568 a = op_append_list(OP_LINESEQ, a, iv_op(2));
3569 check_op(a, "lineseq[const(1).const(2).]");
3570 a = op_append_list(OP_LINESEQ, a, iv_op(3));
3571 check_op(a, "lineseq[const(1).const(2).const(3).]");
3572 a = op_append_list(OP_LINESEQ, iv_op(4), a);
3573 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3574 a = op_append_list(OP_LINESEQ, a, NULL);
3575 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3576 a = op_append_list(OP_LINESEQ, NULL, a);
3577 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3578 a = op_append_list(OP_LINESEQ, a,
3579 op_append_list(OP_LINESEQ, iv_op(5), iv_op(6)));
3580 check_op(a, "lineseq[const(4).const(1).const(2).const(3)."
3581 "const(5).const(6).]");
3583 a = op_append_list(OP_LINESEQ,
3584 op_append_list(OP_LINESEQ, iv_op(1), iv_op(2)),
3585 op_append_list(OP_LIST, iv_op(3), iv_op(4)));
3586 check_op(a, "lineseq[const(1).const(2)."
3587 "list[pushmark.const(3).const(4).]]");
3589 a = op_append_list(OP_LINESEQ,
3590 op_append_list(OP_LIST, iv_op(1), iv_op(2)),
3591 op_append_list(OP_LINESEQ, iv_op(3), iv_op(4)));
3592 check_op(a, "lineseq[list[pushmark.const(1).const(2).]"
3593 "const(3).const(4).]");
3602 #define check_ll(o, expect) \
3604 if (strNE(test_op_linklist_describe(o), (expect))) \
3605 croak("fail %s %s", test_op_linklist_describe(o), (expect)); \
3608 check_ll(o, ".const1");
3611 o = mkUNOP(OP_NOT, iv_op(1));
3612 check_ll(o, ".const1.not");
3615 o = mkUNOP(OP_NOT, mkUNOP(OP_NEGATE, iv_op(1)));
3616 check_ll(o, ".const1.negate.not");
3619 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3620 check_ll(o, ".const1.const2.add");
3623 o = mkBINOP(OP_ADD, mkUNOP(OP_NOT, iv_op(1)), iv_op(2));
3624 check_ll(o, ".const1.not.const2.add");
3627 o = mkUNOP(OP_NOT, mkBINOP(OP_ADD, iv_op(1), iv_op(2)));
3628 check_ll(o, ".const1.const2.add.not");
3631 o = mkLISTOP(OP_LINESEQ, iv_op(1), iv_op(2), iv_op(3));
3632 check_ll(o, ".const1.const2.const3.lineseq");
3635 o = mkLISTOP(OP_LINESEQ,
3636 mkBINOP(OP_ADD, iv_op(1), iv_op(2)),
3637 mkUNOP(OP_NOT, iv_op(3)),
3638 mkLISTOP(OP_SUBSTR, iv_op(4), iv_op(5), iv_op(6)));
3639 check_ll(o, ".const1.const2.add.const3.not"
3640 ".const4.const5.const6.substr.lineseq");
3643 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3645 o = mkBINOP(OP_SUBTRACT, o, iv_op(3));
3646 check_ll(o, ".const1.const2.add.const3.subtract");
3656 av_clear(MY_CXT.peep_recorder);
3657 av_clear(MY_CXT.rpeep_recorder);
3658 MY_CXT.peep_recording = 1;
3665 MY_CXT.peep_recording = 0;
3672 RETVAL = newRV_inc((SV *)MY_CXT.peep_recorder);
3681 RETVAL = newRV_inc((SV *)MY_CXT.rpeep_recorder);
3687 multicall_each: call a sub for each item in the list. Used to test MULTICALL
3692 multicall_each(block,...)
3701 I32 gimme = G_SCALAR;
3702 SV **args = &PL_stack_base[ax];
3708 cv = sv_2cv(block, &stash, &gv, 0);
3710 croak("multicall_each: not a subroutine reference");
3713 SAVESPTR(GvSV(PL_defgv));
3715 for(index = 1 ; index < items ; index++) {
3716 GvSV(PL_defgv) = args[index];
3725 multicall_return(): call the passed sub once in the specificed context
3726 and return whatever it returns
3731 multicall_return(block, context)
3741 I32 gimme = context;
3747 cv = sv_2cv(block, &stash, &gv, 0);
3749 croak("multicall_return not a subroutine reference");
3755 /* copy returned values into an array so they're not freed during
3766 av_push(av, SvREFCNT_inc(TOPs));
3770 for (p = PL_stack_base + 1; p <= SP; p++)
3771 av_push(av, SvREFCNT_inc(*p));
3777 size = AvFILLp(av) + 1;
3779 for (i = 0; i < size; i++)
3780 ST(i) = *av_fetch(av, i, FALSE);
3781 sv_2mortal((SV*)av);
3792 PerlInterpreter *interp = aTHX; /* The original interpreter */
3793 PerlInterpreter *interp_dup; /* The duplicate interpreter */
3794 int oldscope = 1; /* We are responsible for all scopes */
3796 interp_dup = perl_clone(interp, CLONEf_COPY_STACKS | CLONEf_CLONE_HOST );
3798 /* destroy old perl */
3799 PERL_SET_CONTEXT(interp);
3801 POPSTACK_TO(PL_mainstack);
3802 if (cxstack_ix >= 0) {
3804 cx_popblock(cxstack);
3807 PL_scopestack_ix = oldscope;
3810 perl_destruct(interp);
3813 /* switch to new perl */
3814 PERL_SET_CONTEXT(interp_dup);
3816 /* continue after 'clone_with_stack' */
3817 if (interp_dup->Iop)
3818 interp_dup->Iop = interp_dup->Iop->op_next;
3820 /* run with new perl */
3821 Perl_runops_standard(interp_dup);
3823 /* We may have additional unclosed scopes if fork() was called
3824 * from within a BEGIN block. See perlfork.pod for more details.
3825 * We cannot clean up these other scopes because they belong to a
3826 * different interpreter, but we also cannot leave PL_scopestack_ix
3827 * dangling because that can trigger an assertion in perl_destruct().
3829 if (PL_scopestack_ix > oldscope) {
3830 PL_scopestack[oldscope-1] = PL_scopestack[PL_scopestack_ix-1];
3831 PL_scopestack_ix = oldscope;
3834 perl_destruct(interp_dup);
3835 perl_free(interp_dup);
3837 /* call the real 'exit' not PerlProc_exit */
3842 #endif /* USE_ITHREDS */
3845 take_svref(SVREF sv)
3847 RETVAL = newRV_inc(sv);
3854 RETVAL = newRV_inc((SV*)av);
3861 RETVAL = newRV_inc((SV*)hv);
3869 RETVAL = newRV_inc((SV*)cv);
3879 stash = gv_stashpv("XS::APItest::TempLv", 0);
3881 meth = hv_fetchs(stash, "make_temp_mg_lv", 0);
3883 croak("lost method 'make_temp_mg_lv'");
3890 hintkey_rpn_sv = newSVpvs_share("XS::APItest/rpn");
3891 hintkey_calcrpn_sv = newSVpvs_share("XS::APItest/calcrpn");
3892 hintkey_stufftest_sv = newSVpvs_share("XS::APItest/stufftest");
3893 hintkey_swaptwostmts_sv = newSVpvs_share("XS::APItest/swaptwostmts");
3894 hintkey_looprest_sv = newSVpvs_share("XS::APItest/looprest");
3895 hintkey_scopelessblock_sv = newSVpvs_share("XS::APItest/scopelessblock");
3896 hintkey_stmtasexpr_sv = newSVpvs_share("XS::APItest/stmtasexpr");
3897 hintkey_stmtsasexpr_sv = newSVpvs_share("XS::APItest/stmtsasexpr");
3898 hintkey_loopblock_sv = newSVpvs_share("XS::APItest/loopblock");
3899 hintkey_blockasexpr_sv = newSVpvs_share("XS::APItest/blockasexpr");
3900 hintkey_swaplabel_sv = newSVpvs_share("XS::APItest/swaplabel");
3901 hintkey_labelconst_sv = newSVpvs_share("XS::APItest/labelconst");
3902 hintkey_arrayfullexpr_sv = newSVpvs_share("XS::APItest/arrayfullexpr");
3903 hintkey_arraylistexpr_sv = newSVpvs_share("XS::APItest/arraylistexpr");
3904 hintkey_arraytermexpr_sv = newSVpvs_share("XS::APItest/arraytermexpr");
3905 hintkey_arrayarithexpr_sv = newSVpvs_share("XS::APItest/arrayarithexpr");
3906 hintkey_arrayexprflags_sv = newSVpvs_share("XS::APItest/arrayexprflags");
3907 hintkey_DEFSV_sv = newSVpvs_share("XS::APItest/DEFSV");
3908 hintkey_with_vars_sv = newSVpvs_share("XS::APItest/with_vars");
3909 hintkey_join_with_space_sv = newSVpvs_share("XS::APItest/join_with_space");
3910 wrap_keyword_plugin(my_keyword_plugin, &next_keyword_plugin);
3914 establish_cleanup(...)
3917 PERL_UNUSED_VAR(items);
3918 croak("establish_cleanup called as a function");
3922 CV *estcv = get_cv("XS::APItest::establish_cleanup", 0);
3923 cv_set_call_checker(estcv, THX_ck_entersub_establish_cleanup, (SV*)estcv);
3930 PERL_UNUSED_VAR(items);
3931 croak("postinc called as a function");
3936 filter_add(filter_call, NULL);
3940 CV *asscv = get_cv("XS::APItest::postinc", 0);
3941 cv_set_call_checker(asscv, THX_ck_entersub_postinc, (SV*)asscv);
3949 newRV_noinc(newSV(0)),
3950 gv_stashpvs("XS::APItest::TempObj",GV_ADD)
3951 ); /* Package defined in test script */
3956 fill_hash_with_nulls(HV *hv)
3960 for(; i < 1000; ++i) {
3961 HE *entry = hv_fetch_ent(hv, sv_2mortal(newSVuv(i)), 1, 0);
3962 SvREFCNT_dec(HeVAL(entry));
3963 HeVAL(entry) = NULL;
3969 RETVAL = newHVhv(hv);
3976 RETVAL = SvIsCOW(sv);
3984 PERL_UNUSED_VAR(items);
3985 croak("pad_scalar called as a function");
3989 CV *pscv = get_cv("XS::APItest::pad_scalar", 0);
3990 cv_set_call_checker(pscv, THX_ck_entersub_pad_scalar, (SV*)pscv);
3994 fetch_pad_names( cv )
3998 PADNAMELIST *pad_namelist;
3999 AV *retav = newAV();
4001 pad_namelist = PadlistNAMES(CvPADLIST(cv));
4003 for ( i = PadnamelistMAX(pad_namelist); i >= 0; i-- ) {
4004 PADNAME* name = PadnamelistARRAY(pad_namelist)[i];
4006 if (PadnameLEN(name)) {
4007 av_push(retav, newSVpadname(name));
4010 RETVAL = newRV_noinc((SV*)retav);
4022 u = find_rundefsv();
4023 pv = (U8*)SvPV(u, bytelen);
4024 RETVAL = SvUTF8(u) ? utf8_length(pv, pv+bytelen) : bytelen;
4031 (void)SvPV_nolen(sv);
4036 RETVAL = hv && HvENAME(hv)
4038 HvENAME(hv),HvENAMELEN(hv),
4039 (HvENAMEUTF8(hv) ? SVf_UTF8 : 0)
4046 xs_cmp(int a, int b)
4048 /* Odd sorting (odd numbers first), to make sure we are actually
4050 RETVAL = a % 2 != b % 2
4052 : a < b ? -1 : a == b ? 0 : 1;
4057 xs_cmp_undef(SV *a, SV *b)
4061 RETVAL = &PL_sv_undef;
4068 RETVAL = SvPVbyte_nolen(sv);
4075 RETVAL = SvPVutf8_nolen(sv);
4082 wrap_op_checker(OP_ADD, addissub_myck_add, &addissub_nxck_add);
4085 setup_rv2cv_addunderbar()
4087 wrap_op_checker(OP_RV2CV, my_ck_rv2cv, &old_ck_rv2cv);
4092 test_alloccopstash()
4094 RETVAL = PL_stashpad[alloccopstash(PL_defstash)] == PL_defstash;
4101 test_newFOROP_without_slab()
4104 const I32 floor = start_subparse(0,0);
4106 /* The slab allocator does not like CvROOT being set. */
4107 CvROOT(PL_compcv) = (OP *)1;
4108 o = newFOROP(0, 0, newOP(OP_PUSHMARK, 0), 0, 0);
4109 #ifdef PERL_OP_PARENT
4110 if (cLOOPx(cUNOPo->op_first)->op_last->op_sibparent
4111 != cUNOPo->op_first)
4113 Perl_warn(aTHX_ "Op parent pointer is stale");
4118 /* If we do not crash before returning, the test passes. */
4121 CvROOT(PL_compcv) = NULL;
4122 SvREFCNT_dec(PL_compcv);
4128 # provide access to CALLREGEXEC, except replace pointers within the
4129 # string with offsets from the start of the string
4132 callregexec(SV *prog, STRLEN stringarg, STRLEN strend, I32 minend, SV *sv, U32 nosave)
4139 strbeg = SvPV_force(sv, len);
4140 RETVAL = CALLREGEXEC((REGEXP *)prog,
4153 lexical_import(SV *name, CV *cv)
4160 "lexical_import can only be called at compile time");
4161 pl = CvPADLIST(PL_compcv);
4163 SAVESPTR(PL_comppad_name); PL_comppad_name = PadlistNAMES(pl);
4164 SAVESPTR(PL_comppad); PL_comppad = PadlistARRAY(pl)[1];
4165 SAVESPTR(PL_curpad); PL_curpad = PadARRAY(PL_comppad);
4166 off = pad_add_name_sv(sv_2mortal(newSVpvf("&%" SVf,name)),
4167 padadd_STATE, 0, 0);
4168 SvREFCNT_dec(PL_curpad[off]);
4169 PL_curpad[off] = SvREFCNT_inc(cv);
4175 sv_mortalcopy(SV *sv)
4177 RETVAL = SvREFCNT_inc(sv_mortalcopy(sv));
4185 alias_av(AV *av, IV ix, SV *sv)
4187 av_store(av, ix, SvREFCNT_inc(sv));
4190 cv_name(SVREF ref, ...)
4192 RETVAL = SvREFCNT_inc(cv_name((CV *)ref,
4193 items>1 && ST(1) != &PL_sv_undef
4196 items>2 ? SvUV(ST(2)) : 0));
4201 sv_catpvn(SV *sv, SV *sv2)
4205 const char *s = SvPV(sv2,len);
4206 sv_catpvn_flags(sv,s,len, SvUTF8(sv2) ? SV_CATUTF8 : SV_CATBYTES);
4213 OP *o = newLISTOP(OP_CUSTOM, 0, NULL, NULL);
4215 o = newOP(OP_CUSTOM, 0);
4217 o = newUNOP(OP_CUSTOM, 0, NULL);
4219 o = newUNOP_AUX(OP_CUSTOM, 0, NULL, NULL);
4221 o = newMETHOP(OP_CUSTOM, 0, newOP(OP_NULL,0));
4223 o = newMETHOP_named(OP_CUSTOM, 0, newSV(0));
4225 o = newBINOP(OP_CUSTOM, 0, NULL, NULL);
4227 o = newPMOP(OP_CUSTOM, 0);
4229 o = newSVOP(OP_CUSTOM, 0, newSV(0));
4233 lex_start(NULL, NULL, 0);
4235 I32 ix = start_subparse(FALSE,0);
4236 o = newPADOP(OP_CUSTOM, 0, newSV(0));
4242 o = newPVOP(OP_CUSTOM, 0, NULL);
4244 o = newLOGOP(OP_CUSTOM, 0, newOP(OP_NULL,0), newOP(OP_NULL,0));
4246 o = newLOOPEX(OP_CUSTOM, newOP(OP_NULL,0));
4254 test_sv_catpvf(SV *fmtsv)
4259 fmt = SvPV_nolen(fmtsv);
4260 sv = sv_2mortal(newSVpvn("", 0));
4261 sv_catpvf(sv, fmt, 5, 6, 7, 8);
4264 load_module(flags, name, ...)
4269 Perl_load_module(aTHX_ flags, SvREFCNT_inc(name), NULL);
4270 } else if (items == 3) {
4271 Perl_load_module(aTHX_ flags, SvREFCNT_inc(name), SvREFCNT_inc(ST(2)));
4273 Perl_croak(aTHX_ "load_module can't yet support %" IVdf " items",
4277 string_without_null(SV *sv)
4281 const char *s = SvPV(sv, len);
4282 RETVAL = newSVpvn_flags(s, len, SvUTF8(sv));
4283 *SvEND(RETVAL) = 0xff;
4293 const char *s = SvPV(sv, len);
4294 RETVAL = get_cvn_flags(s, len, 0);
4300 get_cv_flags(SV *sv, UV flags)
4304 const char *s = SvPV(sv, len);
4305 RETVAL = get_cvn_flags(s, len, flags);
4320 #define FILE NativeFile
4323 PerlIO_exportFILE(PerlIO *f, const char *mode)
4325 MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest
4331 SV* class_and_method;
4333 PERL_UNUSED_ARG(items);
4334 class_and_method = GvSV(CvGV(cv));
4335 comms = get_sv("main::the_method", 1);
4336 if (class_and_method == NULL) {
4338 } else if (!SvOK(class_and_method)) {
4340 } else if (!SvPOK(class_and_method)) {
4343 sv_setsv(comms, class_and_method);
4349 MODULE = XS::APItest PACKAGE = XS::APItest::Magic
4354 sv_magic_foo(SV *sv, SV *thingy)
4358 sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo, (const char *)thingy, 0);
4365 MAGIC *mg = mg_findext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4366 RETVAL = mg ? SvREFCNT_inc((SV *)mg->mg_ptr) : &PL_sv_undef;
4371 sv_unmagic_foo(SV *sv)
4375 sv_unmagicext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4378 sv_magic(SV *sv, SV *thingy)
4380 sv_magic(SvRV(sv), NULL, PERL_MAGIC_ext, (const char *)thingy, 0);
4388 #define test_get_this_vtable(name) \
4389 want = (MGVTBL*)CAT2(&PL_vtbl_, name); \
4390 have = get_vtbl(CAT2(want_vtbl_, name)); \
4392 croak("fail %p!=%p for get_vtbl(want_vtbl_" STRINGIFY(name) ") at " __FILE__ " line %d", have, want, __LINE__)
4394 test_get_this_vtable(sv);
4395 test_get_this_vtable(env);
4396 test_get_this_vtable(envelem);
4397 test_get_this_vtable(sigelem);
4398 test_get_this_vtable(pack);
4399 test_get_this_vtable(packelem);
4400 test_get_this_vtable(dbline);
4401 test_get_this_vtable(isa);
4402 test_get_this_vtable(isaelem);
4403 test_get_this_vtable(arylen);
4404 test_get_this_vtable(mglob);
4405 test_get_this_vtable(nkeys);
4406 test_get_this_vtable(taint);
4407 test_get_this_vtable(substr);
4408 test_get_this_vtable(vec);
4409 test_get_this_vtable(pos);
4410 test_get_this_vtable(bm);
4411 test_get_this_vtable(fm);
4412 test_get_this_vtable(uvar);
4413 test_get_this_vtable(defelem);
4414 test_get_this_vtable(regexp);
4415 test_get_this_vtable(regdata);
4416 test_get_this_vtable(regdatum);
4417 #ifdef USE_LOCALE_COLLATE
4418 test_get_this_vtable(collxfrm);
4420 test_get_this_vtable(backref);
4421 test_get_this_vtable(utf8);
4423 RETVAL = PTR2UV(get_vtbl(-1));
4428 # attach ext magic to the SV pointed to by rsv that only has set magic,
4429 # where that magic's job is to increment thingy
4432 sv_magic_myset(SV *rsv, SV *thingy)
4434 sv_magicext(SvRV(rsv), NULL, PERL_MAGIC_ext, &vtbl_myset,
4435 (const char *)thingy, 0);
4440 test_isBLANK_uni(UV ord)
4442 RETVAL = isBLANK_uni(ord);
4447 test_isBLANK_uvchr(UV ord)
4449 RETVAL = isBLANK_uvchr(ord);
4454 test_isBLANK_LC_uvchr(UV ord)
4456 RETVAL = isBLANK_LC_uvchr(ord);
4461 test_isBLANK(UV ord)
4463 RETVAL = isBLANK(ord);
4468 test_isBLANK_A(UV ord)
4470 RETVAL = isBLANK_A(ord);
4475 test_isBLANK_L1(UV ord)
4477 RETVAL = isBLANK_L1(ord);
4482 test_isBLANK_LC(UV ord)
4484 RETVAL = isBLANK_LC(ord);
4489 test_isBLANK_utf8(unsigned char * p, int type)
4491 const unsigned char * e;
4494 /* In this function and those that follow, the boolean 'type'
4495 * indicates if to pass a malformed UTF-8 string to the tested macro
4496 * (malformed by making it too short) */
4498 e = p + UTF8SKIP(p) - type;
4499 RETVAL = isBLANK_utf8_safe(p, e);
4502 RETVAL = isBLANK_utf8(p);
4508 test_isBLANK_LC_utf8(unsigned char * p, int type)
4510 const unsigned char * e;
4513 e = p + UTF8SKIP(p) - type;
4514 RETVAL = isBLANK_LC_utf8_safe(p, e);
4517 RETVAL = isBLANK_LC_utf8(p);
4523 test_isVERTWS_uni(UV ord)
4525 RETVAL = isVERTWS_uni(ord);
4530 test_isVERTWS_uvchr(UV ord)
4532 RETVAL = isVERTWS_uvchr(ord);
4537 test_isVERTWS_utf8(unsigned char * p, int type)
4539 const unsigned char * e;
4542 e = p + UTF8SKIP(p) - type;
4543 RETVAL = isVERTWS_utf8_safe(p, e);
4546 RETVAL = isVERTWS_utf8(p);
4552 test_isUPPER_uni(UV ord)
4554 RETVAL = isUPPER_uni(ord);
4559 test_isUPPER_uvchr(UV ord)
4561 RETVAL = isUPPER_uvchr(ord);
4566 test_isUPPER_LC_uvchr(UV ord)
4568 RETVAL = isUPPER_LC_uvchr(ord);
4573 test_isUPPER(UV ord)
4575 RETVAL = isUPPER(ord);
4580 test_isUPPER_A(UV ord)
4582 RETVAL = isUPPER_A(ord);
4587 test_isUPPER_L1(UV ord)
4589 RETVAL = isUPPER_L1(ord);
4594 test_isUPPER_LC(UV ord)
4596 RETVAL = isUPPER_LC(ord);
4601 test_isUPPER_utf8(unsigned char * p, int type)
4603 const unsigned char * e;
4606 e = p + UTF8SKIP(p) - type;
4607 RETVAL = isUPPER_utf8_safe(p, e);
4610 RETVAL = isUPPER_utf8(p);
4616 test_isUPPER_LC_utf8(unsigned char * p, int type)
4618 const unsigned char * e;
4621 e = p + UTF8SKIP(p) - type;
4622 RETVAL = isUPPER_LC_utf8_safe(p, e);
4625 RETVAL = isUPPER_LC_utf8(p);
4631 test_isLOWER_uni(UV ord)
4633 RETVAL = isLOWER_uni(ord);
4638 test_isLOWER_uvchr(UV ord)
4640 RETVAL = isLOWER_uvchr(ord);
4645 test_isLOWER_LC_uvchr(UV ord)
4647 RETVAL = isLOWER_LC_uvchr(ord);
4652 test_isLOWER(UV ord)
4654 RETVAL = isLOWER(ord);
4659 test_isLOWER_A(UV ord)
4661 RETVAL = isLOWER_A(ord);
4666 test_isLOWER_L1(UV ord)
4668 RETVAL = isLOWER_L1(ord);
4673 test_isLOWER_LC(UV ord)
4675 RETVAL = isLOWER_LC(ord);
4680 test_isLOWER_utf8(unsigned char * p, int type)
4682 const unsigned char * e;
4685 e = p + UTF8SKIP(p) - type;
4686 RETVAL = isLOWER_utf8_safe(p, e);
4689 RETVAL = isLOWER_utf8(p);
4695 test_isLOWER_LC_utf8(unsigned char * p, int type)
4697 const unsigned char * e;
4700 e = p + UTF8SKIP(p) - type;
4701 RETVAL = isLOWER_LC_utf8_safe(p, e);
4704 RETVAL = isLOWER_LC_utf8(p);
4710 test_isALPHA_uni(UV ord)
4712 RETVAL = isALPHA_uni(ord);
4717 test_isALPHA_uvchr(UV ord)
4719 RETVAL = isALPHA_uvchr(ord);
4724 test_isALPHA_LC_uvchr(UV ord)
4726 RETVAL = isALPHA_LC_uvchr(ord);
4731 test_isALPHA(UV ord)
4733 RETVAL = isALPHA(ord);
4738 test_isALPHA_A(UV ord)
4740 RETVAL = isALPHA_A(ord);
4745 test_isALPHA_L1(UV ord)
4747 RETVAL = isALPHA_L1(ord);
4752 test_isALPHA_LC(UV ord)
4754 RETVAL = isALPHA_LC(ord);
4759 test_isALPHA_utf8(unsigned char * p, int type)
4761 const unsigned char * e;
4764 e = p + UTF8SKIP(p) - type;
4765 RETVAL = isALPHA_utf8_safe(p, e);
4768 RETVAL = isALPHA_utf8(p);
4774 test_isALPHA_LC_utf8(unsigned char * p, int type)
4776 const unsigned char * e;
4779 e = p + UTF8SKIP(p) - type;
4780 RETVAL = isALPHA_LC_utf8_safe(p, e);
4783 RETVAL = isALPHA_LC_utf8(p);
4789 test_isWORDCHAR_uni(UV ord)
4791 RETVAL = isWORDCHAR_uni(ord);
4796 test_isWORDCHAR_uvchr(UV ord)
4798 RETVAL = isWORDCHAR_uvchr(ord);
4803 test_isWORDCHAR_LC_uvchr(UV ord)
4805 RETVAL = isWORDCHAR_LC_uvchr(ord);
4810 test_isWORDCHAR(UV ord)
4812 RETVAL = isWORDCHAR(ord);
4817 test_isWORDCHAR_A(UV ord)
4819 RETVAL = isWORDCHAR_A(ord);
4824 test_isWORDCHAR_L1(UV ord)
4826 RETVAL = isWORDCHAR_L1(ord);
4831 test_isWORDCHAR_LC(UV ord)
4833 RETVAL = isWORDCHAR_LC(ord);
4838 test_isWORDCHAR_utf8(unsigned char * p, int type)
4840 const unsigned char * e;
4843 e = p + UTF8SKIP(p) - type;
4844 RETVAL = isWORDCHAR_utf8_safe(p, e);
4847 RETVAL = isWORDCHAR_utf8(p);
4853 test_isWORDCHAR_LC_utf8(unsigned char * p, int type)
4855 const unsigned char * e;
4858 e = p + UTF8SKIP(p) - type;
4859 RETVAL = isWORDCHAR_LC_utf8_safe(p, e);
4862 RETVAL = isWORDCHAR_LC_utf8(p);
4868 test_isALPHANUMERIC_uni(UV ord)
4870 RETVAL = isALPHANUMERIC_uni(ord);
4875 test_isALPHANUMERIC_uvchr(UV ord)
4877 RETVAL = isALPHANUMERIC_uvchr(ord);
4882 test_isALPHANUMERIC_LC_uvchr(UV ord)
4884 RETVAL = isALPHANUMERIC_LC_uvchr(ord);
4889 test_isALPHANUMERIC(UV ord)
4891 RETVAL = isALPHANUMERIC(ord);
4896 test_isALPHANUMERIC_A(UV ord)
4898 RETVAL = isALPHANUMERIC_A(ord);
4903 test_isALPHANUMERIC_L1(UV ord)
4905 RETVAL = isALPHANUMERIC_L1(ord);
4910 test_isALPHANUMERIC_LC(UV ord)
4912 RETVAL = isALPHANUMERIC_LC(ord);
4917 test_isALPHANUMERIC_utf8(unsigned char * p, int type)
4919 const unsigned char * e;
4922 e = p + UTF8SKIP(p) - type;
4923 RETVAL = isALPHANUMERIC_utf8_safe(p, e);
4926 RETVAL = isALPHANUMERIC_utf8(p);
4932 test_isALPHANUMERIC_LC_utf8(unsigned char * p, int type)
4934 const unsigned char * e;
4937 e = p + UTF8SKIP(p) - type;
4938 RETVAL = isALPHANUMERIC_LC_utf8_safe(p, e);
4941 RETVAL = isALPHANUMERIC_LC_utf8(p);
4947 test_isALNUM(UV ord)
4949 RETVAL = isALNUM(ord);
4954 test_isALNUM_uni(UV ord)
4956 RETVAL = isALNUM_uni(ord);
4961 test_isALNUM_LC_uvchr(UV ord)
4963 RETVAL = isALNUM_LC_uvchr(ord);
4968 test_isALNUM_LC(UV ord)
4970 RETVAL = isALNUM_LC(ord);
4975 test_isALNUM_utf8(unsigned char * p, int type)
4977 const unsigned char * e;
4980 e = p + UTF8SKIP(p) - type;
4981 RETVAL = isWORDCHAR_utf8_safe(p, e);
4984 RETVAL = isWORDCHAR_utf8(p);
4990 test_isALNUM_LC_utf8(unsigned char * p, int type)
4992 const unsigned char * e;
4995 e = p + UTF8SKIP(p) - type;
4996 RETVAL = isWORDCHAR_LC_utf8_safe(p, e);
4999 RETVAL = isWORDCHAR_LC_utf8(p);
5005 test_isDIGIT_uni(UV ord)
5007 RETVAL = isDIGIT_uni(ord);
5012 test_isDIGIT_uvchr(UV ord)
5014 RETVAL = isDIGIT_uvchr(ord);
5019 test_isDIGIT_LC_uvchr(UV ord)
5021 RETVAL = isDIGIT_LC_uvchr(ord);
5026 test_isDIGIT_utf8(unsigned char * p, int type)
5028 const unsigned char * e;
5031 e = p + UTF8SKIP(p) - type;
5032 RETVAL = isDIGIT_utf8_safe(p, e);
5035 RETVAL = isDIGIT_utf8(p);
5041 test_isDIGIT_LC_utf8(unsigned char * p, int type)
5043 const unsigned char * e;
5046 e = p + UTF8SKIP(p) - type;
5047 RETVAL = isDIGIT_LC_utf8_safe(p, e);
5050 RETVAL = isDIGIT_LC_utf8(p);
5056 test_isDIGIT(UV ord)
5058 RETVAL = isDIGIT(ord);
5063 test_isDIGIT_A(UV ord)
5065 RETVAL = isDIGIT_A(ord);
5070 test_isDIGIT_L1(UV ord)
5072 RETVAL = isDIGIT_L1(ord);
5077 test_isDIGIT_LC(UV ord)
5079 RETVAL = isDIGIT_LC(ord);
5084 test_isOCTAL(UV ord)
5086 RETVAL = isOCTAL(ord);
5091 test_isOCTAL_A(UV ord)
5093 RETVAL = isOCTAL_A(ord);
5098 test_isOCTAL_L1(UV ord)
5100 RETVAL = isOCTAL_L1(ord);
5105 test_isIDFIRST_uni(UV ord)
5107 RETVAL = isIDFIRST_uni(ord);
5112 test_isIDFIRST_uvchr(UV ord)
5114 RETVAL = isIDFIRST_uvchr(ord);
5119 test_isIDFIRST_LC_uvchr(UV ord)
5121 RETVAL = isIDFIRST_LC_uvchr(ord);
5126 test_isIDFIRST(UV ord)
5128 RETVAL = isIDFIRST(ord);
5133 test_isIDFIRST_A(UV ord)
5135 RETVAL = isIDFIRST_A(ord);
5140 test_isIDFIRST_L1(UV ord)
5142 RETVAL = isIDFIRST_L1(ord);
5147 test_isIDFIRST_LC(UV ord)
5149 RETVAL = isIDFIRST_LC(ord);
5154 test_isIDFIRST_utf8(unsigned char * p, int type)
5156 const unsigned char * e;
5159 e = p + UTF8SKIP(p) - type;
5160 RETVAL = isIDFIRST_utf8_safe(p, e);
5163 RETVAL = isIDFIRST_utf8(p);
5169 test_isIDFIRST_LC_utf8(unsigned char * p, int type)
5171 const unsigned char * e;
5174 e = p + UTF8SKIP(p) - type;
5175 RETVAL = isIDFIRST_LC_utf8_safe(p, e);
5178 RETVAL = isIDFIRST_LC_utf8(p);
5184 test_isIDCONT_uni(UV ord)
5186 RETVAL = isIDCONT_uni(ord);
5191 test_isIDCONT_uvchr(UV ord)
5193 RETVAL = isIDCONT_uvchr(ord);
5198 test_isIDCONT_LC_uvchr(UV ord)
5200 RETVAL = isIDCONT_LC_uvchr(ord);
5205 test_isIDCONT(UV ord)
5207 RETVAL = isIDCONT(ord);
5212 test_isIDCONT_A(UV ord)
5214 RETVAL = isIDCONT_A(ord);
5219 test_isIDCONT_L1(UV ord)
5221 RETVAL = isIDCONT_L1(ord);
5226 test_isIDCONT_LC(UV ord)
5228 RETVAL = isIDCONT_LC(ord);
5233 test_isIDCONT_utf8(unsigned char * p, int type)
5235 const unsigned char * e;
5238 e = p + UTF8SKIP(p) - type;
5239 RETVAL = isIDCONT_utf8_safe(p, e);
5242 RETVAL = isIDCONT_utf8(p);
5248 test_isIDCONT_LC_utf8(unsigned char * p, int type)
5250 const unsigned char * e;
5253 e = p + UTF8SKIP(p) - type;
5254 RETVAL = isIDCONT_LC_utf8_safe(p, e);
5257 RETVAL = isIDCONT_LC_utf8(p);
5263 test_isSPACE_uni(UV ord)
5265 RETVAL = isSPACE_uni(ord);
5270 test_isSPACE_uvchr(UV ord)
5272 RETVAL = isSPACE_uvchr(ord);
5277 test_isSPACE_LC_uvchr(UV ord)
5279 RETVAL = isSPACE_LC_uvchr(ord);
5284 test_isSPACE(UV ord)
5286 RETVAL = isSPACE(ord);
5291 test_isSPACE_A(UV ord)
5293 RETVAL = isSPACE_A(ord);
5298 test_isSPACE_L1(UV ord)
5300 RETVAL = isSPACE_L1(ord);
5305 test_isSPACE_LC(UV ord)
5307 RETVAL = isSPACE_LC(ord);
5312 test_isSPACE_utf8(unsigned char * p, int type)
5314 const unsigned char * e;
5317 e = p + UTF8SKIP(p) - type;
5318 RETVAL = isSPACE_utf8_safe(p, e);
5321 RETVAL = isSPACE_utf8(p);
5327 test_isSPACE_LC_utf8(unsigned char * p, int type)
5329 const unsigned char * e;
5332 e = p + UTF8SKIP(p) - type;
5333 RETVAL = isSPACE_LC_utf8_safe(p, e);
5336 RETVAL = isSPACE_LC_utf8(p);
5342 test_isASCII_uni(UV ord)
5344 RETVAL = isASCII_uni(ord);
5349 test_isASCII_uvchr(UV ord)
5351 RETVAL = isASCII_uvchr(ord);
5356 test_isASCII_LC_uvchr(UV ord)
5358 RETVAL = isASCII_LC_uvchr(ord);
5363 test_isASCII(UV ord)
5365 RETVAL = isASCII(ord);
5370 test_isASCII_A(UV ord)
5372 RETVAL = isASCII_A(ord);
5377 test_isASCII_L1(UV ord)
5379 RETVAL = isASCII_L1(ord);
5384 test_isASCII_LC(UV ord)
5386 RETVAL = isASCII_LC(ord);
5391 test_isASCII_utf8(unsigned char * p, int type)
5393 const unsigned char * e;
5399 e = p + UTF8SKIP(p) - type;
5400 RETVAL = isASCII_utf8_safe(p, e);
5403 RETVAL = isASCII_utf8(p);
5409 test_isASCII_LC_utf8(unsigned char * p, int type)
5411 const unsigned char * e;
5417 e = p + UTF8SKIP(p) - type;
5418 RETVAL = isASCII_LC_utf8_safe(p, e);
5421 RETVAL = isASCII_LC_utf8(p);
5427 test_isCNTRL_uni(UV ord)
5429 RETVAL = isCNTRL_uni(ord);
5434 test_isCNTRL_uvchr(UV ord)
5436 RETVAL = isCNTRL_uvchr(ord);
5441 test_isCNTRL_LC_uvchr(UV ord)
5443 RETVAL = isCNTRL_LC_uvchr(ord);
5448 test_isCNTRL(UV ord)
5450 RETVAL = isCNTRL(ord);
5455 test_isCNTRL_A(UV ord)
5457 RETVAL = isCNTRL_A(ord);
5462 test_isCNTRL_L1(UV ord)
5464 RETVAL = isCNTRL_L1(ord);
5469 test_isCNTRL_LC(UV ord)
5471 RETVAL = isCNTRL_LC(ord);
5476 test_isCNTRL_utf8(unsigned char * p, int type)
5478 const unsigned char * e;
5481 e = p + UTF8SKIP(p) - type;
5482 RETVAL = isCNTRL_utf8_safe(p, e);
5485 RETVAL = isCNTRL_utf8(p);
5491 test_isCNTRL_LC_utf8(unsigned char * p, int type)
5493 const unsigned char * e;
5496 e = p + UTF8SKIP(p) - type;
5497 RETVAL = isCNTRL_LC_utf8_safe(p, e);
5500 RETVAL = isCNTRL_LC_utf8(p);
5506 test_isPRINT_uni(UV ord)
5508 RETVAL = isPRINT_uni(ord);
5513 test_isPRINT_uvchr(UV ord)
5515 RETVAL = isPRINT_uvchr(ord);
5520 test_isPRINT_LC_uvchr(UV ord)
5522 RETVAL = isPRINT_LC_uvchr(ord);
5527 test_isPRINT(UV ord)
5529 RETVAL = isPRINT(ord);
5534 test_isPRINT_A(UV ord)
5536 RETVAL = isPRINT_A(ord);
5541 test_isPRINT_L1(UV ord)
5543 RETVAL = isPRINT_L1(ord);
5548 test_isPRINT_LC(UV ord)
5550 RETVAL = isPRINT_LC(ord);
5555 test_isPRINT_utf8(unsigned char * p, int type)
5557 const unsigned char * e;
5560 e = p + UTF8SKIP(p) - type;
5561 RETVAL = isPRINT_utf8_safe(p, e);
5564 RETVAL = isPRINT_utf8(p);
5570 test_isPRINT_LC_utf8(unsigned char * p, int type)
5572 const unsigned char * e;
5575 e = p + UTF8SKIP(p) - type;
5576 RETVAL = isPRINT_LC_utf8_safe(p, e);
5579 RETVAL = isPRINT_LC_utf8(p);
5585 test_isGRAPH_uni(UV ord)
5587 RETVAL = isGRAPH_uni(ord);
5592 test_isGRAPH_uvchr(UV ord)
5594 RETVAL = isGRAPH_uvchr(ord);
5599 test_isGRAPH_LC_uvchr(UV ord)
5601 RETVAL = isGRAPH_LC_uvchr(ord);
5606 test_isGRAPH(UV ord)
5608 RETVAL = isGRAPH(ord);
5613 test_isGRAPH_A(UV ord)
5615 RETVAL = isGRAPH_A(ord);
5620 test_isGRAPH_L1(UV ord)
5622 RETVAL = isGRAPH_L1(ord);
5627 test_isGRAPH_LC(UV ord)
5629 RETVAL = isGRAPH_LC(ord);
5634 test_isGRAPH_utf8(unsigned char * p, int type)
5636 const unsigned char * e;
5639 e = p + UTF8SKIP(p) - type;
5640 RETVAL = isGRAPH_utf8_safe(p, e);
5643 RETVAL = isGRAPH_utf8(p);
5649 test_isGRAPH_LC_utf8(unsigned char * p, int type)
5651 const unsigned char * e;
5654 e = p + UTF8SKIP(p) - type;
5655 RETVAL = isGRAPH_LC_utf8_safe(p, e);
5658 RETVAL = isGRAPH_LC_utf8(p);
5664 test_isPUNCT_uni(UV ord)
5666 RETVAL = isPUNCT_uni(ord);
5671 test_isPUNCT_uvchr(UV ord)
5673 RETVAL = isPUNCT_uvchr(ord);
5678 test_isPUNCT_LC_uvchr(UV ord)
5680 RETVAL = isPUNCT_LC_uvchr(ord);
5685 test_isPUNCT(UV ord)
5687 RETVAL = isPUNCT(ord);
5692 test_isPUNCT_A(UV ord)
5694 RETVAL = isPUNCT_A(ord);
5699 test_isPUNCT_L1(UV ord)
5701 RETVAL = isPUNCT_L1(ord);
5706 test_isPUNCT_LC(UV ord)
5708 RETVAL = isPUNCT_LC(ord);
5713 test_isPUNCT_utf8(unsigned char * p, int type)
5715 const unsigned char * e;
5718 e = p + UTF8SKIP(p) - type;
5719 RETVAL = isPUNCT_utf8_safe(p, e);
5722 RETVAL = isPUNCT_utf8(p);
5728 test_isPUNCT_LC_utf8(unsigned char * p, int type)
5730 const unsigned char * e;
5733 e = p + UTF8SKIP(p) - type;
5734 RETVAL = isPUNCT_LC_utf8_safe(p, e);
5737 RETVAL = isPUNCT_LC_utf8(p);
5743 test_isXDIGIT_uni(UV ord)
5745 RETVAL = isXDIGIT_uni(ord);
5750 test_isXDIGIT_uvchr(UV ord)
5752 RETVAL = isXDIGIT_uvchr(ord);
5757 test_isXDIGIT_LC_uvchr(UV ord)
5759 RETVAL = isXDIGIT_LC_uvchr(ord);
5764 test_isXDIGIT(UV ord)
5766 RETVAL = isXDIGIT(ord);
5771 test_isXDIGIT_A(UV ord)
5773 RETVAL = isXDIGIT_A(ord);
5778 test_isXDIGIT_L1(UV ord)
5780 RETVAL = isXDIGIT_L1(ord);
5785 test_isXDIGIT_LC(UV ord)
5787 RETVAL = isXDIGIT_LC(ord);
5792 test_isXDIGIT_utf8(unsigned char * p, int type)
5794 const unsigned char * e;
5797 e = p + UTF8SKIP(p) - type;
5798 RETVAL = isXDIGIT_utf8_safe(p, e);
5801 RETVAL = isXDIGIT_utf8(p);
5807 test_isXDIGIT_LC_utf8(unsigned char * p, int type)
5809 const unsigned char * e;
5812 e = p + UTF8SKIP(p) - type;
5813 RETVAL = isXDIGIT_LC_utf8_safe(p, e);
5816 RETVAL = isXDIGIT_LC_utf8(p);
5822 test_isPSXSPC_uni(UV ord)
5824 RETVAL = isPSXSPC_uni(ord);
5829 test_isPSXSPC_uvchr(UV ord)
5831 RETVAL = isPSXSPC_uvchr(ord);
5836 test_isPSXSPC_LC_uvchr(UV ord)
5838 RETVAL = isPSXSPC_LC_uvchr(ord);
5843 test_isPSXSPC(UV ord)
5845 RETVAL = isPSXSPC(ord);
5850 test_isPSXSPC_A(UV ord)
5852 RETVAL = isPSXSPC_A(ord);
5857 test_isPSXSPC_L1(UV ord)
5859 RETVAL = isPSXSPC_L1(ord);
5864 test_isPSXSPC_LC(UV ord)
5866 RETVAL = isPSXSPC_LC(ord);
5871 test_isPSXSPC_utf8(unsigned char * p, int type)
5873 const unsigned char * e;
5876 e = p + UTF8SKIP(p) - type;
5877 RETVAL = isPSXSPC_utf8_safe(p, e);
5880 RETVAL = isPSXSPC_utf8(p);
5886 test_isPSXSPC_LC_utf8(unsigned char * p, int type)
5888 const unsigned char * e;
5891 e = p + UTF8SKIP(p) - type;
5892 RETVAL = isPSXSPC_LC_utf8_safe(p, e);
5895 RETVAL = isPSXSPC_LC_utf8(p);
5901 test_isQUOTEMETA(UV ord)
5903 RETVAL = _isQUOTEMETA(ord);
5908 test_OFFUNISKIP(UV ord)
5910 RETVAL = OFFUNISKIP(ord);
5915 test_OFFUNI_IS_INVARIANT(UV ord)
5917 RETVAL = OFFUNI_IS_INVARIANT(ord);
5922 test_UVCHR_IS_INVARIANT(UV ord)
5924 RETVAL = UVCHR_IS_INVARIANT(ord);
5929 test_UTF8_IS_INVARIANT(char ch)
5931 RETVAL = UTF8_IS_INVARIANT(ch);
5936 test_UVCHR_SKIP(UV ord)
5938 RETVAL = UVCHR_SKIP(ord);
5943 test_UTF8_SKIP(char * ch)
5945 RETVAL = UTF8_SKIP(ch);
5950 test_UTF8_IS_START(char ch)
5952 RETVAL = UTF8_IS_START(ch);
5957 test_UTF8_IS_CONTINUATION(char ch)
5959 RETVAL = UTF8_IS_CONTINUATION(ch);
5964 test_UTF8_IS_CONTINUED(char ch)
5966 RETVAL = UTF8_IS_CONTINUED(ch);
5971 test_UTF8_IS_DOWNGRADEABLE_START(char ch)
5973 RETVAL = UTF8_IS_DOWNGRADEABLE_START(ch);
5978 test_UTF8_IS_ABOVE_LATIN1(char ch)
5980 RETVAL = UTF8_IS_ABOVE_LATIN1(ch);
5985 test_isUTF8_POSSIBLY_PROBLEMATIC(char ch)
5987 RETVAL = isUTF8_POSSIBLY_PROBLEMATIC(ch);
5992 test_isUTF8_CHAR(char *s, STRLEN len)
5994 RETVAL = isUTF8_CHAR((U8 *) s, (U8 *) s + len);
5999 test_isUTF8_CHAR_flags(char *s, STRLEN len, U32 flags)
6001 RETVAL = isUTF8_CHAR_flags((U8 *) s, (U8 *) s + len, flags);
6006 test_isSTRICT_UTF8_CHAR(char *s, STRLEN len)
6008 RETVAL = isSTRICT_UTF8_CHAR((U8 *) s, (U8 *) s + len);
6013 test_isC9_STRICT_UTF8_CHAR(char *s, STRLEN len)
6015 RETVAL = isC9_STRICT_UTF8_CHAR((U8 *) s, (U8 *) s + len);
6020 test_is_utf8_valid_partial_char_flags(char *s, STRLEN len, U32 flags)
6022 /* RETVAL should be bool (here and in tests below), but making it IV
6023 * allows us to test it returning 0 or 1 */
6024 RETVAL = is_utf8_valid_partial_char_flags((U8 *) s, (U8 *) s + len, flags);
6029 test_is_utf8_string(char *s, STRLEN len)
6031 RETVAL = is_utf8_string((U8 *) s, len);
6035 #define WORDSIZE sizeof(PERL_UINTMAX_T)
6038 test_is_utf8_invariant_string_loc(unsigned char *s, STRLEN offset, STRLEN len)
6041 const U8 * ep = NULL;
6042 PERL_UINTMAX_T* copy;
6044 /* 'offset' is number of bytes past a word boundary the testing of 's'
6045 * is to start at. Allocate space that does start at the word
6046 * boundary, and copy 's' to the correct offset past it. Then call the
6047 * tested function with that position */
6048 Newx(copy, 1 + ((len + WORDSIZE - 1) / WORDSIZE), PERL_UINTMAX_T);
6049 Copy(s, (U8 *) copy + offset, len, U8);
6051 av_push(av, newSViv(is_utf8_invariant_string_loc((U8 *) copy + offset, len, &ep)));
6052 av_push(av, newSViv(ep - ((U8 *) copy + offset)));
6059 test_variant_under_utf8_count(unsigned char *s, STRLEN offset, STRLEN len)
6061 PERL_UINTMAX_T * copy;
6063 Newx(copy, 1 + ((len + WORDSIZE - 1) / WORDSIZE), PERL_UINTMAX_T);
6064 Copy(s, (U8 *) copy + offset, len, U8);
6065 RETVAL = variant_under_utf8_count((U8 *) copy + offset, (U8 *) copy + offset + len);
6071 test_utf8_length(unsigned char *s, STRLEN offset, STRLEN len)
6073 RETVAL = utf8_length(s + offset, s + len);
6078 test_is_utf8_string_loc(char *s, STRLEN len)
6084 av_push(av, newSViv(is_utf8_string_loc((U8 *) s, len, &ep)));
6085 av_push(av, newSViv(ep - (U8 *) s));
6091 test_is_utf8_string_loclen(char *s, STRLEN len)
6098 av_push(av, newSViv(is_utf8_string_loclen((U8 *) s, len, &ep, &ret_len)));
6099 av_push(av, newSViv(ep - (U8 *) s));
6100 av_push(av, newSVuv(ret_len));
6106 test_is_utf8_string_flags(char *s, STRLEN len, U32 flags)
6108 RETVAL = is_utf8_string_flags((U8 *) s, len, flags);
6113 test_is_utf8_string_loc_flags(char *s, STRLEN len, U32 flags)
6119 av_push(av, newSViv(is_utf8_string_loc_flags((U8 *) s, len, &ep, flags)));
6120 av_push(av, newSViv(ep - (U8 *) s));
6126 test_is_utf8_string_loclen_flags(char *s, STRLEN len, U32 flags)
6133 av_push(av, newSViv(is_utf8_string_loclen_flags((U8 *) s, len, &ep, &ret_len, flags)));
6134 av_push(av, newSViv(ep - (U8 *) s));
6135 av_push(av, newSVuv(ret_len));
6141 test_is_strict_utf8_string(char *s, STRLEN len)
6143 RETVAL = is_strict_utf8_string((U8 *) s, len);
6148 test_is_strict_utf8_string_loc(char *s, STRLEN len)
6154 av_push(av, newSViv(is_strict_utf8_string_loc((U8 *) s, len, &ep)));
6155 av_push(av, newSViv(ep - (U8 *) s));
6161 test_is_strict_utf8_string_loclen(char *s, STRLEN len)
6168 av_push(av, newSViv(is_strict_utf8_string_loclen((U8 *) s, len, &ep, &ret_len)));
6169 av_push(av, newSViv(ep - (U8 *) s));
6170 av_push(av, newSVuv(ret_len));
6176 test_is_c9strict_utf8_string(char *s, STRLEN len)
6178 RETVAL = is_c9strict_utf8_string((U8 *) s, len);
6183 test_is_c9strict_utf8_string_loc(char *s, STRLEN len)
6189 av_push(av, newSViv(is_c9strict_utf8_string_loc((U8 *) s, len, &ep)));
6190 av_push(av, newSViv(ep - (U8 *) s));
6196 test_is_c9strict_utf8_string_loclen(char *s, STRLEN len)
6203 av_push(av, newSViv(is_c9strict_utf8_string_loclen((U8 *) s, len, &ep, &ret_len)));
6204 av_push(av, newSViv(ep - (U8 *) s));
6205 av_push(av, newSVuv(ret_len));
6211 test_is_utf8_fixed_width_buf_flags(char *s, STRLEN len, U32 flags)
6213 RETVAL = is_utf8_fixed_width_buf_flags((U8 *) s, len, flags);
6218 test_is_utf8_fixed_width_buf_loc_flags(char *s, STRLEN len, U32 flags)
6224 av_push(av, newSViv(is_utf8_fixed_width_buf_loc_flags((U8 *) s, len, &ep, flags)));
6225 av_push(av, newSViv(ep - (U8 *) s));
6231 test_is_utf8_fixed_width_buf_loclen_flags(char *s, STRLEN len, U32 flags)
6238 av_push(av, newSViv(is_utf8_fixed_width_buf_loclen_flags((U8 *) s, len, &ep, &ret_len, flags)));
6239 av_push(av, newSViv(ep - (U8 *) s));
6240 av_push(av, newSVuv(ret_len));
6246 test_utf8_hop_safe(SV *s_sv, STRLEN s_off, IV off)
6252 p = (U8 *)SvPV(s_sv, len);
6253 r = utf8_hop_safe(p + s_off, off, p, p + len);
6259 test_toLOWER(UV ord)
6261 RETVAL = toLOWER(ord);
6266 test_toLOWER_L1(UV ord)
6268 RETVAL = toLOWER_L1(ord);
6273 test_toLOWER_LC(UV ord)
6275 RETVAL = toLOWER_LC(ord);
6280 test_toLOWER_uni(UV ord)
6282 U8 s[UTF8_MAXBYTES_CASE + 1];
6288 av_push(av, newSVuv(toLOWER_uni(ord, s, &len)));
6290 utf8 = newSVpvn((char *) s, len);
6294 av_push(av, newSVuv(len));
6300 test_toLOWER_uvchr(UV ord)
6302 U8 s[UTF8_MAXBYTES_CASE + 1];
6308 av_push(av, newSVuv(toLOWER_uvchr(ord, s, &len)));
6310 utf8 = newSVpvn((char *) s, len);
6314 av_push(av, newSVuv(len));
6320 test_toLOWER_utf8(SV * p, int type)
6323 U8 s[UTF8_MAXBYTES_CASE + 1];
6327 const unsigned char * e;
6328 UV resultant_cp = UV_MAX; /* Initialized because of dumb compilers */
6330 input = (U8 *) SvPV(p, len);
6333 e = input + UTF8SKIP(input) - type;
6334 resultant_cp = toLOWER_utf8_safe(input, e, s, &len);
6336 else if (type == -1) {
6337 resultant_cp = toLOWER_utf8(input, s, &len);
6341 resultant_cp = Perl_to_utf8_lower(aTHX_ input, s, &len);
6344 av_push(av, newSVuv(resultant_cp));
6346 utf8 = newSVpvn((char *) s, len);
6350 av_push(av, newSVuv(len));
6358 RETVAL = toFOLD(ord);
6363 test_toFOLD_LC(UV ord)
6365 RETVAL = toFOLD_LC(ord);
6370 test_toFOLD_uni(UV ord)
6372 U8 s[UTF8_MAXBYTES_CASE + 1];
6378 av_push(av, newSVuv(toFOLD_uni(ord, s, &len)));
6380 utf8 = newSVpvn((char *) s, len);
6384 av_push(av, newSVuv(len));
6390 test_toFOLD_uvchr(UV ord)
6392 U8 s[UTF8_MAXBYTES_CASE + 1];
6398 av_push(av, newSVuv(toFOLD_uvchr(ord, s, &len)));
6400 utf8 = newSVpvn((char *) s, len);
6404 av_push(av, newSVuv(len));
6410 test_toFOLD_utf8(SV * p, int type)
6413 U8 s[UTF8_MAXBYTES_CASE + 1];
6417 const unsigned char * e;
6418 UV resultant_cp = UV_MAX;
6420 input = (U8 *) SvPV(p, len);
6423 e = input + UTF8SKIP(input) - type;
6424 resultant_cp = toFOLD_utf8_safe(input, e, s, &len);
6426 else if (type == -1) {
6427 resultant_cp = toFOLD_utf8(input, s, &len);
6431 resultant_cp = Perl_to_utf8_fold(aTHX_ input, s, &len);
6434 av_push(av, newSVuv(resultant_cp));
6436 utf8 = newSVpvn((char *) s, len);
6440 av_push(av, newSVuv(len));
6446 test_toUPPER(UV ord)
6448 RETVAL = toUPPER(ord);
6453 test_toUPPER_LC(UV ord)
6455 RETVAL = toUPPER_LC(ord);
6460 test_toUPPER_uni(UV ord)
6462 U8 s[UTF8_MAXBYTES_CASE + 1];
6468 av_push(av, newSVuv(toUPPER_uni(ord, s, &len)));
6470 utf8 = newSVpvn((char *) s, len);
6474 av_push(av, newSVuv(len));
6480 test_toUPPER_uvchr(UV ord)
6482 U8 s[UTF8_MAXBYTES_CASE + 1];
6488 av_push(av, newSVuv(toUPPER_uvchr(ord, s, &len)));
6490 utf8 = newSVpvn((char *) s, len);
6494 av_push(av, newSVuv(len));
6500 test_toUPPER_utf8(SV * p, int type)
6503 U8 s[UTF8_MAXBYTES_CASE + 1];
6507 const unsigned char * e;
6508 UV resultant_cp = UV_MAX;
6510 input = (U8 *) SvPV(p, len);
6513 e = input + UTF8SKIP(input) - type;
6514 resultant_cp = toUPPER_utf8_safe(input, e, s, &len);
6516 else if (type == -1) {
6517 resultant_cp = toUPPER_utf8(input, s, &len);
6521 resultant_cp = Perl_to_utf8_upper(aTHX_ input, s, &len);
6524 av_push(av, newSVuv(resultant_cp));
6526 utf8 = newSVpvn((char *) s, len);
6530 av_push(av, newSVuv(len));
6536 test_toTITLE(UV ord)
6538 RETVAL = toTITLE(ord);
6543 test_toTITLE_uni(UV ord)
6545 U8 s[UTF8_MAXBYTES_CASE + 1];
6551 av_push(av, newSVuv(toTITLE_uni(ord, s, &len)));
6553 utf8 = newSVpvn((char *) s, len);
6557 av_push(av, newSVuv(len));
6563 test_toTITLE_uvchr(UV ord)
6565 U8 s[UTF8_MAXBYTES_CASE + 1];
6571 av_push(av, newSVuv(toTITLE_uvchr(ord, s, &len)));
6573 utf8 = newSVpvn((char *) s, len);
6577 av_push(av, newSVuv(len));
6583 test_toTITLE_utf8(SV * p, int type)
6586 U8 s[UTF8_MAXBYTES_CASE + 1];
6590 const unsigned char * e;
6591 UV resultant_cp = UV_MAX;
6593 input = (U8 *) SvPV(p, len);
6596 e = input + UTF8SKIP(input) - type;
6597 resultant_cp = toTITLE_utf8_safe(input, e, s, &len);
6599 else if (type == -1) {
6600 resultant_cp = toTITLE_utf8(input, s, &len);
6604 resultant_cp = Perl_to_utf8_title(aTHX_ input, s, &len);
6607 av_push(av, newSVuv(resultant_cp));
6609 utf8 = newSVpvn((char *) s, len);
6613 av_push(av, newSVuv(len));
6619 test_Gconvert(SV * number, SV * num_digits)
6624 len = (int) SvIV(num_digits);
6625 if (len > 99) croak("Too long a number for test_Gconvert");
6626 if (len < 0) croak("Too short a number for test_Gconvert");
6627 PERL_UNUSED_RESULT(Gconvert(SvNV(number), len,
6628 0, /* No trailing zeroes */
6630 RETVAL = newSVpv(buffer, 0);
6635 test_Perl_langinfo(SV * item)
6637 RETVAL = newSVpv(Perl_langinfo(SvIV(item)), 0);
6641 MODULE = XS::APItest PACKAGE = XS::APItest::Backrefs
6644 apitest_weaken(SV *sv)
6650 has_backrefs(SV *sv)
6652 if (SvROK(sv) && sv_get_backrefs(SvRV(sv)))
6653 RETVAL = &PL_sv_yes;
6660 #ifdef PERL_IMPLICIT_SYS
6663 PerlDir_mapA(const char *path)
6666 PerlDir_mapW(const WCHAR *wpath)
6674 VS_FIXEDFILEINFO *info;
6680 dll = GetModuleHandle("comctl32.dll"); /* must already be in proc */
6682 croak("Comctl32Version: comctl32.dll not in process???");
6683 hrsc = FindResource(dll, MAKEINTRESOURCE(VS_VERSION_INFO),
6684 MAKEINTRESOURCE(VS_FILE_INFO));
6686 croak("Comctl32Version: comctl32.dll no version???");
6687 ver = LoadResource(dll, hrsc);
6688 len = SizeofResource(dll, hrsc);
6689 vercopy = _alloca(len);
6690 memcpy(vercopy, ver, len);
6691 if (VerQueryValue(vercopy, "\\", (void**)&info, &len)) {
6692 int dwValueMS1 = (info->dwFileVersionMS>>16);
6693 int dwValueMS2 = (info->dwFileVersionMS&0xffff);
6694 int dwValueLS1 = (info->dwFileVersionLS>>16);
6695 int dwValueLS2 = (info->dwFileVersionLS&0xffff);