X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLexical-Types.git;a=blobdiff_plain;f=Types.xs;h=9c02bd8a434caf16346b08e3edfb0dfa6c6cc064;hp=4b3856225042fa8b68990568595565812b8cb535;hb=c5d3b9e2115202f79337d1fcfe44ae673c2d9251;hpb=edbeb65399a0fb7d5735dbacfb04ffb9bdf64b34 diff --git a/Types.xs b/Types.xs index 4b38562..9c02bd8 100644 --- a/Types.xs +++ b/Types.xs @@ -39,12 +39,17 @@ # define HvNAMELEN_get(H) strlen(HvNAME_get(H)) #endif -#ifndef SvREFCNT_inc_simple_NN -# define SvREFCNT_inc_simple_NN SvREFCNT_inc +#ifndef SvREFCNT_inc_simple_void_NN +# define SvREFCNT_inc_simple_void_NN(S) ((void) SvREFCNT_inc(S)) #endif /* ... Thread safety and multiplicity ...................................... */ +/* Safe unless stated otherwise in Makefile.PL */ +#ifndef LT_FORKSAFE +# define LT_FORKSAFE 1 +#endif + #ifndef LT_MULTIPLICITY # if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT) # define LT_MULTIPLICITY 1 @@ -140,14 +145,15 @@ typedef SV lt_hint_t; /* ... "Seen" pointer table ................................................ */ -#if !LT_HAS_RPEEP - #define PTABLE_NAME ptable_seen #define PTABLE_VAL_FREE(V) NOOP #include "ptable.h" -#endif /* !LT_HAS_RPEEP */ +/* 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)) /* ... Global data ......................................................... */ @@ -158,9 +164,7 @@ typedef struct { ptable *tbl; /* It really is a ptable_hints */ tTHX owner; #endif -#if !LT_HAS_RPEEP ptable *seen; /* It really is a ptable_seen */ -#endif SV *default_meth; } my_cxt_t; @@ -223,9 +227,7 @@ STATIC void lt_thread_cleanup(pTHX_ void *ud) { dMY_CXT; ptable_hints_free(MY_CXT.tbl); -#if !LT_HAS_RPEEP ptable_seen_free(MY_CXT.seen); -#endif /* !LT_HAS_RPEEP */ } #endif /* LT_THREADSAFE */ @@ -289,7 +291,7 @@ STATIC SV *lt_tag(pTHX_ SV *value) { value = SvRV(value); if (SvTYPE(value) >= SVt_PVCV) { code = value; - SvREFCNT_inc_simple_NN(code); + SvREFCNT_inc_simple_void_NN(code); } } @@ -352,7 +354,7 @@ STATIC SV *lt_hint(pTHX) { 0, lt_hash); #else - SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, lt_hash); + SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, 0); if (!val) return 0; hint = *val; @@ -369,6 +371,7 @@ STATIC SV *lt_hint(pTHX) { /* 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 *lt_op_map = NULL; @@ -487,60 +490,56 @@ STATIC OP *lt_pp_padsv(pTHX) { lt_op_info oi; if (lt_map_fetch(PL_op, &oi)) { - PADOFFSET targ = PL_op->op_targ; - SV *sv = PAD_SVl(targ); - - if (sv) { - SV *orig_pkg, *type_pkg, *type_meth; - int items; - dSP; + SV *orig_pkg, *type_pkg, *type_meth; + int items; + dSP; + dTARGET; - ENTER; - SAVETMPS; + ENTER; + SAVETMPS; #ifdef MULTIPLICITY - { - STRLEN op_len = oi.orig_pkg_len, tp_len = oi.type_pkg_len; - char *buf = oi.buf; - orig_pkg = sv_2mortal(newSVpvn(buf, op_len)); - SvREADONLY_on(orig_pkg); - buf += op_len; - type_pkg = sv_2mortal(newSVpvn(buf, tp_len)); - SvREADONLY_on(type_pkg); - buf += tp_len; - type_meth = sv_2mortal(newSVpvn(buf, oi.type_meth_len)); - SvREADONLY_on(type_meth); - } + { + STRLEN op_len = oi.orig_pkg_len, tp_len = oi.type_pkg_len; + char *buf = oi.buf; + orig_pkg = sv_2mortal(newSVpvn(buf, op_len)); + SvREADONLY_on(orig_pkg); + buf += op_len; + type_pkg = sv_2mortal(newSVpvn(buf, tp_len)); + SvREADONLY_on(type_pkg); + buf += tp_len; + type_meth = sv_2mortal(newSVpvn(buf, oi.type_meth_len)); + SvREADONLY_on(type_meth); + } #else /* MULTIPLICITY */ - orig_pkg = oi.orig_pkg; - type_pkg = oi.type_pkg; - type_meth = oi.type_meth; + orig_pkg = oi.orig_pkg; + type_pkg = oi.type_pkg; + type_meth = oi.type_meth; #endif /* !MULTIPLICITY */ - PUSHMARK(SP); - EXTEND(SP, 3); - PUSHs(type_pkg); - PUSHs(sv); - PUSHs(orig_pkg); - PUTBACK; - - items = call_sv(type_meth, G_ARRAY | G_METHOD); - - SPAGAIN; - switch (items) { - case 0: - break; - case 1: - sv_setsv(sv, POPs); - break; - default: - croak("Typed scalar initializer method should return zero or one scalar, but got %d", items); - } - PUTBACK; + PUSHMARK(SP); + EXTEND(SP, 3); + PUSHs(type_pkg); + PUSHTARG; + PUSHs(orig_pkg); + PUTBACK; - FREETMPS; - LEAVE; + items = call_sv(type_meth, G_ARRAY | G_METHOD); + + SPAGAIN; + switch (items) { + case 0: + break; + case 1: + sv_setsv(TARG, POPs); + break; + default: + croak("Typed scalar initializer method should return zero or one scalar, but got %d", items); } + PUTBACK; + + FREETMPS; + LEAVE; return oi.old_pp_padsv(aTHX); } @@ -617,12 +616,12 @@ STATIC OP *lt_ck_padany(pTHX_ OP *o) { if (!type_pkg) { type_pkg = orig_pkg; - SvREFCNT_inc(orig_pkg); + SvREFCNT_inc_simple_void_NN(orig_pkg); } if (!type_meth) { type_meth = orig_meth; - SvREFCNT_inc(orig_meth); + SvREFCNT_inc_simple_void_NN(orig_meth); } lt_map_store(o, orig_pkg, type_pkg, type_meth, o->op_ppaddr); @@ -646,31 +645,15 @@ STATIC OP *lt_ck_padsv(pTHX_ OP *o) { STATIC peep_t lt_old_peep = 0; /* This is actually the rpeep past 5.13.5 */ -#if !LT_HAS_RPEEP -# define LT_PEEP_REC_PROTO STATIC void lt_peep_rec(pTHX_ OP *o, ptable *seen) -#else /* !LT_HAS_RPEEP */ -# define LT_PEEP_REC_PROTO STATIC void lt_peep_rec(pTHX_ OP *o) -#endif /* LT_HAS_RPEEP */ - -LT_PEEP_REC_PROTO; -LT_PEEP_REC_PROTO { -#if !LT_HAS_RPEEP -# define lt_peep_rec(O) lt_peep_rec(aTHX_ (O), seen) -#else /* !LT_HAS_RPEEP */ -# define lt_peep_rec(O) lt_peep_rec(aTHX_ (O)) -#endif /* LT_HAS_RPEEP */ - -#if !LT_HAS_RPEEP - if (ptable_fetch(seen, o)) - return; -#endif - +STATIC void lt_peep_rec(pTHX_ OP *o, ptable *seen) { +#define lt_peep_rec(O) lt_peep_rec(aTHX_ (O), seen) for (; o; o = o->op_next) { lt_op_info *oi = NULL; -#if !LT_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 != lt_pp_padsv && o->op_private & OPpLVAL_INTRO) { @@ -724,15 +707,14 @@ LT_PEEP_REC_PROTO { } STATIC void lt_peep(pTHX_ OP *o) { -#if !LT_HAS_RPEEP dMY_CXT; ptable *seen = MY_CXT.seen; - ptable_seen_clear(seen); -#endif /* !LT_HAS_RPEEP */ - lt_old_peep(aTHX_ o); + + ptable_seen_clear(seen); lt_peep_rec(o); + ptable_seen_clear(seen); } /* --- Interpreter setup/teardown ------------------------------------------ */ @@ -754,9 +736,7 @@ STATIC void lt_teardown(pTHX_ void *root) { #if LT_THREADSAFE ptable_hints_free(MY_CXT.tbl); #endif -#if !LT_HAS_RPEEP ptable_seen_free(MY_CXT.seen); -#endif SvREFCNT_dec(MY_CXT.default_meth); } @@ -786,9 +766,7 @@ STATIC void lt_setup(pTHX) { MY_CXT.tbl = ptable_new(); MY_CXT.owner = aTHX; #endif -#if !LT_HAS_RPEEP MY_CXT.seen = ptable_new(); -#endif MY_CXT.default_meth = newSVpvn("TYPEDSCALAR", 11); SvREADONLY_on(MY_CXT.default_meth); } @@ -837,6 +815,7 @@ BOOT: stash = gv_stashpvn(__PACKAGE__, __PACKAGE_LEN__, 1); newCONSTSUB(stash, "LT_THREADSAFE", newSVuv(LT_THREADSAFE)); + newCONSTSUB(stash, "LT_FORKSAFE", newSVuv(LT_FORKSAFE)); } lt_setup(); @@ -849,9 +828,7 @@ CLONE(...) PROTOTYPE: DISABLE PREINIT: ptable *t; -#if !LT_HAS_RPEEP ptable *s; -#endif SV *cloned_default_meth; PPCODE: { @@ -865,17 +842,13 @@ PPCODE: cloned_default_meth = lt_dup_inc(MY_CXT.default_meth, &ud); lt_ptable_clone_ud_deinit(ud); } -#if !LT_HAS_RPEEP s = ptable_new(); -#endif } { MY_CXT_CLONE; MY_CXT.tbl = t; MY_CXT.owner = aTHX; -#if !LT_HAS_RPEEP MY_CXT.seen = s; -#endif MY_CXT.default_meth = cloned_default_meth; } reap(3, lt_thread_cleanup, NULL);