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.25 by root, Sun May 18 18:44:08 2014 UTC

13#endif 13#endif
14 14
15#if !PERL_VERSION_ATLEAST (5,10,0) 15#if !PERL_VERSION_ATLEAST (5,10,0)
16# define SvPAD_OUR(dummy) 0 16# define SvPAD_OUR(dummy) 0
17#endif 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
25# define PadARRAY(pad) AvARRAY (pad)
26# define PadlistARRAY(pl) ((PAD **)AvARRAY (pl))
27#endif
28
18 29
19#define res_pair(text) \ 30#define res_pair(text) \
20 do { \ 31 do { \
21 AV *av = newAV (); \ 32 AV *av = newAV (); \
22 av_push (av, newSVpv (text, 0)); \ 33 av_push (av, newSVpv (text, 0)); \
32 av_push (av, newSVpv (text, 0)); \ 43 av_push (av, newSVpv (text, 0)); \
33 av_push (about, newRV_noinc ((SV *)av)); \ 44 av_push (about, newRV_noinc ((SV *)av)); \
34 } while (0) 45 } while (0)
35 46
36#define res_gv(sigil) \ 47#define res_gv(sigil) \
37 res_text (form ("in the global %c%s::%.*s", sigil, \ 48 res_text (form ("the global %c%s::%.*s", sigil, \
38 HvNAME (GvSTASH (sv)), \ 49 HvNAME (GvSTASH (sv)), \
39 GvNAMELEN (sv), \ 50 GvNAME_HEK (sv) ? GvNAMELEN (sv) : 11, \
40 GvNAME (sv) ? GvNAME (sv) : "<anonymous>")) 51 GvNAME_HEK (sv) ? GvNAME (sv) : "<anonymous>"))
41 52
42MODULE = Devel::FindRef PACKAGE = Devel::FindRef 53MODULE = Devel::FindRef PACKAGE = Devel::FindRef
43 54
44PROTOTYPES: ENABLE 55PROTOTYPES: ENABLE
45 56
96 { 107 {
97 /* I have no clue what this is */ 108 /* I have no clue what this is */
98 /* maybe some placeholder for our variables for eval? */ 109 /* maybe some placeholder for our variables for eval? */
99 /* it doesn't seem to reference anything, so we should be able to ignore it */ 110 /* it doesn't seem to reference anything, so we should be able to ignore it */
100 } 111 }
101 else 112 else if (SvMAGICAL (sv)) /* name-pads use SvMAGIC for other purposes */
102 { 113 {
103 MAGIC *mg = SvMAGIC (sv); 114 MAGIC *mg = SvMAGIC (sv);
104 115
105 while (mg) 116 while (mg)
106 { 117 {
127 { 138 {
128 case SVt_PVAV: 139 case SVt_PVAV:
129 if (AvREAL (sv)) 140 if (AvREAL (sv))
130 for (i = AvFILLp (sv) + 1; i--; ) 141 for (i = AvFILLp (sv) + 1; i--; )
131 if (AvARRAY (sv)[i] == targ) 142 if (AvARRAY (sv)[i] == targ)
132 res_pair (form ("in array element %d of", i)); 143 res_pair (form ("the array element %d of", i));
133 144
134 break; 145 break;
135 146
136 case SVt_PVHV: 147 case SVt_PVHV:
137 if (hv_iterinit ((HV *)sv)) 148 if (hv_iterinit ((HV *)sv))
138 { 149 {
139 HE *he; 150 HE *he;
140 151
141 while ((he = hv_iternext ((HV *)sv))) 152 while ((he = hv_iternext ((HV *)sv)))
142 if (HeVAL (he) == targ) 153 if (HeVAL (he) == targ)
143 res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); 154 res_pair (form ("the hash member '%.*s' of", HeKLEN (he), HeKEY (he)));
144 } 155 }
145 156
146 break; 157 break;
147 158
148 case SVt_PVCV: 159 case SVt_PVCV:
149 { 160 {
150 int depth = CvDEPTH (sv); 161 PADLIST *padlist = CvPADLIST (sv);
151 162
152 /* Anonymous subs have a padlist but zero depth */
153 if (CvANON (sv) && !depth && CvPADLIST (sv))
154 depth = 1;
155
156 if (depth) 163 if (padlist)
157 { 164 {
158 AV *padlist = CvPADLIST (sv); 165 int depth = CvDEPTH (sv);
166
167 /* Anonymous subs have a padlist but zero depth */
168 /* some hacks switch CvANON off, so we just blindly assume a minimum of 1 */
169 if (!depth)
170 depth = 1;
159 171
160 while (depth) 172 while (depth)
161 { 173 {
162 AV *pad = (AV *)AvARRAY (padlist)[depth]; 174 PAD *pad = PadlistARRAY (padlist)[depth];
163 175
164 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ 176 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */
165 177
166 /* The 0th pad slot is @_ */ 178 /* The 0th pad slot is @_ */
167 if (AvARRAY (pad)[0] == targ) 179 if (PadARRAY (pad)[0] == targ)
168 res_pair ("the argument array for"); 180 res_pair ("the argument array for");
169 181
170 for (i = AvFILLp (pad) + 1; --i; ) 182 for (i = AvFILLp (pad) + 1; --i; )
171 if (AvARRAY (pad)[i] == targ) 183 if (AvARRAY (pad)[i] == targ)
172 { 184 {
173 /* Values from constant functions are stored in the pad without any name */ 185 /* Values from constant functions are stored in the pad without any name */
174 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; 186 SV *name_sv = PadARRAY (PadlistARRAY (padlist)[0])[i];
175 187
176 if (name_sv && SvPOK (name_sv)) 188 if (name_sv && SvPOK (name_sv))
177 res_pair (form ("in the lexical '%s' in", SvPVX (name_sv))); 189 res_pair (form ("the lexical '%s' in", SvPVX (name_sv)));
178 else 190 else
179 res_pair ("in an unnamed lexical in"); 191 res_pair ("an unnamed lexical in");
180 } 192 }
181 193
182 --depth; 194 --depth;
183 } 195 }
184 } 196 }
221 { 233 {
222 MAGIC *mg = mg_find (sv, PERL_MAGIC_defelem); 234 MAGIC *mg = mg_find (sv, PERL_MAGIC_defelem);
223 235
224 if (mg && mg->mg_obj) 236 if (mg && mg->mg_obj)
225 res_pair (form ("the target for the lvalue hash element '%.*s',", 237 res_pair (form ("the target for the lvalue hash element '%.*s',",
226 SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj))); 238 (int)SvCUR (mg->mg_obj), SvPV_nolen (mg->mg_obj)));
227 else 239 else
228 res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv))); 240 res_pair (form ("the target for the lvalue array element #%d,", LvTARGOFF (sv)));
229 } 241 }
230 else 242 else
231 res_pair (form ("an lvalue reference target (type '%c', ofs %d, len %d),", 243 res_pair (form ("an lvalue reference target (type '%c', ofs %d, len %d),",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines