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.12 by root, Sat Jul 19 01:17:12 2008 UTC vs.
Revision 1.15 by root, Mon Dec 1 13:47:09 2008 UTC

41 41
42MODULE = Devel::FindRef PACKAGE = Devel::FindRef 42MODULE = Devel::FindRef PACKAGE = Devel::FindRef
43 43
44PROTOTYPES: ENABLE 44PROTOTYPES: ENABLE
45 45
46SV *
47ptr2ref (UV ptr)
48 CODE:
49 RETVAL = newRV_inc (INT2PTR (SV *, ptr));
50 OUTPUT:
51 RETVAL
52
53UV
54ref2ptr (SV *rv)
55 CODE:
56 RETVAL = PTR2UV (SvRV (rv));
57 OUTPUT:
58 RETVAL
59
60void 46void
61find_ (SV *target) 47find_ (SV *target_ref)
62 PPCODE: 48 PPCODE:
63{ 49{
64 SV *arena, *targ; 50 SV *arena, *targ;
65 U32 rmagical; 51 U32 rmagical;
66 int i; 52 int i;
67 AV *about = newAV (); 53 AV *about = newAV ();
68 AV *excl = newAV (); 54 AV *excl = newAV ();
69 55
70 if (!SvROK (target)) 56 if (!SvROK (target_ref))
71 croak ("find expects a reference to a perl value"); 57 croak ("find expects a reference to a perl value");
72 58
73 targ = SvRV (target); 59 targ = SvRV (target_ref);
74 60
75 for (arena = PL_sv_arenaroot; arena; arena = SvANY (arena)) 61 for (arena = PL_sv_arenaroot; arena; arena = SvANY (arena))
76 { 62 {
77 UV idx = SvREFCNT (arena); 63 UV idx = SvREFCNT (arena);
78 64
114 } 100 }
115 } 101 }
116 102
117 if (SvROK (sv)) 103 if (SvROK (sv))
118 { 104 {
119 if (sv != target && SvRV (sv) == targ && !SvWEAKREF (sv)) 105 if (SvRV (sv) == targ && !SvWEAKREF (sv) && sv != target_ref)
120 res_pair ("referenced by"); 106 res_pair ("referenced by");
121 } 107 }
122 else 108 else
123 switch (SvTYPE (sv)) 109 switch (SvTYPE (sv))
124 { 110 {
158 { 144 {
159 AV *pad = (AV *)AvARRAY (padlist)[depth]; 145 AV *pad = (AV *)AvARRAY (padlist)[depth];
160 146
161 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */ 147 av_push (excl, newSVuv (PTR2UV (pad))); /* exclude pads themselves from being found */
162 148
149 /* The 0th pad slot is @_ */
150 if (AvARRAY (pad)[0] == targ)
151 res_pair ("the argument array for");
152
163 for (i = AvFILLp (pad) + 1; i--; ) 153 for (i = AvFILLp (pad) + 1; --i; )
164 if (AvARRAY (pad)[i] == targ) 154 if (AvARRAY (pad)[i] == targ)
165 { 155 {
166 /* Values from constant functions are stored in the pad without any name */ 156 /* Values from constant functions are stored in the pad without any name */
167 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; 157 SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i];
168 158
211 if (rmagical) 201 if (rmagical)
212 SvRMAGICAL_on (sv); 202 SvRMAGICAL_on (sv);
213 } 203 }
214 } 204 }
215 205
206 /* look at the mortalise stack of the current coroutine */
207 for (i = 0; i <= PL_tmps_ix; ++i)
208 if (PL_tmps_stack [i] == targ)
209 res_text ("a temporary on the stack");
210
211 if (targ == (SV*)PL_main_cv)
212 res_text ("the main body of the program");
213
216 EXTEND (SP, 2); 214 EXTEND (SP, 2);
217 PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); 215 PUSHs (sv_2mortal (newRV_noinc ((SV *)about)));
218 PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); 216 PUSHs (sv_2mortal (newRV_noinc ((SV *)excl)));
219} 217}
220 218
219SV *
220ptr2ref (UV ptr)
221 CODE:
222 RETVAL = newRV_inc (INT2PTR (SV *, ptr));
223 OUTPUT:
224 RETVAL
225
226UV
227ref2ptr (SV *rv)
228 CODE:
229 RETVAL = PTR2UV (SvRV (rv));
230 OUTPUT:
231 RETVAL
232
233U32
234_refcnt (SV *rv)
235 CODE:
236 RETVAL = SvREFCNT (SvRV (rv));
237 OUTPUT:
238 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines