X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=blobdiff_plain;f=indirect.xs;h=45309ce648a1cf43b3b0cccd4a31b076d864a616;hp=9347467ea034cad3ae3aa75631cd5a2982ae74e9;hb=8e1c49f42da7671812398f92d819da04c7a41e1b;hpb=9e8840b03b5cfb27dc88d7e1e85533fc6bbef6b5 diff --git a/indirect.xs b/indirect.xs index 9347467..45309ce 100644 --- a/indirect.xs +++ b/indirect.xs @@ -164,6 +164,7 @@ typedef struct { const char *pos; char *buf; STRLEN len, size; + line_t line; } indirect_op_info_t; #define PTABLE_NAME ptable @@ -350,6 +351,10 @@ STATIC U32 indirect_hash = 0; STATIC SV *indirect_hint(pTHX) { #define indirect_hint() indirect_hint(aTHX) SV *hint; + + if (IN_PERL_RUNTIME) + return NULL; + #if I_HAS_PERL(5, 9, 5) hint = Perl_refcounted_he_fetch(aTHX_ PL_curcop->cop_hints_hash, NULL, @@ -357,19 +362,21 @@ STATIC SV *indirect_hint(pTHX) { 0, indirect_hash); #else - SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, + { + SV **val = hv_fetch(GvHV(PL_hintgv), __PACKAGE__, __PACKAGE_LEN__, indirect_hash); - if (!val) - return 0; - hint = *val; + if (!val) + return 0; + hint = *val; + } #endif return indirect_detag(hint); } /* ... op -> source position ............................................... */ -STATIC void indirect_map_store(pTHX_ const OP *o, const char *src, SV *sv) { -#define indirect_map_store(O, S, N) indirect_map_store(aTHX_ (O), (S), (N)) +STATIC void indirect_map_store(pTHX_ const OP *o, const char *src, SV *sv, line_t line) { +#define indirect_map_store(O, S, N, L) indirect_map_store(aTHX_ (O), (S), (N), (L)) indirect_op_info_t *oi; const char *s; STRLEN len; @@ -401,8 +408,9 @@ STATIC void indirect_map_store(pTHX_ const OP *o, const char *src, SV *sv) { oi->size = len; } Copy(s, oi->buf, len, char); - oi->len = len; - oi->pos = src; + oi->len = len; + oi->pos = src; + oi->line = line; } STATIC const indirect_op_info_t *indirect_map_fetch(pTHX_ const OP *o) { @@ -459,7 +467,8 @@ STATIC OP *indirect_ck_const(pTHX_ OP *o) { if (indirect_hint()) { SV *sv = cSVOPo_sv; if (SvPOK(sv) && (SvTYPE(sv) >= SVt_PV)) { - indirect_map_store(o, indirect_find(sv, PL_oldbufptr), sv); + const char *s = indirect_find(sv, PL_oldbufptr); + indirect_map_store(o, s, sv, CopLINE(&PL_compiling)); return o; } } @@ -524,7 +533,7 @@ STATIC OP *indirect_ck_rv2sv(pTHX_ OP *o) { } o = CALL_FPTR(indirect_old_ck_rv2sv)(aTHX_ o); - indirect_map_store(o, s, sv); + indirect_map_store(o, s, sv, CopLINE(&PL_compiling)); return o; } @@ -552,7 +561,7 @@ STATIC OP *indirect_ck_padany(pTHX_ OP *o) { while (s < t && isSPACE(*t)) --t; sv = sv_2mortal(newSVpvn("$", 1)); sv_catpvn_nomg(sv, s, t - s + 1); - indirect_map_store(o, s, sv); + indirect_map_store(o, s, sv, CopLINE(&PL_compiling)); return o; } } @@ -570,22 +579,25 @@ STATIC OP *indirect_ck_method(pTHX_ OP *o) { OP *op = cUNOPo->op_first; const indirect_op_info_t *oi = indirect_map_fetch(op); const char *s = NULL; + line_t line; SV *sv; if (oi && (s = oi->pos)) { - sv = sv_2mortal(newSVpvn(oi->buf, oi->len)); + sv = sv_2mortal(newSVpvn(oi->buf, oi->len)); + line = oi->line; /* Keep the old line so that we really point to the first */ } else { sv = cSVOPx_sv(op); if (!SvPOK(sv) || (SvTYPE(sv) < SVt_PV)) goto done; - sv = sv_mortalcopy(sv); - s = indirect_find(sv, PL_oldbufptr); + sv = sv_mortalcopy(sv); + s = indirect_find(sv, PL_oldbufptr); + line = CopLINE(&PL_compiling); } o = CALL_FPTR(indirect_old_ck_method)(aTHX_ o); /* o may now be a method_named */ - indirect_map_store(o, s, sv); + indirect_map_store(o, s, sv, line); return o; } @@ -598,6 +610,16 @@ done: /* ... ck_entersub ......................................................... */ +STATIC int indirect_is_indirect(const indirect_op_info_t *moi, const indirect_op_info_t *ooi) { + if (moi->pos > ooi->pos) + return 0; + + if (moi->pos == ooi->pos) + return moi->len == ooi->len && !memcmp(moi->buf, ooi->buf, moi->len); + + return 1; +} + STATIC OP *(*indirect_old_ck_entersub)(pTHX_ OP *) = 0; STATIC OP *indirect_ck_entersub(pTHX_ OP *o) { @@ -645,9 +667,8 @@ STATIC OP *indirect_ck_entersub(pTHX_ OP *o) { if (!(ooi && ooi->pos)) goto done; - if (moi->pos < ooi->pos) { - SV *file; - line_t line; + if (indirect_is_indirect(moi, ooi)) { + SV *file; dSP; ENTER; @@ -658,14 +679,13 @@ STATIC OP *indirect_ck_entersub(pTHX_ OP *o) { #else file = sv_mortalcopy(CopFILESV(&PL_compiling)); #endif - line = CopLINE(&PL_compiling); PUSHMARK(SP); EXTEND(SP, 4); mPUSHp(ooi->buf, ooi->len); mPUSHp(moi->buf, moi->len); PUSHs(file); - mPUSHu(line); + mPUSHu(moi->line); PUTBACK; call_sv(code, G_VOID);