lua-users home
lua-l archive

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


have a program that loads lua file containing multidimensional table 
and sequentially reads values from this table in a loop using C API 
functions.
Everything is ok when this table is relatively small, but 
when number of entries becomes about several thousands, program crashes.

As
 I have found, lua_tolstring() functions returns NULL, and type on the 
stack is nil, but should be string, according to the program logic.
The reasons why NULL is returned are unknown.

Problem is reproducible with latest lua-5.2.1, downloaded from official site. Tested on Gentoo Linux x86_64 and Fedora 17 32bit.

Test program can be copied from here:
http://pastebin.com/41ybLyzd
Test Lua file with multidimensional table
http://pastebin.com/dGxR91SA ; 

save it under the name "testmanifest.lua"


Program has the following workflow:

1. Lua state is initialised.
2. Lua file that contains big table is loaded using luaL_dofile(). Table looks like this:

MANIFEST = 
{

    {'lame-3.99.5.tar.gz', 1445348, '84835b313d4a8b68f5349816d33e07ce', 'u', '0664'},
    {'texlive-module-abstract.doc-2011.tar.xz', 146720, '42128ce393e115ad92b5209f5f09ea33', 'u', '0664'},
    {'texlive-module-listofsymbols.doc-2011.tar.xz', 50936, 'f54e6a29fe81197edff2d24606173347', 'u', '0664'},
    {'gcc-4.6.2.tar.bz2', 71995338, '028115c4fbfb6cfd75d6369f4a90d87e', 'u', '0664'},
    ... 
}

3. Size of MANIFEST table is computed using lua_len()

4. for loop iterates from i = 1 to #MANIFEST and prints values MANIFEST[i][1], MANIFEST[i][2], MANIFEST[i][3]

at some point, NULL is returned instead of the  MANIFEST[i][j] value.

If
 I create new Lua state in each iteration, load this file into the new 
state, acces MANIFEST[i][j] values using local state and destroy the 
state at the end of iteration, the problem still remains

Compile the program:

g++ -o bug -I ~/lua-5.2.1/src/ bug.cpp ~/lua-5.2.1/src/liblua.a -lm -ldl


and execute it:
./bug

On my machine bug is triggered on 2634 iteration of the loop:
...

MANIFEST[2633][1] = texlive-module-HA-prosper.doc-2011.tar.xz
MANIFEST[2633][2] = 205064
MANIFEST[2633][3] = e3615a136c769fc708d1cffcebf0fc91
lua_gettop() = 1
MANIFEST[2634][1] = .texlive-module-aurical-2010.tar.xz.portage_lockfile
MANIFEST[2634][2] = No permission to read
lua_tolstring() returned NULL!
type on stack top is nil