Re: segfault when get_pointer returns null
"Nigel Atkinson" <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I had a similar problem with pointers to things created and destroyed by
C++ code, but held in Lua. i.e.
thingy = CreateThingy()
...
...
DestroyThingy( thingy )
--Accidently use pointer later on...
thingy:method() // Boom!
I solved this with the following code:
https://github.com/merlinblack/Game-Engine-Testbed/blob/master/include/ward_ptr.h
and some glue functions..
void DestroyThingy( ward_ptr ptr )
{
RealDestroyThingy( ptr.get() );
ptr.invalidate();
}
On Sun, February 27, 2011 9:57 am, Andreas Grob wrote:
> Hello all,
>
> right now I am trying to write a wrapping pointer to hold objects passed
> to luabind. The idea is to change the behaviour of get_pointer at
> runtime to invalidate objects.
> While I can wrap null pointers and receive luabind::error upon trying to
> call a member, the program segfaults in luabind when I change the result
> of get_pointer from a normal pointer to null at a later time, i.e. after
> passing the wrapped object to luabind.
>
> Here is the stacktrace when get_pointer just returned null before the
> segfault:
>
> #0 luabind::detail::pointer_holder<fuse_ptr<myclass>, void const>::get
> (this=0x805b630, target=3)
> at /usr/include/luabind/detail/instance_holder.hpp:100
> #1 0x0804bd60 in luabind::detail::object_rep::get_instance
> (this=0x805b62c, target=3)
> at /usr/include/luabind/detail/object_rep.hpp:59
> #2 0x0804f99a in luabind::detail::ref_converter::match<myclass>
> (this=0xbfffee94, L=0x80550a8, index=1)
> at /usr/include/luabind/detail/policy.hpp:402
> #3 0x0804f776 in luabind::detail::invoke_member<void (myclass::*)(),
> boost::mpl::vector2<void, myclass&>, luabind::detail::null_type>
> (L=0x80550a8, self=..., ctx=..., f=@0x805a5b8)
> at /usr/include/luabind/detail/call.hpp:257
> #4 0x0804f6d3 in luabind::detail::invoke0<void (myclass::*)(),
> boost::mpl::vector2<void, myclass&>, luabind::detail::null_type,
> boost::is_void<void> > (L=0x80550a8, self=..., ctx=..., f=@0x805a5b8,
> policies=...) at /usr/include/luabind/detail/call.hpp:78
> #5 0x0804f698 in luabind::detail::invoke<void (myclass::*)(),
> boost::mpl::vector2<void, myclass&>, luabind::detail::null_type> (
> L=0x80550a8, self=..., ctx=..., f=@0x805a5b8, policies=...)
> at /usr/include/luabind/detail/call.hpp:101
> #6 0x0804f5d6 in luabind::detail::function_object_impl<void
> (myclass::*)(), boost::mpl::vector2<void, myclass&>,
> luabind::detail::null_type>::entry_point (L=0x80550a8)
> at /usr/include/luabind/make_function.hpp:62
> [...calls from lua...]
>
> If continued it segfaults in frame 3, line 287:
> (c0.apply(L, LUABIND_DECORATE_TYPE(a0), index0).*f)(
>
>
> My question is: Why is the call to a member of null not detected and an
> exception thrown?
>
> The code is attached (using lua 5.1.4 and luabind 0.9.1).
>
> Thank you very much.
>
> Best regards,
> Andreas
>
>
>
> ------------------------------------------------------------------------------
> Free Software Download: Index, Search & Analyze Logs and other IT data in
> Real-Time with Splunk. Collect, index and harness all the fast moving IT
> data
> generated by your applications, servers and devices whether physical,
> virtual
> or in the cloud. Deliver compliance at lower cost and gain new business
> insights. http://p.sf.net/sfu/splunk-dev2dev
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev