Commit | Line | Data |
---|---|---|
6a93a7e5 | 1 | #define PERL_IN_XS_APITEST |
3e61d65a JH |
2 | #include "EXTERN.h" |
3 | #include "perl.h" | |
4 | #include "XSUB.h" | |
5 | ||
36c2b1d0 NC |
6 | typedef SV *SVREF; |
7 | typedef 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 | ||
16 | typedef 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; | |
85ce96a1 DM |
28 | } my_cxt_t; |
29 | ||
30 | START_MY_CXT | |
31 | ||
32 | /* indirect functions to test the [pa]MY_CXT macros */ | |
f16dd614 | 33 | |
85ce96a1 DM |
34 | int |
35 | my_cxt_getint_p(pMY_CXT) | |
36 | { | |
37 | return MY_CXT.i; | |
38 | } | |
f16dd614 | 39 | |
85ce96a1 DM |
40 | void |
41 | my_cxt_setint_p(pMY_CXT_ int i) | |
42 | { | |
43 | MY_CXT.i = i; | |
44 | } | |
f16dd614 DM |
45 | |
46 | SV* | |
9568a123 | 47 | my_cxt_getsv_interp_context(void) |
f16dd614 | 48 | { |
f16dd614 DM |
49 | dTHX; |
50 | dMY_CXT_INTERP(my_perl); | |
9568a123 NC |
51 | return MY_CXT.sv; |
52 | } | |
53 | ||
54 | SV* | |
55 | my_cxt_getsv_interp(void) | |
56 | { | |
f16dd614 | 57 | dMY_CXT; |
f16dd614 DM |
58 | return MY_CXT.sv; |
59 | } | |
60 | ||
85ce96a1 DM |
61 | void |
62 | my_cxt_setsv_p(SV* sv _pMY_CXT) | |
63 | { | |
64 | MY_CXT.sv = sv; | |
65 | } | |
66 | ||
67 | ||
9b5c3821 | 68 | /* from exception.c */ |
7a646707 | 69 | int apitest_exception(int); |
0314122a | 70 | |
ff66e713 SH |
71 | /* from core_or_not.inc */ |
72 | bool sv_setsv_cow_hashkey_core(void); | |
73 | bool sv_setsv_cow_hashkey_notcore(void); | |
74 | ||
2dc92170 NC |
75 | /* A routine to test hv_delayfree_ent |
76 | (which itself is tested by testing on hv_free_ent */ | |
77 | ||
78 | typedef void (freeent_function)(pTHX_ HV *, register HE *); | |
79 | ||
80 | void | |
81 | test_freeent(freeent_function *f) { | |
82 | dTHX; | |
83 | dSP; | |
84 | HV *test_hash = newHV(); | |
85 | HE *victim; | |
86 | SV *test_scalar; | |
87 | U32 results[4]; | |
88 | int i; | |
89 | ||
8afd2d2e NC |
90 | #ifdef PURIFY |
91 | victim = (HE*)safemalloc(sizeof(HE)); | |
92 | #else | |
2dc92170 NC |
93 | /* Storing then deleting something should ensure that a hash entry is |
94 | available. */ | |
95 | hv_store(test_hash, "", 0, &PL_sv_yes, 0); | |
96 | hv_delete(test_hash, "", 0, 0); | |
97 | ||
98 | /* We need to "inline" new_he here as it's static, and the functions we | |
99 | test expect to be able to call del_HE on the HE */ | |
6a93a7e5 | 100 | if (!PL_body_roots[HE_SVSLOT]) |
2dc92170 | 101 | croak("PL_he_root is 0"); |
8a722a80 | 102 | victim = (HE*) PL_body_roots[HE_SVSLOT]; |
6a93a7e5 | 103 | PL_body_roots[HE_SVSLOT] = HeNEXT(victim); |
8afd2d2e | 104 | #endif |
2dc92170 NC |
105 | |
106 | victim->hent_hek = Perl_share_hek(aTHX_ "", 0, 0); | |
107 | ||
108 | test_scalar = newSV(0); | |
109 | SvREFCNT_inc(test_scalar); | |
de616631 | 110 | HeVAL(victim) = test_scalar; |
2dc92170 NC |
111 | |
112 | /* Need this little game else we free the temps on the return stack. */ | |
113 | results[0] = SvREFCNT(test_scalar); | |
114 | SAVETMPS; | |
115 | results[1] = SvREFCNT(test_scalar); | |
116 | f(aTHX_ test_hash, victim); | |
117 | results[2] = SvREFCNT(test_scalar); | |
118 | FREETMPS; | |
119 | results[3] = SvREFCNT(test_scalar); | |
120 | ||
121 | i = 0; | |
122 | do { | |
123 | mPUSHu(results[i]); | |
124 | } while (++i < sizeof(results)/sizeof(results[0])); | |
125 | ||
126 | /* Goodbye to our extra reference. */ | |
127 | SvREFCNT_dec(test_scalar); | |
128 | } | |
129 | ||
b54b4831 NC |
130 | |
131 | static I32 | |
53c40a8f NC |
132 | bitflip_key(pTHX_ IV action, SV *field) { |
133 | MAGIC *mg = mg_find(field, PERL_MAGIC_uvar); | |
134 | SV *keysv; | |
135 | if (mg && (keysv = mg->mg_obj)) { | |
136 | STRLEN len; | |
137 | const char *p = SvPV(keysv, len); | |
138 | ||
139 | if (len) { | |
140 | SV *newkey = newSV(len); | |
141 | char *new_p = SvPVX(newkey); | |
142 | ||
143 | if (SvUTF8(keysv)) { | |
144 | const char *const end = p + len; | |
145 | while (p < end) { | |
146 | STRLEN len; | |
a75fcbca SP |
147 | UV chr = utf8_to_uvuni((U8 *)p, &len); |
148 | new_p = (char *)uvuni_to_utf8((U8 *)new_p, chr ^ 32); | |
53c40a8f NC |
149 | p += len; |
150 | } | |
151 | SvUTF8_on(newkey); | |
152 | } else { | |
153 | while (len--) | |
154 | *new_p++ = *p++ ^ 32; | |
155 | } | |
156 | *new_p = '\0'; | |
157 | SvCUR_set(newkey, SvCUR(keysv)); | |
158 | SvPOK_on(newkey); | |
159 | ||
160 | mg->mg_obj = newkey; | |
161 | } | |
162 | } | |
163 | return 0; | |
164 | } | |
165 | ||
166 | static I32 | |
b54b4831 NC |
167 | rot13_key(pTHX_ IV action, SV *field) { |
168 | MAGIC *mg = mg_find(field, PERL_MAGIC_uvar); | |
169 | SV *keysv; | |
170 | if (mg && (keysv = mg->mg_obj)) { | |
171 | STRLEN len; | |
172 | const char *p = SvPV(keysv, len); | |
173 | ||
174 | if (len) { | |
175 | SV *newkey = newSV(len); | |
176 | char *new_p = SvPVX(newkey); | |
177 | ||
178 | /* There's a deliberate fencepost error here to loop len + 1 times | |
179 | to copy the trailing \0 */ | |
180 | do { | |
181 | char new_c = *p++; | |
182 | /* Try doing this cleanly and clearly in EBCDIC another way: */ | |
183 | switch (new_c) { | |
184 | case 'A': new_c = 'N'; break; | |
185 | case 'B': new_c = 'O'; break; | |
186 | case 'C': new_c = 'P'; break; | |
187 | case 'D': new_c = 'Q'; break; | |
188 | case 'E': new_c = 'R'; break; | |
189 | case 'F': new_c = 'S'; break; | |
190 | case 'G': new_c = 'T'; break; | |
191 | case 'H': new_c = 'U'; break; | |
192 | case 'I': new_c = 'V'; break; | |
193 | case 'J': new_c = 'W'; break; | |
194 | case 'K': new_c = 'X'; break; | |
195 | case 'L': new_c = 'Y'; break; | |
196 | case 'M': new_c = 'Z'; break; | |
197 | case 'N': new_c = 'A'; break; | |
198 | case 'O': new_c = 'B'; break; | |
199 | case 'P': new_c = 'C'; break; | |
200 | case 'Q': new_c = 'D'; break; | |
201 | case 'R': new_c = 'E'; break; | |
202 | case 'S': new_c = 'F'; break; | |
203 | case 'T': new_c = 'G'; break; | |
204 | case 'U': new_c = 'H'; break; | |
205 | case 'V': new_c = 'I'; break; | |
206 | case 'W': new_c = 'J'; break; | |
207 | case 'X': new_c = 'K'; break; | |
208 | case 'Y': new_c = 'L'; break; | |
209 | case 'Z': new_c = 'M'; break; | |
210 | case 'a': new_c = 'n'; break; | |
211 | case 'b': new_c = 'o'; break; | |
212 | case 'c': new_c = 'p'; break; | |
213 | case 'd': new_c = 'q'; break; | |
214 | case 'e': new_c = 'r'; break; | |
215 | case 'f': new_c = 's'; break; | |
216 | case 'g': new_c = 't'; break; | |
217 | case 'h': new_c = 'u'; break; | |
218 | case 'i': new_c = 'v'; break; | |
219 | case 'j': new_c = 'w'; break; | |
220 | case 'k': new_c = 'x'; break; | |
221 | case 'l': new_c = 'y'; break; | |
222 | case 'm': new_c = 'z'; break; | |
223 | case 'n': new_c = 'a'; break; | |
224 | case 'o': new_c = 'b'; break; | |
225 | case 'p': new_c = 'c'; break; | |
226 | case 'q': new_c = 'd'; break; | |
227 | case 'r': new_c = 'e'; break; | |
228 | case 's': new_c = 'f'; break; | |
229 | case 't': new_c = 'g'; break; | |
230 | case 'u': new_c = 'h'; break; | |
231 | case 'v': new_c = 'i'; break; | |
232 | case 'w': new_c = 'j'; break; | |
233 | case 'x': new_c = 'k'; break; | |
234 | case 'y': new_c = 'l'; break; | |
235 | case 'z': new_c = 'm'; break; | |
236 | } | |
237 | *new_p++ = new_c; | |
238 | } while (len--); | |
239 | SvCUR_set(newkey, SvCUR(keysv)); | |
240 | SvPOK_on(newkey); | |
241 | if (SvUTF8(keysv)) | |
242 | SvUTF8_on(newkey); | |
243 | ||
244 | mg->mg_obj = newkey; | |
245 | } | |
246 | } | |
247 | return 0; | |
248 | } | |
249 | ||
218787bd VP |
250 | STATIC I32 |
251 | rmagical_a_dummy(pTHX_ IV idx, SV *sv) { | |
252 | return 0; | |
253 | } | |
254 | ||
255 | STATIC MGVTBL rmagical_b = { 0 }; | |
256 | ||
03569ecf | 257 | STATIC void |
13b6b3bc | 258 | blockhook_csc_start(pTHX_ int full) |
03569ecf BM |
259 | { |
260 | dMY_CXT; | |
261 | AV *const cur = GvAV(MY_CXT.cscgv); | |
262 | ||
263 | SAVEGENERICSV(GvAV(MY_CXT.cscgv)); | |
264 | ||
265 | if (cur) { | |
266 | I32 i; | |
d024465f | 267 | AV *const new_av = newAV(); |
03569ecf BM |
268 | |
269 | for (i = 0; i <= av_len(cur); i++) { | |
d024465f | 270 | av_store(new_av, i, newSVsv(*av_fetch(cur, i, 0))); |
03569ecf BM |
271 | } |
272 | ||
d024465f | 273 | GvAV(MY_CXT.cscgv) = new_av; |
03569ecf BM |
274 | } |
275 | } | |
276 | ||
277 | STATIC void | |
13b6b3bc | 278 | blockhook_csc_pre_end(pTHX_ OP **o) |
03569ecf BM |
279 | { |
280 | dMY_CXT; | |
281 | ||
282 | /* if we hit the end of a scope we missed the start of, we need to | |
283 | * unconditionally clear @CSC */ | |
52db365a | 284 | if (GvAV(MY_CXT.cscgv) == MY_CXT.cscav && MY_CXT.cscav) { |
03569ecf | 285 | av_clear(MY_CXT.cscav); |
52db365a | 286 | } |
03569ecf BM |
287 | |
288 | } | |
289 | ||
13b6b3bc BM |
290 | STATIC void |
291 | blockhook_test_start(pTHX_ int full) | |
292 | { | |
293 | dMY_CXT; | |
294 | AV *av; | |
295 | ||
296 | if (MY_CXT.bhk_record) { | |
297 | av = newAV(); | |
298 | av_push(av, newSVpvs("start")); | |
299 | av_push(av, newSViv(full)); | |
300 | av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av))); | |
301 | } | |
302 | } | |
303 | ||
304 | STATIC void | |
305 | blockhook_test_pre_end(pTHX_ OP **o) | |
306 | { | |
307 | dMY_CXT; | |
308 | ||
309 | if (MY_CXT.bhk_record) | |
310 | av_push(MY_CXT.bhkav, newSVpvs("pre_end")); | |
311 | } | |
312 | ||
313 | STATIC void | |
314 | blockhook_test_post_end(pTHX_ OP **o) | |
315 | { | |
316 | dMY_CXT; | |
317 | ||
318 | if (MY_CXT.bhk_record) | |
319 | av_push(MY_CXT.bhkav, newSVpvs("post_end")); | |
320 | } | |
321 | ||
322 | STATIC void | |
323 | blockhook_test_eval(pTHX_ OP *const o) | |
324 | { | |
325 | dMY_CXT; | |
326 | AV *av; | |
327 | ||
328 | if (MY_CXT.bhk_record) { | |
329 | av = newAV(); | |
330 | av_push(av, newSVpvs("eval")); | |
331 | av_push(av, newSVpv(OP_NAME(o), 0)); | |
332 | av_push(MY_CXT.bhkav, newRV_noinc(MUTABLE_SV(av))); | |
333 | } | |
334 | } | |
335 | ||
336 | STATIC BHK bhk_csc, bhk_test; | |
337 | ||
201c7e1f FR |
338 | STATIC void |
339 | my_peep (pTHX_ OP *o) | |
340 | { | |
341 | dMY_CXT; | |
342 | ||
343 | if (!o) | |
344 | return; | |
345 | ||
346 | MY_CXT.orig_peep(aTHX_ o); | |
347 | ||
348 | if (!MY_CXT.peep_recording) | |
349 | return; | |
350 | ||
351 | for (; o; o = o->op_next) { | |
352 | if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) { | |
353 | av_push(MY_CXT.peep_recorder, newSVsv(cSVOPx_sv(o))); | |
354 | } | |
355 | } | |
356 | } | |
357 | ||
358 | STATIC void | |
359 | my_rpeep (pTHX_ OP *o) | |
360 | { | |
361 | dMY_CXT; | |
362 | ||
363 | if (!o) | |
364 | return; | |
365 | ||
366 | MY_CXT.orig_rpeep(aTHX_ o); | |
367 | ||
368 | if (!MY_CXT.peep_recording) | |
369 | return; | |
370 | ||
371 | for (; o; o = o->op_next) { | |
372 | if (o->op_type == OP_CONST && cSVOPx_sv(o) && SvPOK(cSVOPx_sv(o))) { | |
373 | av_push(MY_CXT.rpeep_recorder, newSVsv(cSVOPx_sv(o))); | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
d9088386 Z |
378 | STATIC OP * |
379 | THX_ck_entersub_args_lists(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) | |
380 | { | |
381 | return ck_entersub_args_list(entersubop); | |
382 | } | |
383 | ||
384 | STATIC OP * | |
385 | THX_ck_entersub_args_scalars(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) | |
386 | { | |
387 | OP *aop = cUNOPx(entersubop)->op_first; | |
388 | if (!aop->op_sibling) | |
389 | aop = cUNOPx(aop)->op_first; | |
390 | for (aop = aop->op_sibling; aop->op_sibling; aop = aop->op_sibling) { | |
391 | op_contextualize(aop, G_SCALAR); | |
392 | } | |
393 | return entersubop; | |
394 | } | |
395 | ||
396 | STATIC OP * | |
397 | THX_ck_entersub_multi_sum(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) | |
398 | { | |
399 | OP *sumop = NULL; | |
400 | OP *pushop = cUNOPx(entersubop)->op_first; | |
401 | if (!pushop->op_sibling) | |
402 | pushop = cUNOPx(pushop)->op_first; | |
403 | while (1) { | |
404 | OP *aop = pushop->op_sibling; | |
405 | if (!aop->op_sibling) | |
406 | break; | |
407 | pushop->op_sibling = aop->op_sibling; | |
408 | aop->op_sibling = NULL; | |
409 | op_contextualize(aop, G_SCALAR); | |
410 | if (sumop) { | |
411 | sumop = newBINOP(OP_ADD, 0, sumop, aop); | |
412 | } else { | |
413 | sumop = aop; | |
414 | } | |
415 | } | |
416 | if (!sumop) | |
417 | sumop = newSVOP(OP_CONST, 0, newSViv(0)); | |
418 | op_free(entersubop); | |
419 | return sumop; | |
420 | } | |
421 | ||
2fcb4757 Z |
422 | STATIC void test_op_list_describe_part(SV *res, OP *o); |
423 | STATIC void | |
424 | test_op_list_describe_part(SV *res, OP *o) | |
425 | { | |
426 | sv_catpv(res, PL_op_name[o->op_type]); | |
427 | switch (o->op_type) { | |
428 | case OP_CONST: { | |
429 | sv_catpvf(res, "(%d)", (int)SvIV(cSVOPx(o)->op_sv)); | |
430 | } break; | |
431 | } | |
432 | if (o->op_flags & OPf_KIDS) { | |
433 | OP *k; | |
434 | sv_catpvs(res, "["); | |
435 | for (k = cUNOPx(o)->op_first; k; k = k->op_sibling) | |
436 | test_op_list_describe_part(res, k); | |
437 | sv_catpvs(res, "]"); | |
438 | } else { | |
439 | sv_catpvs(res, "."); | |
440 | } | |
441 | } | |
442 | ||
443 | STATIC char * | |
444 | test_op_list_describe(OP *o) | |
445 | { | |
446 | SV *res = sv_2mortal(newSVpvs("")); | |
447 | if (o) | |
448 | test_op_list_describe_part(res, o); | |
449 | return SvPVX(res); | |
450 | } | |
451 | ||
5983a79d BM |
452 | /* the real new*OP functions have a tendancy to call fold_constants, and |
453 | * other such unhelpful things, so we need our own versions for testing */ | |
454 | ||
455 | #define mkUNOP(t, f) THX_mkUNOP(aTHX_ (t), (f)) | |
456 | static OP * | |
457 | THX_mkUNOP(pTHX_ U32 type, OP *first) | |
458 | { | |
459 | UNOP *unop; | |
460 | NewOp(1103, unop, 1, UNOP); | |
461 | unop->op_type = (OPCODE)type; | |
462 | unop->op_first = first; | |
463 | unop->op_flags = OPf_KIDS; | |
464 | return (OP *)unop; | |
465 | } | |
466 | ||
467 | #define mkBINOP(t, f, l) THX_mkBINOP(aTHX_ (t), (f), (l)) | |
468 | static OP * | |
469 | THX_mkBINOP(pTHX_ U32 type, OP *first, OP *last) | |
470 | { | |
471 | BINOP *binop; | |
472 | NewOp(1103, binop, 1, BINOP); | |
473 | binop->op_type = (OPCODE)type; | |
474 | binop->op_first = first; | |
475 | binop->op_flags = OPf_KIDS; | |
476 | binop->op_last = last; | |
477 | first->op_sibling = last; | |
478 | return (OP *)binop; | |
479 | } | |
480 | ||
481 | #define mkLISTOP(t, f, s, l) THX_mkLISTOP(aTHX_ (t), (f), (s), (l)) | |
482 | static OP * | |
483 | THX_mkLISTOP(pTHX_ U32 type, OP *first, OP *sib, OP *last) | |
484 | { | |
485 | LISTOP *listop; | |
486 | NewOp(1103, listop, 1, LISTOP); | |
487 | listop->op_type = (OPCODE)type; | |
488 | listop->op_flags = OPf_KIDS; | |
489 | listop->op_first = first; | |
490 | first->op_sibling = sib; | |
491 | sib->op_sibling = last; | |
492 | listop->op_last = last; | |
493 | return (OP *)listop; | |
494 | } | |
495 | ||
496 | static char * | |
497 | test_op_linklist_describe(OP *start) | |
498 | { | |
499 | SV *rv = sv_2mortal(newSVpvs("")); | |
500 | OP *o; | |
501 | o = start = LINKLIST(start); | |
502 | do { | |
503 | sv_catpvs(rv, "."); | |
504 | sv_catpv(rv, OP_NAME(o)); | |
505 | if (o->op_type == OP_CONST) | |
506 | sv_catsv(rv, cSVOPo->op_sv); | |
507 | o = o->op_next; | |
508 | } while (o && o != start); | |
509 | return SvPVX(rv); | |
510 | } | |
511 | ||
8f89e5a9 Z |
512 | /** establish_cleanup operator, ripped off from Scope::Cleanup **/ |
513 | ||
514 | STATIC void | |
515 | THX_run_cleanup(pTHX_ void *cleanup_code_ref) | |
516 | { | |
517 | dSP; | |
518 | ENTER; | |
519 | SAVETMPS; | |
520 | PUSHMARK(SP); | |
521 | call_sv((SV*)cleanup_code_ref, G_VOID|G_DISCARD); | |
522 | FREETMPS; | |
523 | LEAVE; | |
524 | } | |
525 | ||
526 | STATIC OP * | |
527 | THX_pp_establish_cleanup(pTHX) | |
528 | { | |
529 | dSP; | |
530 | SV *cleanup_code_ref; | |
531 | cleanup_code_ref = newSVsv(POPs); | |
532 | SAVEFREESV(cleanup_code_ref); | |
533 | SAVEDESTRUCTOR_X(THX_run_cleanup, cleanup_code_ref); | |
534 | if(GIMME_V != G_VOID) PUSHs(&PL_sv_undef); | |
535 | RETURN; | |
536 | } | |
537 | ||
538 | STATIC OP * | |
539 | THX_ck_entersub_establish_cleanup(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) | |
540 | { | |
541 | OP *pushop, *argop, *estop; | |
542 | ck_entersub_args_proto(entersubop, namegv, ckobj); | |
543 | pushop = cUNOPx(entersubop)->op_first; | |
544 | if(!pushop->op_sibling) pushop = cUNOPx(pushop)->op_first; | |
545 | argop = pushop->op_sibling; | |
546 | pushop->op_sibling = argop->op_sibling; | |
547 | argop->op_sibling = NULL; | |
548 | op_free(entersubop); | |
549 | NewOpSz(0, estop, sizeof(UNOP)); | |
550 | estop->op_type = OP_RAND; | |
551 | estop->op_ppaddr = THX_pp_establish_cleanup; | |
552 | cUNOPx(estop)->op_flags = OPf_KIDS; | |
553 | cUNOPx(estop)->op_first = argop; | |
554 | PL_hints |= HINT_BLOCK_SCOPE; | |
555 | return estop; | |
556 | } | |
557 | ||
3ad73efd Z |
558 | STATIC OP * |
559 | THX_ck_entersub_postinc(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) | |
560 | { | |
561 | OP *pushop, *argop, *estop; | |
562 | ck_entersub_args_proto(entersubop, namegv, ckobj); | |
563 | pushop = cUNOPx(entersubop)->op_first; | |
564 | if(!pushop->op_sibling) pushop = cUNOPx(pushop)->op_first; | |
565 | argop = pushop->op_sibling; | |
566 | pushop->op_sibling = argop->op_sibling; | |
567 | argop->op_sibling = NULL; | |
568 | op_free(entersubop); | |
569 | return newUNOP(OP_POSTINC, 0, | |
570 | op_lvalue(op_contextualize(argop, G_SCALAR), OP_POSTINC)); | |
571 | } | |
572 | ||
83f8bb56 Z |
573 | /** RPN keyword parser **/ |
574 | ||
575 | #define sv_is_glob(sv) (SvTYPE(sv) == SVt_PVGV) | |
576 | #define sv_is_regexp(sv) (SvTYPE(sv) == SVt_REGEXP) | |
577 | #define sv_is_string(sv) \ | |
578 | (!sv_is_glob(sv) && !sv_is_regexp(sv) && \ | |
579 | (SvFLAGS(sv) & (SVf_IOK|SVf_NOK|SVf_POK|SVp_IOK|SVp_NOK|SVp_POK))) | |
580 | ||
581 | static SV *hintkey_rpn_sv, *hintkey_calcrpn_sv, *hintkey_stufftest_sv; | |
07ffcb73 | 582 | static SV *hintkey_swaptwostmts_sv, *hintkey_looprest_sv; |
a7aaec61 | 583 | static SV *hintkey_scopelessblock_sv; |
e53d8f76 Z |
584 | static SV *hintkey_stmtasexpr_sv, *hintkey_stmtsasexpr_sv; |
585 | static SV *hintkey_loopblock_sv, *hintkey_blockasexpr_sv; | |
361d9b55 | 586 | static SV *hintkey_swaplabel_sv, *hintkey_labelconst_sv; |
83f8bb56 Z |
587 | static int (*next_keyword_plugin)(pTHX_ char *, STRLEN, OP **); |
588 | ||
589 | /* low-level parser helpers */ | |
590 | ||
591 | #define PL_bufptr (PL_parser->bufptr) | |
592 | #define PL_bufend (PL_parser->bufend) | |
593 | ||
594 | /* RPN parser */ | |
595 | ||
596 | #define parse_var() THX_parse_var(aTHX) | |
597 | static OP *THX_parse_var(pTHX) | |
598 | { | |
599 | char *s = PL_bufptr; | |
600 | char *start = s; | |
601 | PADOFFSET varpos; | |
602 | OP *padop; | |
603 | if(*s != '$') croak("RPN syntax error"); | |
604 | while(1) { | |
605 | char c = *++s; | |
606 | if(!isALNUM(c)) break; | |
607 | } | |
608 | if(s-start < 2) croak("RPN syntax error"); | |
609 | lex_read_to(s); | |
610 | { | |
611 | /* because pad_findmy() doesn't really use length yet */ | |
612 | SV *namesv = sv_2mortal(newSVpvn(start, s-start)); | |
613 | varpos = pad_findmy(SvPVX(namesv), s-start, 0); | |
614 | } | |
615 | if(varpos == NOT_IN_PAD || PAD_COMPNAME_FLAGS_isOUR(varpos)) | |
616 | croak("RPN only supports \"my\" variables"); | |
617 | padop = newOP(OP_PADSV, 0); | |
618 | padop->op_targ = varpos; | |
619 | return padop; | |
620 | } | |
621 | ||
622 | #define push_rpn_item(o) \ | |
623 | (tmpop = (o), tmpop->op_sibling = stack, stack = tmpop) | |
624 | #define pop_rpn_item() \ | |
625 | (!stack ? (croak("RPN stack underflow"), (OP*)NULL) : \ | |
626 | (tmpop = stack, stack = stack->op_sibling, \ | |
627 | tmpop->op_sibling = NULL, tmpop)) | |
628 | ||
629 | #define parse_rpn_expr() THX_parse_rpn_expr(aTHX) | |
630 | static OP *THX_parse_rpn_expr(pTHX) | |
631 | { | |
632 | OP *stack = NULL, *tmpop; | |
633 | while(1) { | |
634 | I32 c; | |
635 | lex_read_space(0); | |
636 | c = lex_peek_unichar(0); | |
637 | switch(c) { | |
638 | case /*(*/')': case /*{*/'}': { | |
639 | OP *result = pop_rpn_item(); | |
640 | if(stack) croak("RPN expression must return a single value"); | |
641 | return result; | |
642 | } break; | |
643 | case '0': case '1': case '2': case '3': case '4': | |
644 | case '5': case '6': case '7': case '8': case '9': { | |
645 | UV val = 0; | |
646 | do { | |
647 | lex_read_unichar(0); | |
648 | val = 10*val + (c - '0'); | |
649 | c = lex_peek_unichar(0); | |
650 | } while(c >= '0' && c <= '9'); | |
651 | push_rpn_item(newSVOP(OP_CONST, 0, newSVuv(val))); | |
652 | } break; | |
653 | case '$': { | |
654 | push_rpn_item(parse_var()); | |
655 | } break; | |
656 | case '+': { | |
657 | OP *b = pop_rpn_item(); | |
658 | OP *a = pop_rpn_item(); | |
659 | lex_read_unichar(0); | |
660 | push_rpn_item(newBINOP(OP_I_ADD, 0, a, b)); | |
661 | } break; | |
662 | case '-': { | |
663 | OP *b = pop_rpn_item(); | |
664 | OP *a = pop_rpn_item(); | |
665 | lex_read_unichar(0); | |
666 | push_rpn_item(newBINOP(OP_I_SUBTRACT, 0, a, b)); | |
667 | } break; | |
668 | case '*': { | |
669 | OP *b = pop_rpn_item(); | |
670 | OP *a = pop_rpn_item(); | |
671 | lex_read_unichar(0); | |
672 | push_rpn_item(newBINOP(OP_I_MULTIPLY, 0, a, b)); | |
673 | } break; | |
674 | case '/': { | |
675 | OP *b = pop_rpn_item(); | |
676 | OP *a = pop_rpn_item(); | |
677 | lex_read_unichar(0); | |
678 | push_rpn_item(newBINOP(OP_I_DIVIDE, 0, a, b)); | |
679 | } break; | |
680 | case '%': { | |
681 | OP *b = pop_rpn_item(); | |
682 | OP *a = pop_rpn_item(); | |
683 | lex_read_unichar(0); | |
684 | push_rpn_item(newBINOP(OP_I_MODULO, 0, a, b)); | |
685 | } break; | |
686 | default: { | |
687 | croak("RPN syntax error"); | |
688 | } break; | |
689 | } | |
690 | } | |
691 | } | |
692 | ||
693 | #define parse_keyword_rpn() THX_parse_keyword_rpn(aTHX) | |
694 | static OP *THX_parse_keyword_rpn(pTHX) | |
695 | { | |
696 | OP *op; | |
697 | lex_read_space(0); | |
698 | if(lex_peek_unichar(0) != '('/*)*/) | |
699 | croak("RPN expression must be parenthesised"); | |
700 | lex_read_unichar(0); | |
701 | op = parse_rpn_expr(); | |
702 | if(lex_peek_unichar(0) != /*(*/')') | |
703 | croak("RPN expression must be parenthesised"); | |
704 | lex_read_unichar(0); | |
705 | return op; | |
706 | } | |
707 | ||
708 | #define parse_keyword_calcrpn() THX_parse_keyword_calcrpn(aTHX) | |
709 | static OP *THX_parse_keyword_calcrpn(pTHX) | |
710 | { | |
711 | OP *varop, *exprop; | |
712 | lex_read_space(0); | |
713 | varop = parse_var(); | |
714 | lex_read_space(0); | |
715 | if(lex_peek_unichar(0) != '{'/*}*/) | |
716 | croak("RPN expression must be braced"); | |
717 | lex_read_unichar(0); | |
718 | exprop = parse_rpn_expr(); | |
719 | if(lex_peek_unichar(0) != /*{*/'}') | |
720 | croak("RPN expression must be braced"); | |
721 | lex_read_unichar(0); | |
722 | return newASSIGNOP(OPf_STACKED, varop, 0, exprop); | |
723 | } | |
724 | ||
725 | #define parse_keyword_stufftest() THX_parse_keyword_stufftest(aTHX) | |
726 | static OP *THX_parse_keyword_stufftest(pTHX) | |
727 | { | |
728 | I32 c; | |
729 | bool do_stuff; | |
730 | lex_read_space(0); | |
731 | do_stuff = lex_peek_unichar(0) == '+'; | |
732 | if(do_stuff) { | |
733 | lex_read_unichar(0); | |
734 | lex_read_space(0); | |
735 | } | |
736 | c = lex_peek_unichar(0); | |
737 | if(c == ';') { | |
738 | lex_read_unichar(0); | |
739 | } else if(c != /*{*/'}') { | |
740 | croak("syntax error"); | |
741 | } | |
742 | if(do_stuff) lex_stuff_pvs(" ", 0); | |
743 | return newOP(OP_NULL, 0); | |
744 | } | |
745 | ||
746 | #define parse_keyword_swaptwostmts() THX_parse_keyword_swaptwostmts(aTHX) | |
747 | static OP *THX_parse_keyword_swaptwostmts(pTHX) | |
748 | { | |
749 | OP *a, *b; | |
750 | a = parse_fullstmt(0); | |
751 | b = parse_fullstmt(0); | |
752 | if(a && b) | |
753 | PL_hints |= HINT_BLOCK_SCOPE; | |
2fcb4757 | 754 | return op_append_list(OP_LINESEQ, b, a); |
83f8bb56 Z |
755 | } |
756 | ||
07ffcb73 Z |
757 | #define parse_keyword_looprest() THX_parse_keyword_looprest(aTHX) |
758 | static OP *THX_parse_keyword_looprest(pTHX) | |
759 | { | |
94bf0465 Z |
760 | return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes), |
761 | parse_stmtseq(0), NULL, 1); | |
07ffcb73 Z |
762 | } |
763 | ||
a7aaec61 Z |
764 | #define parse_keyword_scopelessblock() THX_parse_keyword_scopelessblock(aTHX) |
765 | static OP *THX_parse_keyword_scopelessblock(pTHX) | |
766 | { | |
767 | I32 c; | |
768 | OP *body; | |
769 | lex_read_space(0); | |
770 | if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error"); | |
771 | lex_read_unichar(0); | |
772 | body = parse_stmtseq(0); | |
773 | c = lex_peek_unichar(0); | |
774 | if(c != /*{*/'}' && c != /*[*/']' && c != /*(*/')') croak("syntax error"); | |
775 | lex_read_unichar(0); | |
776 | return body; | |
777 | } | |
778 | ||
9eb5c532 Z |
779 | #define parse_keyword_stmtasexpr() THX_parse_keyword_stmtasexpr(aTHX) |
780 | static OP *THX_parse_keyword_stmtasexpr(pTHX) | |
781 | { | |
8359b381 | 782 | OP *o = parse_barestmt(0); |
3ad73efd Z |
783 | if (!o) o = newOP(OP_STUB, 0); |
784 | if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS; | |
785 | return op_scope(o); | |
9eb5c532 Z |
786 | } |
787 | ||
788 | #define parse_keyword_stmtsasexpr() THX_parse_keyword_stmtsasexpr(aTHX) | |
789 | static OP *THX_parse_keyword_stmtsasexpr(pTHX) | |
790 | { | |
791 | OP *o; | |
792 | lex_read_space(0); | |
793 | if(lex_peek_unichar(0) != '{'/*}*/) croak("syntax error"); | |
794 | lex_read_unichar(0); | |
795 | o = parse_stmtseq(0); | |
796 | lex_read_space(0); | |
797 | if(lex_peek_unichar(0) != /*{*/'}') croak("syntax error"); | |
798 | lex_read_unichar(0); | |
3ad73efd Z |
799 | if (!o) o = newOP(OP_STUB, 0); |
800 | if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS; | |
801 | return op_scope(o); | |
9eb5c532 Z |
802 | } |
803 | ||
e53d8f76 Z |
804 | #define parse_keyword_loopblock() THX_parse_keyword_loopblock(aTHX) |
805 | static OP *THX_parse_keyword_loopblock(pTHX) | |
806 | { | |
94bf0465 Z |
807 | return newWHILEOP(0, 1, NULL, newSVOP(OP_CONST, 0, &PL_sv_yes), |
808 | parse_block(0), NULL, 1); | |
e53d8f76 Z |
809 | } |
810 | ||
811 | #define parse_keyword_blockasexpr() THX_parse_keyword_blockasexpr(aTHX) | |
812 | static OP *THX_parse_keyword_blockasexpr(pTHX) | |
813 | { | |
814 | OP *o = parse_block(0); | |
3ad73efd Z |
815 | if (!o) o = newOP(OP_STUB, 0); |
816 | if (PL_hints & HINT_BLOCK_SCOPE) o->op_flags |= OPf_PARENS; | |
817 | return op_scope(o); | |
e53d8f76 Z |
818 | } |
819 | ||
361d9b55 Z |
820 | #define parse_keyword_swaplabel() THX_parse_keyword_swaplabel(aTHX) |
821 | static OP *THX_parse_keyword_swaplabel(pTHX) | |
822 | { | |
823 | OP *sop = parse_barestmt(0); | |
824 | SV *label = parse_label(PARSE_OPTIONAL); | |
825 | if (label) sv_2mortal(label); | |
826 | return newSTATEOP(0, label ? savepv(SvPVX(label)) : NULL, sop); | |
827 | } | |
828 | ||
829 | #define parse_keyword_labelconst() THX_parse_keyword_labelconst(aTHX) | |
830 | static OP *THX_parse_keyword_labelconst(pTHX) | |
831 | { | |
832 | return newSVOP(OP_CONST, 0, parse_label(0)); | |
833 | } | |
834 | ||
83f8bb56 Z |
835 | /* plugin glue */ |
836 | ||
837 | #define keyword_active(hintkey_sv) THX_keyword_active(aTHX_ hintkey_sv) | |
838 | static int THX_keyword_active(pTHX_ SV *hintkey_sv) | |
839 | { | |
840 | HE *he; | |
841 | if(!GvHV(PL_hintgv)) return 0; | |
842 | he = hv_fetch_ent(GvHV(PL_hintgv), hintkey_sv, 0, | |
843 | SvSHARED_HASH(hintkey_sv)); | |
844 | return he && SvTRUE(HeVAL(he)); | |
845 | } | |
846 | ||
847 | static int my_keyword_plugin(pTHX_ | |
848 | char *keyword_ptr, STRLEN keyword_len, OP **op_ptr) | |
849 | { | |
850 | if(keyword_len == 3 && strnEQ(keyword_ptr, "rpn", 3) && | |
851 | keyword_active(hintkey_rpn_sv)) { | |
852 | *op_ptr = parse_keyword_rpn(); | |
853 | return KEYWORD_PLUGIN_EXPR; | |
854 | } else if(keyword_len == 7 && strnEQ(keyword_ptr, "calcrpn", 7) && | |
855 | keyword_active(hintkey_calcrpn_sv)) { | |
856 | *op_ptr = parse_keyword_calcrpn(); | |
857 | return KEYWORD_PLUGIN_STMT; | |
858 | } else if(keyword_len == 9 && strnEQ(keyword_ptr, "stufftest", 9) && | |
859 | keyword_active(hintkey_stufftest_sv)) { | |
860 | *op_ptr = parse_keyword_stufftest(); | |
861 | return KEYWORD_PLUGIN_STMT; | |
862 | } else if(keyword_len == 12 && | |
863 | strnEQ(keyword_ptr, "swaptwostmts", 12) && | |
864 | keyword_active(hintkey_swaptwostmts_sv)) { | |
865 | *op_ptr = parse_keyword_swaptwostmts(); | |
866 | return KEYWORD_PLUGIN_STMT; | |
07ffcb73 Z |
867 | } else if(keyword_len == 8 && strnEQ(keyword_ptr, "looprest", 8) && |
868 | keyword_active(hintkey_looprest_sv)) { | |
869 | *op_ptr = parse_keyword_looprest(); | |
870 | return KEYWORD_PLUGIN_STMT; | |
a7aaec61 Z |
871 | } else if(keyword_len == 14 && strnEQ(keyword_ptr, "scopelessblock", 14) && |
872 | keyword_active(hintkey_scopelessblock_sv)) { | |
873 | *op_ptr = parse_keyword_scopelessblock(); | |
874 | return KEYWORD_PLUGIN_STMT; | |
9eb5c532 Z |
875 | } else if(keyword_len == 10 && strnEQ(keyword_ptr, "stmtasexpr", 10) && |
876 | keyword_active(hintkey_stmtasexpr_sv)) { | |
877 | *op_ptr = parse_keyword_stmtasexpr(); | |
878 | return KEYWORD_PLUGIN_EXPR; | |
879 | } else if(keyword_len == 11 && strnEQ(keyword_ptr, "stmtsasexpr", 11) && | |
880 | keyword_active(hintkey_stmtsasexpr_sv)) { | |
881 | *op_ptr = parse_keyword_stmtsasexpr(); | |
882 | return KEYWORD_PLUGIN_EXPR; | |
e53d8f76 Z |
883 | } else if(keyword_len == 9 && strnEQ(keyword_ptr, "loopblock", 9) && |
884 | keyword_active(hintkey_loopblock_sv)) { | |
885 | *op_ptr = parse_keyword_loopblock(); | |
886 | return KEYWORD_PLUGIN_STMT; | |
887 | } else if(keyword_len == 11 && strnEQ(keyword_ptr, "blockasexpr", 11) && | |
888 | keyword_active(hintkey_blockasexpr_sv)) { | |
889 | *op_ptr = parse_keyword_blockasexpr(); | |
890 | return KEYWORD_PLUGIN_EXPR; | |
361d9b55 Z |
891 | } else if(keyword_len == 9 && strnEQ(keyword_ptr, "swaplabel", 9) && |
892 | keyword_active(hintkey_swaplabel_sv)) { | |
893 | *op_ptr = parse_keyword_swaplabel(); | |
894 | return KEYWORD_PLUGIN_STMT; | |
895 | } else if(keyword_len == 10 && strnEQ(keyword_ptr, "labelconst", 10) && | |
896 | keyword_active(hintkey_labelconst_sv)) { | |
897 | *op_ptr = parse_keyword_labelconst(); | |
898 | return KEYWORD_PLUGIN_EXPR; | |
83f8bb56 Z |
899 | } else { |
900 | return next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr); | |
901 | } | |
902 | } | |
903 | ||
7b20c7cd | 904 | XS(XS_XS__APItest__XSUB_XS_VERSION_undef); |
f9cc56fa | 905 | XS(XS_XS__APItest__XSUB_XS_VERSION_empty); |
88c4b02d | 906 | XS(XS_XS__APItest__XSUB_XS_APIVERSION_invalid); |
7b20c7cd | 907 | |
55289a74 NC |
908 | #include "const-c.inc" |
909 | ||
ffe53d21 | 910 | MODULE = XS::APItest PACKAGE = XS::APItest |
0314122a | 911 | |
55289a74 NC |
912 | INCLUDE: const-xs.inc |
913 | ||
ffe53d21 NC |
914 | INCLUDE: numeric.xs |
915 | ||
7d255dc8 NC |
916 | MODULE = XS::APItest:Overload PACKAGE = XS::APItest::Overload |
917 | ||
918 | SV * | |
919 | tryAMAGICunDEREF_var(sv, what) | |
920 | SV *sv | |
921 | int what | |
922 | PPCODE: | |
923 | { | |
924 | SV **sp = &sv; | |
925 | tryAMAGICunDEREF_var(what); | |
926 | } | |
927 | /* The reference is owned by something else. */ | |
928 | PUSHs(sv); | |
929 | ||
7b20c7cd NC |
930 | MODULE = XS::APItest PACKAGE = XS::APItest::XSUB |
931 | ||
932 | BOOT: | |
933 | newXS("XS::APItest::XSUB::XS_VERSION_undef", XS_XS__APItest__XSUB_XS_VERSION_undef, __FILE__); | |
f9cc56fa | 934 | newXS("XS::APItest::XSUB::XS_VERSION_empty", XS_XS__APItest__XSUB_XS_VERSION_empty, __FILE__); |
88c4b02d | 935 | newXS("XS::APItest::XSUB::XS_APIVERSION_invalid", XS_XS__APItest__XSUB_XS_APIVERSION_invalid, __FILE__); |
7b20c7cd NC |
936 | |
937 | void | |
938 | XS_VERSION_defined(...) | |
939 | PPCODE: | |
940 | XS_VERSION_BOOTCHECK; | |
941 | XSRETURN_EMPTY; | |
942 | ||
88c4b02d NC |
943 | void |
944 | XS_APIVERSION_valid(...) | |
945 | PPCODE: | |
946 | XS_APIVERSION_BOOTCHECK; | |
947 | XSRETURN_EMPTY; | |
948 | ||
ffe53d21 NC |
949 | MODULE = XS::APItest:Hash PACKAGE = XS::APItest::Hash |
950 | ||
b54b4831 NC |
951 | void |
952 | rot13_hash(hash) | |
953 | HV *hash | |
954 | CODE: | |
955 | { | |
956 | struct ufuncs uf; | |
957 | uf.uf_val = rot13_key; | |
958 | uf.uf_set = 0; | |
959 | uf.uf_index = 0; | |
960 | ||
961 | sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf)); | |
962 | } | |
963 | ||
53c40a8f NC |
964 | void |
965 | bitflip_hash(hash) | |
966 | HV *hash | |
967 | CODE: | |
968 | { | |
969 | struct ufuncs uf; | |
970 | uf.uf_val = bitflip_key; | |
971 | uf.uf_set = 0; | |
972 | uf.uf_index = 0; | |
973 | ||
974 | sv_magic((SV*)hash, NULL, PERL_MAGIC_uvar, (char*)&uf, sizeof(uf)); | |
975 | } | |
976 | ||
028f8eaa MHM |
977 | #define UTF8KLEN(sv, len) (SvUTF8(sv) ? -(I32)len : (I32)len) |
978 | ||
0314122a NC |
979 | bool |
980 | exists(hash, key_sv) | |
981 | PREINIT: | |
982 | STRLEN len; | |
983 | const char *key; | |
984 | INPUT: | |
985 | HV *hash | |
986 | SV *key_sv | |
987 | CODE: | |
988 | key = SvPV(key_sv, len); | |
028f8eaa | 989 | RETVAL = hv_exists(hash, key, UTF8KLEN(key_sv, len)); |
0314122a NC |
990 | OUTPUT: |
991 | RETVAL | |
992 | ||
bdee33e4 NC |
993 | bool |
994 | exists_ent(hash, key_sv) | |
995 | PREINIT: | |
996 | INPUT: | |
997 | HV *hash | |
998 | SV *key_sv | |
999 | CODE: | |
1000 | RETVAL = hv_exists_ent(hash, key_sv, 0); | |
1001 | OUTPUT: | |
1002 | RETVAL | |
1003 | ||
b60cf05a | 1004 | SV * |
55289a74 | 1005 | delete(hash, key_sv, flags = 0) |
b60cf05a NC |
1006 | PREINIT: |
1007 | STRLEN len; | |
1008 | const char *key; | |
1009 | INPUT: | |
1010 | HV *hash | |
1011 | SV *key_sv | |
55289a74 | 1012 | I32 flags; |
b60cf05a NC |
1013 | CODE: |
1014 | key = SvPV(key_sv, len); | |
1015 | /* It's already mortal, so need to increase reference count. */ | |
55289a74 NC |
1016 | RETVAL |
1017 | = SvREFCNT_inc(hv_delete(hash, key, UTF8KLEN(key_sv, len), flags)); | |
1018 | OUTPUT: | |
1019 | RETVAL | |
1020 | ||
1021 | SV * | |
1022 | delete_ent(hash, key_sv, flags = 0) | |
1023 | INPUT: | |
1024 | HV *hash | |
1025 | SV *key_sv | |
1026 | I32 flags; | |
1027 | CODE: | |
1028 | /* It's already mortal, so need to increase reference count. */ | |
1029 | RETVAL = SvREFCNT_inc(hv_delete_ent(hash, key_sv, flags, 0)); | |
b60cf05a NC |
1030 | OUTPUT: |
1031 | RETVAL | |
1032 | ||
1033 | SV * | |
858117f8 NC |
1034 | store_ent(hash, key, value) |
1035 | PREINIT: | |
1036 | SV *copy; | |
1037 | HE *result; | |
1038 | INPUT: | |
1039 | HV *hash | |
1040 | SV *key | |
1041 | SV *value | |
1042 | CODE: | |
1043 | copy = newSV(0); | |
1044 | result = hv_store_ent(hash, key, copy, 0); | |
1045 | SvSetMagicSV(copy, value); | |
1046 | if (!result) { | |
1047 | SvREFCNT_dec(copy); | |
1048 | XSRETURN_EMPTY; | |
1049 | } | |
1050 | /* It's about to become mortal, so need to increase reference count. | |
1051 | */ | |
1052 | RETVAL = SvREFCNT_inc(HeVAL(result)); | |
1053 | OUTPUT: | |
1054 | RETVAL | |
1055 | ||
858117f8 | 1056 | SV * |
b60cf05a NC |
1057 | store(hash, key_sv, value) |
1058 | PREINIT: | |
1059 | STRLEN len; | |
1060 | const char *key; | |
1061 | SV *copy; | |
1062 | SV **result; | |
1063 | INPUT: | |
1064 | HV *hash | |
1065 | SV *key_sv | |
1066 | SV *value | |
1067 | CODE: | |
1068 | key = SvPV(key_sv, len); | |
1069 | copy = newSV(0); | |
028f8eaa | 1070 | result = hv_store(hash, key, UTF8KLEN(key_sv, len), copy, 0); |
858117f8 | 1071 | SvSetMagicSV(copy, value); |
b60cf05a NC |
1072 | if (!result) { |
1073 | SvREFCNT_dec(copy); | |
1074 | XSRETURN_EMPTY; | |
1075 | } | |
1076 | /* It's about to become mortal, so need to increase reference count. | |
1077 | */ | |
1078 | RETVAL = SvREFCNT_inc(*result); | |
1079 | OUTPUT: | |
1080 | RETVAL | |
1081 | ||
bdee33e4 NC |
1082 | SV * |
1083 | fetch_ent(hash, key_sv) | |
1084 | PREINIT: | |
1085 | HE *result; | |
1086 | INPUT: | |
1087 | HV *hash | |
1088 | SV *key_sv | |
1089 | CODE: | |
1090 | result = hv_fetch_ent(hash, key_sv, 0, 0); | |
1091 | if (!result) { | |
1092 | XSRETURN_EMPTY; | |
1093 | } | |
1094 | /* Force mg_get */ | |
1095 | RETVAL = newSVsv(HeVAL(result)); | |
1096 | OUTPUT: | |
1097 | RETVAL | |
b60cf05a NC |
1098 | |
1099 | SV * | |
1100 | fetch(hash, key_sv) | |
1101 | PREINIT: | |
1102 | STRLEN len; | |
1103 | const char *key; | |
1104 | SV **result; | |
1105 | INPUT: | |
1106 | HV *hash | |
1107 | SV *key_sv | |
1108 | CODE: | |
1109 | key = SvPV(key_sv, len); | |
028f8eaa | 1110 | result = hv_fetch(hash, key, UTF8KLEN(key_sv, len), 0); |
b60cf05a NC |
1111 | if (!result) { |
1112 | XSRETURN_EMPTY; | |
1113 | } | |
1114 | /* Force mg_get */ | |
1115 | RETVAL = newSVsv(*result); | |
1116 | OUTPUT: | |
1117 | RETVAL | |
2dc92170 | 1118 | |
9568a123 NC |
1119 | #if defined (hv_common) |
1120 | ||
6b4de907 NC |
1121 | SV * |
1122 | common(params) | |
1123 | INPUT: | |
1124 | HV *params | |
1125 | PREINIT: | |
1126 | HE *result; | |
1127 | HV *hv = NULL; | |
1128 | SV *keysv = NULL; | |
1129 | const char *key = NULL; | |
1130 | STRLEN klen = 0; | |
1131 | int flags = 0; | |
1132 | int action = 0; | |
1133 | SV *val = NULL; | |
1134 | U32 hash = 0; | |
1135 | SV **svp; | |
1136 | CODE: | |
1137 | if ((svp = hv_fetchs(params, "hv", 0))) { | |
1138 | SV *const rv = *svp; | |
1139 | if (!SvROK(rv)) | |
1140 | croak("common passed a non-reference for parameter hv"); | |
1141 | hv = (HV *)SvRV(rv); | |
1142 | } | |
1143 | if ((svp = hv_fetchs(params, "keysv", 0))) | |
1144 | keysv = *svp; | |
1145 | if ((svp = hv_fetchs(params, "keypv", 0))) { | |
1146 | key = SvPV_const(*svp, klen); | |
1147 | if (SvUTF8(*svp)) | |
1148 | flags = HVhek_UTF8; | |
1149 | } | |
1150 | if ((svp = hv_fetchs(params, "action", 0))) | |
1151 | action = SvIV(*svp); | |
1152 | if ((svp = hv_fetchs(params, "val", 0))) | |
527df579 | 1153 | val = newSVsv(*svp); |
6b4de907 | 1154 | if ((svp = hv_fetchs(params, "hash", 0))) |
a44093a9 | 1155 | hash = SvUV(*svp); |
6b4de907 | 1156 | |
527df579 NC |
1157 | if ((svp = hv_fetchs(params, "hash_pv", 0))) { |
1158 | PERL_HASH(hash, key, klen); | |
1159 | } | |
58ca560a NC |
1160 | if ((svp = hv_fetchs(params, "hash_sv", 0))) { |
1161 | STRLEN len; | |
1162 | const char *const p = SvPV(keysv, len); | |
1163 | PERL_HASH(hash, p, len); | |
1164 | } | |
527df579 | 1165 | |
a75fcbca | 1166 | result = (HE *)hv_common(hv, keysv, key, klen, flags, action, val, hash); |
6b4de907 NC |
1167 | if (!result) { |
1168 | XSRETURN_EMPTY; | |
1169 | } | |
1170 | /* Force mg_get */ | |
1171 | RETVAL = newSVsv(HeVAL(result)); | |
1172 | OUTPUT: | |
1173 | RETVAL | |
1174 | ||
9568a123 NC |
1175 | #endif |
1176 | ||
439efdfe | 1177 | void |
2dc92170 NC |
1178 | test_hv_free_ent() |
1179 | PPCODE: | |
1180 | test_freeent(&Perl_hv_free_ent); | |
1181 | XSRETURN(4); | |
1182 | ||
439efdfe | 1183 | void |
2dc92170 NC |
1184 | test_hv_delayfree_ent() |
1185 | PPCODE: | |
1186 | test_freeent(&Perl_hv_delayfree_ent); | |
1187 | XSRETURN(4); | |
35ab5632 NC |
1188 | |
1189 | SV * | |
1190 | test_share_unshare_pvn(input) | |
1191 | PREINIT: | |
35ab5632 NC |
1192 | STRLEN len; |
1193 | U32 hash; | |
1194 | char *pvx; | |
1195 | char *p; | |
1196 | INPUT: | |
1197 | SV *input | |
1198 | CODE: | |
1199 | pvx = SvPV(input, len); | |
1200 | PERL_HASH(hash, pvx, len); | |
1201 | p = sharepvn(pvx, len, hash); | |
1202 | RETVAL = newSVpvn(p, len); | |
1203 | unsharepvn(p, len, hash); | |
1204 | OUTPUT: | |
1205 | RETVAL | |
d8c5b3c5 | 1206 | |
9568a123 NC |
1207 | #if PERL_VERSION >= 9 |
1208 | ||
d8c5b3c5 NC |
1209 | bool |
1210 | refcounted_he_exists(key, level=0) | |
1211 | SV *key | |
1212 | IV level | |
1213 | CODE: | |
1214 | if (level) { | |
1215 | croak("level must be zero, not %"IVdf, level); | |
1216 | } | |
20439bc7 | 1217 | RETVAL = (cop_hints_fetch_sv(PL_curcop, key, 0, 0) != &PL_sv_placeholder); |
d8c5b3c5 NC |
1218 | OUTPUT: |
1219 | RETVAL | |
1220 | ||
d8c5b3c5 NC |
1221 | SV * |
1222 | refcounted_he_fetch(key, level=0) | |
1223 | SV *key | |
1224 | IV level | |
1225 | CODE: | |
1226 | if (level) { | |
1227 | croak("level must be zero, not %"IVdf, level); | |
1228 | } | |
20439bc7 | 1229 | RETVAL = cop_hints_fetch_sv(PL_curcop, key, 0, 0); |
d8c5b3c5 NC |
1230 | SvREFCNT_inc(RETVAL); |
1231 | OUTPUT: | |
1232 | RETVAL | |
65bfe90c | 1233 | |
9568a123 | 1234 | #endif |
65bfe90c | 1235 | |
0314122a NC |
1236 | =pod |
1237 | ||
1238 | sub TIEHASH { bless {}, $_[0] } | |
1239 | sub STORE { $_[0]->{$_[1]} = $_[2] } | |
1240 | sub FETCH { $_[0]->{$_[1]} } | |
1241 | sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} } | |
1242 | sub NEXTKEY { each %{$_[0]} } | |
1243 | sub EXISTS { exists $_[0]->{$_[1]} } | |
1244 | sub DELETE { delete $_[0]->{$_[1]} } | |
1245 | sub CLEAR { %{$_[0]} = () } | |
1246 | ||
1247 | =cut | |
1248 | ||
e2fe06dd EB |
1249 | MODULE = XS::APItest:TempLv PACKAGE = XS::APItest::TempLv |
1250 | ||
1251 | void | |
1252 | make_temp_mg_lv(sv) | |
1253 | SV* sv | |
1254 | PREINIT: | |
1255 | SV * const lv = newSV_type(SVt_PVLV); | |
1256 | STRLEN len; | |
1257 | PPCODE: | |
1258 | SvPV(sv, len); | |
1259 | ||
1260 | sv_magic(lv, NULL, PERL_MAGIC_substr, NULL, 0); | |
1261 | LvTYPE(lv) = 'x'; | |
1262 | LvTARG(lv) = SvREFCNT_inc_simple(sv); | |
1263 | LvTARGOFF(lv) = len == 0 ? 0 : 1; | |
1264 | LvTARGLEN(lv) = len < 2 ? 0 : len-2; | |
1265 | ||
1266 | EXTEND(SP, 1); | |
1267 | ST(0) = sv_2mortal(lv); | |
1268 | XSRETURN(1); | |
1269 | ||
1270 | ||
36c2b1d0 NC |
1271 | MODULE = XS::APItest::PtrTable PACKAGE = XS::APItest::PtrTable PREFIX = ptr_table_ |
1272 | ||
1273 | void | |
1274 | ptr_table_new(classname) | |
1275 | const char * classname | |
1276 | PPCODE: | |
1277 | PUSHs(sv_setref_pv(sv_newmortal(), classname, (void*)ptr_table_new())); | |
1278 | ||
1279 | void | |
1280 | DESTROY(table) | |
1281 | XS::APItest::PtrTable table | |
1282 | CODE: | |
1283 | ptr_table_free(table); | |
1284 | ||
1285 | void | |
992b2363 | 1286 | ptr_table_store(table, from, to) |
36c2b1d0 | 1287 | XS::APItest::PtrTable table |
992b2363 NC |
1288 | SVREF from |
1289 | SVREF to | |
36c2b1d0 | 1290 | CODE: |
992b2363 | 1291 | ptr_table_store(table, from, to); |
36c2b1d0 NC |
1292 | |
1293 | UV | |
992b2363 | 1294 | ptr_table_fetch(table, from) |
36c2b1d0 | 1295 | XS::APItest::PtrTable table |
992b2363 | 1296 | SVREF from |
36c2b1d0 | 1297 | CODE: |
992b2363 | 1298 | RETVAL = PTR2UV(ptr_table_fetch(table, from)); |
36c2b1d0 NC |
1299 | OUTPUT: |
1300 | RETVAL | |
1301 | ||
1302 | void | |
1303 | ptr_table_split(table) | |
1304 | XS::APItest::PtrTable table | |
1305 | ||
1306 | void | |
1307 | ptr_table_clear(table) | |
1308 | XS::APItest::PtrTable table | |
1309 | ||
3e61d65a JH |
1310 | MODULE = XS::APItest PACKAGE = XS::APItest |
1311 | ||
1312 | PROTOTYPES: DISABLE | |
1313 | ||
85ce96a1 DM |
1314 | BOOT: |
1315 | { | |
1316 | MY_CXT_INIT; | |
03569ecf | 1317 | |
85ce96a1 DM |
1318 | MY_CXT.i = 99; |
1319 | MY_CXT.sv = newSVpv("initial",0); | |
13b6b3bc BM |
1320 | |
1321 | MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI); | |
1322 | MY_CXT.bhk_record = 0; | |
1323 | ||
a88d97bf BM |
1324 | BhkENTRY_set(&bhk_test, bhk_start, blockhook_test_start); |
1325 | BhkENTRY_set(&bhk_test, bhk_pre_end, blockhook_test_pre_end); | |
1326 | BhkENTRY_set(&bhk_test, bhk_post_end, blockhook_test_post_end); | |
1327 | BhkENTRY_set(&bhk_test, bhk_eval, blockhook_test_eval); | |
13b6b3bc BM |
1328 | Perl_blockhook_register(aTHX_ &bhk_test); |
1329 | ||
65bfe90c | 1330 | MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER", |
13b6b3bc | 1331 | GV_ADDMULTI, SVt_PVAV); |
03569ecf BM |
1332 | MY_CXT.cscav = GvAV(MY_CXT.cscgv); |
1333 | ||
a88d97bf BM |
1334 | BhkENTRY_set(&bhk_csc, bhk_start, blockhook_csc_start); |
1335 | BhkENTRY_set(&bhk_csc, bhk_pre_end, blockhook_csc_pre_end); | |
13b6b3bc | 1336 | Perl_blockhook_register(aTHX_ &bhk_csc); |
201c7e1f FR |
1337 | |
1338 | MY_CXT.peep_recorder = newAV(); | |
1339 | MY_CXT.rpeep_recorder = newAV(); | |
1340 | ||
1341 | MY_CXT.orig_peep = PL_peepp; | |
1342 | MY_CXT.orig_rpeep = PL_rpeepp; | |
1343 | PL_peepp = my_peep; | |
1344 | PL_rpeepp = my_rpeep; | |
65bfe90c | 1345 | } |
85ce96a1 DM |
1346 | |
1347 | void | |
1348 | CLONE(...) | |
1349 | CODE: | |
1350 | MY_CXT_CLONE; | |
1351 | MY_CXT.sv = newSVpv("initial_clone",0); | |
65bfe90c | 1352 | MY_CXT.cscgv = gv_fetchpvs("XS::APItest::COMPILE_SCOPE_CONTAINER", |
13b6b3bc | 1353 | GV_ADDMULTI, SVt_PVAV); |
03569ecf | 1354 | MY_CXT.cscav = NULL; |
13b6b3bc BM |
1355 | MY_CXT.bhkav = get_av("XS::APItest::bhkav", GV_ADDMULTI); |
1356 | MY_CXT.bhk_record = 0; | |
201c7e1f FR |
1357 | MY_CXT.peep_recorder = newAV(); |
1358 | MY_CXT.rpeep_recorder = newAV(); | |
85ce96a1 | 1359 | |
3e61d65a JH |
1360 | void |
1361 | print_double(val) | |
1362 | double val | |
1363 | CODE: | |
1364 | printf("%5.3f\n",val); | |
1365 | ||
1366 | int | |
1367 | have_long_double() | |
1368 | CODE: | |
1369 | #ifdef HAS_LONG_DOUBLE | |
1370 | RETVAL = 1; | |
1371 | #else | |
1372 | RETVAL = 0; | |
1373 | #endif | |
cabb36f0 CN |
1374 | OUTPUT: |
1375 | RETVAL | |
3e61d65a JH |
1376 | |
1377 | void | |
1378 | print_long_double() | |
1379 | CODE: | |
1380 | #ifdef HAS_LONG_DOUBLE | |
fc0bf671 | 1381 | # if defined(PERL_PRIfldbl) && (LONG_DOUBLESIZE > DOUBLESIZE) |
3e61d65a JH |
1382 | long double val = 7.0; |
1383 | printf("%5.3" PERL_PRIfldbl "\n",val); | |
1384 | # else | |
1385 | double val = 7.0; | |
1386 | printf("%5.3f\n",val); | |
1387 | # endif | |
1388 | #endif | |
1389 | ||
1390 | void | |
3e61d65a JH |
1391 | print_int(val) |
1392 | int val | |
1393 | CODE: | |
1394 | printf("%d\n",val); | |
1395 | ||
1396 | void | |
1397 | print_long(val) | |
1398 | long val | |
1399 | CODE: | |
1400 | printf("%ld\n",val); | |
1401 | ||
1402 | void | |
1403 | print_float(val) | |
1404 | float val | |
1405 | CODE: | |
1406 | printf("%5.3f\n",val); | |
9d911683 NIS |
1407 | |
1408 | void | |
1409 | print_flush() | |
1410 | CODE: | |
1411 | fflush(stdout); | |
d4b90eee SH |
1412 | |
1413 | void | |
1414 | mpushp() | |
1415 | PPCODE: | |
1416 | EXTEND(SP, 3); | |
1417 | mPUSHp("one", 3); | |
1418 | mPUSHp("two", 3); | |
1419 | mPUSHp("three", 5); | |
1420 | XSRETURN(3); | |
1421 | ||
1422 | void | |
1423 | mpushn() | |
1424 | PPCODE: | |
1425 | EXTEND(SP, 3); | |
1426 | mPUSHn(0.5); | |
1427 | mPUSHn(-0.25); | |
1428 | mPUSHn(0.125); | |
1429 | XSRETURN(3); | |
1430 | ||
1431 | void | |
1432 | mpushi() | |
1433 | PPCODE: | |
1434 | EXTEND(SP, 3); | |
d75b63cf MHM |
1435 | mPUSHi(-1); |
1436 | mPUSHi(2); | |
1437 | mPUSHi(-3); | |
d4b90eee SH |
1438 | XSRETURN(3); |
1439 | ||
1440 | void | |
1441 | mpushu() | |
1442 | PPCODE: | |
1443 | EXTEND(SP, 3); | |
d75b63cf MHM |
1444 | mPUSHu(1); |
1445 | mPUSHu(2); | |
1446 | mPUSHu(3); | |
d4b90eee SH |
1447 | XSRETURN(3); |
1448 | ||
1449 | void | |
1450 | mxpushp() | |
1451 | PPCODE: | |
1452 | mXPUSHp("one", 3); | |
1453 | mXPUSHp("two", 3); | |
1454 | mXPUSHp("three", 5); | |
1455 | XSRETURN(3); | |
1456 | ||
1457 | void | |
1458 | mxpushn() | |
1459 | PPCODE: | |
1460 | mXPUSHn(0.5); | |
1461 | mXPUSHn(-0.25); | |
1462 | mXPUSHn(0.125); | |
1463 | XSRETURN(3); | |
1464 | ||
1465 | void | |
1466 | mxpushi() | |
1467 | PPCODE: | |
d75b63cf MHM |
1468 | mXPUSHi(-1); |
1469 | mXPUSHi(2); | |
1470 | mXPUSHi(-3); | |
d4b90eee SH |
1471 | XSRETURN(3); |
1472 | ||
1473 | void | |
1474 | mxpushu() | |
1475 | PPCODE: | |
d75b63cf MHM |
1476 | mXPUSHu(1); |
1477 | mXPUSHu(2); | |
1478 | mXPUSHu(3); | |
d4b90eee | 1479 | XSRETURN(3); |
d1f347d7 DM |
1480 | |
1481 | ||
1482 | void | |
1483 | call_sv(sv, flags, ...) | |
1484 | SV* sv | |
1485 | I32 flags | |
1486 | PREINIT: | |
1487 | I32 i; | |
1488 | PPCODE: | |
1489 | for (i=0; i<items-2; i++) | |
1490 | ST(i) = ST(i+2); /* pop first two args */ | |
1491 | PUSHMARK(SP); | |
1492 | SP += items - 2; | |
1493 | PUTBACK; | |
1494 | i = call_sv(sv, flags); | |
1495 | SPAGAIN; | |
1496 | EXTEND(SP, 1); | |
1497 | PUSHs(sv_2mortal(newSViv(i))); | |
1498 | ||
1499 | void | |
1500 | call_pv(subname, flags, ...) | |
1501 | char* subname | |
1502 | I32 flags | |
1503 | PREINIT: | |
1504 | I32 i; | |
1505 | PPCODE: | |
1506 | for (i=0; i<items-2; i++) | |
1507 | ST(i) = ST(i+2); /* pop first two args */ | |
1508 | PUSHMARK(SP); | |
1509 | SP += items - 2; | |
1510 | PUTBACK; | |
1511 | i = call_pv(subname, flags); | |
1512 | SPAGAIN; | |
1513 | EXTEND(SP, 1); | |
1514 | PUSHs(sv_2mortal(newSViv(i))); | |
1515 | ||
1516 | void | |
1517 | call_method(methname, flags, ...) | |
1518 | char* methname | |
1519 | I32 flags | |
1520 | PREINIT: | |
1521 | I32 i; | |
1522 | PPCODE: | |
1523 | for (i=0; i<items-2; i++) | |
1524 | ST(i) = ST(i+2); /* pop first two args */ | |
1525 | PUSHMARK(SP); | |
1526 | SP += items - 2; | |
1527 | PUTBACK; | |
1528 | i = call_method(methname, flags); | |
1529 | SPAGAIN; | |
1530 | EXTEND(SP, 1); | |
1531 | PUSHs(sv_2mortal(newSViv(i))); | |
1532 | ||
1533 | void | |
1534 | eval_sv(sv, flags) | |
1535 | SV* sv | |
1536 | I32 flags | |
1537 | PREINIT: | |
1538 | I32 i; | |
1539 | PPCODE: | |
1540 | PUTBACK; | |
1541 | i = eval_sv(sv, flags); | |
1542 | SPAGAIN; | |
1543 | EXTEND(SP, 1); | |
1544 | PUSHs(sv_2mortal(newSViv(i))); | |
1545 | ||
b8e65a9b | 1546 | void |
d1f347d7 DM |
1547 | eval_pv(p, croak_on_error) |
1548 | const char* p | |
1549 | I32 croak_on_error | |
d1f347d7 DM |
1550 | PPCODE: |
1551 | PUTBACK; | |
1552 | EXTEND(SP, 1); | |
1553 | PUSHs(eval_pv(p, croak_on_error)); | |
1554 | ||
1555 | void | |
1556 | require_pv(pv) | |
1557 | const char* pv | |
d1f347d7 DM |
1558 | PPCODE: |
1559 | PUTBACK; | |
1560 | require_pv(pv); | |
1561 | ||
0ca3a874 | 1562 | int |
7a646707 | 1563 | apitest_exception(throw_e) |
0ca3a874 MHM |
1564 | int throw_e |
1565 | OUTPUT: | |
1566 | RETVAL | |
d1f347d7 | 1567 | |
ef469b03 | 1568 | void |
7e7a3dfc GA |
1569 | mycroak(sv) |
1570 | SV* sv | |
ef469b03 | 1571 | CODE: |
7e7a3dfc GA |
1572 | if (SvOK(sv)) { |
1573 | Perl_croak(aTHX_ "%s", SvPV_nolen(sv)); | |
1574 | } | |
1575 | else { | |
1576 | Perl_croak(aTHX_ NULL); | |
1577 | } | |
5d2b1485 NC |
1578 | |
1579 | SV* | |
1580 | strtab() | |
1581 | CODE: | |
1582 | RETVAL = newRV_inc((SV*)PL_strtab); | |
1583 | OUTPUT: | |
1584 | RETVAL | |
85ce96a1 DM |
1585 | |
1586 | int | |
1587 | my_cxt_getint() | |
1588 | CODE: | |
1589 | dMY_CXT; | |
1590 | RETVAL = my_cxt_getint_p(aMY_CXT); | |
1591 | OUTPUT: | |
1592 | RETVAL | |
1593 | ||
1594 | void | |
1595 | my_cxt_setint(i) | |
1596 | int i; | |
1597 | CODE: | |
1598 | dMY_CXT; | |
1599 | my_cxt_setint_p(aMY_CXT_ i); | |
1600 | ||
1601 | void | |
9568a123 NC |
1602 | my_cxt_getsv(how) |
1603 | bool how; | |
85ce96a1 | 1604 | PPCODE: |
85ce96a1 | 1605 | EXTEND(SP, 1); |
9568a123 | 1606 | ST(0) = how ? my_cxt_getsv_interp_context() : my_cxt_getsv_interp(); |
85ce96a1 DM |
1607 | XSRETURN(1); |
1608 | ||
1609 | void | |
1610 | my_cxt_setsv(sv) | |
1611 | SV *sv; | |
1612 | CODE: | |
1613 | dMY_CXT; | |
1614 | SvREFCNT_dec(MY_CXT.sv); | |
1615 | my_cxt_setsv_p(sv _aMY_CXT); | |
1616 | SvREFCNT_inc(sv); | |
34482cd6 NC |
1617 | |
1618 | bool | |
1619 | sv_setsv_cow_hashkey_core() | |
1620 | ||
1621 | bool | |
1622 | sv_setsv_cow_hashkey_notcore() | |
84ac5fd7 NC |
1623 | |
1624 | void | |
218787bd VP |
1625 | rmagical_cast(sv, type) |
1626 | SV *sv; | |
1627 | SV *type; | |
1628 | PREINIT: | |
1629 | struct ufuncs uf; | |
1630 | PPCODE: | |
1631 | if (!SvOK(sv) || !SvROK(sv) || !SvOK(type)) { XSRETURN_UNDEF; } | |
1632 | sv = SvRV(sv); | |
1633 | if (SvTYPE(sv) != SVt_PVHV) { XSRETURN_UNDEF; } | |
1634 | uf.uf_val = rmagical_a_dummy; | |
1635 | uf.uf_set = NULL; | |
1636 | uf.uf_index = 0; | |
1637 | if (SvTRUE(type)) { /* b */ | |
1638 | sv_magicext(sv, NULL, PERL_MAGIC_ext, &rmagical_b, NULL, 0); | |
1639 | } else { /* a */ | |
1640 | sv_magic(sv, NULL, PERL_MAGIC_uvar, (char *) &uf, sizeof(uf)); | |
1641 | } | |
1642 | XSRETURN_YES; | |
1643 | ||
1644 | void | |
1645 | rmagical_flags(sv) | |
1646 | SV *sv; | |
1647 | PPCODE: | |
1648 | if (!SvOK(sv) || !SvROK(sv)) { XSRETURN_UNDEF; } | |
1649 | sv = SvRV(sv); | |
1650 | EXTEND(SP, 3); | |
1651 | mXPUSHu(SvFLAGS(sv) & SVs_GMG); | |
1652 | mXPUSHu(SvFLAGS(sv) & SVs_SMG); | |
1653 | mXPUSHu(SvFLAGS(sv) & SVs_RMG); | |
1654 | XSRETURN(3); | |
1655 | ||
1656 | void | |
90d1f214 BM |
1657 | my_caller(level) |
1658 | I32 level | |
1659 | PREINIT: | |
1660 | const PERL_CONTEXT *cx, *dbcx; | |
1661 | const char *pv; | |
1662 | const GV *gv; | |
1663 | HV *hv; | |
1664 | PPCODE: | |
1665 | cx = caller_cx(level, &dbcx); | |
1666 | EXTEND(SP, 8); | |
1667 | ||
1668 | pv = CopSTASHPV(cx->blk_oldcop); | |
1669 | ST(0) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef; | |
1670 | gv = CvGV(cx->blk_sub.cv); | |
1671 | ST(1) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef; | |
1672 | ||
1673 | pv = CopSTASHPV(dbcx->blk_oldcop); | |
1674 | ST(2) = pv ? sv_2mortal(newSVpv(pv, 0)) : &PL_sv_undef; | |
1675 | gv = CvGV(dbcx->blk_sub.cv); | |
1676 | ST(3) = isGV(gv) ? sv_2mortal(newSVpv(GvNAME(gv), 0)) : &PL_sv_undef; | |
1677 | ||
20439bc7 Z |
1678 | ST(4) = cop_hints_fetch_pvs(cx->blk_oldcop, "foo", 0); |
1679 | ST(5) = cop_hints_fetch_pvn(cx->blk_oldcop, "foo", 3, 0, 0); | |
1680 | ST(6) = cop_hints_fetch_sv(cx->blk_oldcop, | |
1681 | sv_2mortal(newSVpvn("foo", 3)), 0, 0); | |
90d1f214 | 1682 | |
20439bc7 | 1683 | hv = cop_hints_2hv(cx->blk_oldcop, 0); |
90d1f214 BM |
1684 | ST(7) = hv ? sv_2mortal(newRV_noinc((SV *)hv)) : &PL_sv_undef; |
1685 | ||
1686 | XSRETURN(8); | |
1687 | ||
1688 | void | |
f9c17636 MB |
1689 | DPeek (sv) |
1690 | SV *sv | |
1691 | ||
1692 | PPCODE: | |
5b1f7359 | 1693 | ST (0) = newSVpv (Perl_sv_peek (aTHX_ sv), 0); |
f9c17636 MB |
1694 | XSRETURN (1); |
1695 | ||
1696 | void | |
84ac5fd7 NC |
1697 | BEGIN() |
1698 | CODE: | |
1699 | sv_inc(get_sv("XS::APItest::BEGIN_called", GV_ADD|GV_ADDMULTI)); | |
1700 | ||
1701 | void | |
1702 | CHECK() | |
1703 | CODE: | |
1704 | sv_inc(get_sv("XS::APItest::CHECK_called", GV_ADD|GV_ADDMULTI)); | |
1705 | ||
1706 | void | |
1707 | UNITCHECK() | |
1708 | CODE: | |
0932863f | 1709 | sv_inc(get_sv("XS::APItest::UNITCHECK_called", GV_ADD|GV_ADDMULTI)); |
84ac5fd7 NC |
1710 | |
1711 | void | |
1712 | INIT() | |
1713 | CODE: | |
1714 | sv_inc(get_sv("XS::APItest::INIT_called", GV_ADD|GV_ADDMULTI)); | |
1715 | ||
1716 | void | |
1717 | END() | |
1718 | CODE: | |
1719 | sv_inc(get_sv("XS::APItest::END_called", GV_ADD|GV_ADDMULTI)); | |
30685b56 NC |
1720 | |
1721 | void | |
1722 | utf16_to_utf8 (sv, ...) | |
1723 | SV* sv | |
1724 | ALIAS: | |
1725 | utf16_to_utf8_reversed = 1 | |
1726 | PREINIT: | |
1727 | STRLEN len; | |
1728 | U8 *source; | |
1729 | SV *dest; | |
1730 | I32 got; /* Gah, badly thought out APIs */ | |
1731 | CODE: | |
1732 | source = (U8 *)SvPVbyte(sv, len); | |
1733 | /* Optionally only convert part of the buffer. */ | |
1734 | if (items > 1) { | |
1735 | len = SvUV(ST(1)); | |
1736 | } | |
1737 | /* Mortalise this right now, as we'll be testing croak()s */ | |
1738 | dest = sv_2mortal(newSV(len * 3 / 2 + 1)); | |
1739 | if (ix) { | |
25f2e844 | 1740 | utf16_to_utf8_reversed(source, (U8 *)SvPVX(dest), len, &got); |
30685b56 | 1741 | } else { |
25f2e844 | 1742 | utf16_to_utf8(source, (U8 *)SvPVX(dest), len, &got); |
30685b56 NC |
1743 | } |
1744 | SvCUR_set(dest, got); | |
1745 | SvPVX(dest)[got] = '\0'; | |
1746 | SvPOK_on(dest); | |
1747 | ST(0) = dest; | |
1748 | XSRETURN(1); | |
879d0c72 | 1749 | |
6bd7445c GG |
1750 | void |
1751 | my_exit(int exitcode) | |
1752 | PPCODE: | |
1753 | my_exit(exitcode); | |
d97c33b5 | 1754 | |
209e41dc NT |
1755 | U8 |
1756 | first_byte(sv) | |
1757 | SV *sv | |
1758 | CODE: | |
1759 | char *s; | |
1760 | STRLEN len; | |
1761 | s = SvPVbyte(sv, len); | |
1762 | RETVAL = s[0]; | |
1763 | OUTPUT: | |
1764 | RETVAL | |
1765 | ||
d97c33b5 DM |
1766 | I32 |
1767 | sv_count() | |
1768 | CODE: | |
1769 | RETVAL = PL_sv_count; | |
1770 | OUTPUT: | |
1771 | RETVAL | |
13b6b3bc BM |
1772 | |
1773 | void | |
1774 | bhk_record(bool on) | |
1775 | CODE: | |
1776 | dMY_CXT; | |
1777 | MY_CXT.bhk_record = on; | |
1778 | if (on) | |
1779 | av_clear(MY_CXT.bhkav); | |
65bfe90c | 1780 | |
defdfed5 | 1781 | void |
d9088386 Z |
1782 | test_magic_chain() |
1783 | PREINIT: | |
1784 | SV *sv; | |
1785 | MAGIC *callmg, *uvarmg; | |
1786 | CODE: | |
1787 | sv = sv_2mortal(newSV(0)); | |
11f9f0ed NC |
1788 | if (SvTYPE(sv) >= SVt_PVMG) croak_fail(); |
1789 | if (SvMAGICAL(sv)) croak_fail(); | |
d9088386 | 1790 | sv_magic(sv, &PL_sv_yes, PERL_MAGIC_checkcall, (char*)&callmg, 0); |
11f9f0ed NC |
1791 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
1792 | if (!SvMAGICAL(sv)) croak_fail(); | |
1793 | if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail(); | |
d9088386 | 1794 | callmg = mg_find(sv, PERL_MAGIC_checkcall); |
11f9f0ed | 1795 | if (!callmg) croak_fail(); |
d9088386 | 1796 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
11f9f0ed | 1797 | croak_fail(); |
d9088386 | 1798 | sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0); |
11f9f0ed NC |
1799 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
1800 | if (!SvMAGICAL(sv)) croak_fail(); | |
1801 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); | |
d9088386 | 1802 | uvarmg = mg_find(sv, PERL_MAGIC_uvar); |
11f9f0ed | 1803 | if (!uvarmg) croak_fail(); |
d9088386 | 1804 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
11f9f0ed | 1805 | croak_fail(); |
d9088386 | 1806 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
11f9f0ed | 1807 | croak_fail(); |
d9088386 | 1808 | mg_free_type(sv, PERL_MAGIC_vec); |
11f9f0ed NC |
1809 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
1810 | if (!SvMAGICAL(sv)) croak_fail(); | |
1811 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); | |
1812 | if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail(); | |
d9088386 | 1813 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
11f9f0ed | 1814 | croak_fail(); |
d9088386 | 1815 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
11f9f0ed | 1816 | croak_fail(); |
d9088386 | 1817 | mg_free_type(sv, PERL_MAGIC_uvar); |
11f9f0ed NC |
1818 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
1819 | if (!SvMAGICAL(sv)) croak_fail(); | |
1820 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); | |
1821 | if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail(); | |
d9088386 | 1822 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
11f9f0ed | 1823 | croak_fail(); |
d9088386 | 1824 | sv_magic(sv, &PL_sv_no, PERL_MAGIC_uvar, (char*)&uvarmg, 0); |
11f9f0ed NC |
1825 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
1826 | if (!SvMAGICAL(sv)) croak_fail(); | |
1827 | if (mg_find(sv, PERL_MAGIC_checkcall) != callmg) croak_fail(); | |
d9088386 | 1828 | uvarmg = mg_find(sv, PERL_MAGIC_uvar); |
11f9f0ed | 1829 | if (!uvarmg) croak_fail(); |
d9088386 | 1830 | if (callmg->mg_obj != &PL_sv_yes || callmg->mg_ptr != (char*)&callmg) |
11f9f0ed | 1831 | croak_fail(); |
d9088386 | 1832 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
11f9f0ed | 1833 | croak_fail(); |
d9088386 | 1834 | mg_free_type(sv, PERL_MAGIC_checkcall); |
11f9f0ed NC |
1835 | if (SvTYPE(sv) < SVt_PVMG) croak_fail(); |
1836 | if (!SvMAGICAL(sv)) croak_fail(); | |
1837 | if (mg_find(sv, PERL_MAGIC_uvar) != uvarmg) croak_fail(); | |
1838 | if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail(); | |
d9088386 | 1839 | if (uvarmg->mg_obj != &PL_sv_no || uvarmg->mg_ptr != (char*)&uvarmg) |
11f9f0ed | 1840 | croak_fail(); |
d9088386 | 1841 | mg_free_type(sv, PERL_MAGIC_uvar); |
11f9f0ed NC |
1842 | if (SvMAGICAL(sv)) croak_fail(); |
1843 | if (mg_find(sv, PERL_MAGIC_checkcall)) croak_fail(); | |
1844 | if (mg_find(sv, PERL_MAGIC_uvar)) croak_fail(); | |
d9088386 Z |
1845 | |
1846 | void | |
1847 | test_op_contextualize() | |
1848 | PREINIT: | |
1849 | OP *o; | |
1850 | CODE: | |
1851 | o = newSVOP(OP_CONST, 0, newSViv(0)); | |
1852 | o->op_flags &= ~OPf_WANT; | |
1853 | o = op_contextualize(o, G_SCALAR); | |
1854 | if (o->op_type != OP_CONST || | |
1855 | (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR) | |
11f9f0ed | 1856 | croak_fail(); |
d9088386 Z |
1857 | op_free(o); |
1858 | o = newSVOP(OP_CONST, 0, newSViv(0)); | |
1859 | o->op_flags &= ~OPf_WANT; | |
1860 | o = op_contextualize(o, G_ARRAY); | |
1861 | if (o->op_type != OP_CONST || | |
1862 | (o->op_flags & OPf_WANT) != OPf_WANT_LIST) | |
11f9f0ed | 1863 | croak_fail(); |
d9088386 Z |
1864 | op_free(o); |
1865 | o = newSVOP(OP_CONST, 0, newSViv(0)); | |
1866 | o->op_flags &= ~OPf_WANT; | |
1867 | o = op_contextualize(o, G_VOID); | |
11f9f0ed | 1868 | if (o->op_type != OP_NULL) croak_fail(); |
d9088386 Z |
1869 | op_free(o); |
1870 | ||
1871 | void | |
1872 | test_rv2cv_op_cv() | |
1873 | PROTOTYPE: | |
1874 | PREINIT: | |
1875 | GV *troc_gv, *wibble_gv; | |
1876 | CV *troc_cv; | |
1877 | OP *o; | |
1878 | CODE: | |
1879 | troc_gv = gv_fetchpv("XS::APItest::test_rv2cv_op_cv", 0, SVt_PVGV); | |
1880 | troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0); | |
1881 | wibble_gv = gv_fetchpv("XS::APItest::wibble", 0, SVt_PVGV); | |
1882 | o = newCVREF(0, newGVOP(OP_GV, 0, troc_gv)); | |
11f9f0ed | 1883 | if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail(); |
d9088386 | 1884 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv) |
11f9f0ed | 1885 | croak_fail(); |
d9088386 | 1886 | o->op_private |= OPpENTERSUB_AMPER; |
11f9f0ed NC |
1887 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
1888 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); | |
d9088386 | 1889 | o->op_private &= ~OPpENTERSUB_AMPER; |
11f9f0ed NC |
1890 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
1891 | if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail(); | |
1892 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); | |
d9088386 Z |
1893 | op_free(o); |
1894 | o = newSVOP(OP_CONST, 0, newSVpv("XS::APItest::test_rv2cv_op_cv", 0)); | |
1895 | o->op_private = OPpCONST_BARE; | |
1896 | o = newCVREF(0, o); | |
11f9f0ed | 1897 | if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail(); |
d9088386 | 1898 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv) |
11f9f0ed | 1899 | croak_fail(); |
d9088386 | 1900 | o->op_private |= OPpENTERSUB_AMPER; |
11f9f0ed NC |
1901 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
1902 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); | |
d9088386 Z |
1903 | op_free(o); |
1904 | o = newCVREF(0, newSVOP(OP_CONST, 0, newRV_inc((SV*)troc_cv))); | |
11f9f0ed | 1905 | if (rv2cv_op_cv(o, 0) != troc_cv) croak_fail(); |
d9088386 | 1906 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV) != (CV*)troc_gv) |
11f9f0ed | 1907 | croak_fail(); |
d9088386 | 1908 | o->op_private |= OPpENTERSUB_AMPER; |
11f9f0ed NC |
1909 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
1910 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); | |
d9088386 | 1911 | o->op_private &= ~OPpENTERSUB_AMPER; |
11f9f0ed NC |
1912 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
1913 | if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY) != troc_cv) croak_fail(); | |
1914 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); | |
d9088386 Z |
1915 | op_free(o); |
1916 | o = newCVREF(0, newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0)))); | |
11f9f0ed NC |
1917 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
1918 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); | |
d9088386 | 1919 | o->op_private |= OPpENTERSUB_AMPER; |
11f9f0ed NC |
1920 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
1921 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); | |
d9088386 | 1922 | o->op_private &= ~OPpENTERSUB_AMPER; |
11f9f0ed NC |
1923 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); |
1924 | if (rv2cv_op_cv(o, RV2CVOPCV_MARK_EARLY)) croak_fail(); | |
1925 | if (cUNOPx(o)->op_first->op_private & OPpEARLY_CV) croak_fail(); | |
d9088386 Z |
1926 | op_free(o); |
1927 | o = newUNOP(OP_RAND, 0, newSVOP(OP_CONST, 0, newSViv(0))); | |
11f9f0ed NC |
1928 | if (rv2cv_op_cv(o, 0)) croak_fail(); |
1929 | if (rv2cv_op_cv(o, RV2CVOPCV_RETURN_NAME_GV)) croak_fail(); | |
d9088386 Z |
1930 | op_free(o); |
1931 | ||
1932 | void | |
1933 | test_cv_getset_call_checker() | |
1934 | PREINIT: | |
1935 | CV *troc_cv, *tsh_cv; | |
1936 | Perl_call_checker ckfun; | |
1937 | SV *ckobj; | |
1938 | CODE: | |
1939 | #define check_cc(cv, xckfun, xckobj) \ | |
1940 | do { \ | |
1941 | cv_get_call_checker((cv), &ckfun, &ckobj); \ | |
779bc08a NC |
1942 | if (ckfun != (xckfun)) croak_fail_ne(FPTR2DPTR(void *, ckfun), xckfun); \ |
1943 | if (ckobj != (xckobj)) croak_fail_ne(FPTR2DPTR(void *, ckobj), xckobj); \ | |
d9088386 Z |
1944 | } while(0) |
1945 | troc_cv = get_cv("XS::APItest::test_rv2cv_op_cv", 0); | |
1946 | tsh_cv = get_cv("XS::APItest::test_savehints", 0); | |
1947 | check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv); | |
1948 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv); | |
1949 | cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list, | |
1950 | &PL_sv_yes); | |
1951 | check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv); | |
1952 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes); | |
1953 | cv_set_call_checker(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no); | |
1954 | check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no); | |
1955 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, &PL_sv_yes); | |
1956 | cv_set_call_checker(tsh_cv, Perl_ck_entersub_args_proto_or_list, | |
1957 | (SV*)tsh_cv); | |
1958 | check_cc(troc_cv, THX_ck_entersub_args_scalars, &PL_sv_no); | |
1959 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv); | |
1960 | cv_set_call_checker(troc_cv, Perl_ck_entersub_args_proto_or_list, | |
1961 | (SV*)troc_cv); | |
1962 | check_cc(troc_cv, Perl_ck_entersub_args_proto_or_list, (SV*)troc_cv); | |
1963 | check_cc(tsh_cv, Perl_ck_entersub_args_proto_or_list, (SV*)tsh_cv); | |
11f9f0ed NC |
1964 | if (SvMAGICAL((SV*)troc_cv) || SvMAGIC((SV*)troc_cv)) croak_fail(); |
1965 | if (SvMAGICAL((SV*)tsh_cv) || SvMAGIC((SV*)tsh_cv)) croak_fail(); | |
d9088386 Z |
1966 | #undef check_cc |
1967 | ||
1968 | void | |
1969 | cv_set_call_checker_lists(CV *cv) | |
1970 | CODE: | |
1971 | cv_set_call_checker(cv, THX_ck_entersub_args_lists, &PL_sv_undef); | |
1972 | ||
1973 | void | |
1974 | cv_set_call_checker_scalars(CV *cv) | |
1975 | CODE: | |
1976 | cv_set_call_checker(cv, THX_ck_entersub_args_scalars, &PL_sv_undef); | |
1977 | ||
1978 | void | |
1979 | cv_set_call_checker_proto(CV *cv, SV *proto) | |
1980 | CODE: | |
1981 | if (SvROK(proto)) | |
1982 | proto = SvRV(proto); | |
1983 | cv_set_call_checker(cv, Perl_ck_entersub_args_proto, proto); | |
1984 | ||
1985 | void | |
1986 | cv_set_call_checker_proto_or_list(CV *cv, SV *proto) | |
1987 | CODE: | |
1988 | if (SvROK(proto)) | |
1989 | proto = SvRV(proto); | |
1990 | cv_set_call_checker(cv, Perl_ck_entersub_args_proto_or_list, proto); | |
1991 | ||
1992 | void | |
1993 | cv_set_call_checker_multi_sum(CV *cv) | |
1994 | CODE: | |
1995 | cv_set_call_checker(cv, THX_ck_entersub_multi_sum, &PL_sv_undef); | |
1996 | ||
1997 | void | |
20439bc7 Z |
1998 | test_cophh() |
1999 | PREINIT: | |
2000 | COPHH *a, *b; | |
2001 | CODE: | |
2002 | #define check_ph(EXPR) \ | |
2003 | do { if((EXPR) != &PL_sv_placeholder) croak("fail"); } while(0) | |
2004 | #define check_iv(EXPR, EXPECT) \ | |
2005 | do { if(SvIV(EXPR) != (EXPECT)) croak("fail"); } while(0) | |
2006 | #define msvpvs(STR) sv_2mortal(newSVpvs(STR)) | |
2007 | #define msviv(VALUE) sv_2mortal(newSViv(VALUE)) | |
2008 | a = cophh_new_empty(); | |
2009 | check_ph(cophh_fetch_pvn(a, "foo_1", 5, 0, 0)); | |
2010 | check_ph(cophh_fetch_pvs(a, "foo_1", 0)); | |
2011 | check_ph(cophh_fetch_pv(a, "foo_1", 0, 0)); | |
2012 | check_ph(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0)); | |
2013 | a = cophh_store_pvn(a, "foo_1abc", 5, 0, msviv(111), 0); | |
2014 | a = cophh_store_pvs(a, "foo_2", msviv(222), 0); | |
2015 | a = cophh_store_pv(a, "foo_3", 0, msviv(333), 0); | |
2016 | a = cophh_store_sv(a, msvpvs("foo_4"), 0, msviv(444), 0); | |
2017 | check_iv(cophh_fetch_pvn(a, "foo_1xyz", 5, 0, 0), 111); | |
2018 | check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111); | |
2019 | check_iv(cophh_fetch_pv(a, "foo_1", 0, 0), 111); | |
2020 | check_iv(cophh_fetch_sv(a, msvpvs("foo_1"), 0, 0), 111); | |
2021 | check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222); | |
2022 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); | |
2023 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); | |
2024 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); | |
2025 | b = cophh_copy(a); | |
2026 | b = cophh_store_pvs(b, "foo_1", msviv(1111), 0); | |
2027 | check_iv(cophh_fetch_pvs(a, "foo_1", 0), 111); | |
2028 | check_iv(cophh_fetch_pvs(a, "foo_2", 0), 222); | |
2029 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); | |
2030 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); | |
2031 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); | |
2032 | check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111); | |
2033 | check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222); | |
2034 | check_iv(cophh_fetch_pvs(b, "foo_3", 0), 333); | |
2035 | check_iv(cophh_fetch_pvs(b, "foo_4", 0), 444); | |
2036 | check_ph(cophh_fetch_pvs(b, "foo_5", 0)); | |
2037 | a = cophh_delete_pvn(a, "foo_1abc", 5, 0, 0); | |
2038 | a = cophh_delete_pvs(a, "foo_2", 0); | |
2039 | b = cophh_delete_pv(b, "foo_3", 0, 0); | |
2040 | b = cophh_delete_sv(b, msvpvs("foo_4"), 0, 0); | |
2041 | check_ph(cophh_fetch_pvs(a, "foo_1", 0)); | |
2042 | check_ph(cophh_fetch_pvs(a, "foo_2", 0)); | |
2043 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); | |
2044 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); | |
2045 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); | |
2046 | check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111); | |
2047 | check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222); | |
2048 | check_ph(cophh_fetch_pvs(b, "foo_3", 0)); | |
2049 | check_ph(cophh_fetch_pvs(b, "foo_4", 0)); | |
2050 | check_ph(cophh_fetch_pvs(b, "foo_5", 0)); | |
2051 | b = cophh_delete_pvs(b, "foo_3", 0); | |
2052 | b = cophh_delete_pvs(b, "foo_5", 0); | |
2053 | check_iv(cophh_fetch_pvs(b, "foo_1", 0), 1111); | |
2054 | check_iv(cophh_fetch_pvs(b, "foo_2", 0), 222); | |
2055 | check_ph(cophh_fetch_pvs(b, "foo_3", 0)); | |
2056 | check_ph(cophh_fetch_pvs(b, "foo_4", 0)); | |
2057 | check_ph(cophh_fetch_pvs(b, "foo_5", 0)); | |
2058 | cophh_free(b); | |
2059 | check_ph(cophh_fetch_pvs(a, "foo_1", 0)); | |
2060 | check_ph(cophh_fetch_pvs(a, "foo_2", 0)); | |
2061 | check_iv(cophh_fetch_pvs(a, "foo_3", 0), 333); | |
2062 | check_iv(cophh_fetch_pvs(a, "foo_4", 0), 444); | |
2063 | check_ph(cophh_fetch_pvs(a, "foo_5", 0)); | |
2064 | a = cophh_store_pvs(a, "foo_1", msviv(11111), COPHH_KEY_UTF8); | |
2065 | a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0); | |
2066 | a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8); | |
2067 | a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8); | |
2068 | a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8); | |
2069 | check_iv(cophh_fetch_pvs(a, "foo_1", 0), 11111); | |
2070 | check_iv(cophh_fetch_pvs(a, "foo_1", COPHH_KEY_UTF8), 11111); | |
2071 | check_iv(cophh_fetch_pvs(a, "foo_\xaa", 0), 123); | |
2072 | check_iv(cophh_fetch_pvs(a, "foo_\xc2\xaa", COPHH_KEY_UTF8), 123); | |
2073 | check_ph(cophh_fetch_pvs(a, "foo_\xc2\xaa", 0)); | |
2074 | check_iv(cophh_fetch_pvs(a, "foo_\xbb", 0), 456); | |
2075 | check_iv(cophh_fetch_pvs(a, "foo_\xc2\xbb", COPHH_KEY_UTF8), 456); | |
2076 | check_ph(cophh_fetch_pvs(a, "foo_\xc2\xbb", 0)); | |
2077 | check_iv(cophh_fetch_pvs(a, "foo_\xcc", 0), 789); | |
2078 | check_iv(cophh_fetch_pvs(a, "foo_\xc3\x8c", COPHH_KEY_UTF8), 789); | |
2079 | check_ph(cophh_fetch_pvs(a, "foo_\xc2\x8c", 0)); | |
2080 | check_iv(cophh_fetch_pvs(a, "foo_\xd9\xa6", COPHH_KEY_UTF8), 666); | |
2081 | check_ph(cophh_fetch_pvs(a, "foo_\xd9\xa6", 0)); | |
3987a177 Z |
2082 | ENTER; |
2083 | SAVEFREECOPHH(a); | |
2084 | LEAVE; | |
20439bc7 Z |
2085 | #undef check_ph |
2086 | #undef check_iv | |
2087 | #undef msvpvs | |
2088 | #undef msviv | |
2089 | ||
2090 | HV * | |
2091 | example_cophh_2hv() | |
2092 | PREINIT: | |
2093 | COPHH *a; | |
2094 | CODE: | |
2095 | #define msviv(VALUE) sv_2mortal(newSViv(VALUE)) | |
2096 | a = cophh_new_empty(); | |
2097 | a = cophh_store_pvs(a, "foo_0", msviv(999), 0); | |
2098 | a = cophh_store_pvs(a, "foo_1", msviv(111), 0); | |
2099 | a = cophh_store_pvs(a, "foo_\xaa", msviv(123), 0); | |
2100 | a = cophh_store_pvs(a, "foo_\xc2\xbb", msviv(456), COPHH_KEY_UTF8); | |
2101 | a = cophh_store_pvs(a, "foo_\xc3\x8c", msviv(789), COPHH_KEY_UTF8); | |
2102 | a = cophh_store_pvs(a, "foo_\xd9\xa6", msviv(666), COPHH_KEY_UTF8); | |
2103 | a = cophh_delete_pvs(a, "foo_0", 0); | |
2104 | a = cophh_delete_pvs(a, "foo_2", 0); | |
2105 | RETVAL = cophh_2hv(a, 0); | |
2106 | cophh_free(a); | |
2107 | #undef msviv | |
2108 | OUTPUT: | |
2109 | RETVAL | |
2110 | ||
2111 | void | |
defdfed5 Z |
2112 | test_savehints() |
2113 | PREINIT: | |
2114 | SV **svp, *sv; | |
2115 | CODE: | |
2116 | #define store_hint(KEY, VALUE) \ | |
2117 | sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), KEY, 1), (VALUE)) | |
2118 | #define hint_ok(KEY, EXPECT) \ | |
2119 | ((svp = hv_fetchs(GvHV(PL_hintgv), KEY, 0)) && \ | |
2120 | (sv = *svp) && SvIV(sv) == (EXPECT) && \ | |
20439bc7 | 2121 | (sv = cop_hints_fetch_pvs(&PL_compiling, KEY, 0)) && \ |
defdfed5 Z |
2122 | SvIV(sv) == (EXPECT)) |
2123 | #define check_hint(KEY, EXPECT) \ | |
11f9f0ed | 2124 | do { if (!hint_ok(KEY, EXPECT)) croak_fail(); } while(0) |
defdfed5 Z |
2125 | PL_hints |= HINT_LOCALIZE_HH; |
2126 | ENTER; | |
2127 | SAVEHINTS(); | |
2128 | PL_hints &= HINT_INTEGER; | |
2129 | store_hint("t0", 123); | |
2130 | store_hint("t1", 456); | |
11f9f0ed | 2131 | if (PL_hints & HINT_INTEGER) croak_fail(); |
defdfed5 Z |
2132 | check_hint("t0", 123); check_hint("t1", 456); |
2133 | ENTER; | |
2134 | SAVEHINTS(); | |
11f9f0ed | 2135 | if (PL_hints & HINT_INTEGER) croak_fail(); |
defdfed5 Z |
2136 | check_hint("t0", 123); check_hint("t1", 456); |
2137 | PL_hints |= HINT_INTEGER; | |
2138 | store_hint("t0", 321); | |
11f9f0ed | 2139 | if (!(PL_hints & HINT_INTEGER)) croak_fail(); |
defdfed5 Z |
2140 | check_hint("t0", 321); check_hint("t1", 456); |
2141 | LEAVE; | |
11f9f0ed | 2142 | if (PL_hints & HINT_INTEGER) croak_fail(); |
defdfed5 Z |
2143 | check_hint("t0", 123); check_hint("t1", 456); |
2144 | ENTER; | |
2145 | SAVEHINTS(); | |
11f9f0ed | 2146 | if (PL_hints & HINT_INTEGER) croak_fail(); |
defdfed5 Z |
2147 | check_hint("t0", 123); check_hint("t1", 456); |
2148 | store_hint("t1", 654); | |
11f9f0ed | 2149 | if (PL_hints & HINT_INTEGER) croak_fail(); |
defdfed5 Z |
2150 | check_hint("t0", 123); check_hint("t1", 654); |
2151 | LEAVE; | |
11f9f0ed | 2152 | if (PL_hints & HINT_INTEGER) croak_fail(); |
defdfed5 Z |
2153 | check_hint("t0", 123); check_hint("t1", 456); |
2154 | LEAVE; | |
2155 | #undef store_hint | |
2156 | #undef hint_ok | |
2157 | #undef check_hint | |
2158 | ||
2159 | void | |
2160 | test_copyhints() | |
2161 | PREINIT: | |
2162 | HV *a, *b; | |
2163 | CODE: | |
2164 | PL_hints |= HINT_LOCALIZE_HH; | |
2165 | ENTER; | |
2166 | SAVEHINTS(); | |
2167 | sv_setiv_mg(*hv_fetchs(GvHV(PL_hintgv), "t0", 1), 123); | |
20439bc7 Z |
2168 | if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123) |
2169 | croak_fail(); | |
defdfed5 Z |
2170 | a = newHVhv(GvHV(PL_hintgv)); |
2171 | sv_2mortal((SV*)a); | |
2172 | sv_setiv_mg(*hv_fetchs(a, "t0", 1), 456); | |
20439bc7 Z |
2173 | if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 123) |
2174 | croak_fail(); | |
defdfed5 Z |
2175 | b = hv_copy_hints_hv(a); |
2176 | sv_2mortal((SV*)b); | |
2177 | sv_setiv_mg(*hv_fetchs(b, "t0", 1), 789); | |
20439bc7 Z |
2178 | if (SvIV(cop_hints_fetch_pvs(&PL_compiling, "t0", 0)) != 789) |
2179 | croak_fail(); | |
defdfed5 Z |
2180 | LEAVE; |
2181 | ||
201c7e1f | 2182 | void |
2fcb4757 Z |
2183 | test_op_list() |
2184 | PREINIT: | |
2185 | OP *a; | |
2186 | CODE: | |
2187 | #define iv_op(iv) newSVOP(OP_CONST, 0, newSViv(iv)) | |
2188 | #define check_op(o, expect) \ | |
2189 | do { \ | |
2190 | if (strcmp(test_op_list_describe(o), (expect))) \ | |
2191 | croak("fail %s %s", test_op_list_describe(o), (expect)); \ | |
2192 | } while(0) | |
2193 | a = op_append_elem(OP_LIST, NULL, NULL); | |
2194 | check_op(a, ""); | |
2195 | a = op_append_elem(OP_LIST, iv_op(1), a); | |
2196 | check_op(a, "const(1)."); | |
2197 | a = op_append_elem(OP_LIST, NULL, a); | |
2198 | check_op(a, "const(1)."); | |
2199 | a = op_append_elem(OP_LIST, a, iv_op(2)); | |
2200 | check_op(a, "list[pushmark.const(1).const(2).]"); | |
2201 | a = op_append_elem(OP_LIST, a, iv_op(3)); | |
2202 | check_op(a, "list[pushmark.const(1).const(2).const(3).]"); | |
2203 | a = op_append_elem(OP_LIST, a, NULL); | |
2204 | check_op(a, "list[pushmark.const(1).const(2).const(3).]"); | |
2205 | a = op_append_elem(OP_LIST, NULL, a); | |
2206 | check_op(a, "list[pushmark.const(1).const(2).const(3).]"); | |
2207 | a = op_append_elem(OP_LIST, iv_op(4), a); | |
2208 | check_op(a, "list[pushmark.const(4)." | |
2209 | "list[pushmark.const(1).const(2).const(3).]]"); | |
2210 | a = op_append_elem(OP_LIST, a, iv_op(5)); | |
2211 | check_op(a, "list[pushmark.const(4)." | |
2212 | "list[pushmark.const(1).const(2).const(3).]const(5).]"); | |
2213 | a = op_append_elem(OP_LIST, a, | |
2214 | op_append_elem(OP_LIST, iv_op(7), iv_op(6))); | |
2215 | check_op(a, "list[pushmark.const(4)." | |
2216 | "list[pushmark.const(1).const(2).const(3).]const(5)." | |
2217 | "list[pushmark.const(7).const(6).]]"); | |
2218 | op_free(a); | |
2219 | a = op_append_elem(OP_LINESEQ, iv_op(1), iv_op(2)); | |
2220 | check_op(a, "lineseq[const(1).const(2).]"); | |
2221 | a = op_append_elem(OP_LINESEQ, a, iv_op(3)); | |
2222 | check_op(a, "lineseq[const(1).const(2).const(3).]"); | |
2223 | op_free(a); | |
2224 | a = op_append_elem(OP_LINESEQ, | |
2225 | op_append_elem(OP_LIST, iv_op(1), iv_op(2)), | |
2226 | iv_op(3)); | |
2227 | check_op(a, "lineseq[list[pushmark.const(1).const(2).]const(3).]"); | |
2228 | op_free(a); | |
2229 | a = op_prepend_elem(OP_LIST, NULL, NULL); | |
2230 | check_op(a, ""); | |
2231 | a = op_prepend_elem(OP_LIST, a, iv_op(1)); | |
2232 | check_op(a, "const(1)."); | |
2233 | a = op_prepend_elem(OP_LIST, a, NULL); | |
2234 | check_op(a, "const(1)."); | |
2235 | a = op_prepend_elem(OP_LIST, iv_op(2), a); | |
2236 | check_op(a, "list[pushmark.const(2).const(1).]"); | |
2237 | a = op_prepend_elem(OP_LIST, iv_op(3), a); | |
2238 | check_op(a, "list[pushmark.const(3).const(2).const(1).]"); | |
2239 | a = op_prepend_elem(OP_LIST, NULL, a); | |
2240 | check_op(a, "list[pushmark.const(3).const(2).const(1).]"); | |
2241 | a = op_prepend_elem(OP_LIST, a, NULL); | |
2242 | check_op(a, "list[pushmark.const(3).const(2).const(1).]"); | |
2243 | a = op_prepend_elem(OP_LIST, a, iv_op(4)); | |
2244 | check_op(a, "list[pushmark." | |
2245 | "list[pushmark.const(3).const(2).const(1).]const(4).]"); | |
2246 | a = op_prepend_elem(OP_LIST, iv_op(5), a); | |
2247 | check_op(a, "list[pushmark.const(5)." | |
2248 | "list[pushmark.const(3).const(2).const(1).]const(4).]"); | |
2249 | a = op_prepend_elem(OP_LIST, | |
2250 | op_prepend_elem(OP_LIST, iv_op(6), iv_op(7)), a); | |
2251 | check_op(a, "list[pushmark.list[pushmark.const(6).const(7).]const(5)." | |
2252 | "list[pushmark.const(3).const(2).const(1).]const(4).]"); | |
2253 | op_free(a); | |
2254 | a = op_prepend_elem(OP_LINESEQ, iv_op(2), iv_op(1)); | |
2255 | check_op(a, "lineseq[const(2).const(1).]"); | |
2256 | a = op_prepend_elem(OP_LINESEQ, iv_op(3), a); | |
2257 | check_op(a, "lineseq[const(3).const(2).const(1).]"); | |
2258 | op_free(a); | |
2259 | a = op_prepend_elem(OP_LINESEQ, iv_op(3), | |
2260 | op_prepend_elem(OP_LIST, iv_op(2), iv_op(1))); | |
2261 | check_op(a, "lineseq[const(3).list[pushmark.const(2).const(1).]]"); | |
2262 | op_free(a); | |
2263 | a = op_append_list(OP_LINESEQ, NULL, NULL); | |
2264 | check_op(a, ""); | |
2265 | a = op_append_list(OP_LINESEQ, iv_op(1), a); | |
2266 | check_op(a, "const(1)."); | |
2267 | a = op_append_list(OP_LINESEQ, NULL, a); | |
2268 | check_op(a, "const(1)."); | |
2269 | a = op_append_list(OP_LINESEQ, a, iv_op(2)); | |
2270 | check_op(a, "lineseq[const(1).const(2).]"); | |
2271 | a = op_append_list(OP_LINESEQ, a, iv_op(3)); | |
2272 | check_op(a, "lineseq[const(1).const(2).const(3).]"); | |
2273 | a = op_append_list(OP_LINESEQ, iv_op(4), a); | |
2274 | check_op(a, "lineseq[const(4).const(1).const(2).const(3).]"); | |
2275 | a = op_append_list(OP_LINESEQ, a, NULL); | |
2276 | check_op(a, "lineseq[const(4).const(1).const(2).const(3).]"); | |
2277 | a = op_append_list(OP_LINESEQ, NULL, a); | |
2278 | check_op(a, "lineseq[const(4).const(1).const(2).const(3).]"); | |
2279 | a = op_append_list(OP_LINESEQ, a, | |
2280 | op_append_list(OP_LINESEQ, iv_op(5), iv_op(6))); | |
2281 | check_op(a, "lineseq[const(4).const(1).const(2).const(3)." | |
2282 | "const(5).const(6).]"); | |
2283 | op_free(a); | |
2284 | a = op_append_list(OP_LINESEQ, | |
2285 | op_append_list(OP_LINESEQ, iv_op(1), iv_op(2)), | |
2286 | op_append_list(OP_LIST, iv_op(3), iv_op(4))); | |
2287 | check_op(a, "lineseq[const(1).const(2)." | |
2288 | "list[pushmark.const(3).const(4).]]"); | |
2289 | op_free(a); | |
2290 | a = op_append_list(OP_LINESEQ, | |
2291 | op_append_list(OP_LIST, iv_op(1), iv_op(2)), | |
2292 | op_append_list(OP_LINESEQ, iv_op(3), iv_op(4))); | |
2293 | check_op(a, "lineseq[list[pushmark.const(1).const(2).]" | |
2294 | "const(3).const(4).]"); | |
2295 | op_free(a); | |
2fcb4757 Z |
2296 | #undef check_op |
2297 | ||
2298 | void | |
5983a79d BM |
2299 | test_op_linklist () |
2300 | PREINIT: | |
2301 | OP *o; | |
2302 | CODE: | |
2303 | #define check_ll(o, expect) \ | |
2304 | STMT_START { \ | |
2305 | if (strNE(test_op_linklist_describe(o), (expect))) \ | |
2306 | croak("fail %s %s", test_op_linklist_describe(o), (expect)); \ | |
2307 | } STMT_END | |
2308 | o = iv_op(1); | |
2309 | check_ll(o, ".const1"); | |
2310 | op_free(o); | |
2311 | ||
2312 | o = mkUNOP(OP_NOT, iv_op(1)); | |
2313 | check_ll(o, ".const1.not"); | |
2314 | op_free(o); | |
2315 | ||
2316 | o = mkUNOP(OP_NOT, mkUNOP(OP_NEGATE, iv_op(1))); | |
2317 | check_ll(o, ".const1.negate.not"); | |
2318 | op_free(o); | |
2319 | ||
2320 | o = mkBINOP(OP_ADD, iv_op(1), iv_op(2)); | |
2321 | check_ll(o, ".const1.const2.add"); | |
2322 | op_free(o); | |
2323 | ||
2324 | o = mkBINOP(OP_ADD, mkUNOP(OP_NOT, iv_op(1)), iv_op(2)); | |
2325 | check_ll(o, ".const1.not.const2.add"); | |
2326 | op_free(o); | |
2327 | ||
2328 | o = mkUNOP(OP_NOT, mkBINOP(OP_ADD, iv_op(1), iv_op(2))); | |
2329 | check_ll(o, ".const1.const2.add.not"); | |
2330 | op_free(o); | |
2331 | ||
2332 | o = mkLISTOP(OP_LINESEQ, iv_op(1), iv_op(2), iv_op(3)); | |
2333 | check_ll(o, ".const1.const2.const3.lineseq"); | |
2334 | op_free(o); | |
2335 | ||
2336 | o = mkLISTOP(OP_LINESEQ, | |
2337 | mkBINOP(OP_ADD, iv_op(1), iv_op(2)), | |
2338 | mkUNOP(OP_NOT, iv_op(3)), | |
2339 | mkLISTOP(OP_SUBSTR, iv_op(4), iv_op(5), iv_op(6))); | |
2340 | check_ll(o, ".const1.const2.add.const3.not" | |
2341 | ".const4.const5.const6.substr.lineseq"); | |
2342 | op_free(o); | |
2343 | ||
2344 | o = mkBINOP(OP_ADD, iv_op(1), iv_op(2)); | |
2345 | LINKLIST(o); | |
2346 | o = mkBINOP(OP_SUBTRACT, o, iv_op(3)); | |
2347 | check_ll(o, ".const1.const2.add.const3.subtract"); | |
2348 | op_free(o); | |
2349 | #undef check_ll | |
2350 | #undef iv_op | |
2351 | ||
2352 | void | |
201c7e1f FR |
2353 | peep_enable () |
2354 | PREINIT: | |
2355 | dMY_CXT; | |
2356 | CODE: | |
2357 | av_clear(MY_CXT.peep_recorder); | |
2358 | av_clear(MY_CXT.rpeep_recorder); | |
2359 | MY_CXT.peep_recording = 1; | |
2360 | ||
2361 | void | |
2362 | peep_disable () | |
2363 | PREINIT: | |
2364 | dMY_CXT; | |
2365 | CODE: | |
2366 | MY_CXT.peep_recording = 0; | |
2367 | ||
2368 | SV * | |
2369 | peep_record () | |
2370 | PREINIT: | |
2371 | dMY_CXT; | |
2372 | CODE: | |
95d2461a | 2373 | RETVAL = newRV_inc((SV *)MY_CXT.peep_recorder); |
201c7e1f FR |
2374 | OUTPUT: |
2375 | RETVAL | |
2376 | ||
2377 | SV * | |
2378 | rpeep_record () | |
2379 | PREINIT: | |
2380 | dMY_CXT; | |
2381 | CODE: | |
95d2461a | 2382 | RETVAL = newRV_inc((SV *)MY_CXT.rpeep_recorder); |
201c7e1f FR |
2383 | OUTPUT: |
2384 | RETVAL | |
2385 | ||
9c540340 DM |
2386 | =pod |
2387 | ||
2388 | multicall_each: call a sub for each item in the list. Used to test MULTICALL | |
2389 | ||
2390 | =cut | |
2391 | ||
2392 | void | |
2393 | multicall_each(block,...) | |
2394 | SV * block | |
2395 | PROTOTYPE: &@ | |
2396 | CODE: | |
2397 | { | |
2398 | dMULTICALL; | |
2399 | int index; | |
2400 | GV *gv; | |
2401 | HV *stash; | |
2402 | I32 gimme = G_SCALAR; | |
2403 | SV **args = &PL_stack_base[ax]; | |
2404 | CV *cv; | |
2405 | ||
2406 | if(items <= 1) { | |
2407 | XSRETURN_UNDEF; | |
2408 | } | |
2409 | cv = sv_2cv(block, &stash, &gv, 0); | |
2410 | if (cv == Nullcv) { | |
2411 | croak("multicall_each: not a subroutine reference"); | |
2412 | } | |
2413 | PUSH_MULTICALL(cv); | |
2414 | SAVESPTR(GvSV(PL_defgv)); | |
2415 | ||
2416 | for(index = 1 ; index < items ; index++) { | |
2417 | GvSV(PL_defgv) = args[index]; | |
2418 | MULTICALL; | |
2419 | } | |
2420 | POP_MULTICALL; | |
2421 | XSRETURN_UNDEF; | |
2422 | } | |
2423 | ||
2424 | ||
e2fe06dd EB |
2425 | BOOT: |
2426 | { | |
2427 | HV* stash; | |
2428 | SV** meth = NULL; | |
2429 | CV* cv; | |
2430 | stash = gv_stashpv("XS::APItest::TempLv", 0); | |
2431 | if (stash) | |
2432 | meth = hv_fetchs(stash, "make_temp_mg_lv", 0); | |
2433 | if (!meth) | |
2434 | croak("lost method 'make_temp_mg_lv'"); | |
2435 | cv = GvCV(*meth); | |
2436 | CvLVALUE_on(cv); | |
2437 | } | |
83f8bb56 Z |
2438 | |
2439 | BOOT: | |
2440 | { | |
2441 | hintkey_rpn_sv = newSVpvs_share("XS::APItest/rpn"); | |
2442 | hintkey_calcrpn_sv = newSVpvs_share("XS::APItest/calcrpn"); | |
2443 | hintkey_stufftest_sv = newSVpvs_share("XS::APItest/stufftest"); | |
2444 | hintkey_swaptwostmts_sv = newSVpvs_share("XS::APItest/swaptwostmts"); | |
07ffcb73 | 2445 | hintkey_looprest_sv = newSVpvs_share("XS::APItest/looprest"); |
a7aaec61 | 2446 | hintkey_scopelessblock_sv = newSVpvs_share("XS::APItest/scopelessblock"); |
9eb5c532 Z |
2447 | hintkey_stmtasexpr_sv = newSVpvs_share("XS::APItest/stmtasexpr"); |
2448 | hintkey_stmtsasexpr_sv = newSVpvs_share("XS::APItest/stmtsasexpr"); | |
e53d8f76 Z |
2449 | hintkey_loopblock_sv = newSVpvs_share("XS::APItest/loopblock"); |
2450 | hintkey_blockasexpr_sv = newSVpvs_share("XS::APItest/blockasexpr"); | |
361d9b55 Z |
2451 | hintkey_swaplabel_sv = newSVpvs_share("XS::APItest/swaplabel"); |
2452 | hintkey_labelconst_sv = newSVpvs_share("XS::APItest/labelconst"); | |
83f8bb56 Z |
2453 | next_keyword_plugin = PL_keyword_plugin; |
2454 | PL_keyword_plugin = my_keyword_plugin; | |
2455 | } | |
8f89e5a9 Z |
2456 | |
2457 | void | |
2458 | establish_cleanup(...) | |
2459 | PROTOTYPE: $ | |
2460 | CODE: | |
2461 | croak("establish_cleanup called as a function"); | |
2462 | ||
2463 | BOOT: | |
2464 | { | |
2465 | CV *estcv = get_cv("XS::APItest::establish_cleanup", 0); | |
2466 | cv_set_call_checker(estcv, THX_ck_entersub_establish_cleanup, (SV*)estcv); | |
2467 | } | |
3ad73efd Z |
2468 | |
2469 | void | |
2470 | postinc(...) | |
2471 | PROTOTYPE: $ | |
2472 | CODE: | |
2473 | croak("postinc called as a function"); | |
2474 | ||
2475 | BOOT: | |
2476 | { | |
2477 | CV *asscv = get_cv("XS::APItest::postinc", 0); | |
2478 | cv_set_call_checker(asscv, THX_ck_entersub_postinc, (SV*)asscv); | |
2479 | } |