[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Must a userdata void* point to a valid memory location?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 25 Nov 2002 10:16:13 -0200
>In my application it would be more convenient if the userdata was an int,
>rather than the address of a memory location.
Use lua_newuserdata to allocate sizeof(int) bytes and store your int there.
>However could the current
>lua interpreter, or a lua program running in the interpreter, ever perform an
>action (such as dereference, free, realloc, etc...) on a userdata with the
>expectation that it is a pointer to a valid memory location?
No. Lua never looks inside userdata.
>Secondly, if it is safe to provide userdata values which are not pointers to a
>valid area of memory, then is this safety guaranteed by the specification, so
>I can likely expect this to work with future versions.
I think that ANSI C says (or implies) that implementations are free to flag
invalid pointers, even if they are never dereferenced.