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_utf8_to_bytes(bytes, len)
1390 sv_2mortal((SV*)RETVAL);
1392 ret = (char *) utf8_to_bytes(bytes, &len);
1393 av_push(RETVAL, newSVpv(ret, 0));
1395 /* utf8_to_bytes uses (STRLEN)-1 to signal errors, and we want to
1396 * return that as -1 to perl, so cast to SSize_t in case
1397 * sizeof(IV) > sizeof(STRLEN) */
1398 av_push(RETVAL, newSViv((SSize_t)len));
1399 av_push(RETVAL, newSVpv((const char *) bytes, 0));
1405 test_utf8n_to_uvchr_msgs(s, len, flags)
1417 sv_2mortal((SV*)RETVAL);
1419 ret = utf8n_to_uvchr_msgs((U8*) s,
1426 /* Returns the return value in [0]; <retlen> in [1], <errors> in [2] */
1427 av_push(RETVAL, newSVuv(ret));
1428 if (retlen == (STRLEN) -1) {
1429 av_push(RETVAL, newSViv(-1));
1432 av_push(RETVAL, newSVuv(retlen));
1434 av_push(RETVAL, newSVuv(errors));
1436 /* And any messages in [3] */
1438 av_push(RETVAL, newRV_noinc((SV*)msgs));
1445 test_utf8n_to_uvchr_error(s, len, flags)
1456 /* Now that utf8n_to_uvchr() is a trivial wrapper for
1457 * utf8n_to_uvchr_error(), call the latter with the inputs. It always
1458 * asks for the actual length to be returned and errors to be returned
1460 * Length to assume <s> is; not checked, so could have buffer overflow
1463 sv_2mortal((SV*)RETVAL);
1465 ret = utf8n_to_uvchr_error((U8*) s,
1471 /* Returns the return value in [0]; <retlen> in [1], <errors> in [2] */
1472 av_push(RETVAL, newSVuv(ret));
1473 if (retlen == (STRLEN) -1) {
1474 av_push(RETVAL, newSViv(-1));
1477 av_push(RETVAL, newSVuv(retlen));
1479 av_push(RETVAL, newSVuv(errors));
1485 test_valid_utf8_to_uvchr(s)
1493 /* Call utf8n_to_uvchr() with the inputs. It always asks for the
1494 * actual length to be returned
1496 * Length to assume <s> is; not checked, so could have buffer overflow
1499 sv_2mortal((SV*)RETVAL);
1501 ret = valid_utf8_to_uvchr((U8*) SvPV_nolen(s), &retlen);
1503 /* Returns the return value in [0]; <retlen> in [1] */
1504 av_push(RETVAL, newSVuv(ret));
1505 av_push(RETVAL, newSVuv(retlen));
1511 test_uvchr_to_utf8_flags(uv, flags)
1516 U8 dest[UTF8_MAXBYTES + 1];
1520 /* Call uvchr_to_utf8_flags() with the inputs. */
1521 ret = uvchr_to_utf8_flags(dest, SvUV(uv), SvUV(flags));
1525 RETVAL = newSVpvn((char *) dest, ret - dest);
1531 test_uvchr_to_utf8_flags_msgs(uv, flags)
1536 U8 dest[UTF8_MAXBYTES + 1];
1542 sv_2mortal((SV*)RETVAL);
1544 ret = uvchr_to_utf8_flags_msgs(dest, SvUV(uv), SvUV(flags), &msgs);
1547 av_push(RETVAL, newSVpvn((char *) dest, ret - dest));
1550 av_push(RETVAL, &PL_sv_undef);
1554 av_push(RETVAL, newRV_noinc((SV*)msgs));
1560 MODULE = XS::APItest:Overload PACKAGE = XS::APItest::Overload
1563 amagic_deref_call(sv, what)
1567 /* The reference is owned by something else. */
1568 PUSHs(amagic_deref_call(sv, what));
1570 # I'd certainly like to discourage the use of this macro, given that we now
1571 # have amagic_deref_call
1574 tryAMAGICunDEREF_var(sv, what)
1582 tryAMAGICunDEREF(to_av);
1585 tryAMAGICunDEREF(to_cv);
1588 tryAMAGICunDEREF(to_gv);
1591 tryAMAGICunDEREF(to_hv);
1594 tryAMAGICunDEREF(to_sv);
1597 croak("Invalid value %d passed to tryAMAGICunDEREF_var", what);
1600 /* The reference is owned by something else. */
1603 MODULE = XS::APItest PACKAGE = XS::APItest::XSUB
1606 newXS("XS::APItest::XSUB::XS_VERSION_undef", XS_XS__APItest__XSUB_XS_VERSION_undef, __FILE__);
1607 newXS("XS::APItest::XSUB::XS_VERSION_empty", XS_XS__APItest__XSUB_XS_VERSION_empty, __FILE__);
1608 newXS("XS::APItest::XSUB::XS_APIVERSION_invalid", XS_XS__APItest__XSUB_XS_APIVERSION_invalid, __FILE__);
1611 XS_VERSION_defined(...)
1613 XS_VERSION_BOOTCHECK;
1617 XS_APIVERSION_valid(...)
1619 XS_APIVERSION_BOOTCHECK;
1627 for ( ; i < len; i++ ) {
1628 ST(i) = sv_2mortal( newSViv(i) );
1635 XSRETURN_IV(I32_MIN + 1);
1640 XSRETURN_UV( (U32)((1U<<31) + 1) );
1650 XSRETURN_PV("returned");
1655 XSRETURN_PVN("returned too much",8);
1677 MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash
1685 uf.uf_val = rot13_key;
1689 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1698 uf.uf_val = bitflip_key;
1702 sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf));
1705 #define UTF8KLEN(sv, len) (SvUTF8(sv) ? -(I32)len : (I32)len)
1708 exists(hash, key_sv)
1716 key = SvPV(key_sv, len);
1717 RETVAL = hv_exists(hash, key, UTF8KLEN(key_sv, len));
1722 exists_ent(hash, key_sv)
1728 RETVAL = hv_exists_ent(hash, key_sv, 0);
1733 delete(hash, key_sv, flags = 0)
1742 key = SvPV(key_sv, len);
1743 /* It's already mortal, so need to increase reference count. */
1745 = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags));
1750 delete_ent(hash, key_sv, flags = 0)
1756 /* It's already mortal, so need to increase reference count. */
1757 RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0));
1762 store_ent(hash, key, value)
1772 result = hv_store_ent(hash, key, copy, 0);
1773 SvSetMagicSV(copy, value);
1778 /* It's about to become mortal, so need to increase reference count.
1780 RETVAL = SvREFCNT_inc(HeVAL(result));
1785 store(hash, key_sv, value)
1796 key = SvPV(key_sv, len);
1798 result = hv_store(hash, key, UTF8KLEN(key_sv, len), copy, 0);
1799 SvSetMagicSV(copy, value);
1804 /* It's about to become mortal, so need to increase reference count.
1806 RETVAL = SvREFCNT_inc(*result);
1811 fetch_ent(hash, key_sv)
1818 result = hv_fetch_ent(hash, key_sv, 0, 0);
1823 RETVAL = newSVsv(HeVAL(result));
1837 key = SvPV(key_sv, len);
1838 result = hv_fetch(hash, key, UTF8KLEN(key_sv, len), 0);
1843 RETVAL = newSVsv(*result);
1847 #if defined (hv_common)
1857 const char *key = NULL;
1865 if ((svp = hv_fetchs(params, "hv", 0))) {
1866 SV *const rv = *svp;
1868 croak("common passed a non-reference for parameter hv");
1869 hv = (HV *)SvRV(rv);
1871 if ((svp = hv_fetchs(params, "keysv", 0)))
1873 if ((svp = hv_fetchs(params, "keypv", 0))) {
1874 key = SvPV_const(*svp, klen);
1878 if ((svp = hv_fetchs(params, "action", 0)))
1879 action = SvIV(*svp);
1880 if ((svp = hv_fetchs(params, "val", 0)))
1881 val = newSVsv(*svp);
1882 if ((svp = hv_fetchs(params, "hash", 0)))
1885 if (hv_fetchs(params, "hash_pv", 0)) {
1887 PERL_HASH(hash, key, klen);
1889 if (hv_fetchs(params, "hash_sv", 0)) {
1893 const char *const p = SvPV(keysv, len);
1894 PERL_HASH(hash, p, len);
1898 result = (HE *)hv_common(hv, keysv, key, klen, flags, action, val, hash);
1903 RETVAL = newSVsv(HeVAL(result));
1912 test_freeent(&Perl_hv_free_ent);
1916 test_hv_delayfree_ent()
1918 test_freeent(&Perl_hv_delayfree_ent);
1922 test_share_unshare_pvn(input)
1931 pvx = SvPV(input, len);
1932 PERL_HASH(hash, pvx, len);
1933 p = sharepvn(pvx, len, hash);
1934 RETVAL = newSVpvn(p, len);
1935 unsharepvn(p, len, hash);
1939 #if PERL_VERSION >= 9
1942 refcounted_he_exists(key, level=0)
1947 croak("level must be zero, not %" IVdf, level);
1949 RETVAL = (cop_hints_fetch_sv(PL_curcop, key, 0, 0) != &PL_sv_placeholder);
1954 refcounted_he_fetch(key, level=0)
1959 croak("level must be zero, not %" IVdf, level);
1961 RETVAL = cop_hints_fetch_sv(PL_curcop, key, 0, 0);
1962 SvREFCNT_inc(RETVAL);
1969 test_force_keys(HV *hv)
1975 he = hv_iternext(hv);
1977 SV *sv = HeSVKEY_force(he);
1980 PUSHs(sv_mortalcopy(sv));
1981 he = hv_iternext(hv);
1986 sub TIEHASH { bless {}, $_[0] }
1987 sub STORE { $_[0]->{$_[1]} = $_[2] }
1988 sub FETCH { $_[0]->{$_[1]} }
1989 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
1990 sub NEXTKEY { each %{$_[0]} }
1991 sub EXISTS { exists $_[0]->{$_[1]} }
1992 sub DELETE { delete $_[0]->{$_[1]} }
1993 sub CLEAR { %{$_[0]} = () }
1997 MODULE = XS::APItest:TempLv PACKAGE = XS::APItest::TempLv
2003 SV * const lv = newSV_type(SVt_PVLV);
2008 sv_magic(lv, NULL, PERL_MAGIC_substr, NULL, 0);
2010 LvTARG(lv) = SvREFCNT_inc_simple(sv);
2011 LvTARGOFF(lv) = len == 0 ? 0 : 1;
2012 LvTARGLEN(lv) = len < 2 ? 0 : len-2;
2015 ST(0) = sv_2mortal(lv);
2019 MODULE = XS::APItest::PtrTable PACKAGE = XS::APItest::PtrTable PREFIX = ptr_table_
2022 ptr_table_new(classname)
2023 const char * classname
2025 PUSHs(sv_setref_pv(sv_newmortal(), classname, (void*)ptr_table_new()));
2029 XS::APItest::PtrTable table
2031 ptr_table_free(table);
2034 ptr_table_store(table, from, to)
2035 XS::APItest::PtrTable table
2039 ptr_table_store(table, from, to);
2042 ptr_table_fetch(table, from)
2043 XS::APItest::PtrTable table
2046 RETVAL = PTR2UV(ptr_table_fetch(table, from));
2051 ptr_table_split(table)
2052 XS::APItest::PtrTable table
2055 ptr_table_clear(table)
2056 XS::APItest::PtrTable table
2058 MODULE = XS::APItest::AutoLoader PACKAGE = XS::APItest::AutoLoader
2063 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
2071 PERL_UNUSED_ARG(items);
2072 RETVAL = newSVpvn_flags(SvPVX(cv), SvCUR(cv), SvUTF8(cv));
2077 MODULE = XS::APItest PACKAGE = XS::APItest
2082 mymro.resolve = myget_linear_isa;
2083 mymro.name = "justisa";
2087 Perl_mro_register(aTHX_ &mymro);
2092 RETVAL = PL_custom_ops;
2097 xop_custom_op_names ()
2099 PL_custom_op_names = newHV();
2100 RETVAL = PL_custom_op_names;
2105 xop_custom_op_descs ()
2107 PL_custom_op_descs = newHV();
2108 RETVAL = PL_custom_op_descs;
2115 XopENTRY_set(&my_xop, xop_name, "my_xop");
2116 XopENTRY_set(&my_xop, xop_desc, "XOP for testing");
2117 XopENTRY_set(&my_xop, xop_class, OA_UNOP);
2118 XopENTRY_set(&my_xop, xop_peep, peep_xop);
2119 Perl_custom_op_register(aTHX_ pp_xop, &my_xop);
2124 XopDISABLE(&my_xop, xop_name);
2125 XopDISABLE(&my_xop, xop_desc);
2126 XopDISABLE(&my_xop, xop_class);
2127 XopDISABLE(&my_xop, xop_peep);
2132 RETVAL = PTR2IV(&my_xop);
2139 RETVAL = PTR2IV(pp_xop);
2157 MY_CXT.xop_record = newAV();
2159 kid = newSVOP(OP_CONST, 0, newSViv(42));
2161 unop = (UNOP*)mkUNOP(OP_CUSTOM, kid);
2162 unop->op_ppaddr = pp_xop;
2163 unop->op_private = 0;
2164 unop->op_next = NULL;
2165 kid->op_next = (OP*)unop;
2167 av_push(MY_CXT.xop_record, newSVpvf("unop:%" UVxf, PTR2UV(unop)));
2168 av_push(MY_CXT.xop_record, newSVpvf("kid:%" UVxf, PTR2UV(kid)));
2170 av_push(MY_CXT.xop_record, newSVpvf("NAME:%s", OP_NAME((OP*)unop)));
2171 av_push(MY_CXT.xop_record, newSVpvf("DESC:%s", OP_DESC((OP*)unop)));
2172 av_push(MY_CXT.xop_record, newSVpvf("CLASS:%d", (int)OP_CLASS((OP*)unop)));
2174 PL_rpeepp(aTHX_ kid);
2179 RETVAL = MY_CXT.xop_record;
2180 MY_CXT.xop_record = NULL;
2185 xop_from_custom_op ()
2187 /* author note: this test doesn't imply Perl_custom_op_xop is or isn't public
2188 API or that Perl_custom_op_xop is known to be used outside the core */
2192 unop = (UNOP*)mkUNOP(OP_CUSTOM, NULL);
2193 unop->op_ppaddr = pp_xop;
2194 unop->op_private = 0;
2195 unop->op_next = NULL;
2197 xop = Perl_custom_op_xop(aTHX_ (OP *)unop);
2199 RETVAL = PTR2IV(xop);
2208 MY_CXT.sv = newSVpv("initial",0);
2210 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2211 MY_CXT.bhk_record = 0;
2213 BhkENTRY_set(&bhk_test, bhk_start, blockhook_test_start);
2214 BhkENTRY_set(&bhk_test, bhk_pre_end, blockhook_test_pre_end);
2215 BhkENTRY_set(&bhk_test, bhk_post_end, blockhook_test_post_end);
2216 BhkENTRY_set(&bhk_test, bhk_eval, blockhook_test_eval);
2217 Perl_blockhook_register(aTHX_ &bhk_test);
2219 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2220 GV_ADDMULTI, SVt_PVAV);
2221 MY_CXT.cscav = GvAV(MY_CXT.cscgv);
2223 BhkENTRY_set(&bhk_csc, bhk_start, blockhook_csc_start);
2224 BhkENTRY_set(&bhk_csc, bhk_pre_end, blockhook_csc_pre_end);
2225 Perl_blockhook_register(aTHX_ &bhk_csc);
2227 MY_CXT.peep_recorder = newAV();
2228 MY_CXT.rpeep_recorder = newAV();
2230 MY_CXT.orig_peep = PL_peepp;
2231 MY_CXT.orig_rpeep = PL_rpeepp;
2233 PL_rpeepp = my_rpeep;
2240 PERL_UNUSED_VAR(items);
2241 MY_CXT.sv = newSVpv("initial_clone",0);
2242 MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER",
2243 GV_ADDMULTI, SVt_PVAV);
2244 MY_CXT.cscav = NULL;
2245 MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI);
2246 MY_CXT.bhk_record = 0;
2247 MY_CXT.peep_recorder = newAV();
2248 MY_CXT.rpeep_recorder = newAV();
2254 printf("%5.3f\n",val);
2259 #ifdef HAS_LONG_DOUBLE
2270 #ifdef HAS_LONG_DOUBLE
2271 # if defined(PERL_PRIfldbl) && (LONG_DOUBLESIZE > DOUBLESIZE)
2272 long double val = 7.0;
2273 printf("%5.3" PERL_PRIfldbl "\n",val);
2276 printf("%5.3f\n",val);
2290 printf("%ld\n",val);
2296 printf("%5.3f\n",val);
2344 mXPUSHp("three", 5);
2372 # test_EXTEND(): excerise the EXTEND() macro.
2373 # After calling EXTEND(), it also does *(p+n) = NULL and
2374 # *PL_stack_max = NULL to allow valgrind etc to spot if the stack hasn't
2375 # actually been extended properly.
2377 # max_offset specifies the SP to use. It is treated as a signed offset
2378 # from PL_stack_max.
2379 # nsv is the SV holding the value of n indicating how many slots
2380 # to extend the stack by.
2381 # use_ss is a boolean indicating that n should be cast to a SSize_t
2384 test_EXTEND(max_offset, nsv, use_ss)
2389 SV **sp = PL_stack_max + max_offset;
2392 SSize_t n = (SSize_t)SvIV(nsv);
2401 *PL_stack_max = NULL;
2413 SV * miscsv = sv_newmortal();
2414 HV * hv = (HV*)sv_2mortal((SV*)newHV());
2416 i_sub = get_cv("i", 0);
2418 /* PUTBACK not needed since this sub was called with 0 args, and is calling
2419 0 args, so global SP doesn't need to be moved before a call_* */
2420 retcnt = call_sv((SV*)i_sub, 0); /* try a CV* */
2422 SP -= retcnt; /* dont care about return count, wipe everything off */
2423 sv_setpvs(miscsv, "i");
2425 retcnt = call_sv(miscsv, 0); /* try a PV */
2428 /* no add and SVt_NULL are intentional, sub i should be defined already */
2429 i_gv = gv_fetchpvn_flags("i", sizeof("i")-1, 0, SVt_NULL);
2431 retcnt = call_sv((SV*)i_gv, 0); /* try a GV* */
2434 /* the tests below are not declaring this being public API behavior,
2435 only current internal behavior, these tests can be changed in the
2436 future if necessery */
2438 retcnt = call_sv(&PL_sv_yes, G_EVAL);
2442 errstr = SvPV(errsv, errlen);
2443 if(memBEGINs(errstr, errlen, "Undefined subroutine &main::1 called at")) {
2445 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2450 retcnt = call_sv(&PL_sv_no, G_EVAL);
2454 errstr = SvPV(errsv, errlen);
2455 if(memBEGINs(errstr, errlen, "Undefined subroutine &main:: called at")) {
2457 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2462 retcnt = call_sv(&PL_sv_undef, G_EVAL);
2466 errstr = SvPV(errsv, errlen);
2467 if(memBEGINs(errstr, errlen, "Can't use an undefined value as a subroutine reference at")) {
2469 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2474 retcnt = call_sv((SV*)hv, G_EVAL);
2478 errstr = SvPV(errsv, errlen);
2479 if(memBEGINs(errstr, errlen, "Not a CODE reference at")) {
2481 retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
2487 call_sv(sv, flags, ...)
2493 for (i=0; i<items-2; i++)
2494 ST(i) = ST(i+2); /* pop first two args */
2498 i = call_sv(sv, flags);
2501 PUSHs(sv_2mortal(newSViv(i)));
2504 call_pv(subname, flags, ...)
2510 for (i=0; i<items-2; i++)
2511 ST(i) = ST(i+2); /* pop first two args */
2515 i = call_pv(subname, flags);
2518 PUSHs(sv_2mortal(newSViv(i)));
2521 call_argv(subname, flags, ...)
2528 for (i=0; i<items-2; i++)
2529 tmpary[i] = SvPV_nolen(ST(i+2)); /* ignore first two args */
2532 i = call_argv(subname, flags, tmpary);
2535 PUSHs(sv_2mortal(newSViv(i)));
2538 call_method(methname, flags, ...)
2544 for (i=0; i<items-2; i++)
2545 ST(i) = ST(i+2); /* pop first two args */
2549 i = call_method(methname, flags);
2552 PUSHs(sv_2mortal(newSViv(i)));
2555 newCONSTSUB(stash, name, flags, sv)
2561 newCONSTSUB_flags = 1
2565 const char *pv = SvPV(name, len);
2569 mycv = newCONSTSUB(stash, pv, SvOK(sv) ? SvREFCNT_inc(sv) : NULL);
2572 mycv = newCONSTSUB_flags(
2573 stash, pv, len, flags | SvUTF8(name), SvOK(sv) ? SvREFCNT_inc(sv) : NULL
2579 PUSHs( CvCONST(mycv) ? &PL_sv_yes : &PL_sv_no );
2580 PUSHs((SV*)CvGV(mycv));
2583 gv_init_type(namesv, multi, flags, type)
2590 const char * const name = SvPV_const(namesv, len);
2591 GV *gv = *(GV**)hv_fetch(PL_defstash, name, len, TRUE);
2593 if (SvTYPE(gv) == SVt_PVGV)
2594 Perl_croak(aTHX_ "GV is already a PVGV");
2595 if (multi) flags |= GV_ADDMULTI;
2598 gv_init(gv, PL_defstash, name, len, multi);
2601 gv_init_sv(gv, PL_defstash, namesv, flags);
2604 gv_init_pv(gv, PL_defstash, name, flags | SvUTF8(namesv));
2607 gv_init_pvn(gv, PL_defstash, name, len, flags | SvUTF8(namesv));
2610 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2613 gv_fetchmeth_type(stash, methname, type, level, flags)
2621 const char * const name = SvPV_const(methname, len);
2626 gv = gv_fetchmeth(stash, name, len, level);
2629 gv = gv_fetchmeth_sv(stash, methname, level, flags);
2632 gv = gv_fetchmeth_pv(stash, name, level, flags | SvUTF8(methname));
2635 gv = gv_fetchmeth_pvn(stash, name, len, level, flags | SvUTF8(methname));
2638 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2641 gv_fetchmeth_autoload_type(stash, methname, type, level, flags)
2649 const char * const name = SvPV_const(methname, len);
2654 gv = gv_fetchmeth_autoload(stash, name, len, level);
2657 gv = gv_fetchmeth_sv_autoload(stash, methname, level, flags);
2660 gv = gv_fetchmeth_pv_autoload(stash, name, level, flags | SvUTF8(methname));
2663 gv = gv_fetchmeth_pvn_autoload(stash, name, len, level, flags | SvUTF8(methname));
2666 XPUSHs( gv ? MUTABLE_SV(gv) : &PL_sv_undef );
2669 gv_fetchmethod_flags_type(stash, methname, type, flags)
2679 gv = gv_fetchmethod_flags(stash, SvPVX_const(methname), flags);
2682 gv = gv_fetchmethod_sv_flags(stash, methname, flags);
2685 gv = gv_fetchmethod_pv_flags(stash, SvPV_nolen(methname), flags | SvUTF8(methname));
2689 const char * const name = SvPV_const(methname, len);
2690 gv = gv_fetchmethod_pvn_flags(stash, name, len, flags | SvUTF8(methname));
2694 gv = gv_fetchmethod_pvn_flags(stash, SvPV_nolen(methname),
2695 flags, SvUTF8(methname));
2697 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2700 gv_autoload_type(stash, methname, type, method)
2707 const char * const name = SvPV_const(methname, len);
2709 I32 flags = method ? GV_AUTOLOAD_ISMETHOD : 0;
2713 gv = gv_autoload4(stash, name, len, method);
2716 gv = gv_autoload_sv(stash, methname, flags);
2719 gv = gv_autoload_pv(stash, name, flags | SvUTF8(methname));
2722 gv = gv_autoload_pvn(stash, name, len, flags | SvUTF8(methname));
2725 XPUSHs( gv ? (SV*)gv : &PL_sv_undef);
2728 gv_const_sv(SV *name)
2733 HV *stash = gv_stashpv("main",0);
2734 HE *he = hv_fetch_ent(stash, name, 0, 0);
2735 gv = (GV *)HeVAL(he);
2740 RETVAL = gv_const_sv(gv);
2743 RETVAL = newSVsv(RETVAL);
2748 whichsig_type(namesv, type)
2753 const char * const name = SvPV_const(namesv, len);
2761 i = whichsig_sv(namesv);
2764 i = whichsig_pv(name);
2767 i = whichsig_pvn(name, len);
2770 XPUSHs(sv_2mortal(newSViv(i)));
2780 i = eval_sv(sv, flags);
2783 PUSHs(sv_2mortal(newSViv(i)));
2786 eval_pv(p, croak_on_error)
2792 PUSHs(eval_pv(p, croak_on_error));
2802 apitest_exception(throw_e)
2812 Perl_croak(aTHX_ "%s", SvPV_nolen(sv));
2815 Perl_croak(aTHX_ NULL);
2821 RETVAL = newRV_inc((SV*)PL_strtab);
2829 RETVAL = my_cxt_getint_p(aMY_CXT);
2838 my_cxt_setint_p(aMY_CXT_ i);
2845 ST(0) = how ? my_cxt_getsv_interp_context() : my_cxt_getsv_interp();
2853 SvREFCNT_dec(MY_CXT.sv);
2854 my_cxt_setsv_p(sv _aMY_CXT);
2858 sv_setsv_cow_hashkey_core()
2861 sv_setsv_cow_hashkey_notcore()
2864 sv_set_deref(SV *sv, SV *sv2, int which)
2868 const char *pv = SvPV(sv2,len);
2869 if (!SvROK(sv)) croak("Not a ref");
2872 case 0: sv_setsv(sv,sv2); break;
2873 case 1: sv_setpv(sv,pv); break;
2874 case 2: sv_setpvn(sv,pv,len); break;
2879 rmagical_cast(sv, type)
2885 if (!SvOK(sv) || !SvROK(sv) || !SvOK(type)) { XSRETURN_UNDEF; }
2887 if (SvTYPE(sv) != SVt_PVHV) { XSRETURN_UNDEF; }
2888 uf.uf_val = rmagical_a_dummy;
2891 if (SvTRUE(type)) { /* b */
2892 sv_magicext(sv, NULL, PERL_MAGIC_ext, &rmagical_b, NULL, 0);
2894 sv_magic(sv, NULL, PERL_MAGIC_uvar, (char *) &uf, sizeof(uf));
2902 if (!SvOK(sv) || !SvROK(sv)) { XSRETURN_UNDEF; }
2905 mXPUSHu(SvFLAGS(sv) & SVs_GMG);
2906 mXPUSHu(SvFLAGS(sv) & SVs_SMG);
2907 mXPUSHu(SvFLAGS(sv) & SVs_RMG);
2914 const PERL_CONTEXT *cx, *dbcx;
2919 cx = caller_cx(level, &dbcx);
2922 pv = CopSTASHPV(cx->blk_oldcop);
2923 ST(0) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2924 gv = CvGV(cx->blk_sub.cv);
2925 ST(1) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2927 pv = CopSTASHPV(dbcx->blk_oldcop);
2928 ST(2) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef;
2929 gv = CvGV(dbcx->blk_sub.cv);
2930 ST(3) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef;
2932 ST(4) = cop_hints_fetch_pvs(cx->blk_oldcop, "foo", 0);
2933 ST(5) = cop_hints_fetch_pvn(cx->blk_oldcop, "foo", 3, 0, 0);
2934 ST(6) = cop_hints_fetch_sv(cx->blk_oldcop,
2935 sv_2mortal(newSVpvs("foo")), 0, 0);
2937 hv = cop_hints_2hv(cx->blk_oldcop, 0);
2938 ST(7) = hv ? sv_2mortal(newRV_noinc((SV *)hv)) : &PL_sv_undef;
2947 ST (0) = newSVpv (Perl_sv_peek (aTHX_ sv), 0);
2953 sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI));
2958 sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI));
2963 sv_inc(get_sv("XS::APItest::UNITCHECK_called", GV_ADD|GV_ADDMULTI));
2968 sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI));
2973 sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI));
2976 utf16_to_utf8 (sv, ...)
2979 utf16_to_utf8_reversed = 1
2984 I32 got; /* Gah, badly thought out APIs */
2986 if (ix) (void)SvPV_force_nolen(sv);
2987 source = (U8 *)SvPVbyte(sv, len);
2988 /* Optionally only convert part of the buffer. */
2992 /* Mortalise this right now, as we'll be testing croak()s */
2993 dest = sv_2mortal(newSV(len * 2 + 1));
2995 utf16_to_utf8_reversed(source, (U8 *)SvPVX(dest), len, &got);
2997 utf16_to_utf8(source, (U8 *)SvPVX(dest), len, &got);
2999 SvCUR_set(dest, got);
3000 SvPVX(dest)[got] = '\0';
3006 my_exit(int exitcode)
3016 s = SvPVbyte(sv, len);
3024 RETVAL = PL_sv_count;
3032 MY_CXT.bhk_record = on;
3034 av_clear(MY_CXT.bhkav);
3040 MAGIC *callmg, *uvarmg;
3042 sv = sv_2mortal(newSV(0));
3043 if (SvTYPE(sv) >= SVt_PVMG) croak_fail();
3044 if (SvMAGICAL(sv)) croak_fail();
3045 sv_magic(sv, &PL_sv_yes, PERL_MAGIC_checkcall, (char*)&callmg, 0);
3046 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3047 if (!SvMAGICAL(sv)) croak_fail();
3048 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
3049 callmg = mg_find(sv, PERL_MAGIC_checkcall);
3050 if (!callmg) croak_fail();
3051 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
3053 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
3054 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3055 if (!SvMAGICAL(sv)) croak_fail();
3056 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
3057 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
3058 if (!uvarmg) croak_fail();
3059 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
3061 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
3063 mg_free_type(sv, PERL_MAGIC_vec);
3064 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3065 if (!SvMAGICAL(sv)) croak_fail();
3066 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
3067 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
3068 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
3070 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
3072 mg_free_type(sv, PERL_MAGIC_uvar);
3073 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3074 if (!SvMAGICAL(sv)) croak_fail();
3075 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
3076 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
3077 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
3079 sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0);
3080 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3081 if (!SvMAGICAL(sv)) croak_fail();
3082 if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail();
3083 uvarmg = mg_find(sv, PERL_MAGIC_uvar);
3084 if (!uvarmg) croak_fail();
3085 if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg)
3087 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
3089 mg_free_type(sv, PERL_MAGIC_checkcall);
3090 if (SvTYPE(sv) < SVt_PVMG) croak_fail();
3091 if (!SvMAGICAL(sv)) croak_fail();
3092 if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail();
3093 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
3094 if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg)
3096 mg_free_type(sv, PERL_MAGIC_uvar);
3097 if (SvMAGICAL(sv)) croak_fail();
3098 if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail();
3099 if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail();
3102 test_op_contextualize()
3106 o = newSVOP(OP_CONST, 0, newSViv(0));
3107 o->op_flags &= ~OPf_WANT;
3108 o = op_contextualize(o, G_SCALAR);
3109 if (o->op_type != OP_CONST ||
3110 (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR)
3113 o = newSVOP(OP_CONST, 0, newSViv(0));
3114 o->op_flags &= ~OPf_WANT;
3115 o = op_contextualize(o, G_ARRAY);
3116 if (o->op_type != OP_CONST ||
3117 (o->op_flags & OPf_WANT) != OPf_WANT_LIST)
3120 o = newSVOP(OP_CONST, 0, newSViv(0));
3121 o->op_flags &= ~OPf_WANT;
3122 o = op_contextualize(o, G_VOID);
3123 if (o->op_type != OP_NULL) croak_fail();
3134 troc_gv = gv_fetchpv("XS::APItest::test_rv2cv_op_cv", 0, SVt_PVGV);
3135 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3136 o = newCVREF(0, newGVOP(OP_GV, 0, troc_gv));
3137 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3138 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3140 o->op_private |= OPpENTERSUB_AMPER;
3141 if (rv2cv_op_cv(o, 0)) croak_fail();
3142 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3143 o->op_private &= ~OPpENTERSUB_AMPER;
3144 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3145 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3146 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3148 o = newSVOP(OP_CONST, 0, newSVpv("XS::APItest::test_rv2cv_op_cv", 0));
3149 o->op_private = OPpCONST_BARE;
3151 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3152 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3154 o->op_private |= OPpENTERSUB_AMPER;
3155 if (rv2cv_op_cv(o, 0)) croak_fail();
3156 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3158 o = newCVREF(0, newSVOP(OP_CONST, 0, newRV_inc((SV*)troc_cv)));
3159 if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail();
3160 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv)
3162 o->op_private |= OPpENTERSUB_AMPER;
3163 if (rv2cv_op_cv(o, 0)) croak_fail();
3164 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3165 o->op_private &= ~OPpENTERSUB_AMPER;
3166 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3167 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail();
3168 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3170 o = newCVREF(0, newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0))));
3171 if (rv2cv_op_cv(o, 0)) croak_fail();
3172 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3173 o->op_private |= OPpENTERSUB_AMPER;
3174 if (rv2cv_op_cv(o, 0)) croak_fail();
3175 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3176 o->op_private &= ~OPpENTERSUB_AMPER;
3177 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3178 if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY)) croak_fail();
3179 if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail();
3181 o = newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0)));
3182 if (rv2cv_op_cv(o, 0)) croak_fail();
3183 if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail();
3187 test_cv_getset_call_checker()
3189 CV *troc_cv, *tsh_cv;
3190 Perl_call_checker ckfun;
3194 #define check_cc(cv, xckfun, xckobj, xckflags) \
3196 cv_get_call_checker((cv), &ckfun, &ckobj); \
3197 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3198 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3199 cv_get_call_checker_flags((cv), CALL_CHECKER_REQUIRE_GV, &ckfun, &ckobj, &ckflags); \
3200 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3201 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3202 if (ckflags != CALL_CHECKER_REQUIRE_GV) croak_fail_nei(ckflags, CALL_CHECKER_REQUIRE_GV); \
3203 cv_get_call_checker_flags((cv), 0, &ckfun, &ckobj, &ckflags); \
3204 if (ckfun != (xckfun)) croak_fail_nep(FPTR2DPTR(void *, ckfun), xckfun); \
3205 if (ckobj != (xckobj)) croak_fail_nep(FPTR2DPTR(void *, ckobj), xckobj); \
3206 if (ckflags != (xckflags)) croak_fail_nei(ckflags, (xckflags)); \
3208 troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0);
3209 tsh_cv = get_cv("XS::APItest::test_savehints", 0);
3210 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3211 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3212 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3214 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3215 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3216 cv_set_call_checker(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no);
3217 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no, CALL_CHECKER_REQUIRE_GV);
3218 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3219 cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3221 check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no, CALL_CHECKER_REQUIRE_GV);
3222 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3223 cv_set_call_checker(troc_cv, Perl_ck_entersub_args_proto_or_list,
3225 check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv, 0);
3226 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3227 if (SvMAGICAL((SV*)troc_cv) || SvMAGIC((SV*)troc_cv)) croak_fail();
3228 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3229 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3231 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, 0);
3232 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3233 &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3234 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3235 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3237 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3238 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3239 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3240 &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3241 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes, CALL_CHECKER_REQUIRE_GV);
3242 cv_set_call_checker_flags(tsh_cv, Perl_ck_entersub_args_proto_or_list,
3243 (SV*)tsh_cv, CALL_CHECKER_REQUIRE_GV);
3244 check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv, 0);
3245 if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail();
3249 cv_set_call_checker_lists(CV *cv)
3251 cv_set_call_checker(cv, THX_ck_entersub_args_lists, &PL_sv_undef);
3254 cv_set_call_checker_scalars(CV *cv)
3256 cv_set_call_checker(cv, THX_ck_entersub_args_scalars, &PL_sv_undef);
3259 cv_set_call_checker_proto(CV *cv, SV *proto)
3262 proto = SvRV(proto);
3263 cv_set_call_checker(cv, Perl_ck_entersub_args_proto, proto);
3266 cv_set_call_checker_proto_or_list(CV *cv, SV *proto)
3269 proto = SvRV(proto);
3270 cv_set_call_checker(cv, Perl_ck_entersub_args_proto_or_list, proto);
3273 cv_set_call_checker_multi_sum(CV *cv)
3275 cv_set_call_checker(cv, THX_ck_entersub_multi_sum, &PL_sv_undef);
3287 #define check_ph(EXPR) \
3288 do { if((EXPR) != &PL_sv_placeholder) croak("fail"); } while(0)
3289 #define check_iv(EXPR, EXPECT) \
3290 do { if(SvIV(EXPR) != (EXPECT)) croak("fail"); } while(0)
3291 #define msvpvs(STR) sv_2mortal(newSVpvs(STR))
3292 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3293 a = cophh_new_empty();
3294 check_ph(cophh_fetch_pvn(a, "foo_1", 5, 0, 0));
3295 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3296 check_ph(cophh_fetch_pv(a, "foo_1", 0, 0));
3297 check_ph(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0));
3298 a = cophh_store_pvn(a, "foo_1abc", 5, 0, msviv(111), 0);
3299 a = cophh_store_pvs(a, "foo_2", msviv(222), 0);
3300 a = cophh_store_pv(a, "foo_3", 0, msviv(333), 0);
3301 a = cophh_store_sv(a, msvpvs("foo_4"), 0, msviv(444), 0);
3302 check_iv(cophh_fetch_pvn(a, "foo_1xyz", 5, 0, 0), 111);
3303 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3304 check_iv(cophh_fetch_pv(a, "foo_1", 0, 0), 111);
3305 check_iv(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0), 111);
3306 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3307 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3308 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3309 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3311 b = cophh_store_pvs(b, "foo_1", msviv(1111), 0);
3312 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111);
3313 check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222);
3314 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3315 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3316 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3317 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3318 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3319 check_iv(cophh_fetch_pvs(b, "foo_3", 0), 333);
3320 check_iv(cophh_fetch_pvs(b, "foo_4", 0), 444);
3321 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3322 a = cophh_delete_pvn(a, "foo_1abc", 5, 0, 0);
3323 a = cophh_delete_pvs(a, "foo_2", 0);
3324 b = cophh_delete_pv(b, "foo_3", 0, 0);
3325 b = cophh_delete_sv(b, msvpvs("foo_4"), 0, 0);
3326 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3327 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3328 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3329 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3330 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3331 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3332 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3333 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3334 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3335 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3336 b = cophh_delete_pvs(b, "foo_3", 0);
3337 b = cophh_delete_pvs(b, "foo_5", 0);
3338 check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111);
3339 check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222);
3340 check_ph(cophh_fetch_pvs(b, "foo_3", 0));
3341 check_ph(cophh_fetch_pvs(b, "foo_4", 0));
3342 check_ph(cophh_fetch_pvs(b, "foo_5", 0));
3344 check_ph(cophh_fetch_pvs(a, "foo_1", 0));
3345 check_ph(cophh_fetch_pvs(a, "foo_2", 0));
3346 check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333);
3347 check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444);
3348 check_ph(cophh_fetch_pvs(a, "foo_5", 0));
3349 a = cophh_store_pvs(a, "foo_1", msviv(11111), COPHH_KEY_UTF8);
3350 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3352 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3354 /* On EBCDIC, we need to translate the UTF-8 in the ASCII test to the
3355 * equivalent UTF-EBCDIC for the code page. This is done at runtime
3356 * (with the helper function in this file). Therefore we can't use
3357 * cophhh_store_pvs(), as we don't have literal string */
3358 key_sv = sv_2mortal(newSVpvs("foo_"));
3359 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3360 key_name = SvPV(key_sv, key_len);
3361 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3364 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3366 sv_setpvs(key_sv, "foo_");
3367 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3368 key_name = SvPV(key_sv, key_len);
3369 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3372 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3374 sv_setpvs(key_sv, "foo_");
3375 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3376 key_name = SvPV(key_sv, key_len);
3377 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3379 check_iv(cophh_fetch_pvs(a, "foo_1", 0), 11111);
3380 check_iv(cophh_fetch_pvs(a, "foo_1", COPHH_KEY_UTF8), 11111);
3381 check_iv(cophh_fetch_pvs(a, "foo_\xaa", 0), 123);
3383 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xaa", COPHH_KEY_UTF8), 123);
3384 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xaa", 0));
3386 sv_setpvs(key_sv, "foo_");
3387 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xaa"));
3388 key_name = SvPV(key_sv, key_len);
3389 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 123);
3390 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3392 check_iv(cophh_fetch_pvs(a, "foo_\xbb", 0), 456);
3394 check_iv(cophh_fetch_pvs(a, "foo_\xc2\xbb", COPHH_KEY_UTF8), 456);
3395 check_ph(cophh_fetch_pvs(a, "foo_\xc2\xbb", 0));
3397 sv_setpvs(key_sv, "foo_");
3398 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3399 key_name = SvPV(key_sv, key_len);
3400 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 456);
3401 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3403 check_iv(cophh_fetch_pvs(a, "foo_\xcc", 0), 789);
3405 check_iv(cophh_fetch_pvs(a, "foo_\xc3\x8c", COPHH_KEY_UTF8), 789);
3406 check_ph(cophh_fetch_pvs(a, "foo_\xc2\x8c", 0));
3408 sv_setpvs(key_sv, "foo_");
3409 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3410 key_name = SvPV(key_sv, key_len);
3411 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 789);
3412 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3415 check_iv(cophh_fetch_pvs(a, "foo_\xd9\xa6", COPHH_KEY_UTF8), 666);
3416 check_ph(cophh_fetch_pvs(a, "foo_\xd9\xa6", 0));
3418 sv_setpvs(key_sv, "foo_");
3419 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3420 key_name = SvPV(key_sv, key_len);
3421 check_iv(cophh_fetch_pvn(a, key_name, key_len, 0, COPHH_KEY_UTF8), 666);
3422 check_ph(cophh_fetch_pvn(a, key_name, key_len, 0, 0));
3440 cop = &PL_compiling;
3441 Perl_cop_store_label(aTHX_ cop, "foo", 3, 0);
3442 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3443 if (strNE(label,"foo")) croak("fail # cop_fetch_label label");
3444 if (len != 3) croak("fail # cop_fetch_label len");
3445 if (utf8) croak("fail # cop_fetch_label utf8");
3446 /* SMALL GERMAN UMLAUT A */
3447 Perl_cop_store_label(aTHX_ cop, "fo\xc3\xa4", 4, SVf_UTF8);
3448 label = Perl_cop_fetch_label(aTHX_ cop, &len, &utf8);
3449 if (strNE(label,"fo\xc3\xa4")) croak("fail # cop_fetch_label label");
3450 if (len != 4) croak("fail # cop_fetch_label len");
3451 if (!utf8) croak("fail # cop_fetch_label utf8");
3464 #define msviv(VALUE) sv_2mortal(newSViv(VALUE))
3465 a = cophh_new_empty();
3466 a = cophh_store_pvs(a, "foo_0", msviv(999), 0);
3467 a = cophh_store_pvs(a, "foo_1", msviv(111), 0);
3468 a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0);
3470 a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8);
3472 key_sv = sv_2mortal(newSVpvs("foo_"));
3473 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc2\xbb"));
3474 key_name = SvPV(key_sv, key_len);
3475 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(456), COPHH_KEY_UTF8);
3478 a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8);
3480 sv_setpvs(key_sv, "foo_");
3481 cat_utf8a2n(key_sv, STR_WITH_LEN("\xc3\x8c"));
3482 key_name = SvPV(key_sv, key_len);
3483 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(789), COPHH_KEY_UTF8);
3486 a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8);
3488 sv_setpvs(key_sv, "foo_");
3489 cat_utf8a2n(key_sv, STR_WITH_LEN("\xd9\xa6"));
3490 key_name = SvPV(key_sv, key_len);
3491 a = cophh_store_pvn(a, key_name, key_len, 0, msviv(666), COPHH_KEY_UTF8);
3493 a = cophh_delete_pvs(a, "foo_0", 0);
3494 a = cophh_delete_pvs(a, "foo_2", 0);
3495 RETVAL = cophh_2hv(a, 0);
3506 #define store_hint(KEY, VALUE) \
3507 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), KEY, 1), (VALUE))
3508 #define hint_ok(KEY, EXPECT) \
3509 ((svp = hv_fetchs(GvHV(PL_hintgv), KEY, 0)) && \
3510 (sv = *svp) && SvIV(sv) == (EXPECT) && \
3511 (sv = cop_hints_fetch_pvs(&PL_compiling, KEY, 0)) && \
3512 SvIV(sv) == (EXPECT))
3513 #define check_hint(KEY, EXPECT) \
3514 do { if (!hint_ok(KEY, EXPECT)) croak_fail(); } while(0)
3515 PL_hints |= HINT_LOCALIZE_HH;
3518 PL_hints &= HINT_INTEGER;
3519 store_hint("t0", 123);
3520 store_hint("t1", 456);
3521 if (PL_hints & HINT_INTEGER) croak_fail();
3522 check_hint("t0", 123); check_hint("t1", 456);
3525 if (PL_hints & HINT_INTEGER) croak_fail();
3526 check_hint("t0", 123); check_hint("t1", 456);
3527 PL_hints |= HINT_INTEGER;
3528 store_hint("t0", 321);
3529 if (!(PL_hints & HINT_INTEGER)) croak_fail();
3530 check_hint("t0", 321); check_hint("t1", 456);
3532 if (PL_hints & HINT_INTEGER) croak_fail();
3533 check_hint("t0", 123); check_hint("t1", 456);
3536 if (PL_hints & HINT_INTEGER) croak_fail();
3537 check_hint("t0", 123); check_hint("t1", 456);
3538 store_hint("t1", 654);
3539 if (PL_hints & HINT_INTEGER) croak_fail();
3540 check_hint("t0", 123); check_hint("t1", 654);
3542 if (PL_hints & HINT_INTEGER) croak_fail();
3543 check_hint("t0", 123); check_hint("t1", 456);
3554 PL_hints |= HINT_LOCALIZE_HH;
3557 sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), "t0", 1), 123);
3558 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3560 a = newHVhv(GvHV(PL_hintgv));
3562 sv_setiv_mg(*hv_fetchs(a, "t0", 1), 456);
3563 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123)
3565 b = hv_copy_hints_hv(a);
3567 sv_setiv_mg(*hv_fetchs(b, "t0", 1), 789);
3568 if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 789)
3577 #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv))
3578 #define check_op(o, expect) \
3580 if (strNE(test_op_list_describe(o), (expect))) \
3581 croak("fail %s %s", test_op_list_describe(o), (expect)); \
3583 a = op_append_elem(OP_LIST, NULL, NULL);
3585 a = op_append_elem(OP_LIST, iv_op(1), a);
3586 check_op(a, "const(1).");
3587 a = op_append_elem(OP_LIST, NULL, a);
3588 check_op(a, "const(1).");
3589 a = op_append_elem(OP_LIST, a, iv_op(2));
3590 check_op(a, "list[pushmark.const(1).const(2).]");
3591 a = op_append_elem(OP_LIST, a, iv_op(3));
3592 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3593 a = op_append_elem(OP_LIST, a, NULL);
3594 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3595 a = op_append_elem(OP_LIST, NULL, a);
3596 check_op(a, "list[pushmark.const(1).const(2).const(3).]");
3597 a = op_append_elem(OP_LIST, iv_op(4), a);
3598 check_op(a, "list[pushmark.const(4)."
3599 "list[pushmark.const(1).const(2).const(3).]]");
3600 a = op_append_elem(OP_LIST, a, iv_op(5));
3601 check_op(a, "list[pushmark.const(4)."
3602 "list[pushmark.const(1).const(2).const(3).]const(5).]");
3603 a = op_append_elem(OP_LIST, a,
3604 op_append_elem(OP_LIST, iv_op(7), iv_op(6)));
3605 check_op(a, "list[pushmark.const(4)."
3606 "list[pushmark.const(1).const(2).const(3).]const(5)."
3607 "list[pushmark.const(7).const(6).]]");
3609 a = op_append_elem(OP_LINESEQ, iv_op(1), iv_op(2));
3610 check_op(a, "lineseq[const(1).const(2).]");
3611 a = op_append_elem(OP_LINESEQ, a, iv_op(3));
3612 check_op(a, "lineseq[const(1).const(2).const(3).]");
3614 a = op_append_elem(OP_LINESEQ,
3615 op_append_elem(OP_LIST, iv_op(1), iv_op(2)),
3617 check_op(a, "lineseq[list[pushmark.const(1).const(2).]const(3).]");
3619 a = op_prepend_elem(OP_LIST, NULL, NULL);
3621 a = op_prepend_elem(OP_LIST, a, iv_op(1));
3622 check_op(a, "const(1).");
3623 a = op_prepend_elem(OP_LIST, a, NULL);
3624 check_op(a, "const(1).");
3625 a = op_prepend_elem(OP_LIST, iv_op(2), a);
3626 check_op(a, "list[pushmark.const(2).const(1).]");
3627 a = op_prepend_elem(OP_LIST, iv_op(3), a);
3628 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3629 a = op_prepend_elem(OP_LIST, NULL, a);
3630 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3631 a = op_prepend_elem(OP_LIST, a, NULL);
3632 check_op(a, "list[pushmark.const(3).const(2).const(1).]");
3633 a = op_prepend_elem(OP_LIST, a, iv_op(4));
3634 check_op(a, "list[pushmark."
3635 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3636 a = op_prepend_elem(OP_LIST, iv_op(5), a);
3637 check_op(a, "list[pushmark.const(5)."
3638 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3639 a = op_prepend_elem(OP_LIST,
3640 op_prepend_elem(OP_LIST, iv_op(6), iv_op(7)), a);
3641 check_op(a, "list[pushmark.list[pushmark.const(6).const(7).]const(5)."
3642 "list[pushmark.const(3).const(2).const(1).]const(4).]");
3644 a = op_prepend_elem(OP_LINESEQ, iv_op(2), iv_op(1));
3645 check_op(a, "lineseq[const(2).const(1).]");
3646 a = op_prepend_elem(OP_LINESEQ, iv_op(3), a);
3647 check_op(a, "lineseq[const(3).const(2).const(1).]");
3649 a = op_prepend_elem(OP_LINESEQ, iv_op(3),
3650 op_prepend_elem(OP_LIST, iv_op(2), iv_op(1)));
3651 check_op(a, "lineseq[const(3).list[pushmark.const(2).const(1).]]");
3653 a = op_append_list(OP_LINESEQ, NULL, NULL);
3655 a = op_append_list(OP_LINESEQ, iv_op(1), a);
3656 check_op(a, "const(1).");
3657 a = op_append_list(OP_LINESEQ, NULL, a);
3658 check_op(a, "const(1).");
3659 a = op_append_list(OP_LINESEQ, a, iv_op(2));
3660 check_op(a, "lineseq[const(1).const(2).]");
3661 a = op_append_list(OP_LINESEQ, a, iv_op(3));
3662 check_op(a, "lineseq[const(1).const(2).const(3).]");
3663 a = op_append_list(OP_LINESEQ, iv_op(4), a);
3664 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3665 a = op_append_list(OP_LINESEQ, a, NULL);
3666 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3667 a = op_append_list(OP_LINESEQ, NULL, a);
3668 check_op(a, "lineseq[const(4).const(1).const(2).const(3).]");
3669 a = op_append_list(OP_LINESEQ, a,
3670 op_append_list(OP_LINESEQ, iv_op(5), iv_op(6)));
3671 check_op(a, "lineseq[const(4).const(1).const(2).const(3)."
3672 "const(5).const(6).]");
3674 a = op_append_list(OP_LINESEQ,
3675 op_append_list(OP_LINESEQ, iv_op(1), iv_op(2)),
3676 op_append_list(OP_LIST, iv_op(3), iv_op(4)));
3677 check_op(a, "lineseq[const(1).const(2)."
3678 "list[pushmark.const(3).const(4).]]");
3680 a = op_append_list(OP_LINESEQ,
3681 op_append_list(OP_LIST, iv_op(1), iv_op(2)),
3682 op_append_list(OP_LINESEQ, iv_op(3), iv_op(4)));
3683 check_op(a, "lineseq[list[pushmark.const(1).const(2).]"
3684 "const(3).const(4).]");
3693 #define check_ll(o, expect) \
3695 if (strNE(test_op_linklist_describe(o), (expect))) \
3696 croak("fail %s %s", test_op_linklist_describe(o), (expect)); \
3699 check_ll(o, ".const1");
3702 o = mkUNOP(OP_NOT, iv_op(1));
3703 check_ll(o, ".const1.not");
3706 o = mkUNOP(OP_NOT, mkUNOP(OP_NEGATE, iv_op(1)));
3707 check_ll(o, ".const1.negate.not");
3710 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3711 check_ll(o, ".const1.const2.add");
3714 o = mkBINOP(OP_ADD, mkUNOP(OP_NOT, iv_op(1)), iv_op(2));
3715 check_ll(o, ".const1.not.const2.add");
3718 o = mkUNOP(OP_NOT, mkBINOP(OP_ADD, iv_op(1), iv_op(2)));
3719 check_ll(o, ".const1.const2.add.not");
3722 o = mkLISTOP(OP_LINESEQ, iv_op(1), iv_op(2), iv_op(3));
3723 check_ll(o, ".const1.const2.const3.lineseq");
3726 o = mkLISTOP(OP_LINESEQ,
3727 mkBINOP(OP_ADD, iv_op(1), iv_op(2)),
3728 mkUNOP(OP_NOT, iv_op(3)),
3729 mkLISTOP(OP_SUBSTR, iv_op(4), iv_op(5), iv_op(6)));
3730 check_ll(o, ".const1.const2.add.const3.not"
3731 ".const4.const5.const6.substr.lineseq");
3734 o = mkBINOP(OP_ADD, iv_op(1), iv_op(2));
3736 o = mkBINOP(OP_SUBTRACT, o, iv_op(3));
3737 check_ll(o, ".const1.const2.add.const3.subtract");
3747 av_clear(MY_CXT.peep_recorder);
3748 av_clear(MY_CXT.rpeep_recorder);
3749 MY_CXT.peep_recording = 1;
3756 MY_CXT.peep_recording = 0;
3763 RETVAL = newRV_inc((SV *)MY_CXT.peep_recorder);
3772 RETVAL = newRV_inc((SV *)MY_CXT.rpeep_recorder);
3778 multicall_each: call a sub for each item in the list. Used to test MULTICALL
3783 multicall_each(block,...)
3792 I32 gimme = G_SCALAR;
3793 SV **args = &PL_stack_base[ax];
3799 cv = sv_2cv(block, &stash, &gv, 0);
3801 croak("multicall_each: not a subroutine reference");
3804 SAVESPTR(GvSV(PL_defgv));
3806 for(index = 1 ; index < items ; index++) {
3807 GvSV(PL_defgv) = args[index];
3816 multicall_return(): call the passed sub once in the specificed context
3817 and return whatever it returns
3822 multicall_return(block, context)
3832 I32 gimme = context;
3838 cv = sv_2cv(block, &stash, &gv, 0);
3840 croak("multicall_return not a subroutine reference");
3846 /* copy returned values into an array so they're not freed during
3857 av_push(av, SvREFCNT_inc(TOPs));
3861 for (p = PL_stack_base + 1; p <= SP; p++)
3862 av_push(av, SvREFCNT_inc(*p));
3868 size = AvFILLp(av) + 1;
3870 for (i = 0; i < size; i++)
3871 ST(i) = *av_fetch(av, i, FALSE);
3872 sv_2mortal((SV*)av);
3883 PerlInterpreter *interp = aTHX; /* The original interpreter */
3884 PerlInterpreter *interp_dup; /* The duplicate interpreter */
3885 int oldscope = 1; /* We are responsible for all scopes */
3887 interp_dup = perl_clone(interp, CLONEf_COPY_STACKS | CLONEf_CLONE_HOST );
3889 /* destroy old perl */
3890 PERL_SET_CONTEXT(interp);
3892 POPSTACK_TO(PL_mainstack);
3893 if (cxstack_ix >= 0) {
3895 cx_popblock(cxstack);
3898 PL_scopestack_ix = oldscope;
3901 perl_destruct(interp);
3904 /* switch to new perl */
3905 PERL_SET_CONTEXT(interp_dup);
3907 /* continue after 'clone_with_stack' */
3908 if (interp_dup->Iop)
3909 interp_dup->Iop = interp_dup->Iop->op_next;
3911 /* run with new perl */
3912 Perl_runops_standard(interp_dup);
3914 /* We may have additional unclosed scopes if fork() was called
3915 * from within a BEGIN block. See perlfork.pod for more details.
3916 * We cannot clean up these other scopes because they belong to a
3917 * different interpreter, but we also cannot leave PL_scopestack_ix
3918 * dangling because that can trigger an assertion in perl_destruct().
3920 if (PL_scopestack_ix > oldscope) {
3921 PL_scopestack[oldscope-1] = PL_scopestack[PL_scopestack_ix-1];
3922 PL_scopestack_ix = oldscope;
3925 perl_destruct(interp_dup);
3926 perl_free(interp_dup);
3928 /* call the real 'exit' not PerlProc_exit */
3933 #endif /* USE_ITHREDS */
3936 take_svref(SVREF sv)
3938 RETVAL = newRV_inc(sv);
3945 RETVAL = newRV_inc((SV*)av);
3952 RETVAL = newRV_inc((SV*)hv);
3960 RETVAL = newRV_inc((SV*)cv);
3970 stash = gv_stashpv("XS::APItest::TempLv", 0);
3972 meth = hv_fetchs(stash, "make_temp_mg_lv", 0);
3974 croak("lost method 'make_temp_mg_lv'");
3981 hintkey_rpn_sv = newSVpvs_share("XS::APItest/rpn");
3982 hintkey_calcrpn_sv = newSVpvs_share("XS::APItest/calcrpn");
3983 hintkey_stufftest_sv = newSVpvs_share("XS::APItest/stufftest");
3984 hintkey_swaptwostmts_sv = newSVpvs_share("XS::APItest/swaptwostmts");
3985 hintkey_looprest_sv = newSVpvs_share("XS::APItest/looprest");
3986 hintkey_scopelessblock_sv = newSVpvs_share("XS::APItest/scopelessblock");
3987 hintkey_stmtasexpr_sv = newSVpvs_share("XS::APItest/stmtasexpr");
3988 hintkey_stmtsasexpr_sv = newSVpvs_share("XS::APItest/stmtsasexpr");
3989 hintkey_loopblock_sv = newSVpvs_share("XS::APItest/loopblock");
3990 hintkey_blockasexpr_sv = newSVpvs_share("XS::APItest/blockasexpr");
3991 hintkey_swaplabel_sv = newSVpvs_share("XS::APItest/swaplabel");
3992 hintkey_labelconst_sv = newSVpvs_share("XS::APItest/labelconst");
3993 hintkey_arrayfullexpr_sv = newSVpvs_share("XS::APItest/arrayfullexpr");
3994 hintkey_arraylistexpr_sv = newSVpvs_share("XS::APItest/arraylistexpr");
3995 hintkey_arraytermexpr_sv = newSVpvs_share("XS::APItest/arraytermexpr");
3996 hintkey_arrayarithexpr_sv = newSVpvs_share("XS::APItest/arrayarithexpr");
3997 hintkey_arrayexprflags_sv = newSVpvs_share("XS::APItest/arrayexprflags");
3998 hintkey_DEFSV_sv = newSVpvs_share("XS::APItest/DEFSV");
3999 hintkey_with_vars_sv = newSVpvs_share("XS::APItest/with_vars");
4000 hintkey_join_with_space_sv = newSVpvs_share("XS::APItest/join_with_space");
4001 wrap_keyword_plugin(my_keyword_plugin, &next_keyword_plugin);
4005 establish_cleanup(...)
4008 PERL_UNUSED_VAR(items);
4009 croak("establish_cleanup called as a function");
4013 CV *estcv = get_cv("XS::APItest::establish_cleanup", 0);
4014 cv_set_call_checker(estcv, THX_ck_entersub_establish_cleanup, (SV*)estcv);
4021 PERL_UNUSED_VAR(items);
4022 croak("postinc called as a function");
4027 filter_add(filter_call, NULL);
4031 CV *asscv = get_cv("XS::APItest::postinc", 0);
4032 cv_set_call_checker(asscv, THX_ck_entersub_postinc, (SV*)asscv);
4040 newRV_noinc(newSV(0)),
4041 gv_stashpvs("XS::APItest::TempObj",GV_ADD)
4042 ); /* Package defined in test script */
4047 fill_hash_with_nulls(HV *hv)
4051 for(; i < 1000; ++i) {
4052 HE *entry = hv_fetch_ent(hv, sv_2mortal(newSVuv(i)), 1, 0);
4053 SvREFCNT_dec(HeVAL(entry));
4054 HeVAL(entry) = NULL;
4060 RETVAL = newHVhv(hv);
4067 RETVAL = SvIsCOW(sv);
4075 PERL_UNUSED_VAR(items);
4076 croak("pad_scalar called as a function");
4080 CV *pscv = get_cv("XS::APItest::pad_scalar", 0);
4081 cv_set_call_checker(pscv, THX_ck_entersub_pad_scalar, (SV*)pscv);
4085 fetch_pad_names( cv )
4089 PADNAMELIST *pad_namelist;
4090 AV *retav = newAV();
4092 pad_namelist = PadlistNAMES(CvPADLIST(cv));
4094 for ( i = PadnamelistMAX(pad_namelist); i >= 0; i-- ) {
4095 PADNAME* name = PadnamelistARRAY(pad_namelist)[i];
4097 if (PadnameLEN(name)) {
4098 av_push(retav, newSVpadname(name));
4101 RETVAL = newRV_noinc((SV*)retav);
4113 u = find_rundefsv();
4114 pv = (U8*)SvPV(u, bytelen);
4115 RETVAL = SvUTF8(u) ? utf8_length(pv, pv+bytelen) : bytelen;
4122 (void)SvPV_nolen(sv);
4127 RETVAL = hv && HvENAME(hv)
4129 HvENAME(hv),HvENAMELEN(hv),
4130 (HvENAMEUTF8(hv) ? SVf_UTF8 : 0)
4137 xs_cmp(int a, int b)
4139 /* Odd sorting (odd numbers first), to make sure we are actually
4141 RETVAL = a % 2 != b % 2
4143 : a < b ? -1 : a == b ? 0 : 1;
4148 xs_cmp_undef(SV *a, SV *b)
4152 RETVAL = &PL_sv_undef;
4159 RETVAL = SvPVbyte_nolen(sv);
4166 RETVAL = SvPVutf8_nolen(sv);
4173 wrap_op_checker(OP_ADD, addissub_myck_add, &addissub_nxck_add);
4176 setup_rv2cv_addunderbar()
4178 wrap_op_checker(OP_RV2CV, my_ck_rv2cv, &old_ck_rv2cv);
4183 test_alloccopstash()
4185 RETVAL = PL_stashpad[alloccopstash(PL_defstash)] == PL_defstash;
4192 test_newFOROP_without_slab()
4195 const I32 floor = start_subparse(0,0);
4197 /* The slab allocator does not like CvROOT being set. */
4198 CvROOT(PL_compcv) = (OP *)1;
4199 o = newFOROP(0, 0, newOP(OP_PUSHMARK, 0), 0, 0);
4200 #ifdef PERL_OP_PARENT
4201 if (cLOOPx(cUNOPo->op_first)->op_last->op_sibparent
4202 != cUNOPo->op_first)
4204 Perl_warn(aTHX_ "Op parent pointer is stale");
4209 /* If we do not crash before returning, the test passes. */
4212 CvROOT(PL_compcv) = NULL;
4213 SvREFCNT_dec(PL_compcv);
4219 # provide access to CALLREGEXEC, except replace pointers within the
4220 # string with offsets from the start of the string
4223 callregexec(SV *prog, STRLEN stringarg, STRLEN strend, I32 minend, SV *sv, U32 nosave)
4230 strbeg = SvPV_force(sv, len);
4231 RETVAL = CALLREGEXEC((REGEXP *)prog,
4244 lexical_import(SV *name, CV *cv)
4251 "lexical_import can only be called at compile time");
4252 pl = CvPADLIST(PL_compcv);
4254 SAVESPTR(PL_comppad_name); PL_comppad_name = PadlistNAMES(pl);
4255 SAVESPTR(PL_comppad); PL_comppad = PadlistARRAY(pl)[1];
4256 SAVESPTR(PL_curpad); PL_curpad = PadARRAY(PL_comppad);
4257 off = pad_add_name_sv(sv_2mortal(newSVpvf("&%" SVf,name)),
4258 padadd_STATE, 0, 0);
4259 SvREFCNT_dec(PL_curpad[off]);
4260 PL_curpad[off] = SvREFCNT_inc(cv);
4266 sv_mortalcopy(SV *sv)
4268 RETVAL = SvREFCNT_inc(sv_mortalcopy(sv));
4276 alias_av(AV *av, IV ix, SV *sv)
4278 av_store(av, ix, SvREFCNT_inc(sv));
4281 cv_name(SVREF ref, ...)
4283 RETVAL = SvREFCNT_inc(cv_name((CV *)ref,
4284 items>1 && ST(1) != &PL_sv_undef
4287 items>2 ? SvUV(ST(2)) : 0));
4292 sv_catpvn(SV *sv, SV *sv2)
4296 const char *s = SvPV(sv2,len);
4297 sv_catpvn_flags(sv,s,len, SvUTF8(sv2) ? SV_CATUTF8 : SV_CATBYTES);
4304 OP *o = newLISTOP(OP_CUSTOM, 0, NULL, NULL);
4306 o = newOP(OP_CUSTOM, 0);
4308 o = newUNOP(OP_CUSTOM, 0, NULL);
4310 o = newUNOP_AUX(OP_CUSTOM, 0, NULL, NULL);
4312 o = newMETHOP(OP_CUSTOM, 0, newOP(OP_NULL,0));
4314 o = newMETHOP_named(OP_CUSTOM, 0, newSV(0));
4316 o = newBINOP(OP_CUSTOM, 0, NULL, NULL);
4318 o = newPMOP(OP_CUSTOM, 0);
4320 o = newSVOP(OP_CUSTOM, 0, newSV(0));
4324 lex_start(NULL, NULL, 0);
4326 I32 ix = start_subparse(FALSE,0);
4327 o = newPADOP(OP_CUSTOM, 0, newSV(0));
4333 o = newPVOP(OP_CUSTOM, 0, NULL);
4335 o = newLOGOP(OP_CUSTOM, 0, newOP(OP_NULL,0), newOP(OP_NULL,0));
4337 o = newLOOPEX(OP_CUSTOM, newOP(OP_NULL,0));
4345 test_sv_catpvf(SV *fmtsv)
4350 fmt = SvPV_nolen(fmtsv);
4351 sv = sv_2mortal(newSVpvn("", 0));
4352 sv_catpvf(sv, fmt, 5, 6, 7, 8);
4355 load_module(flags, name, ...)
4360 Perl_load_module(aTHX_ flags, SvREFCNT_inc(name), NULL);
4361 } else if (items == 3) {
4362 Perl_load_module(aTHX_ flags, SvREFCNT_inc(name), SvREFCNT_inc(ST(2)));
4364 Perl_croak(aTHX_ "load_module can't yet support %" IVdf " items",
4368 string_without_null(SV *sv)
4372 const char *s = SvPV(sv, len);
4373 RETVAL = newSVpvn_flags(s, len, SvUTF8(sv));
4374 *SvEND(RETVAL) = 0xff;
4384 const char *s = SvPV(sv, len);
4385 RETVAL = get_cvn_flags(s, len, 0);
4391 get_cv_flags(SV *sv, UV flags)
4395 const char *s = SvPV(sv, len);
4396 RETVAL = get_cvn_flags(s, len, flags);
4411 #define FILE NativeFile
4414 PerlIO_exportFILE(PerlIO *f, const char *mode)
4416 MODULE = XS::APItest PACKAGE = XS::APItest::AUTOLOADtest
4422 SV* class_and_method;
4424 PERL_UNUSED_ARG(items);
4425 class_and_method = GvSV(CvGV(cv));
4426 comms = get_sv("main::the_method", 1);
4427 if (class_and_method == NULL) {
4429 } else if (!SvOK(class_and_method)) {
4431 } else if (!SvPOK(class_and_method)) {
4434 sv_setsv(comms, class_and_method);
4440 MODULE = XS::APItest PACKAGE = XS::APItest::Magic
4445 sv_magic_foo(SV *sv, SV *thingy)
4449 sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo, (const char *)thingy, 0);
4456 MAGIC *mg = mg_findext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4457 RETVAL = mg ? SvREFCNT_inc((SV *)mg->mg_ptr) : &PL_sv_undef;
4462 sv_unmagic_foo(SV *sv)
4466 sv_unmagicext(SvRV(sv), PERL_MAGIC_ext, ix ? &vtbl_bar : &vtbl_foo);
4469 sv_magic(SV *sv, SV *thingy)
4471 sv_magic(SvRV(sv), NULL, PERL_MAGIC_ext, (const char *)thingy, 0);
4479 #define test_get_this_vtable(name) \
4480 want = (MGVTBL*)CAT2(&PL_vtbl_, name); \
4481 have = get_vtbl(CAT2(want_vtbl_, name)); \
4483 croak("fail %p!=%p for get_vtbl(want_vtbl_" STRINGIFY(name) ") at " __FILE__ " line %d", have, want, __LINE__)
4485 test_get_this_vtable(sv);
4486 test_get_this_vtable(env);
4487 test_get_this_vtable(envelem);
4488 test_get_this_vtable(sigelem);
4489 test_get_this_vtable(pack);
4490 test_get_this_vtable(packelem);
4491 test_get_this_vtable(dbline);
4492 test_get_this_vtable(isa);
4493 test_get_this_vtable(isaelem);
4494 test_get_this_vtable(arylen);
4495 test_get_this_vtable(mglob);
4496 test_get_this_vtable(nkeys);
4497 test_get_this_vtable(taint);
4498 test_get_this_vtable(substr);
4499 test_get_this_vtable(vec);
4500 test_get_this_vtable(pos);
4501 test_get_this_vtable(bm);
4502 test_get_this_vtable(fm);
4503 test_get_this_vtable(uvar);
4504 test_get_this_vtable(defelem);
4505 test_get_this_vtable(regexp);
4506 test_get_this_vtable(regdata);
4507 test_get_this_vtable(regdatum);
4508 #ifdef USE_LOCALE_COLLATE
4509 test_get_this_vtable(collxfrm);
4511 test_get_this_vtable(backref);
4512 test_get_this_vtable(utf8);
4514 RETVAL = PTR2UV(get_vtbl(-1));
4519 # attach ext magic to the SV pointed to by rsv that only has set magic,
4520 # where that magic's job is to increment thingy
4523 sv_magic_myset(SV *rsv, SV *thingy)
4525 sv_magicext(SvRV(rsv), NULL, PERL_MAGIC_ext, &vtbl_myset,
4526 (const char *)thingy, 0);
4531 test_isBLANK_uni(UV ord)
4533 RETVAL = isBLANK_uni(ord);
4538 test_isBLANK_uvchr(UV ord)
4540 RETVAL = isBLANK_uvchr(ord);
4545 test_isBLANK_LC_uvchr(UV ord)
4547 RETVAL = isBLANK_LC_uvchr(ord);
4552 test_isBLANK(UV ord)
4554 RETVAL = isBLANK(ord);
4559 test_isBLANK_A(UV ord)
4561 RETVAL = isBLANK_A(ord);
4566 test_isBLANK_L1(UV ord)
4568 RETVAL = isBLANK_L1(ord);
4573 test_isBLANK_LC(UV ord)
4575 RETVAL = isBLANK_LC(ord);
4580 test_isBLANK_utf8(U8 * p, int type)
4585 /* In this function and those that follow, the boolean 'type'
4586 * indicates if to pass a malformed UTF-8 string to the tested macro
4587 * (malformed by making it too short) */
4589 e = p + UTF8SKIP(p) - type;
4590 RETVAL = isBLANK_utf8_safe(p, e);
4593 RETVAL = isBLANK_utf8(p);
4599 test_isBLANK_LC_utf8(U8 * p, int type)
4604 e = p + UTF8SKIP(p) - type;
4605 RETVAL = isBLANK_LC_utf8_safe(p, e);
4608 RETVAL = isBLANK_LC_utf8(p);
4614 test_isVERTWS_uni(UV ord)
4616 RETVAL = isVERTWS_uni(ord);
4621 test_isVERTWS_uvchr(UV ord)
4623 RETVAL = isVERTWS_uvchr(ord);
4628 test_isVERTWS_utf8(U8 * p, int type)
4633 e = p + UTF8SKIP(p) - type;
4634 RETVAL = isVERTWS_utf8_safe(p, e);
4637 RETVAL = isVERTWS_utf8(p);
4643 test_isUPPER_uni(UV ord)
4645 RETVAL = isUPPER_uni(ord);
4650 test_isUPPER_uvchr(UV ord)
4652 RETVAL = isUPPER_uvchr(ord);
4657 test_isUPPER_LC_uvchr(UV ord)
4659 RETVAL = isUPPER_LC_uvchr(ord);
4664 test_isUPPER(UV ord)
4666 RETVAL = isUPPER(ord);
4671 test_isUPPER_A(UV ord)
4673 RETVAL = isUPPER_A(ord);
4678 test_isUPPER_L1(UV ord)
4680 RETVAL = isUPPER_L1(ord);
4685 test_isUPPER_LC(UV ord)
4687 RETVAL = isUPPER_LC(ord);
4692 test_isUPPER_utf8(U8 * p, int type)
4697 e = p + UTF8SKIP(p) - type;