1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
|
|
4 | |
|
|
5 | #define PERL_VERSION_ATLEAST(a,b,c) \ |
|
|
6 | (PERL_REVISION > (a) \ |
|
|
7 | || (PERL_REVISION == (a) \ |
|
|
8 | && (PERL_VERSION > (b) \ |
|
|
9 | || (PERL_VERSION == (b) && PERLSUBVERSION >= (c))))) |
|
|
10 | |
|
|
11 | #if !PERL_VERSION_ATLEAST (5,8,9) |
|
|
12 | # define SVt_LAST 16 |
|
|
13 | #endif |
4 | |
14 | |
5 | #define res_pair(text) \ |
15 | #define res_pair(text) \ |
6 | { \ |
16 | { \ |
7 | AV *av = newAV (); \ |
17 | AV *av = newAV (); \ |
8 | av_push (av, newSVpv (text, 0)); \ |
18 | av_push (av, newSVpv (text, 0)); \ |
… | |
… | |
39 | int rmagical, i; |
49 | int rmagical, i; |
40 | AV *about = newAV (); |
50 | AV *about = newAV (); |
41 | AV *excl = newAV (); |
51 | AV *excl = newAV (); |
42 | |
52 | |
43 | if (!SvROK (target)) |
53 | if (!SvROK (target)) |
44 | croak ("about expects a reference to a perl value"); |
54 | croak ("find expects a reference to a perl value"); |
45 | |
55 | |
46 | targ = SvRV (target); |
56 | targ = SvRV (target); |
47 | |
57 | |
48 | for (arena = PL_sv_arenaroot; arena; arena = SvANY (arena)) |
58 | for (arena = PL_sv_arenaroot; arena; arena = SvANY (arena)) |
49 | { |
59 | { |
… | |
… | |
52 | /* Remember that the zeroth slot is used as the pointer onwards, so don't |
62 | /* Remember that the zeroth slot is used as the pointer onwards, so don't |
53 | include it. */ |
63 | include it. */ |
54 | while (--idx > 0) |
64 | while (--idx > 0) |
55 | { |
65 | { |
56 | SV *sv = &arena [idx]; |
66 | SV *sv = &arena [idx]; |
57 | |
67 | |
|
|
68 | if (SvTYPE (sv) >= SVt_LAST) |
|
|
69 | continue; |
|
|
70 | |
|
|
71 | /* temporarily disable RMAGICAL, it can easily interfere with us */ |
58 | if ((rmagical = SvRMAGICAL (sv))) |
72 | if ((rmagical = SvRMAGICAL (sv))) |
59 | SvRMAGICAL_off (sv); |
73 | SvRMAGICAL_off (sv); |
60 | |
74 | |
61 | //TODO: magic |
75 | if (SvTYPE (sv) >= SVt_PVMG) |
|
|
76 | { |
|
|
77 | MAGIC *mg = SvMAGIC (sv); |
|
|
78 | while (mg) |
|
|
79 | { |
|
|
80 | if (mg->mg_obj == targ) |
|
|
81 | res_pair (form ("referenced (in mg_obj) by '%c' type magic attached to", mg->mg_type)); |
|
|
82 | if ((SV *)mg->mg_ptr == targ && mg->mg_flags & MGf_REFCOUNTED) |
|
|
83 | res_pair (form ("referenced (in mg_ptr) by '%c' type magic attached to", mg->mg_type)); |
|
|
84 | |
|
|
85 | mg = mg->mg_moremagic; |
|
|
86 | } |
|
|
87 | } |
62 | |
88 | |
63 | switch (SvTYPE (sv)) |
89 | switch (SvTYPE (sv)) |
64 | { |
90 | { |
65 | case SVt_RV: |
91 | case SVt_RV: |
66 | if (sv != target && SvRV (sv) == targ) |
92 | if (sv != target && SvRV (sv) == targ) |
… | |
… | |
82 | if (HeVAL (he) == targ) |
108 | if (HeVAL (he) == targ) |
83 | res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); |
109 | res_pair (form ("in the member '%.*s' of", HeKLEN (he), HeKEY (he))); |
84 | } |
110 | } |
85 | break; |
111 | break; |
86 | |
112 | |
87 | case SVt_PVGV: |
|
|
88 | if (GvGP (sv)) |
|
|
89 | { |
|
|
90 | if (GvSV (sv) == targ) |
|
|
91 | res_gv ('$'); |
|
|
92 | if (GvAV (sv) == (AV *)targ) |
|
|
93 | res_gv ('@'); |
|
|
94 | if (GvHV (sv) == (HV *)targ) |
|
|
95 | res_gv ('%'); |
|
|
96 | if (GvCV (sv) == (CV *)targ) |
|
|
97 | res_gv ('&'); |
|
|
98 | } |
|
|
99 | break; |
|
|
100 | |
|
|
101 | case SVt_PVCV: |
113 | case SVt_PVCV: |
102 | { |
114 | { |
103 | int depth = CvDEPTH (sv); |
115 | int depth = CvDEPTH (sv); |
104 | if (depth) |
116 | if (depth) |
105 | { |
117 | { |
… | |
… | |
115 | --depth; |
127 | --depth; |
116 | } |
128 | } |
117 | } |
129 | } |
118 | } |
130 | } |
119 | break; |
131 | break; |
|
|
132 | |
|
|
133 | case SVt_PVGV: |
|
|
134 | if (GvGP (sv)) |
|
|
135 | { |
|
|
136 | if (GvSV (sv) == targ) |
|
|
137 | res_gv ('$'); |
|
|
138 | if (GvAV (sv) == (AV *)targ) |
|
|
139 | res_gv ('@'); |
|
|
140 | if (GvHV (sv) == (HV *)targ) |
|
|
141 | res_gv ('%'); |
|
|
142 | if (GvCV (sv) == (CV *)targ) |
|
|
143 | res_gv ('&'); |
|
|
144 | } |
|
|
145 | break; |
120 | } |
146 | } |
121 | |
147 | |
122 | if (rmagical) |
148 | if (rmagical) |
123 | SvRMAGICAL_off (sv); |
149 | SvRMAGICAL_off (sv); |
124 | } |
150 | } |