]> git.vpit.fr Git - perl/modules/indirect.git/blob - indirect.xs
Remove unused variable.
[perl/modules/indirect.git] / indirect.xs
1 /* This file is part of the indirect Perl module.
2  * See http://search.cpan.org/dist/indirect/ */
3
4 #define PERL_NO_GET_CONTEXT
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8
9 #define __PACKAGE__     "indirect"
10 #define __PACKAGE_LEN__ (sizeof(__PACKAGE__)-1)
11
12 /* --- Compatibility wrappers ---------------------------------------------- */
13
14 #ifndef NOOP
15 # define NOOP
16 #endif
17
18 #ifndef dNOOP
19 # define dNOOP
20 #endif
21
22 #ifndef SvPV_const
23 # define SvPV_const SvPV
24 #endif
25
26 #ifndef SvPV_nolen_const
27 # define SvPV_nolen_const SvPV_nolen
28 #endif
29
30 #ifndef SvPVX_const
31 # define SvPVX_const SvPVX
32 #endif
33
34 #ifndef sv_catpvn_nomg
35 # define sv_catpvn_nomg sv_catpvn
36 #endif
37
38 #ifndef mPUSHu
39 # define mPUSHu(U) PUSHs(sv_2mortal(newSVuv(U)))
40 #endif
41
42 #ifndef HvNAME_get
43 # define HvNAME_get(H) HvNAME(H)
44 #endif
45
46 #ifndef HvNAMELEN_get
47 # define HvNAMELEN_get(H) strlen(HvNAME_get(H))
48 #endif
49
50 #define I_HAS_PERL(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
51
52 #if I_HAS_PERL(5, 10, 0) || defined(PL_parser)
53 # ifndef PL_lex_inwhat
54 #  define PL_lex_inwhat PL_parser->lex_inwhat
55 # endif
56 # ifndef PL_linestr
57 #  define PL_linestr PL_parser->linestr
58 # endif
59 # ifndef PL_bufptr
60 #  define PL_bufptr PL_parser->bufptr
61 # endif
62 # ifndef PL_oldbufptr
63 #  define PL_oldbufptr PL_parser->oldbufptr
64 # endif
65 #else
66 # ifndef PL_lex_inwhat
67 #  define PL_lex_inwhat PL_Ilex_inwhat
68 # endif
69 # ifndef PL_linestr
70 #  define PL_linestr PL_Ilinestr
71 # endif
72 # ifndef PL_bufptr
73 #  define PL_bufptr PL_Ibufptr
74 # endif
75 # ifndef PL_oldbufptr
76 #  define PL_oldbufptr PL_Ioldbufptr
77 # endif
78 #endif
79
80 #ifndef I_WORKAROUND_REQUIRE_PROPAGATION
81 # define I_WORKAROUND_REQUIRE_PROPAGATION !I_HAS_PERL(5, 10, 1)
82 #endif
83
84 /* ... Thread safety and multiplicity ...................................... */
85
86 #ifndef I_MULTIPLICITY
87 # if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT)
88 #  define I_MULTIPLICITY 1
89 # else
90 #  define I_MULTIPLICITY 0
91 # endif
92 #endif
93 #if I_MULTIPLICITY && !defined(tTHX)
94 # define tTHX PerlInterpreter*
95 #endif
96
97 #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))
98 # define I_THREADSAFE 1
99 # ifndef MY_CXT_CLONE
100 #  define MY_CXT_CLONE \
101     dMY_CXT_SV;                                                      \
102     my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1)); \
103     Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t); \
104     sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
105 # endif
106 #else
107 # define I_THREADSAFE 0
108 # undef  dMY_CXT
109 # define dMY_CXT      dNOOP
110 # undef  MY_CXT
111 # define MY_CXT       indirect_globaldata
112 # undef  START_MY_CXT
113 # define START_MY_CXT STATIC my_cxt_t MY_CXT;
114 # undef  MY_CXT_INIT
115 # define MY_CXT_INIT  NOOP
116 # undef  MY_CXT_CLONE
117 # define MY_CXT_CLONE NOOP
118 #endif
119
120 /* --- Helpers ------------------------------------------------------------- */
121
122 /* ... Thread-safe hints ................................................... */
123
124 /* If any of those are true, we need to store the hint in a global table. */
125
126 #if I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION
127
128 typedef struct {
129  SV  *code;
130 #if I_WORKAROUND_REQUIRE_PROPAGATION
131  I32  requires;
132 #endif
133 } indirect_hint_t;
134
135 #define PTABLE_NAME ptable_hints
136
137 #define PTABLE_VAL_FREE(V) \
138    { indirect_hint_t *h = (V); SvREFCNT_dec(h->code); PerlMemShared_free(h); }
139
140 #define pPTBL  pTHX
141 #define pPTBL_ pTHX_
142 #define aPTBL  aTHX
143 #define aPTBL_ aTHX_
144
145 #include "ptable.h"
146
147 #define ptable_hints_store(T, K, V) ptable_hints_store(aTHX_ (T), (K), (V))
148 #define ptable_hints_free(T)        ptable_hints_free(aTHX_ (T))
149
150 #endif /* I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION */
151
152 /* Define the op->str ptable here because we need to be able to clean it during
153  * thread cleanup. */
154
155 #define PTABLE_NAME        ptable
156 #define PTABLE_VAL_FREE(V) SvREFCNT_dec(V)
157
158 #define pPTBL  pTHX
159 #define pPTBL_ pTHX_
160 #define aPTBL  aTHX
161 #define aPTBL_ aTHX_
162
163 #include "ptable.h"
164
165 #define ptable_store(T, K, V) ptable_store(aTHX_ (T), (K), (V))
166 #define ptable_clear(T)       ptable_clear(aTHX_ (T))
167 #define ptable_free(T)        ptable_free(aTHX_ (T))
168
169 #define MY_CXT_KEY __PACKAGE__ "::_guts" XS_VERSION
170
171 typedef struct {
172 #if I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION
173  ptable     *tbl; /* It really is a ptable_hints */
174 #endif
175  ptable     *map;
176  const char *linestr;
177 #if I_THREADSAFE
178  tTHX        owner;
179 #endif
180 } my_cxt_t;
181
182 START_MY_CXT
183
184 #if I_THREADSAFE
185
186 STATIC void indirect_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) {
187  my_cxt_t        *ud = ud_;
188  indirect_hint_t *h1 = ent->val;
189  indirect_hint_t *h2 = PerlMemShared_malloc(sizeof *h2);
190
191  *h2 = *h1;
192
193  if (ud->owner != aTHX) {
194   SV *val = h1->code;
195   CLONE_PARAMS param;
196   AV *stashes = (SvTYPE(val) == SVt_PVHV && HvNAME_get(val)) ? newAV() : NULL;
197   param.stashes    = stashes;
198   param.flags      = 0;
199   param.proto_perl = ud->owner;
200   h2->code = sv_dup(val, &param);
201   if (stashes) {
202    av_undef(stashes);
203    SvREFCNT_dec(stashes);
204   }
205  }
206
207  ptable_hints_store(ud->tbl, ent->key, h2);
208  SvREFCNT_inc(h2->code);
209 }
210
211 STATIC void indirect_thread_cleanup(pTHX_ void *);
212
213 STATIC void indirect_thread_cleanup(pTHX_ void *ud) {
214  int *level = ud;
215
216  if (*level) {
217   *level = 0;
218   LEAVE;
219   SAVEDESTRUCTOR_X(indirect_thread_cleanup, level);
220   ENTER;
221  } else {
222   dMY_CXT;
223   PerlMemShared_free(level);
224   ptable_free(MY_CXT.map);
225   ptable_hints_free(MY_CXT.tbl);
226  }
227 }
228
229 #endif /* I_THREADSAFE */
230
231 #if I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION
232
233 STATIC SV *indirect_tag(pTHX_ SV *value) {
234 #define indirect_tag(V) indirect_tag(aTHX_ (V))
235  indirect_hint_t *h;
236  dMY_CXT;
237
238  value = SvOK(value) && SvROK(value) ? SvRV(value) : NULL;
239
240  h = PerlMemShared_malloc(sizeof *h);
241  h->code = SvREFCNT_inc(value);
242
243 #if I_WORKAROUND_REQUIRE_PROPAGATION
244  {
245   const PERL_SI *si;
246   I32            requires = 0;
247
248   for (si = PL_curstackinfo; si; si = si->si_prev) {
249    I32 cxix;
250
251    for (cxix = si->si_cxix; cxix >= 0; --cxix) {
252     const PERL_CONTEXT *cx = si->si_cxstack + cxix;
253
254     if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE)
255      ++requires;
256    }
257   }
258
259   h->requires = requires;
260  }
261 #endif
262
263  /* We only need for the key to be an unique tag for looking up the value later.
264   * Allocated memory provides convenient unique identifiers, so that's why we
265   * use the value pointer as the key itself. */
266  ptable_hints_store(MY_CXT.tbl, value, h);
267
268  return newSVuv(PTR2UV(value));
269 }
270
271 STATIC SV *indirect_detag(pTHX_ const SV *hint) {
272 #define indirect_detag(H) indirect_detag(aTHX_ (H))
273  indirect_hint_t *h;
274  dMY_CXT;
275
276  if (!(hint && SvOK(hint) && SvIOK(hint)))
277   return NULL;
278
279  h = ptable_fetch(MY_CXT.tbl, INT2PTR(void *, SvUVX(hint)));
280
281 #if I_WORKAROUND_REQUIRE_PROPAGATION
282  {
283   const PERL_SI *si;
284   I32            requires = 0;
285
286   for (si = PL_curstackinfo; si; si = si->si_prev) {
287    I32 cxix;
288
289    for (cxix = si->si_cxix; cxix >= 0; --cxix) {
290     const PERL_CONTEXT *cx = si->si_cxstack + cxix;
291
292     if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE
293                                && ++requires > h->requires)
294      return NULL;
295    }
296   }
297  }
298 #endif
299
300  return h->code;
301 }
302
303 #else
304
305 STATIC SV *indirect_tag(pTHX_ SV *value) {
306 #define indirect_tag(V) indirect_tag(aTHX_ (V))
307  UV tag = 0;
308
309  if (SvOK(value) && SvROK(value)) {
310   value = SvRV(value);
311   SvREFCNT_inc(value);
312   tag = PTR2UV(value);
313  }
314
315  return newSVuv(tag);
316 }
317
318 #define indirect_detag(H) (((H) && SvOK(H)) ? INT2PTR(SV *, SvUVX(H)) : NULL)
319
320 #endif /* I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION */
321
322 STATIC U32 indirect_hash = 0;
323
324 STATIC SV *indirect_hint(pTHX) {
325 #define indirect_hint() indirect_hint(aTHX)
326  SV *hint;
327 #if I_HAS_PERL(5, 9, 5)
328  hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
329                                        NULL,
330                                        __PACKAGE__, __PACKAGE_LEN__,
331                                        0,
332                                        indirect_hash);
333 #else
334  SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__,
335                                                                  indirect_hash);
336  if (!val)
337   return 0;
338  hint = *val;
339 #endif
340  return indirect_detag(hint);
341 }
342
343 /* ... op -> source position ............................................... */
344
345 STATIC void indirect_map_store(pTHX_ const OP *o, const char *src, SV *sv) {
346 #define indirect_map_store(O, S, N) indirect_map_store(aTHX_ (O), (S), (N))
347  dMY_CXT;
348  SV *val;
349
350  /* When lex_inwhat is set, we're in a quotelike environment (qq, qr, but not q)
351   * In this case the linestr has temporarly changed, but the old buffer should
352   * still be alive somewhere. */
353
354  if (!PL_lex_inwhat) {
355   const char *pl_linestr = SvPVX_const(PL_linestr);
356   if (MY_CXT.linestr != pl_linestr) {
357    ptable_clear(MY_CXT.map);
358    MY_CXT.linestr = pl_linestr;
359   }
360  }
361
362  val = newSVsv(sv);
363  SvUPGRADE(val, SVt_PVIV);
364  SvUVX(val) = PTR2UV(src);
365  SvIOK_on(val);
366  SvIsUV_on(val);
367  SvREADONLY_on(val);
368
369  ptable_store(MY_CXT.map, o, val);
370 }
371
372 STATIC const char *indirect_map_fetch(pTHX_ const OP *o, SV ** const name) {
373 #define indirect_map_fetch(O, S) indirect_map_fetch(aTHX_ (O), (S))
374  dMY_CXT;
375  SV *val;
376
377  if (MY_CXT.linestr != SvPVX_const(PL_linestr))
378   return NULL;
379
380  val = ptable_fetch(MY_CXT.map, o);
381  if (!val) {
382   *name = NULL;
383   return NULL;
384  }
385
386  *name = val;
387  return INT2PTR(const char *, SvUVX(val));
388 }
389
390 STATIC void indirect_map_delete(pTHX_ const OP *o) {
391 #define indirect_map_delete(O) indirect_map_delete(aTHX_ (O))
392  dMY_CXT;
393
394  ptable_store(MY_CXT.map, o, NULL);
395 }
396
397 /* --- Check functions ----------------------------------------------------- */
398
399 STATIC const char *indirect_find(pTHX_ SV *sv, const char *s) {
400 #define indirect_find(N, S) indirect_find(aTHX_ (N), (S))
401  STRLEN len;
402  const char *p = NULL, *r = SvPV_const(sv, len);
403
404  if (len >= 1 && *r == '$') {
405   ++r;
406   --len;
407   s = strchr(s, '$');
408   if (!s)
409    return NULL;
410  }
411
412  p = strstr(s, r);
413  while (p) {
414   p += len;
415   if (!isALNUM(*p))
416    break;
417   p = strstr(p + 1, r);
418  }
419
420  return p;
421 }
422
423 /* ... ck_const ............................................................ */
424
425 STATIC OP *(*indirect_old_ck_const)(pTHX_ OP *) = 0;
426
427 STATIC OP *indirect_ck_const(pTHX_ OP *o) {
428  o = CALL_FPTR(indirect_old_ck_const)(aTHX_ o);
429
430  if (indirect_hint()) {
431   SV *sv = cSVOPo_sv;
432   if (SvPOK(sv) && (SvTYPE(sv) >= SVt_PV)) {
433    indirect_map_store(o, indirect_find(sv, PL_oldbufptr), sv);
434    return o;
435   }
436  }
437
438  indirect_map_delete(o);
439  return o;
440 }
441
442 /* ... ck_rv2sv ............................................................ */
443
444 STATIC OP *(*indirect_old_ck_rv2sv)(pTHX_ OP *) = 0;
445
446 STATIC OP *indirect_ck_rv2sv(pTHX_ OP *o) {
447  if (indirect_hint()) {
448   OP *op = cUNOPo->op_first;
449   SV *sv;
450   const char *name = NULL, *s;
451   STRLEN len;
452   OPCODE type = (OPCODE) op->op_type;
453
454   switch (type) {
455    case OP_GV:
456    case OP_GVSV: {
457     GV *gv = cGVOPx_gv(op);
458     name = GvNAME(gv);
459     len  = GvNAMELEN(gv);
460     break;
461    }
462    default:
463     if ((PL_opargs[type] & OA_CLASS_MASK) == OA_SVOP) {
464      SV *nsv = cSVOPx_sv(op);
465      if (SvPOK(nsv) && (SvTYPE(nsv) >= SVt_PV))
466       name = SvPV_const(nsv, len);
467     }
468   }
469   if (!name)
470    goto done;
471
472   sv = sv_2mortal(newSVpvn("$", 1));
473   sv_catpvn_nomg(sv, name, len);
474   s = indirect_find(sv, PL_oldbufptr);
475   if (!s) { /* If it failed, retry without the current stash */
476    const char *stash = HvNAME_get(PL_curstash);
477    STRLEN stashlen = HvNAMELEN_get(PL_curstash);
478
479    if ((len < stashlen + 2) || strnNE(name, stash, stashlen)
480        || name[stashlen] != ':' || name[stashlen+1] != ':') {
481     /* Failed again ? Try to remove main */
482     stash = "main";
483     stashlen = 4;
484     if ((len < stashlen + 2) || strnNE(name, stash, stashlen)
485         || name[stashlen] != ':' || name[stashlen+1] != ':')
486      goto done;
487    }
488
489    sv_setpvn(sv, "$", 1);
490    stashlen += 2;
491    sv_catpvn_nomg(sv, name + stashlen, len - stashlen);
492    s = indirect_find(sv, PL_oldbufptr);
493    if (!s)
494     goto done;
495   }
496
497   o = CALL_FPTR(indirect_old_ck_rv2sv)(aTHX_ o);
498   indirect_map_store(o, s, sv);
499   return o;
500  }
501
502 done:
503  o = CALL_FPTR(indirect_old_ck_rv2sv)(aTHX_ o);
504
505  indirect_map_delete(o);
506  return o;
507 }
508
509 /* ... ck_padany ........................................................... */
510
511 STATIC OP *(*indirect_old_ck_padany)(pTHX_ OP *) = 0;
512
513 STATIC OP *indirect_ck_padany(pTHX_ OP *o) {
514  o = CALL_FPTR(indirect_old_ck_padany)(aTHX_ o);
515
516  if (indirect_hint()) {
517   SV *sv;
518   const char *s = PL_oldbufptr, *t = PL_bufptr - 1;
519
520   while (s < t && isSPACE(*s)) ++s;
521   if (*s == '$' && ++s <= t) {
522    while (s < t && isSPACE(*s)) ++s;
523    while (s < t && isSPACE(*t)) --t;
524    sv = sv_2mortal(newSVpvn("$", 1));
525    sv_catpvn_nomg(sv, s, t - s + 1);
526    indirect_map_store(o, s, sv);
527    return o;
528   }
529  }
530
531  indirect_map_delete(o);
532  return o;
533 }
534
535 /* ... ck_method ........................................................... */
536
537 STATIC OP *(*indirect_old_ck_method)(pTHX_ OP *) = 0;
538
539 STATIC OP *indirect_ck_method(pTHX_ OP *o) {
540  if (indirect_hint()) {
541   OP *op = cUNOPo->op_first;
542   SV *sv;
543   const char *s = indirect_map_fetch(op, &sv);
544   if (!s) {
545    sv = cSVOPx_sv(op);
546    if (!SvPOK(sv) || (SvTYPE(sv) < SVt_PV))
547     goto done;
548    sv = sv_mortalcopy(sv);
549    s  = indirect_find(sv, PL_oldbufptr);
550   }
551   o = CALL_FPTR(indirect_old_ck_method)(aTHX_ o);
552   /* o may now be a method_named */
553   indirect_map_store(o, s, sv);
554   return o;
555  }
556
557 done:
558  o = CALL_FPTR(indirect_old_ck_method)(aTHX_ o);
559
560  indirect_map_delete(o);
561  return o;
562 }
563
564 /* ... ck_entersub ......................................................... */
565
566 STATIC OP *(*indirect_old_ck_entersub)(pTHX_ OP *) = 0;
567
568 STATIC OP *indirect_ck_entersub(pTHX_ OP *o) {
569  SV *code = indirect_hint();
570
571  o = CALL_FPTR(indirect_old_ck_entersub)(aTHX_ o);
572
573  if (code) {
574   const char *mpos, *opos;
575   SV *mnamesv, *onamesv;
576   OP *mop, *oop;
577   LISTOP *lop;
578
579   oop = o;
580   do {
581    lop = (LISTOP *) oop;
582    if (!(lop->op_flags & OPf_KIDS))
583     goto done;
584    oop = lop->op_first;
585   } while (oop->op_type != OP_PUSHMARK);
586   oop = oop->op_sibling;
587   mop = lop->op_last;
588
589   if (!oop)
590    goto done;
591
592   switch (oop->op_type) {
593    case OP_CONST:
594    case OP_RV2SV:
595    case OP_PADSV:
596     break;
597    default:
598     goto done;
599   }
600
601   if (mop->op_type == OP_METHOD)
602    mop = cUNOPx(mop)->op_first;
603   else if (mop->op_type != OP_METHOD_NAMED)
604    goto done;
605
606   mpos = indirect_map_fetch(mop, &mnamesv);
607   if (!mpos)
608    goto done;
609
610   opos = indirect_map_fetch(oop, &onamesv);
611   if (!opos)
612    goto done;
613
614   if (mpos < opos) {
615    SV     *file;
616    line_t  line;
617    dSP;
618
619    ENTER;
620    SAVETMPS;
621
622    onamesv = sv_mortalcopy(onamesv);
623    mnamesv = sv_mortalcopy(mnamesv);
624
625 #ifdef USE_ITHREADS
626    file = sv_2mortal(newSVpv(CopFILE(&PL_compiling), 0));
627 #else
628    file = sv_mortalcopy(CopFILESV(&PL_compiling));
629 #endif
630    line = CopLINE(&PL_compiling);
631
632    PUSHMARK(SP);
633    EXTEND(SP, 4);
634    PUSHs(onamesv);
635    PUSHs(mnamesv);
636    PUSHs(file);
637    mPUSHu(line);
638    PUTBACK;
639
640    call_sv(code, G_VOID);
641
642    PUTBACK;
643
644    FREETMPS;
645    LEAVE;
646   }
647  }
648
649 done:
650  return o;
651 }
652
653 STATIC U32 indirect_initialized = 0;
654
655 /* --- XS ------------------------------------------------------------------ */
656
657 MODULE = indirect      PACKAGE = indirect
658
659 PROTOTYPES: ENABLE
660
661 BOOT:
662 {
663  if (!indirect_initialized++) {
664   HV *stash;
665
666   MY_CXT_INIT;
667   MY_CXT.map     = ptable_new();
668   MY_CXT.linestr = NULL;
669 #if I_THREADSAFE || I_WORKAROUND_REQUIRE_PROPAGATION
670   MY_CXT.tbl     = ptable_new();
671 #endif
672 #if I_THREADSAFE
673   MY_CXT.owner   = aTHX;
674 #endif
675
676   PERL_HASH(indirect_hash, __PACKAGE__, __PACKAGE_LEN__);
677
678   indirect_old_ck_const    = PL_check[OP_CONST];
679   PL_check[OP_CONST]       = MEMBER_TO_FPTR(indirect_ck_const);
680   indirect_old_ck_rv2sv    = PL_check[OP_RV2SV];
681   PL_check[OP_RV2SV]       = MEMBER_TO_FPTR(indirect_ck_rv2sv);
682   indirect_old_ck_padany   = PL_check[OP_PADANY];
683   PL_check[OP_PADANY]      = MEMBER_TO_FPTR(indirect_ck_padany);
684   indirect_old_ck_method   = PL_check[OP_METHOD];
685   PL_check[OP_METHOD]      = MEMBER_TO_FPTR(indirect_ck_method);
686   indirect_old_ck_entersub = PL_check[OP_ENTERSUB];
687   PL_check[OP_ENTERSUB]    = MEMBER_TO_FPTR(indirect_ck_entersub);
688
689   stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
690   newCONSTSUB(stash, "I_THREADSAFE", newSVuv(I_THREADSAFE));
691  }
692 }
693
694 #if I_THREADSAFE
695
696 void
697 CLONE(...)
698 PROTOTYPE: DISABLE
699 PREINIT:
700  ptable *t;
701  int    *level;
702 CODE:
703  {
704   my_cxt_t ud;
705   dMY_CXT;
706   ud.tbl   = t = ptable_new();
707   ud.owner = MY_CXT.owner;
708   ptable_walk(MY_CXT.tbl, indirect_ptable_clone, &ud);
709  }
710  {
711   MY_CXT_CLONE;
712   MY_CXT.map     = ptable_new();
713   MY_CXT.linestr = NULL;
714   MY_CXT.tbl     = t;
715   MY_CXT.owner   = aTHX;
716  }
717  {
718   level = PerlMemShared_malloc(sizeof *level);
719   *level = 1;
720   LEAVE;
721   SAVEDESTRUCTOR_X(indirect_thread_cleanup, level);
722   ENTER;
723  }
724
725 #endif
726
727 SV *
728 _tag(SV *value)
729 PROTOTYPE: $
730 CODE:
731  RETVAL = indirect_tag(value);
732 OUTPUT:
733  RETVAL