lua-users home
lua-l archive

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


Hi,

I'm using Lua 5.1.4 [now imported in NetBSD] and trying to have a C
function create an array of items, but have found that it is causing the
Lua interpreter to coredump on exit.

I've googled a bit but found no comments about that and am wondering if
this is a generic thing or just local?  My basic test module is attached,
triggering a failure is as easy as calling the function and exiting..

% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> ^D
% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> test.settable(0,0)
> ^D
Segmentation fault (core dumped)
% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> test.settable(1,0)
> ^D
Segmentation fault (core dumped)
% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> test.settable(2,0)
> ^D
Segmentation fault (core dumped)
% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> test.settable(1,0)
> ^D
Segmentation fault (core dumped)
% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> test.settable(0,1)
> ^D
% lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require("test")
> test.settable(1,1)
> ^D
%

note the last two - if any number of nonarray elements is given, then the
interpreter exits without any problem, as it does for adding nonarray
elements. using lua_rawseti() instead causes the same coredump..

gdb reports me the following backtrace

Program terminated with signal 11, Segmentation fault.
#0  0xbbb1115a in _malloc_prefork () from /usr/lib/libc.so.12
(gdb) bt
#0  0xbbb1115a in _malloc_prefork () from /usr/lib/libc.so.12
#1  0xbbb1144b in free () from /usr/lib/libc.so.12
#2  0x08054ba8 in l_alloc (ud=0x0, ptr=0xbba799e8, osize=28, nsize=0)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lauxlib.c:633
#3  0x0805769c in luaM_realloc_ (L=0xbb909040, block=0xbba799e8, osize=28, nsize=0)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lmem.c:81
#4  0x080640cc in luaH_free (L=0xbb909040, t=0xbb95da60)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/ltable.c:378
#5  0x0805863e in freeobj (L=0xbb909040, o=0xbb95da60)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lgc.c:385
#6  0x0805874c in sweeplist (L=0xbb909040, p=0xbb9090cc, count=4294967292)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lgc.c:426
#7  0x08058a16 in luaC_freeall (L=0xbb909040)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lgc.c:489
#8  0x08054f63 in close_state (L=0xbb909040)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lstate.c:110
#9  0x08055373 in lua_close (L=0xbb909040)
    at /var/cvs/NetBSD-current/src/external/mit/lua/dist/src/lstate.c:214
#10 0x08049a6d in main ()

any clues if I might be doing something wrong here?

iain
/*
 *  testing createtable
 */

#include <lauxlib.h>
#include <lua.h>

static int
Tsettable(lua_State *L)
{
	lua_createtable(L, luaL_optint(L, 1, 0), luaL_optint(L, 2, 0));
	lua_pushinteger(L, 1);
	lua_pushstring(L, "using settable");
	lua_settable(L, -3);

	return 1;
}

static int
Trawseti(lua_State *L)
{
	lua_createtable(L, luaL_optint(L, 1, 0), luaL_optint(L, 2, 0));
	lua_pushstring(L, "using rawseti");
	lua_rawseti(L, -2, 1);

	return 1;
}

LUALIB_API int luaopen_test(lua_State *);

static const luaL_Reg LRtest[] = {
	{ "settable",	Tsettable	},
	{ "rawseti",	Trawseti	},
	{ NULL,		NULL		},
};

LUALIB_API int
luaopen_test(lua_State *L)
{
	luaL_register(L, "test", LRtest);
	return 1;
}