Am 10.10.2014 um 20:50 schröbte Hisham:
> On 10 October 2014 15:20, Tomas Guisasola Gorham
> <to...@tecgraf.puc-rio.br> wrote:
>>          Hi Hisham and Philipp

Hi!

>>
>>          I am not sure the pull request is a safe implementation since
>> an error (not enough memory?) could occur after the malloc and before
>> the free...  There is no way to let the compiler accept the problematic
>> construction?  It would be not only safe but also a simpler code to read
>> and maintain :-)
>
> The current construct is not safer: if it runs out of stack space then
> it will crash just like not checking the return of malloc would (and
> running out of stack is more common than running out of heap space).
> The proposed patch with a one-line addition to check the malloc would
> make the code safer[*] and not that uglier: if (!to) return 0;

That's what the mysql driver does: `malloc`, check for NULL, and `free` 
later. However, I still like my proposal better: use `lua_newuserdata` 
for allocating temporary storage. You don't need to check for NULL 
because `lua_newuserdata` would raise an error, you don't have to 
`free`, and you can't leak memory even if the `lua_pushlstring` 
`longjmp`s because the garbage collector will reclaim the memory eventually.

>
> -- Hisham

Philipp


> [*] in principle, because making an entire library resilient to
> out-of-memory failures is usually a lot of work...

Not if you do it right from the beginning. Having programmed in C++ 
usually helps, because you have a clear idea of object ownership, and 
Lua errors in combination with the Lua stack and the GC is a lot like 
C++ exceptions with automatic destructors.




------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://p.sf.net/sfu/Zoho
_______________________________________________
Luarocks-developers mailing list
Luarocks-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/luarocks-developers

Reply via email to