On 10 October 2014 18:43, Philipp Janda <siffie...@gmx.net> wrote:

> Am 10.10.2014 um 20:50 schröbte Hisham:
> 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.


In this circumstance; its perfectly valid to just use `alloca(3)`[1] and
just allocate on the stack.
No need to worry about malloc or even lua_newuserdata (though I do that
frequently too[2])

[1] http://linux.die.net/man/3/alloca
[2] e.g.
https://github.com/daurnimator/lua-systemd/blob/1a6fe1f60a/src/journal.c#L30
------------------------------------------------------------------------------
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