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.

It could keep a weak-value table from C pointers to cdata objects.
But this is not necessary if freeing is deferred until the full
expression has been evaluated.

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

C doesn't have the problem because it doesn't have destructors.