ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.131 by root, Mon Jan 8 18:18:35 2007 UTC vs.
Revision 1.133 by root, Mon Jan 8 23:36:16 2007 UTC

101 101
102unordered_vector<attachable *> attachable::mortals; 102unordered_vector<attachable *> attachable::mortals;
103 103
104attachable::~attachable () 104attachable::~attachable ()
105{ 105{
106 assert (!(flags & F_BORROWED)); 106 assert (!self);
107} 107}
108 108
109int 109int
110attachable::refcnt_cnt () const 110attachable::refcnt_cnt () const
111{ 111{
117{ 117{
118 if (self 118 if (self
119 && SvREFCNT (self) == 1 119 && SvREFCNT (self) == 1
120 && !HvTOTALKEYS (self)) 120 && !HvTOTALKEYS (self))
121 { 121 {
122 flags &= ~F_BORROWED;
123 refcnt_inc (); 122 refcnt_inc ();
124 SvREFCNT_dec ((SV *)self); 123 SvREFCNT_dec ((SV *)self);
125 } 124 }
126} 125}
127 126
128// check wether the object really is dead 127// check wether the object really is dead
129void 128void
130attachable::do_check () 129attachable::do_check ()
131{ 130{
132 if (refcnt > 0) 131 if (refcnt > 0 || refcnt_cnt () > 0)
133 return; 132 return;
134 133
135 optimise (); 134 destroy ();
136 135
137 if (self) 136 if (self)
138 { 137 {
139 if (refcnt + SvREFCNT (self) > 0) 138 hv_clear (self);
140 return; 139 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
141
142 assert (flags & F_BORROWED);
143
144 flags &= ~F_BORROWED;
145 refcnt_inc ();
146 SvREFCNT_dec (self); 140 SvREFCNT_dec (self);
147 self = 0; 141 self = 0;
148 } 142 }
149
150 if (refcnt > 0)
151 return;
152
153 destroy ();
154} 143}
155 144
156void 145void
157attachable::do_destroy () 146attachable::do_destroy ()
158{ 147{
227 216
228static int 217static int
229attachable_free (pTHX_ SV *sv, MAGIC *mg) 218attachable_free (pTHX_ SV *sv, MAGIC *mg)
230{ 219{
231 attachable *at = (attachable *)mg->mg_ptr; 220 attachable *at = (attachable *)mg->mg_ptr;
232 assert (!(at->flags & attachable::F_BORROWED));
233 at->self = 0; 221 at->self = 0;
234 // next line makes sense, but most objects still have refcnt 0 by default 222 // next line makes sense, but most objects still have refcnt 0 by default
235 //at->refcnt_chk (); 223 //at->refcnt_chk ();
236 return 0; 224 return 0;
237} 225}
248 { 236 {
249 obj->self = newHV (); 237 obj->self = newHV ();
250 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 238 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
251 239
252 // borrow the refcnt from the object 240 // borrow the refcnt from the object
253 obj->flags |= attachable::F_BORROWED; 241 // it is important thta no refcnt_chk is being executed here
254 obj->refcnt_dec (); 242 obj->refcnt_dec ();
255 243
256 // now bless the object _once_ 244 // now bless the object _once_
257 return sv_bless (newRV_inc ((SV *)obj->self), stash); 245 return sv_bless (newRV_inc ((SV *)obj->self), stash);
258 } 246 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines