1 /* This file is part of the autovivification Perl module.
2 * See http://search.cpan.org/dist/autovivification/ */
4 #define PERL_NO_GET_CONTEXT
9 #define __PACKAGE__ "autovivification"
10 #define __PACKAGE_LEN__ (sizeof(__PACKAGE__)-1)
12 /* --- Compatibility wrappers ---------------------------------------------- */
15 # define HvNAME_get(H) HvNAME(H)
19 # define HvNAMELEN_get(H) strlen(HvNAME_get(H))
22 #define A_HAS_PERL(R, V, S) (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > (V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S))))))
24 #ifndef A_WORKAROUND_REQUIRE_PROPAGATION
25 # define A_WORKAROUND_REQUIRE_PROPAGATION !A_HAS_PERL(5, 10, 1)
29 # define A_HAS_RPEEP A_HAS_PERL(5, 13, 5)
32 #ifndef A_HAS_MULTIDEREF
33 # define A_HAS_MULTIDEREF A_HAS_PERL(5, 21, 7)
38 # define OpSIBLING(O) OP_SIBLING(O)
40 # define OpSIBLING(O) ((O)->op_sibling)
44 /* ... Our vivify_ref() .................................................... */
46 /* Perl_vivify_ref() is not exported, so we have to reimplement it. */
50 static SV *a_vivify_ref(pTHX_ SV *sv, int to_hash) {
51 #define a_vivify_ref(S, TH) a_vivify_ref(aTHX_ (S), (TH))
58 Perl_croak_no_modify();
60 /* Inlined prepare_SV_for_RV() */
61 if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV) {
62 sv_upgrade(sv, SVt_IV);
63 } else if (SvTYPE(sv) >= SVt_PV) {
69 val = to_hash ? MUTABLE_SV(newHV()) : MUTABLE_SV(newAV());
77 SV *msv = sv_newmortal();
78 sv_setsv_nomg(msv, sv);
85 #endif /* A_HAS_MULTIDEREF */
87 /* ... Thread safety and multiplicity ...................................... */
89 /* Always safe when the workaround isn't needed */
90 #if !A_WORKAROUND_REQUIRE_PROPAGATION
93 /* Otherwise, safe unless Makefile.PL says it's Win32 */
94 #elif !defined(A_FORKSAFE)
98 #ifndef A_MULTIPLICITY
99 # if defined(MULTIPLICITY)
100 # define A_MULTIPLICITY 1
102 # define A_MULTIPLICITY 0
106 # ifndef PERL_IMPLICIT_CONTEXT
107 # error MULTIPLICITY builds must set PERL_IMPLICIT_CONTEXT
112 # define tTHX PerlInterpreter*
115 #if A_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))
116 # define A_THREADSAFE 1
117 # ifndef MY_CXT_CLONE
118 # define MY_CXT_CLONE \
120 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1)); \
121 Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t); \
122 sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
125 # define A_THREADSAFE 0
127 # define dMY_CXT dNOOP
129 # define MY_CXT a_globaldata
131 # define START_MY_CXT static my_cxt_t MY_CXT;
133 # define MY_CXT_INIT NOOP
135 # define MY_CXT_CLONE NOOP
139 /* We must use preexistent global mutexes or we will never be able to destroy
141 # if A_HAS_PERL(5, 9, 3)
142 # define A_LOADED_LOCK MUTEX_LOCK(&PL_my_ctx_mutex)
143 # define A_LOADED_UNLOCK MUTEX_UNLOCK(&PL_my_ctx_mutex)
145 # define A_LOADED_LOCK OP_REFCNT_LOCK
146 # define A_LOADED_UNLOCK OP_REFCNT_UNLOCK
149 # define A_LOADED_LOCK NOOP
150 # define A_LOADED_UNLOCK NOOP
153 #if defined(OP_CHECK_MUTEX_LOCK) && defined(OP_CHECK_MUTEX_UNLOCK)
154 # define A_CHECK_LOCK OP_CHECK_MUTEX_LOCK
155 # define A_CHECK_UNLOCK OP_CHECK_MUTEX_UNLOCK
156 #elif A_HAS_PERL(5, 9, 3)
157 # define A_CHECK_LOCK OP_REFCNT_LOCK
158 # define A_CHECK_UNLOCK OP_REFCNT_UNLOCK
160 /* Before perl 5.9.3, indirect_ck_*() calls are already protected by the
161 * A_LOADED mutex, which falls back to the OP_REFCNT mutex. Make sure we don't
163 # define A_CHECK_LOCK NOOP
164 # define A_CHECK_UNLOCK NOOP
167 typedef OP *(*a_ck_t)(pTHX_ OP *);
169 #ifdef wrap_op_checker
171 # define a_ck_replace(T, NC, OCP) wrap_op_checker((T), (NC), (OCP))
175 static void a_ck_replace(pTHX_ OPCODE type, a_ck_t new_ck, a_ck_t *old_ck_p) {
176 #define a_ck_replace(T, NC, OCP) a_ck_replace(aTHX_ (T), (NC), (OCP))
179 *old_ck_p = PL_check[type];
180 PL_check[type] = new_ck;
187 static void a_ck_restore(pTHX_ OPCODE type, a_ck_t *old_ck_p) {
188 #define a_ck_restore(T, OCP) a_ck_restore(aTHX_ (T), (OCP))
191 PL_check[type] = *old_ck_p;
197 /* --- Helpers ------------------------------------------------------------- */
199 /* ... Check if the module is loaded ....................................... */
201 static I32 a_loaded = 0;
205 #define PTABLE_NAME ptable_loaded
206 #define PTABLE_NEED_DELETE 1
207 #define PTABLE_NEED_WALK 0
211 #define ptable_loaded_store(T, K, V) ptable_loaded_store(aPTBLMS_ (T), (K), (V))
212 #define ptable_loaded_delete(T, K) ptable_loaded_delete(aPTBLMS_ (T), (K))
213 #define ptable_loaded_free(T) ptable_loaded_free(aPTBLMS_ (T))
215 static ptable *a_loaded_cxts = NULL;
217 static int a_is_loaded(pTHX_ void *cxt) {
218 #define a_is_loaded(C) a_is_loaded(aTHX_ (C))
222 if (a_loaded_cxts && ptable_fetch(a_loaded_cxts, cxt))
229 static int a_set_loaded_locked(pTHX_ void *cxt) {
230 #define a_set_loaded_locked(C) a_set_loaded_locked(aTHX_ (C))
231 int global_setup = 0;
234 assert(a_loaded == 0);
235 assert(!a_loaded_cxts);
236 a_loaded_cxts = ptable_new();
240 assert(a_loaded_cxts);
241 ptable_loaded_store(a_loaded_cxts, cxt, cxt);
246 static int a_clear_loaded_locked(pTHX_ void *cxt) {
247 #define a_clear_loaded_locked(C) a_clear_loaded_locked(aTHX_ (C))
248 int global_teardown = 0;
251 assert(a_loaded_cxts);
252 ptable_loaded_delete(a_loaded_cxts, cxt);
254 } else if (a_loaded_cxts) {
255 assert(a_loaded == 1);
256 ptable_loaded_free(a_loaded_cxts);
257 a_loaded_cxts = NULL;
262 return global_teardown;
267 #define a_is_loaded(C) (a_loaded > 0)
268 #define a_set_loaded_locked(C) ((a_loaded++ <= 0) ? 1 : 0)
269 #define a_clear_loaded_locked(C) ((--a_loaded <= 0) ? 1 : 0)
273 /* ... Thread-safe hints ................................................... */
275 #if A_WORKAROUND_REQUIRE_PROPAGATION
282 #define A_HINT_FREE(H) PerlMemShared_free(H)
286 #define PTABLE_NAME ptable_hints
287 #define PTABLE_VAL_FREE(V) A_HINT_FREE(V)
288 #define PTABLE_NEED_DELETE 0
289 #define PTABLE_NEED_WALK 1
298 #define ptable_hints_store(T, K, V) ptable_hints_store(aTHX_ (T), (K), (V))
299 #define ptable_hints_free(T) ptable_hints_free(aTHX_ (T))
301 #endif /* A_THREADSAFE */
303 #endif /* A_WORKAROUND_REQUIRE_PROPAGATION */
305 #define PTABLE_NAME ptable_seen
306 #define PTABLE_NEED_DELETE 0
307 #define PTABLE_NEED_WALK 0
311 /* PerlMemShared_free() needs the [ap]PTBLMS_? default values */
312 #define ptable_seen_store(T, K, V) ptable_seen_store(aPTBLMS_ (T), (K), (V))
313 #define ptable_seen_clear(T) ptable_seen_clear(aPTBLMS_ (T))
314 #define ptable_seen_free(T) ptable_seen_free(aPTBLMS_ (T))
316 #define MY_CXT_KEY __PACKAGE__ "::_guts" XS_VERSION
319 peep_t old_peep; /* This is actually the rpeep past 5.13.5 */
320 ptable *seen; /* It really is a ptable_seen */
321 #if A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION
322 ptable *tbl; /* It really is a ptable_hints */
324 #endif /* A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION */
329 #if A_WORKAROUND_REQUIRE_PROPAGATION
335 #if A_HAS_PERL(5, 13, 2)
336 CLONE_PARAMS *params;
342 #if A_HAS_PERL(5, 13, 2)
343 # define a_ptable_clone_ud_init(U, T, O) \
345 (U).params = Perl_clone_params_new((O), aTHX)
346 # define a_ptable_clone_ud_deinit(U) Perl_clone_params_del((U).params)
347 # define a_dup_inc(S, U) SvREFCNT_inc(sv_dup((S), (U)->params))
349 # define a_ptable_clone_ud_init(U, T, O) \
351 (U).params.stashes = newAV(); \
352 (U).params.flags = 0; \
353 (U).params.proto_perl = (O)
354 # define a_ptable_clone_ud_deinit(U) SvREFCNT_dec((U).params.stashes)
355 # define a_dup_inc(S, U) SvREFCNT_inc(sv_dup((S), &((U)->params)))
358 static void a_ptable_clone(pTHX_ ptable_ent *ent, void *ud_) {
359 a_ptable_clone_ud *ud = ud_;
360 a_hint_t *h1 = ent->val;
363 h2 = PerlMemShared_malloc(sizeof *h2);
365 h2->require_tag = PTR2IV(a_dup_inc(INT2PTR(SV *, h1->require_tag), ud));
367 ptable_hints_store(ud->tbl, ent->key, h2);
370 #endif /* A_THREADSAFE */
372 static IV a_require_tag(pTHX) {
373 #define a_require_tag() a_require_tag(aTHX)
374 const CV *cv, *outside;
379 /* If for some reason the pragma is operational at run-time, try to discover
380 * the current cv in use. */
383 for (si = PL_curstackinfo; si; si = si->si_prev) {
386 for (cxix = si->si_cxix; cxix >= 0; --cxix) {
387 const PERL_CONTEXT *cx = si->si_cxstack + cxix;
389 switch (CxTYPE(cx)) {
392 /* The propagation workaround is only needed up to 5.10.0 and at that
393 * time format and sub contexts were still identical. And even later the
394 * cv members offsets should have been kept the same. */
396 goto get_enclosing_cv;
398 cv = cx->blk_eval.cv;
399 goto get_enclosing_cv;
410 for (outside = CvOUTSIDE(cv); outside; outside = CvOUTSIDE(cv))
416 static SV *a_tag(pTHX_ UV bits) {
417 #define a_tag(B) a_tag(aTHX_ (B))
424 #endif /* A_THREADSAFE */
426 h = PerlMemShared_malloc(sizeof *h);
428 h->require_tag = a_require_tag();
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);
435 #endif /* A_THREADSAFE */
437 return newSViv(PTR2IV(h));
440 static UV a_detag(pTHX_ const SV *hint) {
441 #define a_detag(H) a_detag(aTHX_ (H))
448 #endif /* A_THREADSAFE */
450 if (!(hint && SvIOK(hint)))
453 h = INT2PTR(a_hint_t *, SvIVX(hint));
455 h = ptable_fetch(MY_CXT.tbl, h);
456 #endif /* A_THREADSAFE */
458 if (a_require_tag() != h->require_tag)
464 #else /* A_WORKAROUND_REQUIRE_PROPAGATION */
466 #define a_tag(B) newSVuv(B)
467 /* PVs fetched from the hints chain have their SvLEN set to zero, so get the UV
474 ? sv_2uv(SvLEN(H) ? (H) : sv_mortalcopy(H)) \
480 #endif /* !A_WORKAROUND_REQUIRE_PROPAGATION */
482 /* Used both for hints and op flags */
483 #define A_HINT_STRICT 1
484 #define A_HINT_WARN 2
485 #define A_HINT_FETCH 4
486 #define A_HINT_STORE 8
487 #define A_HINT_EXISTS 16
488 #define A_HINT_DELETE 32
489 #define A_HINT_NOTIFY (A_HINT_STRICT|A_HINT_WARN)
490 #define A_HINT_DO (A_HINT_FETCH|A_HINT_STORE|A_HINT_EXISTS|A_HINT_DELETE)
491 #define A_HINT_MASK (A_HINT_NOTIFY|A_HINT_DO)
493 /* Only used in op flags */
494 #define A_HINT_ROOT 64
495 #define A_HINT_DEREF 128
497 static VOL U32 a_hash = 0;
499 static UV a_hint(pTHX) {
500 #define a_hint() a_hint(aTHX)
502 #ifdef cop_hints_fetch_pvn
503 hint = cop_hints_fetch_pvn(PL_curcop, __PACKAGE__, __PACKAGE_LEN__, a_hash, 0);
504 #elif A_HAS_PERL(5, 9, 5)
505 hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash,
507 __PACKAGE__, __PACKAGE_LEN__,
511 SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, 0);
516 return a_detag(hint);
519 /* ... op => info map ...................................................... */
527 #define PTABLE_NAME ptable_map
528 #define PTABLE_VAL_FREE(V) PerlMemShared_free(V)
529 #define PTABLE_NEED_DELETE 1
530 #define PTABLE_NEED_WALK 0
534 /* PerlMemShared_free() needs the [ap]PTBLMS_? default values */
535 #define ptable_map_store(T, K, V) ptable_map_store(aPTBLMS_ (T), (K), (V))
536 #define ptable_map_delete(T, K) ptable_map_delete(aPTBLMS_ (T), (K))
537 #define ptable_map_free(T) ptable_map_free(aPTBLMS_ (T))
539 static ptable *a_op_map = NULL;
543 #define dA_MAP_THX a_op_info a_op_map_tmp_oi
545 static perl_mutex a_op_map_mutex;
547 #define A_LOCK(M) MUTEX_LOCK(M)
548 #define A_UNLOCK(M) MUTEX_UNLOCK(M)
550 static const a_op_info *a_map_fetch(const OP *o, a_op_info *oi) {
551 const a_op_info *val;
553 A_LOCK(&a_op_map_mutex);
555 val = ptable_fetch(a_op_map, o);
561 A_UNLOCK(&a_op_map_mutex);
566 #define a_map_fetch(O) a_map_fetch((O), &a_op_map_tmp_oi)
568 #else /* USE_ITHREADS */
570 #define dA_MAP_THX dNOOP
572 #define A_LOCK(M) NOOP
573 #define A_UNLOCK(M) NOOP
575 #define a_map_fetch(O) ptable_fetch(a_op_map, (O))
577 #endif /* !USE_ITHREADS */
579 static const a_op_info *a_map_store_locked(pPTBLMS_ const OP *o, OP *(*old_pp)(pTHX), void *next, UV flags) {
580 #define a_map_store_locked(O, PP, N, F) a_map_store_locked(aPTBLMS_ (O), (PP), (N), (F))
583 if (!(oi = ptable_fetch(a_op_map, o))) {
584 oi = PerlMemShared_malloc(sizeof *oi);
585 ptable_map_store(a_op_map, o, oi);
595 static void a_map_store(pPTBLMS_ const OP *o, OP *(*old_pp)(pTHX), void *next, UV flags) {
596 #define a_map_store(O, PP, N, F) a_map_store(aPTBLMS_ (O), (PP), (N), (F))
597 A_LOCK(&a_op_map_mutex);
599 a_map_store_locked(o, old_pp, next, flags);
601 A_UNLOCK(&a_op_map_mutex);
604 static void a_map_delete(pTHX_ const OP *o) {
605 #define a_map_delete(O) a_map_delete(aTHX_ (O))
606 A_LOCK(&a_op_map_mutex);
608 ptable_map_delete(a_op_map, o);
610 A_UNLOCK(&a_op_map_mutex);
613 static const OP *a_map_descend(const OP *o) {
614 switch (PL_opargs[o->op_type] & OA_CLASS_MASK) {
618 case OA_BASEOP_OR_UNOP:
619 return cUNOPo->op_first;
622 return cLISTOPo->op_last;
628 static void a_map_store_root(pPTBLMS_ const OP *root, OP *(*old_pp)(pTHX), UV flags) {
629 #define a_map_store_root(R, PP, F) a_map_store_root(aPTBLMS_ (R), (PP), (F))
630 const a_op_info *roi;
634 A_LOCK(&a_op_map_mutex);
636 roi = a_map_store_locked(o, old_pp, (OP *) root, flags | A_HINT_ROOT);
638 while (o->op_flags & OPf_KIDS) {
639 o = a_map_descend(o);
642 if ((oi = ptable_fetch(a_op_map, o))) {
643 oi->flags &= ~A_HINT_ROOT;
644 oi->next = (a_op_info *) roi;
649 A_UNLOCK(&a_op_map_mutex);
654 static void a_map_update_flags_topdown(const OP *root, UV flags) {
658 A_LOCK(&a_op_map_mutex);
660 flags &= ~A_HINT_ROOT;
663 if ((oi = ptable_fetch(a_op_map, o)))
664 oi->flags = (oi->flags & A_HINT_ROOT) | flags;
665 if (!(o->op_flags & OPf_KIDS))
667 o = a_map_descend(o);
670 A_UNLOCK(&a_op_map_mutex);
675 #define a_map_cancel(R) a_map_update_flags_topdown((R), 0)
677 static void a_map_update_flags_bottomup(const OP *o, UV flags, UV rflags) {
680 A_LOCK(&a_op_map_mutex);
682 flags &= ~A_HINT_ROOT;
683 rflags |= A_HINT_ROOT;
685 oi = ptable_fetch(a_op_map, o);
686 while (!(oi->flags & A_HINT_ROOT)) {
692 A_UNLOCK(&a_op_map_mutex);
697 /* ... Decide whether this expression should be autovivified or not ........ */
699 static UV a_map_resolve(const OP *o, const a_op_info *oi) {
700 UV flags = 0, rflags;
702 const a_op_info *roi = oi;
704 while (!(roi->flags & A_HINT_ROOT))
709 rflags = roi->flags & ~A_HINT_ROOT;
714 if (root->op_flags & OPf_MOD) {
715 if (rflags & A_HINT_STORE)
716 flags = (A_HINT_STORE|A_HINT_DEREF);
717 } else if (rflags & A_HINT_FETCH)
718 flags = (A_HINT_FETCH|A_HINT_DEREF);
722 a_map_update_flags_bottomup(o, 0, 0);
726 flags |= (rflags & A_HINT_NOTIFY);
727 a_map_update_flags_bottomup(o, flags, 0);
729 return oi->flags & A_HINT_ROOT ? 0 : flags;
732 /* ... Inspired from pp_defined() .......................................... */
734 static int a_undef(pTHX_ SV *sv) {
735 #define a_undef(S) a_undef(aTHX_ (S))
736 switch (SvTYPE(sv)) {
740 if (AvMAX(sv) >= 0 || SvGMAGICAL(sv)
741 || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
745 if (HvARRAY(sv) || SvGMAGICAL(sv)
746 || (SvRMAGICAL(sv) && mg_find(sv, PERL_MAGIC_tied)))
758 /* --- PP functions -------------------------------------------------------- */
760 /* Be aware that we restore PL_op->op_ppaddr from the pointer table old_pp
761 * value, another extension might have saved our pp replacement as the ppaddr
762 * for this op, so this doesn't ensure that our function will never be called
763 * again. That's why we don't remove the op info from our map, so that it can
764 * still run correctly if required. */
766 /* ... pp_rv2av ............................................................ */
768 static OP *a_pp_rv2av(pTHX) {
773 oi = a_map_fetch(PL_op);
775 if (oi->flags & A_HINT_DEREF) {
777 /* We always need to push an empty array to fool the pp_aelem() that comes
781 av = sv_2mortal((SV *) newAV());
787 return oi->old_pp(aTHX);
790 /* ... pp_rv2hv ............................................................ */
792 static OP *a_pp_rv2hv_simple(pTHX) {
797 oi = a_map_fetch(PL_op);
799 if (oi->flags & A_HINT_DEREF) {
804 return oi->old_pp(aTHX);
807 static OP *a_pp_rv2hv(pTHX) {
812 oi = a_map_fetch(PL_op);
814 if (oi->flags & A_HINT_DEREF) {
818 hv = sv_2mortal((SV *) newHV());
824 return oi->old_pp(aTHX);
827 /* ... pp_deref (aelem,helem,rv2sv,padsv) .................................. */
829 static void a_cannot_vivify(pTHX_ UV flags) {
830 #define a_cannot_vivify(F) a_cannot_vivify(aTHX_ (F))
831 if (flags & A_HINT_STRICT)
832 croak("Reference vivification forbidden");
833 else if (flags & A_HINT_WARN)
834 warn("Reference was vivified");
835 else /* A_HINT_STORE */
836 croak("Can't vivify reference");
839 static OP *a_pp_deref(pTHX) {
845 oi = a_map_fetch(PL_op);
848 if (flags & A_HINT_DEREF) {
851 o = oi->old_pp(aTHX);
853 if (flags & (A_HINT_NOTIFY|A_HINT_STORE)) {
856 a_cannot_vivify(flags);
862 return oi->old_pp(aTHX);
865 /* ... pp_root (exists,delete,keys,values) ................................. */
867 static OP *a_pp_root_unop(pTHX) {
872 /* Can only be reached by keys or values */
873 if (GIMME_V == G_SCALAR) {
882 const a_op_info *oi = a_map_fetch(PL_op);
883 return oi->old_pp(aTHX);
887 static OP *a_pp_root_binop(pTHX) {
890 if (a_undef(TOPm1s)) {
893 if (PL_op->op_type == OP_EXISTS)
901 const a_op_info *oi = a_map_fetch(PL_op);
902 return oi->old_pp(aTHX);
908 /* ... pp_multideref ....................................................... */
910 /* This pp replacement is actually only called for topmost exists/delete ops,
911 * because we hijack the [ah]elem check functions and this disables the
912 * optimization for lvalue and rvalue dereferencing. In particular, the
913 * OPf_MOD branches should never be covered. In the future, the multideref
914 * optimization might also be disabled for custom exists/delete check functions,
915 * which will make this section unnecessary. However, the code tries to be as
916 * general as possible in case I think of a way to reenable the multideref
917 * optimization even when this module is in use. */
919 static UV a_do_multideref(const OP *o, UV flags) {
920 UV isexdel, other_flags;
922 assert(o->op_type == OP_MULTIDEREF);
924 other_flags = flags & ~A_HINT_DO;
926 isexdel = o->op_private & (OPpMULTIDEREF_EXISTS|OPpMULTIDEREF_DELETE);
928 if (isexdel & OPpMULTIDEREF_EXISTS) {
929 flags &= A_HINT_EXISTS;
931 flags &= A_HINT_DELETE;
934 if (o->op_flags & OPf_MOD) {
935 flags &= A_HINT_STORE;
937 flags &= A_HINT_FETCH;
941 return flags ? (flags | other_flags) : 0;
944 static SV *a_do_fake_pp(pTHX_ OP *op) {
945 #define a_do_fake_pp(O) a_do_fake_pp(aTHX_ (O))
951 PL_op->op_ppaddr(aTHX);
965 static void a_do_fake_pp_unop_init(pTHX_ UNOP *unop, U32 type, U32 flags) {
966 #define a_do_fake_pp_unop_init(O, T, F) a_do_fake_pp_unop_init(aTHX_ (O), (T), (F))
967 unop->op_type = type;
968 unop->op_flags = OPf_WANT_SCALAR | (~OPf_WANT & flags);
969 unop->op_private = 0;
970 unop->op_first = NULL;
971 unop->op_ppaddr = PL_ppaddr[type];
974 static SV *a_do_fake_pp_unop_arg1(pTHX_ U32 type, U32 flags, SV *arg) {
975 #define a_do_fake_pp_unop_arg1(T, F, A) a_do_fake_pp_unop_arg1(aTHX_ (T), (F), (A))
979 a_do_fake_pp_unop_init(&unop, type, flags);
985 return a_do_fake_pp((OP *) &unop);
988 static SV *a_do_fake_pp_unop_arg2(pTHX_ U32 type, U32 flags, SV *arg1, SV *arg2) {
989 #define a_do_fake_pp_unop_arg2(T, F, A1, A2) a_do_fake_pp_unop_arg2(aTHX_ (T), (F), (A1), (A2))
993 a_do_fake_pp_unop_init(&unop, type, flags);
1000 return a_do_fake_pp((OP *) &unop);
1003 #define a_do_pp_rv2av(R) a_do_fake_pp_unop_arg1(OP_RV2AV, OPf_REF, (R))
1004 #define a_do_pp_afetch(A, I) a_do_fake_pp_unop_arg2(OP_AELEM, 0, (A), (I))
1005 #define a_do_pp_afetch_lv(A, I) a_do_fake_pp_unop_arg2(OP_AELEM, OPf_MOD, (A), (I))
1006 #define a_do_pp_aexists(A, I) a_do_fake_pp_unop_arg2(OP_EXISTS, OPf_SPECIAL, (A), (I))
1007 #define a_do_pp_adelete(A, I) a_do_fake_pp_unop_arg2(OP_DELETE, OPf_SPECIAL, (A), (I))
1009 #define a_do_pp_rv2hv(R) a_do_fake_pp_unop_arg1(OP_RV2HV, OPf_REF, (R))
1010 #define a_do_pp_hfetch(H, K) a_do_fake_pp_unop_arg2(OP_HELEM, 0, (H), (K))
1011 #define a_do_pp_hfetch_lv(H, K) a_do_fake_pp_unop_arg2(OP_HELEM, OPf_MOD, (H), (K))
1012 #define a_do_pp_hexists(H, K) a_do_fake_pp_unop_arg2(OP_EXISTS, 0, (H), (K))
1013 #define a_do_pp_hdelete(H, K) a_do_fake_pp_unop_arg2(OP_DELETE, 0, (H), (K))
1015 static OP *a_pp_multideref(pTHX) {
1016 UNOP_AUX_item *items;
1024 const a_op_info *oi = a_map_fetch(PL_op);
1026 flags = a_do_multideref(PL_op, oi->flags);
1028 return oi->old_pp(aTHX);
1031 items = cUNOP_AUXx(PL_op)->op_aux;
1032 actions = items->uv;
1034 PL_multideref_pc = items;
1037 switch (actions & MDEREF_ACTION_MASK) {
1039 actions = (++items)->uv;
1041 case MDEREF_AV_padav_aelem: /* $lex[...] */
1042 sv = PAD_SVl((++items)->pad_offset);
1046 case MDEREF_AV_gvav_aelem: /* $pkg[...] */
1047 sv = UNOP_AUX_item_sv(++items);
1048 assert(isGV_with_GP(sv));
1049 sv = (SV *) GvAVn((GV *) sv);
1053 case MDEREF_AV_pop_rv2av_aelem: /* expr->[...] */
1057 goto do_AV_rv2av_aelem;
1058 case MDEREF_AV_gvsv_vivify_rv2av_aelem: /* $pkg->[...] */
1059 sv = UNOP_AUX_item_sv(++items);
1060 assert(isGV_with_GP(sv));
1061 sv = GvSVn((GV *) sv);
1064 goto do_AV_vivify_rv2av_aelem;
1065 case MDEREF_AV_padsv_vivify_rv2av_aelem: /* $lex->[...] */
1066 sv = PAD_SVl((++items)->pad_offset);
1068 case MDEREF_AV_vivify_rv2av_aelem: /* vivify, ->[...] */
1071 do_AV_vivify_rv2av_aelem:
1072 sv = a_vivify_ref(sv, 0);
1074 sv = a_do_pp_rv2av(sv);
1078 assert(SvTYPE(sv) == SVt_PVAV);
1079 switch (actions & MDEREF_INDEX_MASK) {
1080 case MDEREF_INDEX_none:
1082 case MDEREF_INDEX_const:
1083 esv = sv_2mortal(newSViv((++items)->iv));
1085 case MDEREF_INDEX_padsv:
1086 esv = PAD_SVl((++items)->pad_offset);
1088 case MDEREF_INDEX_gvsv:
1089 esv = UNOP_AUX_item_sv(++items);
1090 assert(isGV_with_GP(esv));
1091 esv = GvSVn((GV *) esv);
1093 if (UNLIKELY(SvROK(esv) && !SvGAMAGIC(esv) && ckWARN(WARN_MISC)))
1094 Perl_warner(aTHX_ packWARN(WARN_MISC),
1095 "Use of reference \"%"SVf"\" as array index",
1099 PL_multideref_pc = items;
1100 if (actions & MDEREF_FLAG_last) {
1101 switch (flags & A_HINT_DO) {
1103 sv = a_do_pp_afetch(sv, esv);
1106 sv = a_do_pp_afetch_lv(sv, esv);
1109 sv = a_do_pp_aexists(sv, esv);
1112 sv = a_do_pp_adelete(sv, esv);
1117 sv = a_do_pp_afetch(sv, esv);
1120 case MDEREF_HV_padhv_helem: /* $lex{...} */
1121 sv = PAD_SVl((++items)->pad_offset);
1125 case MDEREF_HV_gvhv_helem: /* $pkg{...} */
1126 sv = UNOP_AUX_item_sv(++items);
1127 assert(isGV_with_GP(sv));
1128 sv = (SV *) GvHVn((GV *) sv);
1132 case MDEREF_HV_pop_rv2hv_helem: /* expr->{...} */
1136 goto do_HV_rv2hv_helem;
1137 case MDEREF_HV_gvsv_vivify_rv2hv_helem: /* $pkg->{...} */
1138 sv = UNOP_AUX_item_sv(++items);
1139 assert(isGV_with_GP(sv));
1140 sv = GvSVn((GV *) sv);
1143 goto do_HV_vivify_rv2hv_helem;
1144 case MDEREF_HV_padsv_vivify_rv2hv_helem: /* $lex->{...} */
1145 sv = PAD_SVl((++items)->pad_offset);
1147 case MDEREF_HV_vivify_rv2hv_helem: /* vivify, ->{...} */
1150 do_HV_vivify_rv2hv_helem:
1151 sv = a_vivify_ref(sv, 1);
1153 sv = a_do_pp_rv2hv(sv);
1157 assert(SvTYPE(sv) == SVt_PVHV);
1158 switch (actions & MDEREF_INDEX_MASK) {
1159 case MDEREF_INDEX_none:
1161 case MDEREF_INDEX_const:
1162 key = UNOP_AUX_item_sv(++items);
1164 case MDEREF_INDEX_padsv:
1165 key = PAD_SVl((++items)->pad_offset);
1167 case MDEREF_INDEX_gvsv:
1168 key = UNOP_AUX_item_sv(++items);
1169 assert(isGV_with_GP(key));
1170 key = GvSVn((GV *) key);
1173 PL_multideref_pc = items;
1174 if (actions & MDEREF_FLAG_last) {
1175 switch (flags & A_HINT_DO) {
1177 sv = a_do_pp_hfetch(sv, key);
1180 sv = a_do_pp_hfetch_lv(sv, key);
1183 sv = a_do_pp_hexists(sv, key);
1186 sv = a_do_pp_hdelete(sv, key);
1193 sv = a_do_pp_hfetch(sv, key);
1198 actions >>= MDEREF_SHIFT;
1202 if (flags & (A_HINT_NOTIFY|A_HINT_STORE))
1203 a_cannot_vivify(flags);
1204 if (flags & A_HINT_EXISTS)
1213 #endif /* A_HAS_MULTIDEREF */
1215 /* --- Check functions ----------------------------------------------------- */
1217 static void a_recheck_rv2xv(pTHX_ OP *o, OPCODE type, OP *(*new_pp)(pTHX)) {
1218 #define a_recheck_rv2xv(O, T, PP) a_recheck_rv2xv(aTHX_ (O), (T), (PP))
1220 if (o->op_type == type && o->op_ppaddr != new_pp
1221 && cUNOPo->op_first->op_type != OP_GV) {
1223 const a_op_info *oi = a_map_fetch(o);
1225 a_map_store(o, o->op_ppaddr, oi->next, oi->flags);
1226 o->op_ppaddr = new_pp;
1233 /* ... ck_pad{any,sv} ...................................................... */
1235 /* Sadly, the padsv OPs we are interested in don't trigger the padsv check
1236 * function, but are instead manually mutated from a padany. So we store
1237 * the op entry in the op map in the padany check function, and we set their
1238 * op_ppaddr member in our peephole optimizer replacement below. */
1240 static OP *(*a_old_ck_padany)(pTHX_ OP *) = 0;
1242 static OP *a_ck_padany(pTHX_ OP *o) {
1245 o = a_old_ck_padany(aTHX_ o);
1248 if (hint & A_HINT_DO)
1249 a_map_store_root(o, o->op_ppaddr, hint);
1256 static OP *(*a_old_ck_padsv)(pTHX_ OP *) = 0;
1258 static OP *a_ck_padsv(pTHX_ OP *o) {
1261 o = a_old_ck_padsv(aTHX_ o);
1264 if (hint & A_HINT_DO) {
1265 a_map_store_root(o, o->op_ppaddr, hint);
1266 o->op_ppaddr = a_pp_deref;
1273 /* ... ck_deref (aelem,helem,rv2sv) ........................................ */
1275 /* Those ops appear both at the root and inside an expression but there's no
1276 * way to distinguish both situations. Worse, we can't even know if we are in a
1277 * modifying context, so the expression can't be resolved yet. It will be at the
1278 * first invocation of a_pp_deref() for this expression. */
1280 static OP *(*a_old_ck_aelem)(pTHX_ OP *) = 0;
1281 static OP *(*a_old_ck_helem)(pTHX_ OP *) = 0;
1282 static OP *(*a_old_ck_rv2sv)(pTHX_ OP *) = 0;
1284 static OP *a_ck_deref(pTHX_ OP *o) {
1285 OP * (*old_ck)(pTHX_ OP *o) = 0;
1288 switch (o->op_type) {
1290 old_ck = a_old_ck_aelem;
1291 if ((hint & A_HINT_DO) && !(hint & A_HINT_STRICT))
1292 a_recheck_rv2xv(cUNOPo->op_first, OP_RV2AV, a_pp_rv2av);
1295 old_ck = a_old_ck_helem;
1296 if ((hint & A_HINT_DO) && !(hint & A_HINT_STRICT))
1297 a_recheck_rv2xv(cUNOPo->op_first, OP_RV2HV, a_pp_rv2hv_simple);
1300 old_ck = a_old_ck_rv2sv;
1303 o = old_ck(aTHX_ o);
1305 #if A_HAS_MULTIDEREF
1306 if (old_ck == a_old_ck_rv2sv && o->op_flags & OPf_KIDS) {
1307 OP *kid = cUNOPo->op_first;
1308 if (kid && kid->op_type == OP_GV) {
1309 if (hint & A_HINT_DO)
1310 a_map_store(kid, kid->op_ppaddr, NULL, hint);
1317 if (hint & A_HINT_DO) {
1318 a_map_store_root(o, o->op_ppaddr, hint);
1319 o->op_ppaddr = a_pp_deref;
1326 /* ... ck_rv2xv (rv2av,rv2hv) .............................................. */
1328 /* Those ops also appear both inisde and at the root, hence the caveats for
1329 * a_ck_deref() still apply here. Since a padsv/rv2sv must appear before a
1330 * rv2[ah]v, resolution is handled by the first call to a_pp_deref() in the
1333 static OP *(*a_old_ck_rv2av)(pTHX_ OP *) = 0;
1334 static OP *(*a_old_ck_rv2hv)(pTHX_ OP *) = 0;
1336 static OP *a_ck_rv2xv(pTHX_ OP *o) {
1337 OP * (*old_ck)(pTHX_ OP *o) = 0;
1338 OP * (*new_pp)(pTHX) = 0;
1341 switch (o->op_type) {
1342 case OP_RV2AV: old_ck = a_old_ck_rv2av; new_pp = a_pp_rv2av; break;
1343 case OP_RV2HV: old_ck = a_old_ck_rv2hv; new_pp = a_pp_rv2hv_simple; break;
1345 o = old_ck(aTHX_ o);
1347 if (cUNOPo->op_first->op_type == OP_GV)
1351 if (hint & A_HINT_DO && !(hint & A_HINT_STRICT)) {
1352 a_map_store_root(o, o->op_ppaddr, hint);
1353 o->op_ppaddr = new_pp;
1360 /* ... ck_xslice (aslice,hslice) ........................................... */
1362 /* I think those are only found at the root, but there's nothing that really
1363 * prevent them to be inside the expression too. We only need to update the
1364 * root so that the rest of the expression will see the right context when
1365 * resolving. That's why we don't replace the ppaddr. */
1367 static OP *(*a_old_ck_aslice)(pTHX_ OP *) = 0;
1368 static OP *(*a_old_ck_hslice)(pTHX_ OP *) = 0;
1370 static OP *a_ck_xslice(pTHX_ OP *o) {
1371 OP * (*old_ck)(pTHX_ OP *o) = 0;
1374 switch (o->op_type) {
1376 old_ck = a_old_ck_aslice;
1379 old_ck = a_old_ck_hslice;
1380 if (hint & A_HINT_DO)
1381 a_recheck_rv2xv(OpSIBLING(cUNOPo->op_first), OP_RV2HV, a_pp_rv2hv);
1384 o = old_ck(aTHX_ o);
1386 if (hint & A_HINT_DO) {
1387 a_map_store_root(o, 0, hint);
1394 /* ... ck_root (exists,delete,keys,values) ................................. */
1396 /* Those ops are only found at the root of a dereferencing expression. We can
1397 * then resolve at compile time if vivification must take place or not. */
1399 static OP *(*a_old_ck_exists)(pTHX_ OP *) = 0;
1400 static OP *(*a_old_ck_delete)(pTHX_ OP *) = 0;
1401 static OP *(*a_old_ck_keys) (pTHX_ OP *) = 0;
1402 static OP *(*a_old_ck_values)(pTHX_ OP *) = 0;
1404 static OP *a_ck_root(pTHX_ OP *o) {
1405 OP * (*old_ck)(pTHX_ OP *o) = 0;
1406 OP * (*new_pp)(pTHX) = 0;
1407 bool enabled = FALSE;
1410 switch (o->op_type) {
1412 old_ck = a_old_ck_exists;
1413 new_pp = a_pp_root_binop;
1414 enabled = hint & A_HINT_EXISTS;
1417 old_ck = a_old_ck_delete;
1418 new_pp = a_pp_root_binop;
1419 enabled = hint & A_HINT_DELETE;
1422 old_ck = a_old_ck_keys;
1423 new_pp = a_pp_root_unop;
1424 enabled = hint & A_HINT_FETCH;
1427 old_ck = a_old_ck_values;
1428 new_pp = a_pp_root_unop;
1429 enabled = hint & A_HINT_FETCH;
1432 o = old_ck(aTHX_ o);
1434 if (hint & A_HINT_DO) {
1436 a_map_update_flags_topdown(o, hint | A_HINT_DEREF);
1437 a_map_store_root(o, o->op_ppaddr, hint);
1438 o->op_ppaddr = new_pp;
1448 /* ... Our peephole optimizer .............................................. */
1450 static void a_peep_rec(pTHX_ OP *o, ptable *seen);
1452 static void a_peep_rec(pTHX_ OP *o, ptable *seen) {
1453 #define a_peep_rec(O) a_peep_rec(aTHX_ (O), seen)
1454 for (; o; o = o->op_next) {
1456 const a_op_info *oi = NULL;
1460 if (ptable_fetch(seen, o))
1462 ptable_seen_store(seen, o, o);
1465 switch (o->op_type) {
1471 if (ptable_fetch(seen, o))
1473 ptable_seen_store(seen, o, o);
1477 if (o->op_ppaddr != a_pp_deref) {
1478 oi = a_map_fetch(o);
1479 if (oi && (oi->flags & A_HINT_DO)) {
1480 a_map_store(o, o->op_ppaddr, oi->next, oi->flags);
1481 o->op_ppaddr = a_pp_deref;
1489 if (o->op_ppaddr != a_pp_deref)
1491 oi = a_map_fetch(o);
1495 if (!(flags & A_HINT_DEREF)
1496 && (flags & A_HINT_DO)
1497 && (o->op_private & OPpDEREF || flags & A_HINT_ROOT)) {
1498 /* Decide if the expression must autovivify or not. */
1499 flags = a_map_resolve(o, oi);
1501 if (flags & A_HINT_DEREF)
1502 o->op_private = ((o->op_private & ~OPpDEREF) | OPpLVAL_DEFER);
1504 o->op_ppaddr = oi->old_pp;
1508 if ( o->op_ppaddr != a_pp_rv2av
1509 && o->op_ppaddr != a_pp_rv2hv
1510 && o->op_ppaddr != a_pp_rv2hv_simple)
1512 oi = a_map_fetch(o);
1515 if (!(oi->flags & A_HINT_DEREF))
1516 o->op_ppaddr = oi->old_pp;
1518 #if A_HAS_MULTIDEREF
1520 if (o->op_ppaddr != a_pp_multideref) {
1521 oi = a_map_fetch(cUNOPo->op_first);
1525 if (a_do_multideref(o, flags)) {
1526 a_map_store_root(o, o->op_ppaddr, flags & ~A_HINT_DEREF);
1527 o->op_ppaddr = a_pp_multideref;
1541 # if A_HAS_PERL(5, 10, 0)
1546 a_peep_rec(cLOGOPo->op_other);
1550 a_peep_rec(cLOOPo->op_redoop);
1551 a_peep_rec(cLOOPo->op_nextop);
1552 a_peep_rec(cLOOPo->op_lastop);
1554 # if A_HAS_PERL(5, 9, 5)
1556 a_peep_rec(cPMOPo->op_pmstashstartu.op_pmreplstart);
1562 a_peep_rec(cPMOPo->op_pmreplstart);
1565 #endif /* !A_HAS_RPEEP */
1572 static void a_peep(pTHX_ OP *o) {
1576 assert(a_is_loaded(&MY_CXT));
1578 MY_CXT.old_peep(aTHX_ o);
1582 ptable_seen_clear(seen);
1584 ptable_seen_clear(seen);
1588 /* --- Module setup/teardown ----------------------------------------------- */
1590 static void a_teardown(pTHX_ void *root) {
1595 if (a_clear_loaded_locked(&MY_CXT)) {
1596 a_ck_restore(OP_PADANY, &a_old_ck_padany);
1597 a_ck_restore(OP_PADSV, &a_old_ck_padsv);
1599 a_ck_restore(OP_AELEM, &a_old_ck_aelem);
1600 a_ck_restore(OP_HELEM, &a_old_ck_helem);
1601 a_ck_restore(OP_RV2SV, &a_old_ck_rv2sv);
1603 a_ck_restore(OP_RV2AV, &a_old_ck_rv2av);
1604 a_ck_restore(OP_RV2HV, &a_old_ck_rv2hv);
1606 a_ck_restore(OP_ASLICE, &a_old_ck_aslice);
1607 a_ck_restore(OP_HSLICE, &a_old_ck_hslice);
1609 a_ck_restore(OP_EXISTS, &a_old_ck_exists);
1610 a_ck_restore(OP_DELETE, &a_old_ck_delete);
1611 a_ck_restore(OP_KEYS, &a_old_ck_keys);
1612 a_ck_restore(OP_VALUES, &a_old_ck_values);
1614 ptable_map_free(a_op_map);
1618 MUTEX_DESTROY(&a_op_map_mutex);
1624 if (MY_CXT.old_peep) {
1626 PL_rpeepp = MY_CXT.old_peep;
1628 PL_peepp = MY_CXT.old_peep;
1630 MY_CXT.old_peep = 0;
1633 ptable_seen_free(MY_CXT.seen);
1636 #if A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION
1637 ptable_hints_free(MY_CXT.tbl);
1639 #endif /* A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION */
1644 static void a_setup(pTHX) {
1645 #define a_setup() a_setup(aTHX)
1646 MY_CXT_INIT; /* Takes/release PL_my_ctx_mutex */
1650 if (a_set_loaded_locked(&MY_CXT)) {
1651 PERL_HASH(a_hash, __PACKAGE__, __PACKAGE_LEN__);
1653 a_op_map = ptable_new();
1656 MUTEX_INIT(&a_op_map_mutex);
1659 a_ck_replace(OP_PADANY, a_ck_padany, &a_old_ck_padany);
1660 a_ck_replace(OP_PADSV, a_ck_padsv, &a_old_ck_padsv);
1662 a_ck_replace(OP_AELEM, a_ck_deref, &a_old_ck_aelem);
1663 a_ck_replace(OP_HELEM, a_ck_deref, &a_old_ck_helem);
1664 a_ck_replace(OP_RV2SV, a_ck_deref, &a_old_ck_rv2sv);
1666 a_ck_replace(OP_RV2AV, a_ck_rv2xv, &a_old_ck_rv2av);
1667 a_ck_replace(OP_RV2HV, a_ck_rv2xv, &a_old_ck_rv2hv);
1669 a_ck_replace(OP_ASLICE, a_ck_xslice, &a_old_ck_aslice);
1670 a_ck_replace(OP_HSLICE, a_ck_xslice, &a_old_ck_hslice);
1672 a_ck_replace(OP_EXISTS, a_ck_root, &a_old_ck_exists);
1673 a_ck_replace(OP_DELETE, a_ck_root, &a_old_ck_delete);
1674 a_ck_replace(OP_KEYS, a_ck_root, &a_old_ck_keys);
1675 a_ck_replace(OP_VALUES, a_ck_root, &a_old_ck_values);
1683 stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1);
1684 newCONSTSUB(stash, "A_HINT_STRICT", newSVuv(A_HINT_STRICT));
1685 newCONSTSUB(stash, "A_HINT_WARN", newSVuv(A_HINT_WARN));
1686 newCONSTSUB(stash, "A_HINT_FETCH", newSVuv(A_HINT_FETCH));
1687 newCONSTSUB(stash, "A_HINT_STORE", newSVuv(A_HINT_STORE));
1688 newCONSTSUB(stash, "A_HINT_EXISTS", newSVuv(A_HINT_EXISTS));
1689 newCONSTSUB(stash, "A_HINT_DELETE", newSVuv(A_HINT_DELETE));
1690 newCONSTSUB(stash, "A_HINT_MASK", newSVuv(A_HINT_MASK));
1691 newCONSTSUB(stash, "A_THREADSAFE", newSVuv(A_THREADSAFE));
1692 newCONSTSUB(stash, "A_FORKSAFE", newSVuv(A_FORKSAFE));
1696 if (PL_rpeepp != a_peep) {
1697 MY_CXT.old_peep = PL_rpeepp;
1701 if (PL_peepp != a_peep) {
1702 MY_CXT.old_peep = PL_peepp;
1707 MY_CXT.old_peep = 0;
1710 MY_CXT.seen = ptable_new();
1712 #if A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION
1713 MY_CXT.tbl = ptable_new();
1714 MY_CXT.owner = aTHX;
1715 #endif /* A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION */
1717 call_atexit(a_teardown, NULL);
1722 /* --- XS ------------------------------------------------------------------ */
1724 MODULE = autovivification PACKAGE = autovivification
1739 #if A_WORKAROUND_REQUIRE_PROPAGATION
1743 #if A_WORKAROUND_REQUIRE_PROPAGATION
1745 a_ptable_clone_ud ud;
1748 a_ptable_clone_ud_init(ud, t, MY_CXT.owner);
1749 ptable_walk(MY_CXT.tbl, a_ptable_clone, &ud);
1750 a_ptable_clone_ud_deinit(ud);
1755 #if A_WORKAROUND_REQUIRE_PROPAGATION
1757 MY_CXT.owner = aTHX;
1759 MY_CXT.seen = ptable_new();
1763 global_setup = a_set_loaded_locked(&MY_CXT);
1764 assert(!global_setup);
1770 #endif /* A_THREADSAFE */
1776 RETVAL = a_tag(SvOK(hint) ? SvUV(hint) : 0);
1786 RETVAL = newSVuv(a_detag(tag));