lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 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?