ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Devel-FindRef/FindRef.xs
(Generate patch)

Comparing Devel-FindRef/FindRef.xs (file contents):
Revision 1.16 by root, Fri Jun 26 14:47:03 2009 UTC vs.
Revision 1.27 by root, Tue Jul 31 22:55:47 2018 UTC

4 4
5#define PERL_VERSION_ATLEAST(a,b,c) \ 5#define PERL_VERSION_ATLEAST(a,b,c) \
6 (PERL_REVISION > (a) \ 6 (PERL_REVISION > (a) \
7 || (PERL_REVISION == (a) \ 7 || (PERL_REVISION == (a) \
8 && (PERL_VERSION > (b) \ 8 && (PERL_VERSION > (b) \
9 || (PERL_VERSION == (b) && PERLSUBVERSION >= (c))))) 9 || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c)))))
10 10
11#if !PERL_VERSION_ATLEAST (5,8,9) 11#if !PERL_VERSION_ATLEAST (5,8,9)
12# define SVt_LAST 16 12# define SVt_LAST 16
13#endif 13#endif
14 14
15#if !PERL_VERSION_ATLEAST (5,10,0) 15#ifndef SvPAD_OUR
16# define SvPAD_OUR(dummy) 0 16# define SvPAD_OUR(dummy) 0
17#endif
18
19/* pre-5.10 perls always succeed, with 5.10, we have to check first apparently */
20#ifndef GvNAME_HEK
21# define GvNAME_HEK(sv) 1
22#endif
23
24#ifndef PadARRAY
25typedef AV PADNAMELIST;
26typedef SV PADNAME;
27# define PadnamePV(sv) SvPVX (sv)
28# define PadnameLEN(sv) SvCUR (sv)
29# define PadARRAY(pad) AvARRAY (pad)
30# define PadlistARRAY(pl) ((PAD **)AvARRAY (pl))
31#endif
32
33#ifndef PadMAX
34# define PadMAX(pad) AvFILLp (pad)
35#endif
36
37#ifndef padnamelist_fetch
38# define padnamelist_fetch(a,b) *av_fetch (a, b, FALSE)
39#endif
40
41#ifndef PadlistNAMES
42# define PadlistNAMES(padlist) *PadlistARRAY (padlist)
17#endif 43#endif
18 44
19#define res_pair(text) \ 45#define res_pair(text) \
20 do { \ 46 do { \
21 AV *av = newAV (); \ 47 AV *av = newAV (); \
32 av_push (av, newSVpv (text, 0)); \ 58 av_push (av, newSVpv (text, 0)); \
33 av_push (about, newRV_noinc ((SV *)av)); \ 59 av_push (about, newRV_noinc ((SV *)av)); \
34 } while (0) 60 } while (0)
35 61
36#define res_gv(sigil) \ 62#define res_gv(sigil) \
37 res_text (form ("in the global %c%s::%.*s", sigil, \ 63 res_text (form ("the global %c%s::%.*s", sigil, \
38 HvNAME (GvSTASH (sv)), \ 64 HvNAME (GvSTASH (sv)), \
39 GvNAMELEN (sv), \ 65 GvNAME_HEK (sv) ? GvNAMELEN (sv) : 11, \
40 GvNAME (sv) ? GvNAME (sv) : "<anonymous>")) 66 GvNAME_HEK (sv) ? GvNAME (sv) : "<anonymous>"))
41 67
42MODULE = Devel::FindRef PACKAGE = Devel::FindRef 68MODULE = Devel::FindRef PACKAGE = Devel::FindRef
43 69
44PROTOTYPES: ENABLE 70PROTOTYPES: ENABLE
45 71
90 if ((rmagical = SvRMAGICAL (sv))) 116 if ((rmagical = SvRMAGICAL (sv)))
91 SvRMAGICAL_off (sv); 117 SvRMAGICAL_off (sv);
92 118
93 if (SvTYPE (sv) >= SVt_PVMG) 119 if (SvTYPE (sv) >= SVt_PVMG)
94 { 120 {
121#if !PERL_VERSION_ATLEAST (5,21,6)
95 if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv)) 122 if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv))
96 { 123 {
97 /* I have no clue what this is */ 124 /* I have no clue what this is */
98 /* maybe some placeholder for our variables for eval? */ 125 /* maybe some placeholder for our variables for eval? */
99 /* it doesn't seem to reference anything, so we should be able to ignore it */ 126 /* it doesn't seem to reference anything, so we should be able to ignore it */
100 } 127 }
101 else 128 else
129#endif
130 if (SvMAGICAL (sv)) /* name-pads use SvMAGIC for other purposes */
102 { 131 {
103 MAGIC *mg = SvMAGIC (sv); 132 MAGIC *mg = SvMAGIC (sv);
104 133
105 while (mg) 134 while (mg)
106 { 135 {
127 { 156 {
128 case SVt_PVAV: 157 case SVt_PVAV:
129 if (AvREAL (sv)) 158 if (AvREAL (sv))
130 for (i = AvFILLp (sv) + 1; i--; ) 159 for (i = AvFILLp (sv) + 1; i--; )
131 if (AvARRAY (sv)[i] == targ) 160 if (AvARRAY (sv)[i] == targ)
132 res_pair (form ("in array element %d of", i)); 161 res_pair (form ("the array element %d of", i));
133 162
134 break; 163 break;
135 164
136 case SVt_PVHV: 165 case SVt_PVHV:
137 if (hv_iterinit ((HV *)sv)) 166 if (hv_iterinit ((HV *)sv))
138 { 167 {
139 HE *he; 168 HE *he;
140 169
141 while ((he = hv_iternext ((HV *)sv))) 170 while ((he = hv_iternext ((HV *)sv)))
142 if (HeVAL (he) == targ) 171 if (HeVAL (he) == targ)
143 res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); 172 res_pair (form ("the hash member '%.*s' of", HeKLEN (he), HeKEY (he)));
144 } 173 }
145 174
146 break; 175 break;
147 176
148 case SVt_PVCV: 177 case SVt_PVCV:
149 { 178 {
150 int depth = CvDEPTH (sv); 179 PADLIST *padlist = CvISXSUB (cv) ? 0 : CvPADLIST (sv);
151 180
152 /* Anonymous subs have a padlist but zero depth */
153 if (CvANON (sv) && !depth && CvPADLIST (sv))
154 depth = 1;
155
156 if (depth) 181 if (padlist)
157 { 182 {
158 AV *padlist = CvPADLIST (sv); 183 int depth = CvDEPTH (sv);
184
185 /* Anonymous subs have a padlist but zero depth */
186 /* some hacks switch CvANON off, so we just blindly assume a minimum of 1 */
187 if (!depth && !PERL_VERSION_ATLEAST (5,21,6))
188 depth = 1;
159 189
160 while (depth) 190 while (depth)
161 { 191 {
162 AV *pad = (AV *)AvARRAY (padlist)[depth]; 192 PAD *pad = PadlistARRAY (padlist)[depth];
163 193
164 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ 194 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */
165 195
166 /* The 0th pad slot is @_ */ 196 /* The 0th pad slot is @_ */
167 if (AvARRAY (pad)[0] == targ) 197 if (PadARRAY (pad)[0] == targ)
168 res_pair ("the argument array for"); 198 res_pair ("the argument array for");
169 199
170 for (i = AvFILLp (pad) + 1; --i; ) 200 for (i = PadMAX (pad) + 1; --i; )
171 if (AvARRAY (pad)[i] == targ) 201 if (PadARRAY (pad)[i] == targ)
172 { 202 {
173 /* Values from constant functions are stored in the pad without any name */ 203 /* Values from constant functions are stored in the pad without any name */
174 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; 204 PADNAME *name = padnamelist_fetch (PadlistNAMES (padlist), i);
175 205
176 if (name_sv && SvPOK (name_sv)) 206 if (name && PadnamePV (name) && *PadnamePV (name))
177 res_pair (form ("in the lexical '%s' in", SvPVX (name_sv))); 207 res_pair (form ("the lexical '%s' in", PadnamePV (name)));
178 else 208 else
179 res_pair ("in an unnamed lexical in"); 209 res_pair ("an unnamed lexical in");
180 } 210 }
181 211
182 --depth; 212 --depth;
183 } 213 }
184 } 214 }
221 { 251 {
222 MAGIC *mg = mg_find (sv, PERL_MAGIC_defelem); 252 MAGIC *mg = mg_find (sv, PERL_MAGIC_defelem);
223 253
224 if (mg && mg->mg_obj) 254 if (mg && mg->mg_obj)
225 res_pair (form ("the target for the lvalue hash element '%.*s',", 255 res_pair (form ("the target for the lvalue hash element '%.*s',",
226 SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj))); 256 (int)SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj)));
227 else 257 else
228 res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv))); 258 res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv)));
229 } 259 }
230 else 260 else
231 res_pair (form ("an lvalue reference target (type '%c', ofs %d, len %d),", 261 res_pair (form ("an lvalue reference target (type '%c', ofs %d, len %d),",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines