--- Devel-FindRef/FindRef.xs 2009/07/01 08:25:04 1.17 +++ Devel-FindRef/FindRef.xs 2014/05/18 18:44:08 1.25 @@ -21,6 +21,12 @@ # define GvNAME_HEK(sv) 1 #endif +#ifndef PadARRAY +# define PadARRAY(pad) AvARRAY (pad) +# define PadlistARRAY(pl) ((PAD **)AvARRAY (pl)) +#endif + + #define res_pair(text) \ do { \ AV *av = newAV (); \ @@ -39,7 +45,7 @@ } while (0) #define res_gv(sigil) \ - res_text (form ("in the global %c%s::%.*s", sigil, \ + res_text (form ("the global %c%s::%.*s", sigil, \ HvNAME (GvSTASH (sv)), \ GvNAME_HEK (sv) ? GvNAMELEN (sv) : 11, \ GvNAME_HEK (sv) ? GvNAME (sv) : "")) @@ -103,7 +109,7 @@ /* maybe some placeholder for our variables for eval? */ /* it doesn't seem to reference anything, so we should be able to ignore it */ } - else + else if (SvMAGICAL (sv)) /* name-pads use SvMAGIC for other purposes */ { MAGIC *mg = SvMAGIC (sv); @@ -134,7 +140,7 @@ if (AvREAL (sv)) for (i = AvFILLp (sv) + 1; i--; ) if (AvARRAY (sv)[i] == targ) - res_pair (form ("in array element %d of", i)); + res_pair (form ("the array element %d of", i)); break; @@ -145,43 +151,44 @@ while ((he = hv_iternext ((HV *)sv))) if (HeVAL (he) == targ) - res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); + res_pair (form ("the hash member '%.*s' of", HeKLEN (he), HeKEY (he))); } break; case SVt_PVCV: { - int depth = CvDEPTH (sv); + PADLIST *padlist = CvPADLIST (sv); - /* Anonymous subs have a padlist but zero depth */ - if (CvANON (sv) && !depth && CvPADLIST (sv)) - depth = 1; - - if (depth) + if (padlist) { - AV *padlist = CvPADLIST (sv); + int depth = CvDEPTH (sv); + + /* Anonymous subs have a padlist but zero depth */ + /* some hacks switch CvANON off, so we just blindly assume a minimum of 1 */ + if (!depth) + depth = 1; while (depth) { - AV *pad = (AV *)AvARRAY (padlist)[depth]; + PAD *pad = PadlistARRAY (padlist)[depth]; av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ /* The 0th pad slot is @_ */ - if (AvARRAY (pad)[0] == targ) + if (PadARRAY (pad)[0] == targ) res_pair ("the argument array for"); for (i = AvFILLp (pad) + 1; --i; ) if (AvARRAY (pad)[i] == targ) { /* Values from constant functions are stored in the pad without any name */ - SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; + SV *name_sv = PadARRAY (PadlistARRAY (padlist)[0])[i]; if (name_sv && SvPOK (name_sv)) - res_pair (form ("in the lexical '%s' in", SvPVX (name_sv))); + res_pair (form ("the lexical '%s' in", SvPVX (name_sv))); else - res_pair ("in an unnamed lexical in"); + res_pair ("an unnamed lexical in"); } --depth; @@ -228,7 +235,7 @@ if (mg && mg->mg_obj) res_pair (form ("the target for the lvalue hash element '%.*s',", - SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj))); + (int)SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj))); else res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv))); }