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.10 by root, Fri Jul 11 15:33:48 2008 UTC vs.
Revision 1.13 by root, Sat Jul 19 01:38:57 2008 UTC

24 av_push (av, sv_rvweaken (newRV_inc (sv))); \ 24 av_push (av, sv_rvweaken (newRV_inc (sv))); \
25 if (rmagical) SvRMAGICAL_off (sv); \ 25 if (rmagical) SvRMAGICAL_off (sv); \
26 av_push (about, newRV_noinc ((SV *)av)); \ 26 av_push (about, newRV_noinc ((SV *)av)); \
27 } while (0) 27 } while (0)
28 28
29#define res_gv(sigil) \ 29#define res_text(text) \
30 do { \ 30 do { \
31 AV *av = newAV (); \ 31 AV *av = newAV (); \
32 av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ 32 av_push (av, newSVpv (text, 0)); \
33 HvNAME (GvSTASH (sv)), \
34 GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \
35 0)); \
36 av_push (about, newRV_noinc ((SV *)av)); \ 33 av_push (about, newRV_noinc ((SV *)av)); \
37 } while (0) 34 } while (0)
38 35
36#define res_gv(sigil) \
37 res_text (form ("in the global %c%s::%.*s", sigil, \
38 HvNAME (GvSTASH (sv)), \
39 GvNAMELEN (sv), \
40 GvNAME (sv) ? GvNAME (sv) : "<anonymous>"))
41
39MODULE = Devel::FindRef PACKAGE = Devel::FindRef 42MODULE = Devel::FindRef PACKAGE = Devel::FindRef
40 43
41PROTOTYPES: ENABLE 44PROTOTYPES: ENABLE
42 45
43SV * 46SV *
44ptr2ref (IV ptr) 47ptr2ref (UV ptr)
45 CODE: 48 CODE:
46 RETVAL = newRV_inc (INT2PTR (SV *, ptr)); 49 RETVAL = newRV_inc (INT2PTR (SV *, ptr));
50 OUTPUT:
51 RETVAL
52
53UV
54ref2ptr (SV *rv)
55 CODE:
56 RETVAL = PTR2UV (SvRV (rv));
47 OUTPUT: 57 OUTPUT:
48 RETVAL 58 RETVAL
49 59
50void 60void
51find_ (SV *target) 61find_ (SV *target)
79 if ((rmagical = SvRMAGICAL (sv))) 89 if ((rmagical = SvRMAGICAL (sv)))
80 SvRMAGICAL_off (sv); 90 SvRMAGICAL_off (sv);
81 91
82 if (SvTYPE (sv) >= SVt_PVMG) 92 if (SvTYPE (sv) >= SVt_PVMG)
83 { 93 {
84
85 if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv)) 94 if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv))
86 { 95 {
87 /* I have no clue what this is */ 96 /* I have no clue what this is */
88 /* maybe some placeholder for our variables for eval? */ 97 /* maybe some placeholder for our variables for eval? */
89 /* it doesn'T seem to reference anything, so we should be able to ignore it */ 98 /* it doesn't seem to reference anything, so we should be able to ignore it */
90 } 99 }
91 else 100 else
92 { 101 {
93 MAGIC *mg = SvMAGIC (sv); 102 MAGIC *mg = SvMAGIC (sv);
94 103
136 case SVt_PVCV: 145 case SVt_PVCV:
137 { 146 {
138 int depth = CvDEPTH (sv); 147 int depth = CvDEPTH (sv);
139 148
140 /* Anonymous subs have a padlist but zero depth */ 149 /* Anonymous subs have a padlist but zero depth */
141 if (!depth && CvPADLIST (sv)) 150 if (CvANON (sv) && !depth && CvPADLIST (sv))
142 depth = 1; 151 depth = 1;
143 152
144 if (depth) 153 if (depth)
145 { 154 {
146 AV *padlist = CvPADLIST (sv); 155 AV *padlist = CvPADLIST (sv);
149 { 158 {
150 AV *pad = (AV *)AvARRAY (padlist)[depth]; 159 AV *pad = (AV *)AvARRAY (padlist)[depth];
151 160
152 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ 161 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */
153 162
163 /* The 0th pad slot is @_ */
164 if (AvARRAY (pad)[0] == targ)
165 res_pair ("the argument array for");
166
154 for (i = AvFILLp (pad) + 1; i--; ) 167 for (i = AvFILLp (pad) + 1; --i; )
155 if (AvARRAY (pad)[i] == targ) 168 if (AvARRAY (pad)[i] == targ)
156 { 169 {
157 /* Values from constant functions are stored in the pad without any name */ 170 /* Values from constant functions are stored in the pad without any name */
158 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; 171 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i];
159 172
170 if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) 183 if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ)
171 res_pair ("the constant value of"); 184 res_pair ("the constant value of");
172 185
173 if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) 186 if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ)
174 res_pair ("the containing scope for"); 187 res_pair ("the containing scope for");
188
189 if (sv == targ && CvANON (sv))
190 if (CvSTART (sv)
191 && CvSTART (sv)->op_type == OP_NEXTSTATE
192 && CopLINE ((COP *)CvSTART (sv)))
193 res_text (form ("the closure created at %s:%d",
194 CopFILE ((COP *)CvSTART (sv)) ? CopFILE ((COP *)CvSTART (sv)) : "<unknown>",
195 CopLINE ((COP *)CvSTART (sv))));
196 else
197 res_text (form ("the closure created somewhere in file %s (PLEASE REPORT!)",
198 CvFILE (sv) ? CvFILE (sv) : "<unknown>"));
175 } 199 }
176 200
177 break; 201 break;
178 202
179 case SVt_PVGV: 203 case SVt_PVGV:
191 if (rmagical) 215 if (rmagical)
192 SvRMAGICAL_on (sv); 216 SvRMAGICAL_on (sv);
193 } 217 }
194 } 218 }
195 219
220 if (targ == (SV*)PL_main_cv)
221 res_text ("the main body of the program");
222
196 EXTEND (SP, 2); 223 EXTEND (SP, 2);
197 PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); 224 PUSHs (sv_2mortal (newRV_noinc ((SV *)about)));
198 PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); 225 PUSHs (sv_2mortal (newRV_noinc ((SV *)excl)));
199} 226}
200 227

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines