Re: Protecting memory

Nigel J Atkinson <[email protected]> Fri, 2 Dec 2011 14:11:45 +1100
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
You might be able to search through _G and any tables you find within, for a particular userdata, and set anything that refs it to nil, but that doesn't strike me as something that could be done quickly, and safely.  That's gut instinct though, I could be wrong.

Nigel

On 02/12/2011, at 3:02 AM, eduard mueller wrote:

> See also "Dangling pointers Lua style" ->
> http://old.nabble.com/Dangling-pointers-Lua-style...-to29848215.html#a29853492
> 
> The only thing which we never could get done is setting such invalid
> C++ pointers to nil in Lua, as soon as they get invalid/NULL in C++.
> 
> Without this, you either have to throw an error in the get_pointer()
> accessor as shown in the linked post, and need to add a helper
> function to Lua which allows checking for nil. Like
> "is_valid_object()" which does not use the get_pointer() wrapper and
> then checks for NULL with the smart pointer in C++. For scripts this
> is not really ideal, because you do expect an object can be compared
> to "nil" in order to check if it's valid. But well, it works, and will
> ensure that access to dead object never causes an access violation...
> 
> Best regards,
> Eduard
> 
> 
> 
> On Thu, Dec 1, 2011 at 16:06, Ryan Pavlik <[email protected]> wrote:
>> This seems like a good time to use boost's shared_ptr and weak_ptr.
>> 
>> Ryan
>> 
>> 
>> On Wed, Nov 30, 2011 at 4:27 PM, Nigel Atkinson <[email protected]>
>> wrote:
>>> 
>>> Hi Colin,
>>> 
>>> You can wrap your pointers up in a smart pointer, made specifically
>>> for the job.  I made what I call a ward_ptr, a class that is really
>>> just a wrapper around a raw pointer, except it has a member called
>>> 'invalidate' which sets the raw pointer it stores to null.  You call
>>> this on the C++ side whenever the object it points to is deleted.  If
>>> the smart pointer is used (dereferenced) while its stored pointer is
>>> null, it throws an exception - which if that happens inside a function/
>>> method called from luabind,  gets turned into  a lua error by luabind.
>>> 
>>> You could have a "isvalid" method too, in order to check a pointer
>>> rather than just using it and causing an exception.  I don't in mine,
>>> as I use it with a library I didn't write bound with luabind.
>>> 
>>> Heres a link to some code!   Feel free to use it.
>>> 
>>> https://github.com/merlinblack/Game-Engine-Testbed/blob/master/include/ward_ptr.h
>>> 
>>> 
>>> Nigel
>>> 
>>> On 30/11/2011, at 10:39 PM, Colin GILLE / congelli501 wrote:
>>> 
>>>> Hi,
>>>> 
>>>> I'm new to this mailing list and quite new to luabind too.
>>>> I'm creating a 2D game engine with lua scripting and I wich to
>>>> protect the memory (against segmentation faults).
>>>> Some of my functions return pointers to objects, and these objects
>>>> can be deleted later by the engine.
>>>> When the user uses a pointer, I would like to check if this pointer
>>>> is still valid before using it in my C++ code.
>>>> I can easily do that if the pointer in a function argument but I
>>>> don't know how to that when the user use the member of the object.
>>>> 
>>>> What is the good way to do it with luabind ?
>>>> 
>>>> Thanks in advance !
>>>> 
>>>> ------------------------------------------------------------------------------
>>>> All the data continuously generated in your IT infrastructure
>>>> contains a definitive record of customers, application performance,
>>>> security threats, fraudulent activity, and more. Splunk takes this
>>>> data and makes sense of it. IT sense. And common sense.
>>>> 
>>>> http://p.sf.net/sfu/splunk-novd2d_______________________________________________
>>>> luabind-user mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>> 
>>> 
>>> 
>>> ------------------------------------------------------------------------------
>>> All the data continuously generated in your IT infrastructure
>>> contains a definitive record of customers, application performance,
>>> security threats, fraudulent activity, and more. Splunk takes this
>>> data and makes sense of it. IT sense. And common sense.
>>> http://p.sf.net/sfu/splunk-novd2d
>>> _______________________________________________
>>> luabind-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>> 
>> 
>> 
>> 
>> --
>> Ryan Pavlik
>> HCI Graduate Student
>> Virtual Reality Applications Center
>> Iowa State University
>> 
>> [email protected]
>> http://academic.cleardefinition.com
>> 
>> ------------------------------------------------------------------------------
>> All the data continuously generated in your IT infrastructure
>> contains a definitive record of customers, application performance,
>> security threats, fraudulent activity, and more. Splunk takes this
>> data and makes sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-novd2d
>> _______________________________________________
>> luabind-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>> 
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure 
> contains a definitive record of customers, application performance, 
> security threats, fraudulent activity, and more. Splunk takes this 
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d