OT: 'best' dynamic language

Manlio Perillo manlio_perillo at libero.it
Sat Apr 26 18:37:52 MSD 2008

Manlio Perillo ha scritto:
> Igor Sysoev ha scritto:
>> [...]
>> The problem is that interpreter MUST TEST EVERY operation result that
>> may fail on memory allocation. And it MUST return an error to all higher
>> levels, closing and freeing all allocated resources on the back way.
>> The existent interpreters either do not test result in most cases (perl),
>> or simply exit(), or in best case they throw exception. Exceptions are 
>> easy
>> way to program (you not need to test most operations) and cheap way to 
>> test
>> results (for the same reason), but they may lead to socket/file 
>> descriptor/etc
>> leak.
> I understand the problem, however I think that Lua is still usable.
> I'm reading the source code of Lua io library, and any opened file is 
> closed when reached by the gc.
> This means that when Nginx detects an error, it can just force a full gc 
> cycle.
> If this still does not sounds safe, Nginx can just create a Lua state 
> (interpreter) for each request, finalizing it when the request is 
> finalized.
> This is both feasible and efficient (but better is one of Lua language 
> developer can confirm it).

I have written a small program and I can confirm that opened files are 
correctly closed when the Lua interpreter is finalized.

The program is attached: the Lua code simply open a big file and read 
all its content in memory.

There is a custom memory allocator that make sure to fail when a large 
amount of memory is required.

There is a strange behaviour, however.
The status code returned by luaL_dostring should be
4 (LUA_ERRMEM), instead 1 is returned.

Regards   Manlio Perillo

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-garbage.c
Type: text/x-csrc
Size: 1638 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx/attachments/20080426/7aab680f/attachment.c>

More information about the nginx mailing list