Re: super bad
Evan Wies <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I'm not sure if it is related, but try applying the attached git patch. It fixed our valgrind woes. -Evan Nigel Atkinson wrote: > Hello list! > > I had a bug in an app I'm writing, and while it was my goof i.e. you > shouldn't really rely on the order of objects being garbage collected, I > thought I'd share a debugging post mortem. I'm using 0.9.0 but it may > apply to 0.8.1 and possibly 0.7 > > So I found that last created instance of a Lua class that has a base > class, stayed around until lua_close, despite having any reference I > knew about set to nil. > > In hind sight 'super' seems almost obvious. Even though it is > deprecated, it's still there, to tell you its deprecated when you use > it. > > It took me awhile to narrow it down to this, as I had shared pointers in > the mix witch sent me barking up the wrong tree. ;-) > > I just commented out the 'super' code in class_rep.cpp in the > > int luabind::detail::class_rep::constructor_dispatcher(lua_State* L) > > function. It's pretty obvious what to zap. > > Seeing as super is depreciated, this problem will go away eventually. A > quick fix I guess would be to set 'super' to nil, after you have created > a class instance. > > Hope this prevents or reduces some face-palms and keyboard thumping. :-) > > Nigel Atkinson > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user
construct_aux.git
(text/plain, 2.1 KB)
commit d306a7783afdb31b6e66ae0d04a3ebd3a1429029 Author: Daniel Wallin <[email protected]> Date: Fri Nov 6 20:54:23 2009 +0100 Allocate storage for instances with object_rep::allocate(). We would allocate storage using operator new for newly constructed instances. The memory would later be released with std::free() when the object_rep was destroyed. Additionally, this allows instances to be allocated inside the object_rep small buffer. diff --git a/luabind/detail/constructor.hpp b/luabind/detail/constructor.hpp index b752cd3..60d97ac 100644 --- a/luabind/detail/constructor.hpp +++ b/luabind/detail/constructor.hpp @@ -39,6 +39,8 @@ struct construct template <class T, class Pointer, class Signature> struct construct_aux<0, T, Pointer, Signature> { + typedef pointer_holder<Pointer, T> holder_type; + void operator()(argument const& self_) const { object_rep* self = touserdata<object_rep>(self_); @@ -50,7 +52,9 @@ struct construct_aux<0, T, Pointer, Signature> void* naked_ptr = instance.get(); Pointer ptr(instance.release()); - self->set_instance(new pointer_holder<Pointer, T>( + void* storage = self->allocate(sizeof(holder_type)); + + self->set_instance(new (storage) holder_type( ptr, registered_class<T>::id, naked_ptr, cls)); } }; @@ -81,6 +85,8 @@ struct construct_aux<N, T, Pointer, Signature> # define BOOST_PP_LOCAL_LIMITS (1,N) # include BOOST_PP_LOCAL_ITERATE() + typedef pointer_holder<Pointer, T> holder_type; + void operator()(argument const& self_, BOOST_PP_ENUM_BINARY_PARAMS(N,a,_)) const { object_rep* self = touserdata<object_rep>(self_); @@ -92,7 +98,9 @@ struct construct_aux<N, T, Pointer, Signature> void* naked_ptr = instance.get(); Pointer ptr(instance.release()); - self->set_instance(new pointer_holder<Pointer, T>( + void* storage = self->allocate(sizeof(holder_type)); + + self->set_instance(new (storage) holder_type( ptr, registered_class<T>::id, naked_ptr, cls)); } };