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);
328 STATIC void indirect_thread_cleanup(pTHX_ void *ud) {
331 SvREFCNT_dec(MY_CXT.global_code);
332 ptable_free(MY_CXT.map);
333 ptable_hints_free(MY_CXT.tbl);
336 #endif /* I_THREADSAFE */
338 #if I_WORKAROUND_REQUIRE_PROPAGATION
339 STATIC IV indirect_require_tag(pTHX) {
340 #define indirect_require_tag() indirect_require_tag(aTHX)
341 const CV *cv, *outside;
346 /* If for some reason the pragma is operational at run-time, try to discover
347 * the current cv in use. */
350 for (si = PL_curstackinfo; si; si = si->si_prev) {
353 for (cxix = si->si_cxix; cxix >= 0; --cxix) {
354 const PERL_CONTEXT *cx = si->si_cxstack + cxix;
356 switch (CxTYPE(cx)) {
359 /* The propagation workaround is only needed up to 5.10.0 and at that
360 * time format and sub contexts were still identical. And even later the
361 * cv members offsets should have been kept the same. */
363 goto get_enclosing_cv;
365 cv = cx->blk_eval.cv;
366 goto get_enclosing_cv;
377 for (outside = CvOUTSIDE(cv); outside; outside = CvOUTSIDE(cv))
382 #endif /* I_WORKAROUND_REQUIRE_PROPAGATION */
384 STATIC SV *indirect_tag(pTHX_ SV *value) {
385 #define indirect_tag(V) indirect_tag(aTHX_ (V))
391 if (SvTYPE(value) >= SVt_PVCV) {
393 SvREFCNT_inc_simple_void_NN(code);
398 h = PerlMemShared_malloc(sizeof *h);
400 # if I_WORKAROUND_REQUIRE_PROPAGATION
401 h->require_tag = indirect_require_tag();
402 # endif /* I_WORKAROUND_REQUIRE_PROPAGATION */
403 #else /* I_HINT_STRUCT */
405 #endif /* !I_HINT_STRUCT */
410 /* We only need for the key to be an unique tag for looking up the value later
411 * Allocated memory provides convenient unique identifiers, so that's why we
412 * use the hint as the key itself. */
413 ptable_hints_store(MY_CXT.tbl, h, h);
415 #endif /* I_THREADSAFE */
417 return newSViv(PTR2IV(h));
420 STATIC SV *indirect_detag(pTHX_ const SV *hint) {
421 #define indirect_detag(H) indirect_detag(aTHX_ (H))
423 #if I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION
427 h = INT2PTR(indirect_hint_t *, SvIVX(hint));
429 h = ptable_fetch(MY_CXT.tbl, h);
430 #endif /* I_THREADSAFE */
432 #if I_WORKAROUND_REQUIRE_PROPAGATION
433 if (indirect_require_tag() != h->require_tag)
434 return MY_CXT.global_code;
435 #endif /* I_WORKAROUND_REQUIRE_PROPAGATION */
437 return I_HINT_CODE(h);
440 STATIC U32 indirect_hash = 0;
442 STATIC SV *indirect_hint(pTHX) {
443 #define indirect_hint() indirect_hint(aTHX)
449 #if I_HAS_PERL(5, 10, 0) || defined(PL_parser)
454 #ifdef cop_hints_fetch_pvn
455 hint = cop_hints_fetch_pvn(PL_curcop, __PACKAGE__, __PACKAGE_LEN__,
457 #elif I_HAS_PERL(5, 9, 5)
458 hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
460 __PACKAGE__, __PACKAGE_LEN__,
465 SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, 0);
471 if (hint && SvIOK(hint))
472 return indirect_detag(hint);
475 return MY_CXT.global_code;
479 /* ... op -> source position ............................................... */
481 STATIC void indirect_map_store(pTHX_ const OP *o, STRLEN pos, SV *sv, line_t line) {
482 #define indirect_map_store(O, P, N, L) indirect_map_store(aTHX_ (O), (P), (N), (L))
483 indirect_op_info_t *oi;
488 if (!(oi = ptable_fetch(MY_CXT.map, o))) {
489 Newx(oi, 1, indirect_op_info_t);
490 ptable_store(MY_CXT.map, o, oi);
496 s = SvPV_const(sv, len);
502 if (len > oi->size) {
504 Newx(oi->buf, len, char);
507 Copy(s, oi->buf, len, char);
514 STATIC const indirect_op_info_t *indirect_map_fetch(pTHX_ const OP *o) {
515 #define indirect_map_fetch(O) indirect_map_fetch(aTHX_ (O))
518 return ptable_fetch(MY_CXT.map, o);
521 STATIC void indirect_map_delete(pTHX_ const OP *o) {
522 #define indirect_map_delete(O) indirect_map_delete(aTHX_ (O))
525 ptable_delete(MY_CXT.map, o);
528 /* --- Check functions ----------------------------------------------------- */
530 STATIC int indirect_find(pTHX_ SV *name_sv, const char *line_bufptr, STRLEN *name_pos) {
531 #define indirect_find(NSV, LBP, NP) indirect_find(aTHX_ (NSV), (LBP), (NP))
532 STRLEN name_len, line_len;
533 const char *name, *name_end;
534 const char *line, *line_end;
537 line = SvPV_const(PL_linestr, line_len);
538 line_end = line + line_len;
540 name = SvPV_const(name_sv, name_len);
541 if (name_len >= 1 && *name == '$') {
544 while (line_bufptr < line_end && *line_bufptr != '$')
546 if (line_bufptr >= line_end)
549 name_end = name + name_len;
553 p = ninstr(p, line_end, name, name_end);
556 if (!isALNUM(p[name_len]))
558 /* p points to a word that has name as prefix, skip the rest of the word */
564 *name_pos = p - line;
569 /* ... ck_const ............................................................ */
571 STATIC OP *(*indirect_old_ck_const)(pTHX_ OP *) = 0;
573 STATIC OP *indirect_ck_const(pTHX_ OP *o) {
574 o = indirect_old_ck_const(aTHX_ o);
576 if (indirect_hint()) {
579 if (SvPOK(sv) && (SvTYPE(sv) >= SVt_PV)) {
582 if (indirect_find(sv, PL_oldbufptr, &pos)) {
585 /* If the constant is equal to the current package name, try to look for
586 * a "__PACKAGE__" coming before what we got. We only need to check this
587 * when we already had a match because __PACKAGE__ can only appear in
588 * direct method calls ("new __PACKAGE__" is a syntax error). */
591 && len == (STRLEN) HvNAMELEN_get(PL_curstash)
592 && memcmp(SvPVX(sv), HvNAME_get(PL_curstash), len) == 0) {
594 SV *pkg = sv_newmortal();
595 sv_setpvn(pkg, "__PACKAGE__", sizeof("__PACKAGE__")-1);
597 if (indirect_find(pkg, PL_oldbufptr, &pos_pkg) && pos_pkg < pos) {
603 indirect_map_store(o, pos, sv, CopLINE(&PL_compiling));
609 indirect_map_delete(o);
613 /* ... ck_rv2sv ............................................................ */
615 STATIC OP *(*indirect_old_ck_rv2sv)(pTHX_ OP *) = 0;
617 STATIC OP *indirect_ck_rv2sv(pTHX_ OP *o) {
618 if (indirect_hint()) {
619 OP *op = cUNOPo->op_first;
621 const char *name = NULL;
623 OPCODE type = (OPCODE) op->op_type;
628 GV *gv = cGVOPx_gv(op);
634 if ((PL_opargs[type] & OA_CLASS_MASK) == OA_SVOP) {
635 SV *nsv = cSVOPx_sv(op);
636 if (SvPOK(nsv) && (SvTYPE(nsv) >= SVt_PV))
637 name = SvPV_const(nsv, len);
643 sv = sv_2mortal(newSVpvn("$", 1));
644 sv_catpvn_nomg(sv, name, len);
645 if (!indirect_find(sv, PL_oldbufptr, &pos)) {
646 /* If it failed, retry without the current stash */
647 const char *stash = HvNAME_get(PL_curstash);
648 STRLEN stashlen = HvNAMELEN_get(PL_curstash);
650 if ((len < stashlen + 2) || strnNE(name, stash, stashlen)
651 || name[stashlen] != ':' || name[stashlen+1] != ':') {
652 /* Failed again ? Try to remove main */
655 if ((len < stashlen + 2) || strnNE(name, stash, stashlen)
656 || name[stashlen] != ':' || name[stashlen+1] != ':')
660 sv_setpvn(sv, "$", 1);
662 sv_catpvn_nomg(sv, name + stashlen, len - stashlen);
663 if (!indirect_find(sv, PL_oldbufptr, &pos))
667 o = indirect_old_ck_rv2sv(aTHX_ o);
669 indirect_map_store(o, pos, sv, CopLINE(&PL_compiling));
674 o = indirect_old_ck_rv2sv(aTHX_ o);
676 indirect_map_delete(o);
680 /* ... ck_padany ........................................................... */
682 STATIC OP *(*indirect_old_ck_padany)(pTHX_ OP *) = 0;
684 STATIC OP *indirect_ck_padany(pTHX_ OP *o) {
685 o = indirect_old_ck_padany(aTHX_ o);
687 if (indirect_hint()) {
689 const char *s = PL_oldbufptr, *t = PL_bufptr - 1;
691 while (s < t && isSPACE(*s)) ++s;
692 if (*s == '$' && ++s <= t) {
693 while (s < t && isSPACE(*s)) ++s;
694 while (s < t && isSPACE(*t)) --t;
695 sv = sv_2mortal(newSVpvn("$", 1));
696 sv_catpvn_nomg(sv, s, t - s + 1);
697 indirect_map_store(o, s - SvPVX_const(PL_linestr),
698 sv, CopLINE(&PL_compiling));
703 indirect_map_delete(o);
707 /* ... ck_scope ............................................................ */
709 STATIC OP *(*indirect_old_ck_scope) (pTHX_ OP *) = 0;
710 STATIC OP *(*indirect_old_ck_lineseq)(pTHX_ OP *) = 0;
712 STATIC OP *indirect_ck_scope(pTHX_ OP *o) {
713 OP *(*old_ck)(pTHX_ OP *) = 0;
715 switch (o->op_type) {
716 case OP_SCOPE: old_ck = indirect_old_ck_scope; break;
717 case OP_LINESEQ: old_ck = indirect_old_ck_lineseq; break;
721 if (indirect_hint()) {
722 indirect_map_store(o, PL_oldbufptr - SvPVX_const(PL_linestr),
723 NULL, CopLINE(&PL_compiling));
727 indirect_map_delete(o);
731 /* We don't need to clean the map entries for leave ops because they can only
732 * be created by mutating from a lineseq. */
734 /* ... ck_method ........................................................... */
736 STATIC OP *(*indirect_old_ck_method)(pTHX_ OP *) = 0;
738 STATIC OP *indirect_ck_method(pTHX_ OP *o) {
739 if (indirect_hint()) {
740 OP *op = cUNOPo->op_first;
742 /* Indirect method call is only possible when the method is a bareword, so
743 * don't trip up on $obj->$meth. */
744 if (op && op->op_type == OP_CONST) {
745 const indirect_op_info_t *oi = indirect_map_fetch(op);
753 sv = sv_2mortal(newSVpvn(oi->buf, oi->len));
755 /* Keep the old line so that we really point to the first line of the
759 o = indirect_old_ck_method(aTHX_ o);
760 /* o may now be a method_named */
762 indirect_map_store(o, pos, sv, line);
768 o = indirect_old_ck_method(aTHX_ o);
770 indirect_map_delete(o);
774 /* ... ck_method_named ..................................................... */
776 /* "use foo/no foo" compiles its call to import/unimport directly to a
777 * method_named op. */
779 STATIC OP *(*indirect_old_ck_method_named)(pTHX_ OP *) = 0;
781 STATIC OP *indirect_ck_method_named(pTHX_ OP *o) {
782 if (indirect_hint()) {
788 if (!SvPOK(sv) || (SvTYPE(sv) < SVt_PV))
790 sv = sv_mortalcopy(sv);
792 if (!indirect_find(sv, PL_oldbufptr, &pos))
794 line = CopLINE(&PL_compiling);
796 o = indirect_old_ck_method_named(aTHX_ o);
798 indirect_map_store(o, pos, sv, line);
803 o = indirect_old_ck_method_named(aTHX_ o);
805 indirect_map_delete(o);
809 /* ... ck_entersub ......................................................... */
811 STATIC OP *(*indirect_old_ck_entersub)(pTHX_ OP *) = 0;
813 STATIC OP *indirect_ck_entersub(pTHX_ OP *o) {
814 SV *code = indirect_hint();
816 o = indirect_old_ck_entersub(aTHX_ o);
819 const indirect_op_info_t *moi, *ooi;
825 lop = (LISTOP *) oop;
826 if (!(lop->op_flags & OPf_KIDS))
829 } while (oop->op_type != OP_PUSHMARK);
830 oop = OP_SIBLING(oop);
836 switch (oop->op_type) {
847 if (mop->op_type == OP_METHOD)
848 mop = cUNOPx(mop)->op_first;
849 else if (mop->op_type != OP_METHOD_NAMED)
852 moi = indirect_map_fetch(mop);
856 ooi = indirect_map_fetch(oop);
860 /* When positions are identical, the method and the object must have the
861 * same name. But it also means that it is an indirect call, as "foo->foo"
862 * results in different positions. */
863 if ( moi->line < ooi->line
864 || (moi->line == ooi->line && moi->pos <= ooi->pos)) {
872 file = sv_2mortal(newSVpv(CopFILE(&PL_compiling), 0));
874 file = sv_mortalcopy(CopFILESV(&PL_compiling));
879 mPUSHp(ooi->buf, ooi->len);
880 mPUSHp(moi->buf, moi->len);
885 call_sv(code, G_VOID);
898 STATIC U32 indirect_initialized = 0;
900 STATIC void indirect_teardown(pTHX_ void *root) {
901 if (!indirect_initialized)
911 ptable_free(MY_CXT.map);
913 ptable_hints_free(MY_CXT.tbl);
917 indirect_ck_restore(OP_CONST, &indirect_old_ck_const);
918 indirect_ck_restore(OP_RV2SV, &indirect_old_ck_rv2sv);
919 indirect_ck_restore(OP_PADANY, &indirect_old_ck_padany);
920 indirect_ck_restore(OP_SCOPE, &indirect_old_ck_scope);
921 indirect_ck_restore(OP_LINESEQ, &indirect_old_ck_lineseq);
923 indirect_ck_restore(OP_METHOD, &indirect_old_ck_method);
924 indirect_ck_restore(OP_METHOD_NAMED, &indirect_old_ck_method_named);
925 indirect_ck_restore(OP_ENTERSUB, &indirect_old_ck_entersub);
927 indirect_initialized = 0;
930 STATIC void indirect_setup(pTHX) {
931 #define indirect_setup() indirect_setup(aTHX)
932 if (indirect_initialized)
938 MY_CXT.tbl = ptable_new();
941 MY_CXT.map = ptable_new();
942 MY_CXT.global_code = NULL;
945 indirect_ck_replace(OP_CONST, indirect_ck_const, &indirect_old_ck_const);
946 indirect_ck_replace(OP_RV2SV, indirect_ck_rv2sv, &indirect_old_ck_rv2sv);
947 indirect_ck_replace(OP_PADANY, indirect_ck_padany, &indirect_old_ck_padany);
948 indirect_ck_replace(OP_SCOPE, indirect_ck_scope, &indirect_old_ck_scope);
949 indirect_ck_replace(OP_LINESEQ, indirect_ck_scope, &indirect_old_ck_lineseq);
951 indirect_ck_replace(OP_METHOD, indirect_ck_method,
952 &indirect_old_ck_method);
953 indirect_ck_replace(OP_METHOD_NAMED, indirect_ck_method_named,
954 &indirect_old_ck_method_named);
955 indirect_ck_replace(OP_ENTERSUB, indirect_ck_entersub,
956 &indirect_old_ck_entersub);
959 call_atexit(indirect_teardown, aTHX);
961 call_atexit(indirect_teardown, NULL);
964 indirect_initialized = 1;
967 STATIC U32 indirect_booted = 0;
969 /* --- XS ------------------------------------------------------------------ */
971 MODULE = indirect PACKAGE = indirect
977 if (!indirect_booted++) {
980 PERL_HASH(indirect_hash, __PACKAGE__, __PACKAGE_LEN__);
982 stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
983 newCONSTSUB(stash, "I_THREADSAFE", newSVuv(I_THREADSAFE));
984 newCONSTSUB(stash, "I_FORKSAFE", newSVuv(I_FORKSAFE));
1002 ud.tbl = t = ptable_new();
1003 ud.owner = MY_CXT.owner;
1004 ptable_walk(MY_CXT.tbl, indirect_ptable_clone, &ud);
1005 global_code_dup = indirect_clone(MY_CXT.global_code, MY_CXT.owner);
1009 MY_CXT.map = ptable_new();
1011 MY_CXT.owner = aTHX;
1012 MY_CXT.global_code = global_code_dup;
1014 reap(3, indirect_thread_cleanup, NULL);
1023 RETVAL = indirect_tag(value);
1033 else if (SvROK(code))
1037 SvREFCNT_dec(MY_CXT.global_code);
1038 MY_CXT.global_code = SvREFCNT_inc(code);