… | |
… | |
41 | |
41 | |
42 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
42 | MODULE = Devel::FindRef PACKAGE = Devel::FindRef |
43 | |
43 | |
44 | PROTOTYPES: ENABLE |
44 | PROTOTYPES: ENABLE |
45 | |
45 | |
46 | SV * |
|
|
47 | ptr2ref (IV ptr) |
|
|
48 | CODE: |
|
|
49 | RETVAL = newRV_inc (INT2PTR (SV *, ptr)); |
|
|
50 | OUTPUT: |
|
|
51 | RETVAL |
|
|
52 | |
|
|
53 | void |
46 | void |
54 | find_ (SV *target) |
47 | find_ (SV *target_ref) |
55 | PPCODE: |
48 | PPCODE: |
56 | { |
49 | { |
57 | SV *arena, *targ; |
50 | SV *arena, *targ; |
58 | U32 rmagical; |
51 | U32 rmagical; |
59 | int i; |
52 | int i; |
60 | AV *about = newAV (); |
53 | AV *about = newAV (); |
61 | AV *excl = newAV (); |
54 | AV *excl = newAV (); |
62 | |
55 | |
63 | if (!SvROK (target)) |
56 | if (!SvROK (target_ref)) |
64 | croak ("find expects a reference to a perl value"); |
57 | croak ("find expects a reference to a perl value"); |
65 | |
58 | |
66 | targ = SvRV (target); |
59 | targ = SvRV (target_ref); |
67 | |
60 | |
68 | for (arena = PL_sv_arenaroot; arena; arena = SvANY (arena)) |
61 | for (arena = PL_sv_arenaroot; arena; arena = SvANY (arena)) |
69 | { |
62 | { |
70 | UV idx = SvREFCNT (arena); |
63 | UV idx = SvREFCNT (arena); |
71 | |
64 | |
… | |
… | |
107 | } |
100 | } |
108 | } |
101 | } |
109 | |
102 | |
110 | if (SvROK (sv)) |
103 | if (SvROK (sv)) |
111 | { |
104 | { |
112 | if (sv != target && SvRV (sv) == targ && !SvWEAKREF (sv)) |
105 | if (SvRV (sv) == targ && !SvWEAKREF (sv) && sv != target_ref) |
113 | res_pair ("referenced by"); |
106 | res_pair ("referenced by"); |
114 | } |
107 | } |
115 | else |
108 | else |
116 | switch (SvTYPE (sv)) |
109 | switch (SvTYPE (sv)) |
117 | { |
110 | { |
… | |
… | |
151 | { |
144 | { |
152 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
145 | AV *pad = (AV *)AvARRAY (padlist)[depth]; |
153 | |
146 | |
154 | 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 */ |
155 | |
148 | |
|
|
149 | /* The 0th pad slot is @_ */ |
|
|
150 | if (AvARRAY (pad)[0] == targ) |
|
|
151 | res_pair ("the argument array for"); |
|
|
152 | |
156 | for (i = AvFILLp (pad) + 1; i--; ) |
153 | for (i = AvFILLp (pad) + 1; --i; ) |
157 | if (AvARRAY (pad)[i] == targ) |
154 | if (AvARRAY (pad)[i] == targ) |
158 | { |
155 | { |
159 | /* 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 */ |
160 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
157 | SV *name_sv = AvARRAY (AvARRAY (padlist)[0])[i]; |
161 | |
158 | |
… | |
… | |
204 | if (rmagical) |
201 | if (rmagical) |
205 | SvRMAGICAL_on (sv); |
202 | SvRMAGICAL_on (sv); |
206 | } |
203 | } |
207 | } |
204 | } |
208 | |
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 | |
209 | EXTEND (SP, 2); |
214 | EXTEND (SP, 2); |
210 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
215 | PUSHs (sv_2mortal (newRV_noinc ((SV *)about))); |
211 | PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); |
216 | PUSHs (sv_2mortal (newRV_noinc ((SV *)excl))); |
212 | } |
217 | } |
213 | |
218 | |
|
|
219 | SV * |
|
|
220 | ptr2ref (UV ptr) |
|
|
221 | CODE: |
|
|
222 | RETVAL = newRV_inc (INT2PTR (SV *, ptr)); |
|
|
223 | OUTPUT: |
|
|
224 | RETVAL |
|
|
225 | |
|
|
226 | UV |
|
|
227 | ref2ptr (SV *rv) |
|
|
228 | CODE: |
|
|
229 | RETVAL = PTR2UV (SvRV (rv)); |
|
|
230 | OUTPUT: |
|
|
231 | RETVAL |
|
|
232 | |
|
|
233 | U32 |
|
|
234 | _refcnt (SV *rv) |
|
|
235 | CODE: |
|
|
236 | RETVAL = SvREFCNT (SvRV (rv)); |
|
|
237 | OUTPUT: |
|
|
238 | RETVAL |