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