[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT 2 ffi (casting / force hotpath)
- From: CrazyButcher <crazybutcher@...>
- Date: Sat, 22 Jan 2011 11:42:59 +0100
> I think the lifetime should extend to full expression, that is, beyond
> the call. The reason is that a function might return a pointer that
> is passed in, such as:
>
> char *check_string(char *);
>
> If this is called as
>
> do_something(check_string(ffi.new(...)))
>
> then the returned pointer will not keep the original pointer live.
How would the system know that the returned pointer matches the input
pointer, if you know, you can just store it locally. Wouldn't you have
the same problem in C, if you don't store a new allocated pointer
before the function call, how'd you be able to manage the memory after
the function call? Cause then you assume the check_string also "frees"
the memory, if it returns NULL?