1 /* This file is part of the indirect Perl module.
2 * See http://search.cpan.org/dist/indirect/ */
4 #define PERL_NO_GET_CONTEXT
9 #define __PACKAGE__ "indirect"
10 #define __PACKAGE_LEN__ (sizeof(__PACKAGE__)-1)
12 /* --- Compatibility wrappers ---------------------------------------------- */
23 # define Newx(v, n, c) New(0, v, n, c)
27 # define SvPV_const SvPV
30 #ifndef SvPV_nolen_const
31 # define SvPV_nolen_const SvPV_nolen
35 # define SvPVX_const SvPVX
38 #ifndef SvREFCNT_inc_simple_void_NN
39 # ifdef SvREFCNT_inc_simple_NN
40 # define SvREFCNT_inc_simple_void_NN SvREFCNT_inc_simple_NN
42 # define SvREFCNT_inc_simple_void_NN SvREFCNT_inc
46 #ifndef sv_catpvn_nomg
47 # define sv_catpvn_nomg sv_catpvn
51 # define mPUSHp(P, L) PUSHs(sv_2mortal(newSVpvn((P), (L))))
55 # define mPUSHu(U) PUSHs(sv_2mortal(newSVuv(U)))
59 # define HvNAME_get(H) HvNAME(H)
63 # define HvNAMELEN_get(H) strlen(HvNAME_get(H))
67 # define OP_SIBLING(O) ((O)->op_sibling)
70 #define I_HAS_PERL(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
72 #if I_HAS_PERL(5, 10, 0) || defined(PL_parser)
74 # define PL_linestr PL_parser->linestr
77 # define PL_bufptr PL_parser->bufptr
80 # define PL_oldbufptr PL_parser->oldbufptr
82 # ifndef PL_lex_inwhat
83 # define PL_lex_inwhat PL_parser->lex_inwhat
87 # define PL_linestr PL_Ilinestr
90 # define PL_bufptr PL_Ibufptr
93 # define PL_oldbufptr PL_Ioldbufptr
95 # ifndef PL_lex_inwhat
96 # define PL_lex_inwhat PL_Ilex_inwhat
100 #ifndef I_WORKAROUND_REQUIRE_PROPAGATION
101 # define I_WORKAROUND_REQUIRE_PROPAGATION !I_HAS_PERL(5, 10, 1)
104 /* ... Thread safety and multiplicity ...................................... */
106 /* Safe unless stated otherwise in Makefile.PL */
108 # define I_FORKSAFE 1
111 #ifndef I_MULTIPLICITY
112 # if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT)
113 # define I_MULTIPLICITY 1
115 # define I_MULTIPLICITY 0
118 #if I_MULTIPLICITY && !defined(tTHX)
119 # define tTHX PerlInterpreter*
122 #if I_MULTIPLICITY && defined(USE_ITHREADS) && defined(dMY_CXT) && defined(MY_CXT) && defined(START_MY_CXT) && defined(MY_CXT_INIT) && (defined(MY_CXT_CLONE) || defined(dMY_CXT_SV))
123 # define I_THREADSAFE 1
124 # ifndef MY_CXT_CLONE
125 # define MY_CXT_CLONE \
127 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1)); \
128 Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t); \
129 sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
132 # define I_THREADSAFE 0
134 # define dMY_CXT dNOOP
136 # define MY_CXT indirect_globaldata
138 # define START_MY_CXT STATIC my_cxt_t MY_CXT;
140 # define MY_CXT_INIT NOOP
142 # define MY_CXT_CLONE NOOP
145 #if defined(OP_CHECK_MUTEX_LOCK) && defined(OP_CHECK_MUTEX_UNLOCK)
146 # define I_CHECK_MUTEX_LOCK OP_CHECK_MUTEX_LOCK
147 # define I_CHECK_MUTEX_UNLOCK OP_CHECK_MUTEX_UNLOCK
149 # define I_CHECK_MUTEX_LOCK OP_REFCNT_LOCK
150 # define I_CHECK_MUTEX_UNLOCK OP_REFCNT_UNLOCK
153 typedef OP *(*indirect_ck_t)(pTHX_ OP *);
155 #ifdef wrap_op_checker
157 # define indirect_ck_replace(T, NC, OCP) wrap_op_checker((T), (NC), (OCP))
161 STATIC void indirect_ck_replace(pTHX_ OPCODE type, indirect_ck_t new_ck, indirect_ck_t *old_ck_p) {
162 #define indirect_ck_replace(T, NC, OCP) indirect_ck_replace(aTHX_ (T), (NC), (OCP))
165 *old_ck_p = PL_check[type];
166 PL_check[type] = new_ck;
168 I_CHECK_MUTEX_UNLOCK;
173 STATIC void indirect_ck_restore(pTHX_ OPCODE type, indirect_ck_t *old_ck_p) {
174 #define indirect_ck_restore(T, OCP) indirect_ck_restore(aTHX_ (T), (OCP))
177 PL_check[type] = *old_ck_p;
180 I_CHECK_MUTEX_UNLOCK;
183 /* --- Helpers ------------------------------------------------------------- */
185 /* ... Thread-safe hints ................................................... */
187 #if I_WORKAROUND_REQUIRE_PROPAGATION
194 #define I_HINT_STRUCT 1
196 #define I_HINT_CODE(H) ((H)->code)
198 #define I_HINT_FREE(H) { \
199 indirect_hint_t *h = (H); \
200 SvREFCNT_dec(h->code); \
201 PerlMemShared_free(h); \
204 #else /* I_WORKAROUND_REQUIRE_PROPAGATION */
206 typedef SV indirect_hint_t;
208 #define I_HINT_STRUCT 0
210 #define I_HINT_CODE(H) (H)
212 #define I_HINT_FREE(H) SvREFCNT_dec(H);
214 #endif /* !I_WORKAROUND_REQUIRE_PROPAGATION */
218 #define PTABLE_NAME ptable_hints
219 #define PTABLE_VAL_FREE(V) I_HINT_FREE(V)
228 #define ptable_hints_store(T, K, V) ptable_hints_store(aTHX_ (T), (K), (V))
229 #define ptable_hints_free(T) ptable_hints_free(aTHX_ (T))
231 #endif /* I_THREADSAFE */
233 /* Define the op->str ptable here because we need to be able to clean it during
242 } indirect_op_info_t;
244 #define PTABLE_NAME ptable
245 #define PTABLE_VAL_FREE(V) if (V) { Safefree(((indirect_op_info_t *) (V))->buf); Safefree(V); }
254 #define ptable_store(T, K, V) ptable_store(aTHX_ (T), (K), (V))
255 #define ptable_delete(T, K) ptable_delete(aTHX_ (T), (K))
256 #define ptable_clear(T) ptable_clear(aTHX_ (T))
257 #define ptable_free(T) ptable_free(aTHX_ (T))
259 #define MY_CXT_KEY __PACKAGE__ "::_guts" XS_VERSION
263 ptable *tbl; /* It really is a ptable_hints */
274 STATIC SV *indirect_clone(pTHX_ SV *sv, tTHX owner) {
275 #define indirect_clone(S, O) indirect_clone(aTHX_ (S), (O))
283 if (SvTYPE(sv) == SVt_PVHV && HvNAME_get(sv))
286 param.stashes = stashes;
288 param.proto_perl = owner;
290 dupsv = sv_dup(sv, ¶m);
294 SvREFCNT_dec(stashes);
297 return SvREFCNT_inc(dupsv);
300 STATIC void indirect_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) {
302 indirect_hint_t *h1 = ent->val;
305 if (ud->owner == aTHX)
310 h2 = PerlMemShared_malloc(sizeof *h2);
311 h2->code = indirect_clone(h1->code, ud->owner);
312 #if I_WORKAROUND_REQUIRE_PROPAGATION
313 h2->require_tag = PTR2IV(indirect_clone(INT2PTR(SV *, h1->require_tag),
317 #else /* I_HINT_STRUCT */
319 h2 = indirect_clone(h1, ud->owner);
321 #endif /* !I_HINT_STRUCT */
323 ptable_hints_store(ud->tbl, ent->key, h2);
326 STATIC void indirect_thread_cleanup(pTHX_ void *ud) {
329 SvREFCNT_dec(MY_CXT.global_code);
330 ptable_free(MY_CXT.map);
331 ptable_hints_free(MY_CXT.tbl);
334 STATIC int indirect_endav_free(pTHX_ SV *sv, MAGIC *mg) {
335 SAVEDESTRUCTOR_X(indirect_thread_cleanup, NULL);
340 STATIC MGVTBL indirect_endav_vtbl = {
357 #endif /* I_THREADSAFE */
359 #if I_WORKAROUND_REQUIRE_PROPAGATION
360 STATIC IV indirect_require_tag(pTHX) {
361 #define indirect_require_tag() indirect_require_tag(aTHX)
362 const CV *cv, *outside;
367 /* If for some reason the pragma is operational at run-time, try to discover
368 * the current cv in use. */
371 for (si = PL_curstackinfo; si; si = si->si_prev) {
374 for (cxix = si->si_cxix; cxix >= 0; --cxix) {
375 const PERL_CONTEXT *cx = si->si_cxstack + cxix;
377 switch (CxTYPE(cx)) {
380 /* The propagation workaround is only needed up to 5.10.0 and at that
381 * time format and sub contexts were still identical. And even later the
382 * cv members offsets should have been kept the same. */
384 goto get_enclosing_cv;
386 cv = cx->blk_eval.cv;
387 goto get_enclosing_cv;
398 for (outside = CvOUTSIDE(cv); outside; outside = CvOUTSIDE(cv))
403 #endif /* I_WORKAROUND_REQUIRE_PROPAGATION */
405 STATIC SV *indirect_tag(pTHX_ SV *value) {
406 #define indirect_tag(V) indirect_tag(aTHX_ (V))
412 if (SvTYPE(value) >= SVt_PVCV) {
414 SvREFCNT_inc_simple_void_NN(code);
419 h = PerlMemShared_malloc(sizeof *h);
421 # if I_WORKAROUND_REQUIRE_PROPAGATION
422 h->require_tag = indirect_require_tag();
423 # endif /* I_WORKAROUND_REQUIRE_PROPAGATION */
424 #else /* I_HINT_STRUCT */
426 #endif /* !I_HINT_STRUCT */
431 /* We only need for the key to be an unique tag for looking up the value later
432 * Allocated memory provides convenient unique identifiers, so that's why we
433 * use the hint as the key itself. */
434 ptable_hints_store(MY_CXT.tbl, h, h);
436 #endif /* I_THREADSAFE */
438 return newSViv(PTR2IV(h));
441 STATIC SV *indirect_detag(pTHX_ const SV *hint) {
442 #define indirect_detag(H) indirect_detag(aTHX_ (H))
444 #if I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION
448 h = INT2PTR(indirect_hint_t *, SvIVX(hint));
450 h = ptable_fetch(MY_CXT.tbl, h);
451 #endif /* I_THREADSAFE */
453 #if I_WORKAROUND_REQUIRE_PROPAGATION
454 if (indirect_require_tag() != h->require_tag)
455 return MY_CXT.global_code;
456 #endif /* I_WORKAROUND_REQUIRE_PROPAGATION */
458 return I_HINT_CODE(h);
461 STATIC U32 indirect_hash = 0;
463 STATIC SV *indirect_hint(pTHX) {
464 #define indirect_hint() indirect_hint(aTHX)
470 #if I_HAS_PERL(5, 10, 0) || defined(PL_parser)
475 #ifdef cop_hints_fetch_pvn
476 hint = cop_hints_fetch_pvn(PL_curcop, __PACKAGE__, __PACKAGE_LEN__,
478 #elif I_HAS_PERL(5, 9, 5)
479 hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
481 __PACKAGE__, __PACKAGE_LEN__,
486 SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, 0);
492 if (hint && SvIOK(hint))
493 return indirect_detag(hint);
496 return MY_CXT.global_code;
500 /* ... op -> source position ............................................... */
502 STATIC void indirect_map_store(pTHX_ const OP *o, STRLEN pos, SV *sv, line_t line) {
503 #define indirect_map_store(O, P, N, L) indirect_map_store(aTHX_ (O), (P), (N), (L))
504 indirect_op_info_t *oi;
509 if (!(oi = ptable_fetch(MY_CXT.map, o))) {
510 Newx(oi, 1, indirect_op_info_t);
511 ptable_store(MY_CXT.map, o, oi);
517 s = SvPV_const(sv, len);
523 if (len > oi->size) {
525 Newx(oi->buf, len, char);
528 Copy(s, oi->buf, len, char);
535 STATIC const indirect_op_info_t *indirect_map_fetch(pTHX_ const OP *o) {
536 #define indirect_map_fetch(O) indirect_map_fetch(aTHX_ (O))
539 return ptable_fetch(MY_CXT.map, o);
542 STATIC void indirect_map_delete(pTHX_ const OP *o) {
543 #define indirect_map_delete(O) indirect_map_delete(aTHX_ (O))
546 ptable_delete(MY_CXT.map, o);
549 /* --- Check functions ----------------------------------------------------- */
551 STATIC int indirect_find(pTHX_ SV *name_sv, const char *line_bufptr, STRLEN *name_pos) {
552 #define indirect_find(NSV, LBP, NP) indirect_find(aTHX_ (NSV), (LBP), (NP))
553 STRLEN name_len, line_len;
554 const char *name, *name_end;
555 const char *line, *line_end;
558 line = SvPV_const(PL_linestr, line_len);
559 line_end = line + line_len;
561 name = SvPV_const(name_sv, name_len);
562 if (name_len >= 1 && *name == '$') {
565 while (line_bufptr < line_end && *line_bufptr != '$')
567 if (line_bufptr >= line_end)
570 name_end = name + name_len;
574 p = ninstr(p, line_end, name, name_end);
577 if (!isALNUM(p[name_len]))
579 /* p points to a word that has name as prefix, skip the rest of the word */
585 *name_pos = p - line;
590 /* ... ck_const ............................................................ */
592 STATIC OP *(*indirect_old_ck_const)(pTHX_ OP *) = 0;
594 STATIC OP *indirect_ck_const(pTHX_ OP *o) {
595 o = indirect_old_ck_const(aTHX_ o);
597 if (indirect_hint()) {
600 if (SvPOK(sv) && (SvTYPE(sv) >= SVt_PV)) {
603 if (indirect_find(sv, PL_oldbufptr, &pos)) {
606 /* If the constant is equal to the current package name, try to look for
607 * a "__PACKAGE__" coming before what we got. We only need to check this
608 * when we already had a match because __PACKAGE__ can only appear in
609 * direct method calls ("new __PACKAGE__" is a syntax error). */
612 && len == (STRLEN) HvNAMELEN_get(PL_curstash)
613 && memcmp(SvPVX(sv), HvNAME_get(PL_curstash), len) == 0) {
615 SV *pkg = sv_newmortal();
616 sv_setpvn(pkg, "__PACKAGE__", sizeof("__PACKAGE__")-1);
618 if (indirect_find(pkg, PL_oldbufptr, &pos_pkg) && pos_pkg < pos) {
624 indirect_map_store(o, pos, sv, CopLINE(&PL_compiling));
630 indirect_map_delete(o);
634 /* ... ck_rv2sv ............................................................ */
636 STATIC OP *(*indirect_old_ck_rv2sv)(pTHX_ OP *) = 0;
638 STATIC OP *indirect_ck_rv2sv(pTHX_ OP *o) {
639 if (indirect_hint()) {
640 OP *op = cUNOPo->op_first;
642 const char *name = NULL;
644 OPCODE type = (OPCODE) op->op_type;
649 GV *gv = cGVOPx_gv(op);
655 if ((PL_opargs[type] & OA_CLASS_MASK) == OA_SVOP) {
656 SV *nsv = cSVOPx_sv(op);
657 if (SvPOK(nsv) && (SvTYPE(nsv) >= SVt_PV))
658 name = SvPV_const(nsv, len);
664 sv = sv_2mortal(newSVpvn("$", 1));
665 sv_catpvn_nomg(sv, name, len);
666 if (!indirect_find(sv, PL_oldbufptr, &pos)) {
667 /* If it failed, retry without the current stash */
668 const char *stash = HvNAME_get(PL_curstash);
669 STRLEN stashlen = HvNAMELEN_get(PL_curstash);
671 if ((len < stashlen + 2) || strnNE(name, stash, stashlen)
672 || name[stashlen] != ':' || name[stashlen+1] != ':') {
673 /* Failed again ? Try to remove main */
676 if ((len < stashlen + 2) || strnNE(name, stash, stashlen)
677 || name[stashlen] != ':' || name[stashlen+1] != ':')
681 sv_setpvn(sv, "$", 1);
683 sv_catpvn_nomg(sv, name + stashlen, len - stashlen);
684 if (!indirect_find(sv, PL_oldbufptr, &pos))
688 o = indirect_old_ck_rv2sv(aTHX_ o);
690 indirect_map_store(o, pos, sv, CopLINE(&PL_compiling));
695 o = indirect_old_ck_rv2sv(aTHX_ o);
697 indirect_map_delete(o);
701 /* ... ck_padany ........................................................... */
703 STATIC OP *(*indirect_old_ck_padany)(pTHX_ OP *) = 0;
705 STATIC OP *indirect_ck_padany(pTHX_ OP *o) {
706 o = indirect_old_ck_padany(aTHX_ o);
708 if (indirect_hint()) {
710 const char *s = PL_oldbufptr, *t = PL_bufptr - 1;
712 while (s < t && isSPACE(*s)) ++s;
713 if (*s == '$' && ++s <= t) {
714 while (s < t && isSPACE(*s)) ++s;
715 while (s < t && isSPACE(*t)) --t;
716 sv = sv_2mortal(newSVpvn("$", 1));
717 sv_catpvn_nomg(sv, s, t - s + 1);
718 indirect_map_store(o, s - SvPVX_const(PL_linestr),
719 sv, CopLINE(&PL_compiling));
724 indirect_map_delete(o);
728 /* ... ck_scope ............................................................ */
730 STATIC OP *(*indirect_old_ck_scope) (pTHX_ OP *) = 0;
731 STATIC OP *(*indirect_old_ck_lineseq)(pTHX_ OP *) = 0;
733 STATIC OP *indirect_ck_scope(pTHX_ OP *o) {
734 OP *(*old_ck)(pTHX_ OP *) = 0;
736 switch (o->op_type) {
737 case OP_SCOPE: old_ck = indirect_old_ck_scope; break;
738 case OP_LINESEQ: old_ck = indirect_old_ck_lineseq; break;
742 if (indirect_hint()) {
743 indirect_map_store(o, PL_oldbufptr - SvPVX_const(PL_linestr),
744 NULL, CopLINE(&PL_compiling));
748 indirect_map_delete(o);
752 /* We don't need to clean the map entries for leave ops because they can only
753 * be created by mutating from a lineseq. */
755 /* ... ck_method ........................................................... */
757 STATIC OP *(*indirect_old_ck_method)(pTHX_ OP *) = 0;
759 STATIC OP *indirect_ck_method(pTHX_ OP *o) {
760 if (indirect_hint()) {
761 OP *op = cUNOPo->op_first;
763 /* Indirect method call is only possible when the method is a bareword, so
764 * don't trip up on $obj->$meth. */
765 if (op && op->op_type == OP_CONST) {
766 const indirect_op_info_t *oi = indirect_map_fetch(op);
774 sv = sv_2mortal(newSVpvn(oi->buf, oi->len));
776 /* Keep the old line so that we really point to the first line of the
780 o = indirect_old_ck_method(aTHX_ o);
781 /* o may now be a method_named */
783 indirect_map_store(o, pos, sv, line);
789 o = indirect_old_ck_method(aTHX_ o);
791 indirect_map_delete(o);
795 /* ... ck_method_named ..................................................... */
797 /* "use foo/no foo" compiles its call to import/unimport directly to a
798 * method_named op. */
800 STATIC OP *(*indirect_old_ck_method_named)(pTHX_ OP *) = 0;
802 STATIC OP *indirect_ck_method_named(pTHX_ OP *o) {
803 if (indirect_hint()) {
809 if (!SvPOK(sv) || (SvTYPE(sv) < SVt_PV))
811 sv = sv_mortalcopy(sv);
813 if (!indirect_find(sv, PL_oldbufptr, &pos))
815 line = CopLINE(&PL_compiling);
817 o = indirect_old_ck_method_named(aTHX_ o);
819 indirect_map_store(o, pos, sv, line);
824 o = indirect_old_ck_method_named(aTHX_ o);
826 indirect_map_delete(o);
830 /* ... ck_entersub ......................................................... */
832 STATIC OP *(*indirect_old_ck_entersub)(pTHX_ OP *) = 0;
834 STATIC OP *indirect_ck_entersub(pTHX_ OP *o) {
835 SV *code = indirect_hint();
837 o = indirect_old_ck_entersub(aTHX_ o);
840 const indirect_op_info_t *moi, *ooi;
846 lop = (LISTOP *) oop;
847 if (!(lop->op_flags & OPf_KIDS))
850 } while (oop->op_type != OP_PUSHMARK);
851 oop = OP_SIBLING(oop);
857 switch (oop->op_type) {
868 if (mop->op_type == OP_METHOD)
869 mop = cUNOPx(mop)->op_first;
870 else if (mop->op_type != OP_METHOD_NAMED)
873 moi = indirect_map_fetch(mop);
877 ooi = indirect_map_fetch(oop);
881 /* When positions are identical, the method and the object must have the
882 * same name. But it also means that it is an indirect call, as "foo->foo"
883 * results in different positions. */
884 if ( moi->line < ooi->line
885 || (moi->line == ooi->line && moi->pos <= ooi->pos)) {
893 file = sv_2mortal(newSVpv(CopFILE(&PL_compiling), 0));
895 file = sv_mortalcopy(CopFILESV(&PL_compiling));
900 mPUSHp(ooi->buf, ooi->len);
901 mPUSHp(moi->buf, moi->len);
906 call_sv(code, G_VOID);
919 STATIC U32 indirect_initialized = 0;
921 STATIC void indirect_teardown(pTHX_ void *root) {
922 if (!indirect_initialized)
932 ptable_free(MY_CXT.map);
934 ptable_hints_free(MY_CXT.tbl);
938 indirect_ck_restore(OP_CONST, &indirect_old_ck_const);
939 indirect_ck_restore(OP_RV2SV, &indirect_old_ck_rv2sv);
940 indirect_ck_restore(OP_PADANY, &indirect_old_ck_padany);
941 indirect_ck_restore(OP_SCOPE, &indirect_old_ck_scope);
942 indirect_ck_restore(OP_LINESEQ, &indirect_old_ck_lineseq);
944 indirect_ck_restore(OP_METHOD, &indirect_old_ck_method);
945 indirect_ck_restore(OP_METHOD_NAMED, &indirect_old_ck_method_named);
946 indirect_ck_restore(OP_ENTERSUB, &indirect_old_ck_entersub);
948 indirect_initialized = 0;
951 STATIC void indirect_setup(pTHX) {
952 #define indirect_setup() indirect_setup(aTHX)
953 if (indirect_initialized)
959 MY_CXT.tbl = ptable_new();
962 MY_CXT.map = ptable_new();
963 MY_CXT.global_code = NULL;
966 indirect_ck_replace(OP_CONST, indirect_ck_const, &indirect_old_ck_const);
967 indirect_ck_replace(OP_RV2SV, indirect_ck_rv2sv, &indirect_old_ck_rv2sv);
968 indirect_ck_replace(OP_PADANY, indirect_ck_padany, &indirect_old_ck_padany);
969 indirect_ck_replace(OP_SCOPE, indirect_ck_scope, &indirect_old_ck_scope);
970 indirect_ck_replace(OP_LINESEQ, indirect_ck_scope, &indirect_old_ck_lineseq);
972 indirect_ck_replace(OP_METHOD, indirect_ck_method,
973 &indirect_old_ck_method);
974 indirect_ck_replace(OP_METHOD_NAMED, indirect_ck_method_named,
975 &indirect_old_ck_method_named);
976 indirect_ck_replace(OP_ENTERSUB, indirect_ck_entersub,
977 &indirect_old_ck_entersub);
980 call_atexit(indirect_teardown, aTHX);
982 call_atexit(indirect_teardown, NULL);
985 indirect_initialized = 1;
988 STATIC U32 indirect_booted = 0;
990 /* --- XS ------------------------------------------------------------------ */
992 MODULE = indirect PACKAGE = indirect
998 if (!indirect_booted++) {
1001 PERL_HASH(indirect_hash, __PACKAGE__, __PACKAGE_LEN__);
1003 stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
1004 newCONSTSUB(stash, "I_THREADSAFE", newSVuv(I_THREADSAFE));
1005 newCONSTSUB(stash, "I_FORKSAFE", newSVuv(I_FORKSAFE));
1018 SV *global_code_dup;
1024 ud.tbl = t = ptable_new();
1025 ud.owner = MY_CXT.owner;
1026 ptable_walk(MY_CXT.tbl, indirect_ptable_clone, &ud);
1027 global_code_dup = indirect_clone(MY_CXT.global_code, MY_CXT.owner);
1031 MY_CXT.map = ptable_new();
1033 MY_CXT.owner = aTHX;
1034 MY_CXT.global_code = global_code_dup;
1036 gv = gv_fetchpv(__PACKAGE__ "::_THREAD_CLEANUP", 0, SVt_PVCV);
1042 if (!av_store(PL_endav, av_len(PL_endav) + 1, (SV *) cv))
1044 sv_magicext((SV *) PL_endav, NULL, PERL_MAGIC_ext, &indirect_endav_vtbl, NULL, 0);
1049 _THREAD_CLEANUP(...)
1052 indirect_thread_cleanup(aTHX_ NULL);
1061 RETVAL = indirect_tag(value);
1071 else if (SvROK(code))
1075 SvREFCNT_dec(MY_CXT.global_code);
1076 MY_CXT.global_code = SvREFCNT_inc(code);