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.6 by root, Sat Dec 29 21:04:46 2007 UTC vs.
Revision 1.10 by root, Fri Jul 11 15:33:48 2008 UTC

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)
16# define SvPAD_OUR(dummy) 0
17#endif
18
15#define res_pair(text) \ 19#define res_pair(text) \
16 { \ 20 do { \
17 AV *av = newAV (); \ 21 AV *av = newAV (); \
18 av_push (av, newSVpv (text, 0)); \ 22 av_push (av, newSVpv (text, 0)); \
23 if (rmagical) SvRMAGICAL_on (sv); \
19 av_push (av, sv_rvweaken (newRV_inc (sv))); \ 24 av_push (av, sv_rvweaken (newRV_inc (sv))); \
25 if (rmagical) SvRMAGICAL_off (sv); \
20 av_push (about, newRV_noinc ((SV *)av)); \ 26 av_push (about, newRV_noinc ((SV *)av)); \
21 } 27 } while (0)
22 28
23#define res_gv(sigil) \ 29#define res_gv(sigil) \
24 { \ 30 do { \
25 AV *av = newAV (); \ 31 AV *av = newAV (); \
26 av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ 32 av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \
27 HvNAME (GvSTASH (sv)), \ 33 HvNAME (GvSTASH (sv)), \
28 GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \ 34 GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \
29 0)); \ 35 0)); \
30 av_push (about, newRV_noinc ((SV *)av)); \ 36 av_push (about, newRV_noinc ((SV *)av)); \
31 } 37 } while (0)
32 38
33MODULE = Devel::FindRef PACKAGE = Devel::FindRef 39MODULE = Devel::FindRef PACKAGE = Devel::FindRef
34 40
35PROTOTYPES: ENABLE 41PROTOTYPES: ENABLE
36 42
44void 50void
45find_ (SV *target) 51find_ (SV *target)
46 PPCODE: 52 PPCODE:
47{ 53{
48 SV *arena, *targ; 54 SV *arena, *targ;
49 int rmagical, i; 55 U32 rmagical;
56 int i;
50 AV *about = newAV (); 57 AV *about = newAV ();
51 AV *excl = newAV (); 58 AV *excl = newAV ();
52 59
53 if (!SvROK (target)) 60 if (!SvROK (target))
54 croak ("find expects a reference to a perl value"); 61 croak ("find expects a reference to a perl value");
72 if ((rmagical = SvRMAGICAL (sv))) 79 if ((rmagical = SvRMAGICAL (sv)))
73 SvRMAGICAL_off (sv); 80 SvRMAGICAL_off (sv);
74 81
75 if (SvTYPE (sv) >= SVt_PVMG) 82 if (SvTYPE (sv) >= SVt_PVMG)
76 { 83 {
77 MAGIC *mg = SvMAGIC (sv); 84
78 while (mg) 85 if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv))
79 { 86 {
87 /* I have no clue what this is */
88 /* maybe some placeholder for our variables for eval? */
89 /* it doesn'T seem to reference anything, so we should be able to ignore it */
90 }
91 else
92 {
93 MAGIC *mg = SvMAGIC (sv);
94
95 while (mg)
96 {
80 if (mg->mg_obj == targ) 97 if (mg->mg_obj == targ)
81 res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); 98 res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type));
82 99
83 if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) 100 if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED)
84 res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); 101 res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type));
85 102
86 mg = mg->mg_moremagic; 103 mg = mg->mg_moremagic;
104 }
87 } 105 }
88 } 106 }
89 107
90 if (SvROK (sv)) 108 if (SvROK (sv))
91 { 109 {
117 135
118 case SVt_PVCV: 136 case SVt_PVCV:
119 { 137 {
120 int depth = CvDEPTH (sv); 138 int depth = CvDEPTH (sv);
121 139
140 /* Anonymous subs have a padlist but zero depth */
141 if (!depth && CvPADLIST (sv))
142 depth = 1;
143
122 if (depth) 144 if (depth)
123 { 145 {
124 AV *padlist = CvPADLIST (sv); 146 AV *padlist = CvPADLIST (sv);
125 147
126 while (depth) 148 while (depth)
127 { 149 {
128 AV *pad = (AV *)AvARRAY (padlist)[depth]; 150 AV *pad = (AV *)AvARRAY (padlist)[depth];
129 151
130 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ 152 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */
131 153
132 for (i = AvFILLp (pad); i--; ) 154 for (i = AvFILLp (pad) + 1; i--; )
133 if (AvARRAY (pad)[i] == targ) 155 if (AvARRAY (pad)[i] == targ)
156 {
157 /* Values from constant functions are stored in the pad without any name */
158 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i];
159
160 if (name_sv && SvPOK (name_sv))
134 res_pair (form ("in the lexical '%s' in", SvPVX (AvARRAY (AvARRAY (padlist)[0])[i]))); 161 res_pair (form ("in the lexical '%s' in", SvPVX (name_sv)));
162 else
163 res_pair ("in an unnamed lexical in");
164 }
135 165
136 --depth; 166 --depth;
137 } 167 }
138 } 168 }
169
170 if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ)
171 res_pair ("the constant value of");
172
173 if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ)
174 res_pair ("the containing scope for");
139 } 175 }
140 176
141 break; 177 break;
142 178
143 case SVt_PVGV: 179 case SVt_PVGV:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines