… | |
… | |
112 | { |
112 | { |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
114 | } |
114 | } |
115 | |
115 | |
116 | void |
116 | void |
|
|
117 | attachable::sever_self () |
|
|
118 | { |
|
|
119 | if (HV *self = this->self) |
|
|
120 | { |
|
|
121 | // keep a refcount because sv_unmagic might call attachable_free, |
|
|
122 | // which might clear self, causing sv_unmagic to crash on a now |
|
|
123 | // invalid object. |
|
|
124 | SvREFCNT_inc (self); |
|
|
125 | hv_clear (self); |
|
|
126 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
127 | SvREFCNT_dec (self); |
|
|
128 | |
|
|
129 | // self *must* be null now because thats sv_unmagic's job. |
|
|
130 | assert (!this->self); |
|
|
131 | } |
|
|
132 | } |
|
|
133 | |
|
|
134 | void |
117 | attachable::optimise () |
135 | attachable::optimise () |
118 | { |
136 | { |
119 | if (self |
137 | if (self |
120 | && SvREFCNT (self) == 1 |
138 | && SvREFCNT (self) == 1 |
121 | && !HvTOTALKEYS (self)) |
139 | && !HvTOTALKEYS (self)) |
122 | { |
140 | sever_self (); |
123 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
124 | assert (!self); |
|
|
125 | } |
|
|
126 | } |
141 | } |
127 | |
142 | |
128 | // check wether the object really is dead |
143 | // check wether the object really is dead |
129 | void |
144 | void |
130 | attachable::do_check () |
145 | attachable::do_check () |
… | |
… | |
145 | SvREFCNT_dec (cb); |
160 | SvREFCNT_dec (cb); |
146 | cb = 0; |
161 | cb = 0; |
147 | } |
162 | } |
148 | |
163 | |
149 | if (self) |
164 | if (self) |
150 | { |
165 | sever_self (); |
151 | hv_clear (self); |
|
|
152 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
153 | // self is now 0 |
|
|
154 | assert (!self);//D//TODO remove soon |
|
|
155 | } |
|
|
156 | |
166 | |
157 | mortals.push_back (this); |
167 | mortals.push_back (this); |
158 | } |
168 | } |
159 | |
169 | |
160 | void |
170 | void |