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.8 by root, Sun Apr 27 05:59:06 2008 UTC vs.
Revision 1.11 by root, Fri Jul 11 17:59:19 2008 UTC

8 && (PERL_VERSION > (b) \ 8 && (PERL_VERSION > (b) \
9 || (PERL_VERSION == (b) && PERLSUBVERSION >= (c))))) 9 || (PERL_VERSION == (b) && PERLSUBVERSION >= (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
14
15#if !PERL_VERSION_ATLEAST (5,10,0)
16# define SvPAD_OUR(dummy) 0
13#endif 17#endif
14 18
15#define res_pair(text) \ 19#define res_pair(text) \
16 do { \ 20 do { \
17 AV *av = newAV (); \ 21 AV *av = newAV (); \
20 av_push (av, sv_rvweaken (newRV_inc (sv))); \ 24 av_push (av, sv_rvweaken (newRV_inc (sv))); \
21 if (rmagical) SvRMAGICAL_off (sv); \ 25 if (rmagical) SvRMAGICAL_off (sv); \
22 av_push (about, newRV_noinc ((SV *)av)); \ 26 av_push (about, newRV_noinc ((SV *)av)); \
23 } while (0) 27 } while (0)
24 28
25#define res_gv(sigil) \ 29#define res_text(text) \
26 do { \ 30 do { \
27 AV *av = newAV (); \ 31 AV *av = newAV (); \
28 av_push (av, newSVpv (form ("in the global %c%s::%.*s", sigil, \ 32 av_push (av, newSVpv (text, 0)); \
29 HvNAME (GvSTASH (sv)), \
30 GvNAMELEN (sv), GvNAME (sv) ? GvNAME (sv) : "<anonymous>"), \
31 0)); \
32 av_push (about, newRV_noinc ((SV *)av)); \ 33 av_push (about, newRV_noinc ((SV *)av)); \
33 } while (0) 34 } while (0)
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>"))
34 41
35MODULE = Devel::FindRef PACKAGE = Devel::FindRef 42MODULE = Devel::FindRef PACKAGE = Devel::FindRef
36 43
37PROTOTYPES: ENABLE 44PROTOTYPES: ENABLE
38 45
46void 53void
47find_ (SV *target) 54find_ (SV *target)
48 PPCODE: 55 PPCODE:
49{ 56{
50 SV *arena, *targ; 57 SV *arena, *targ;
51 int rmagical, i; 58 U32 rmagical;
59 int i;
52 AV *about = newAV (); 60 AV *about = newAV ();
53 AV *excl = newAV (); 61 AV *excl = newAV ();
54 62
55 if (!SvROK (target)) 63 if (!SvROK (target))
56 croak ("find expects a reference to a perl value"); 64 croak ("find expects a reference to a perl value");
74 if ((rmagical = SvRMAGICAL (sv))) 82 if ((rmagical = SvRMAGICAL (sv)))
75 SvRMAGICAL_off (sv); 83 SvRMAGICAL_off (sv);
76 84
77 if (SvTYPE (sv) >= SVt_PVMG) 85 if (SvTYPE (sv) >= SVt_PVMG)
78 { 86 {
79 MAGIC *mg = SvMAGIC (sv); 87 if (SvTYPE (sv) == SVt_PVMG && SvPAD_OUR (sv))
80 while (mg)
81 { 88 {
89 /* I have no clue what this is */
90 /* maybe some placeholder for our variables for eval? */
91 /* it doesn't seem to reference anything, so we should be able to ignore it */
92 }
93 else
94 {
95 MAGIC *mg = SvMAGIC (sv);
96
97 while (mg)
98 {
82 if (mg->mg_obj == targ) 99 if (mg->mg_obj == targ)
83 res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); 100 res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type));
84 101
85 if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) 102 if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED)
86 res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); 103 res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type));
87 104
88 mg = mg->mg_moremagic; 105 mg = mg->mg_moremagic;
106 }
89 } 107 }
90 } 108 }
91 109
92 if (SvROK (sv)) 110 if (SvROK (sv))
93 { 111 {
120 case SVt_PVCV: 138 case SVt_PVCV:
121 { 139 {
122 int depth = CvDEPTH (sv); 140 int depth = CvDEPTH (sv);
123 141
124 /* Anonymous subs have a padlist but zero depth */ 142 /* Anonymous subs have a padlist but zero depth */
125 if (!depth && CvPADLIST (sv)) 143 if (CvANON (sv) && !depth && CvPADLIST (sv))
126 depth = 1; 144 depth = 1;
127 145
128 if (depth) 146 if (depth)
129 { 147 {
130 AV *padlist = CvPADLIST (sv); 148 AV *padlist = CvPADLIST (sv);
154 if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ) 172 if (CvCONST (sv) && (SV*)CvXSUBANY (sv).any_ptr == targ)
155 res_pair ("the constant value of"); 173 res_pair ("the constant value of");
156 174
157 if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ) 175 if (!CvWEAKOUTSIDE (sv) && (SV*)CvOUTSIDE (sv) == targ)
158 res_pair ("the containing scope for"); 176 res_pair ("the containing scope for");
177
178 if (sv == targ && CvANON (sv))
179 if (CvSTART (sv)
180 && CvSTART (sv)->op_type == OP_NEXTSTATE
181 && CopLINE ((COP *)CvSTART (sv)))
182 res_text (form ("the closure created at %s:%d",
183 CopFILE ((COP *)CvSTART (sv)) ? CopFILE ((COP *)CvSTART (sv)) : "<unknown>",
184 CopLINE ((COP *)CvSTART (sv))));
185 else
186 res_text (form ("the closure created somewhere in file %s (PLEASE REPORT!)",
187 CvFILE (sv) ? CvFILE (sv) : "<unknown>"));
159 } 188 }
160 189
161 break; 190 break;
162 191
163 case SVt_PVGV: 192 case SVt_PVGV:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines