X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=autovivification.xs;h=61d3b35015a5921f58f597087d6e3e42ebc745cb;hb=be0d2bc6eefe4e2401f865deee64c9a45133b747;hp=f52d4084762cde520561ee406299b65fc501e036;hpb=45651498cc83f108b5b206393960fe0f72de5e37;p=perl%2Fmodules%2Fautovivification.git diff --git a/autovivification.xs b/autovivification.xs index f52d408..61d3b35 100644 --- a/autovivification.xs +++ b/autovivification.xs @@ -107,18 +107,15 @@ typedef struct { #endif /* A_WORKAROUND_REQUIRE_PROPAGATION */ -#if !A_HAS_RPEEP - #define PTABLE_NAME ptable_seen #define PTABLE_VAL_FREE(V) NOOP #include "ptable.h" -#endif /* !A_HAS_RPEEP */ - -#define A_NEED_CXT ((A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION) || !A_HAS_RPEEP) - -#if A_NEED_CXT +/* PerlMemShared_free() needs the [ap]PTBLMS_? default values */ +#define ptable_seen_store(T, K, V) ptable_seen_store(aPTBLMS_ (T), (K), (V)) +#define ptable_seen_clear(T) ptable_seen_clear(aPTBLMS_ (T)) +#define ptable_seen_free(T) ptable_seen_free(aPTBLMS_ (T)) #define MY_CXT_KEY __PACKAGE__ "::_guts" XS_VERSION @@ -127,9 +124,7 @@ typedef struct { ptable *tbl; /* It really is a ptable_hints */ tTHX owner; #endif /* A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION */ -#if !A_HAS_RPEEP ptable *seen; /* It really is a ptable_seen */ -#endif /* !A_HAS_RPEEP */ } my_cxt_t; START_MY_CXT @@ -139,11 +134,11 @@ START_MY_CXT #if A_WORKAROUND_REQUIRE_PROPAGATION typedef struct { - ptable *tbl; + ptable *tbl; #if A_HAS_PERL(5, 13, 2) CLONE_PARAMS *params; #else - CLONE_PARAMS params; + CLONE_PARAMS params; #endif } a_ptable_clone_ud; @@ -185,15 +180,11 @@ STATIC void a_thread_cleanup(pTHX_ void *ud) { #if A_WORKAROUND_REQUIRE_PROPAGATION ptable_hints_free(MY_CXT.tbl); #endif /* A_WORKAROUND_REQUIRE_PROPAGATION */ -#if !A_HAS_RPEEP ptable_seen_free(MY_CXT.seen); -#endif /* !A_HAS_RPEEP */ } #endif /* A_THREADSAFE */ -#endif /* A_NEED_CXT */ - #if A_WORKAROUND_REQUIRE_PROPAGATION STATIC IV a_require_tag(pTHX) { @@ -243,19 +234,19 @@ get_enclosing_cv: STATIC SV *a_tag(pTHX_ UV bits) { #define a_tag(B) a_tag(aTHX_ (B)) a_hint_t *h; -#if A_THREADSAFE - dMY_CXT; -#endif h = PerlMemShared_malloc(sizeof *h); h->bits = bits; h->require_tag = a_require_tag(); #if A_THREADSAFE - /* We only need for the key to be an unique tag for looking up the value later. - * Allocated memory provides convenient unique identifiers, so that's why we - * use the hint as the key itself. */ - ptable_hints_store(MY_CXT.tbl, h, h); + { + dMY_CXT; + /* We only need for the key to be an unique tag for looking up the value later + * Allocated memory provides convenient unique identifiers, so that's why we + * use the hint as the key itself. */ + ptable_hints_store(MY_CXT.tbl, h, h); + } #endif /* A_THREADSAFE */ return newSViv(PTR2IV(h)); @@ -264,16 +255,16 @@ STATIC SV *a_tag(pTHX_ UV bits) { STATIC UV a_detag(pTHX_ const SV *hint) { #define a_detag(H) a_detag(aTHX_ (H)) a_hint_t *h; -#if A_THREADSAFE - dMY_CXT; -#endif if (!(hint && SvIOK(hint))) return 0; h = INT2PTR(a_hint_t *, SvIVX(hint)); #if A_THREADSAFE - h = ptable_fetch(MY_CXT.tbl, h); + { + dMY_CXT; + h = ptable_fetch(MY_CXT.tbl, h); + } #endif /* A_THREADSAFE */ if (a_require_tag() != h->require_tag) @@ -293,7 +284,7 @@ STATIC UV a_detag(pTHX_ const SV *hint) { ? SvUVX(H) \ : (SvPOK(H) \ ? sv_2uv(SvLEN(H) ? (H) : sv_mortalcopy(H)) \ - : 0 \ + : 0 \ ) \ ) \ : 0) @@ -329,7 +320,7 @@ STATIC UV a_hint(pTHX) { 0, a_hash); #else - SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, a_hash); + SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, 0); if (!val) return 0; hint = *val; @@ -340,9 +331,9 @@ STATIC UV a_hint(pTHX) { /* ... op => info map ...................................................... */ typedef struct { - OP *(*old_pp)(pTHX); - UV flags; - void *next; + OP *(*old_pp)(pTHX); + void *next; + UV flags; } a_op_info; #define PTABLE_NAME ptable_map @@ -352,6 +343,7 @@ typedef struct { /* PerlMemShared_free() needs the [ap]PTBLMS_? default values */ #define ptable_map_store(T, K, V) ptable_map_store(aPTBLMS_ (T), (K), (V)) +#define ptable_map_delete(T, K) ptable_map_delete(aPTBLMS_ (T), (K)) STATIC ptable *a_op_map = NULL; @@ -594,7 +586,7 @@ STATIC OP *a_pp_rv2av(pTHX) { /* We always need to push an empty array to fool the pp_aelem() that comes * later. */ SV *av; - POPs; + (void) POPs; av = sv_2mortal((SV *) newAV()); PUSHs(av); RETURN; @@ -631,7 +623,7 @@ STATIC OP *a_pp_rv2hv(pTHX) { if (oi->flags & A_HINT_DEREF) { if (a_undef(TOPs)) { SV *hv; - POPs; + (void) POPs; hv = sv_2mortal((SV *) newHV()); PUSHs(hv); RETURN; @@ -681,7 +673,7 @@ STATIC OP *a_pp_root_unop(pTHX) { dSP; if (a_undef(TOPs)) { - POPs; + (void) POPs; /* Can only be reached by keys or values */ if (GIMME_V == G_SCALAR) { dTARGET; @@ -701,8 +693,8 @@ STATIC OP *a_pp_root_binop(pTHX) { dSP; if (a_undef(TOPm1s)) { - POPs; - POPs; + (void) POPs; + (void) POPs; if (PL_op->op_type == OP_EXISTS) RETPUSHNO; else @@ -941,33 +933,19 @@ STATIC OP *a_ck_root(pTHX_ OP *o) { STATIC peep_t a_old_peep = 0; /* This is actually the rpeep past 5.13.5 */ -#if !A_HAS_RPEEP -# define A_PEEP_REC_PROTO STATIC void a_peep_rec(pTHX_ OP *o, ptable *seen) -#else /* !A_HAS_RPEEP */ -# define A_PEEP_REC_PROTO STATIC void a_peep_rec(pTHX_ OP *o) -#endif /* A_HAS_RPEEP */ - -A_PEEP_REC_PROTO; -A_PEEP_REC_PROTO { -#if !A_HAS_RPEEP -# define a_peep_rec(O) a_peep_rec(aTHX_ (O), seen) -#else /* !A_HAS_RPEEP */ -# define a_peep_rec(O) a_peep_rec(aTHX_ (O)) -#endif /* A_HAS_RPEEP */ - dA_MAP_THX; - -#if !A_HAS_RPEEP - if (ptable_fetch(seen, o)) - return; -#endif +STATIC void a_peep_rec(pTHX_ OP *o, ptable *seen); +STATIC void a_peep_rec(pTHX_ OP *o, ptable *seen) { +#define a_peep_rec(O) a_peep_rec(aTHX_ (O), seen) for (; o; o = o->op_next) { + dA_MAP_THX; const a_op_info *oi = NULL; UV flags = 0; -#if !A_HAS_RPEEP + if (ptable_fetch(seen, o)) + break; ptable_seen_store(seen, o, o); -#endif + switch (o->op_type) { case OP_PADSV: if (o->op_ppaddr != a_pp_deref) { @@ -1052,15 +1030,14 @@ A_PEEP_REC_PROTO { } STATIC void a_peep(pTHX_ OP *o) { -#if !A_HAS_RPEEP dMY_CXT; ptable *seen = MY_CXT.seen; - ptable_seen_clear(seen); -#endif /* !A_HAS_RPEEP */ - a_old_peep(aTHX_ o); + + ptable_seen_clear(seen); a_peep_rec(o); + ptable_seen_clear(seen); } /* --- Interpreter setup/teardown ------------------------------------------ */ @@ -1077,17 +1054,13 @@ STATIC void a_teardown(pTHX_ void *root) { return; #endif -#if A_NEED_CXT { dMY_CXT; # if A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION ptable_hints_free(MY_CXT.tbl); # endif /* A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION */ -# if !A_HAS_RPEEP ptable_seen_free(MY_CXT.seen); -# endif /* !A_HAS_RPEEP */ } -#endif /* A_NEED_CXT */ PL_check[OP_PADANY] = MEMBER_TO_FPTR(a_old_ck_padany); a_old_ck_padany = 0; @@ -1135,18 +1108,14 @@ STATIC void a_setup(pTHX) { if (a_initialized) return; -#if A_NEED_CXT { MY_CXT_INIT; # if A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION MY_CXT.tbl = ptable_new(); MY_CXT.owner = aTHX; # endif /* A_THREADSAFE && A_WORKAROUND_REQUIRE_PROPAGATION */ -# if !A_HAS_RPEEP MY_CXT.seen = ptable_new(); -# endif /* !A_RPEEP */ } -#endif /* A_NEED_CXT */ a_old_ck_padany = PL_check[OP_PADANY]; PL_check[OP_PADANY] = MEMBER_TO_FPTR(a_ck_padany); @@ -1231,7 +1200,7 @@ BOOT: a_setup(); } -#if A_THREADSAFE && (A_WORKAROUND_REQUIRE_PROPAGATION || !A_HAS_RPEEP) +#if A_THREADSAFE void CLONE(...) @@ -1240,9 +1209,7 @@ PREINIT: #if A_WORKAROUND_REQUIRE_PROPAGATION ptable *t; #endif -#if !A_HAS_RPEEP ptable *s; -#endif PPCODE: { dMY_CXT; @@ -1256,9 +1223,7 @@ PPCODE: a_ptable_clone_ud_deinit(ud); } #endif -#if !A_HAS_RPEEP s = ptable_new(); -#endif } { MY_CXT_CLONE; @@ -1266,14 +1231,12 @@ PPCODE: MY_CXT.tbl = t; MY_CXT.owner = aTHX; #endif -#if !A_HAS_RPEEP MY_CXT.seen = s; -#endif } reap(3, a_thread_cleanup, NULL); XSRETURN(0); -#endif +#endif /* A_THREADSAFE */ SV * _tag(SV *hint)