lua-users home
lua-l archive

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


hi,

i'm having trouble using lua_newthread() in lua-4.1-work.
type errors sometimes lead to segmentation violations at
ldebug.c:36:isLmark():

	return (ci && ci->prev && !ci_func(ci)->c.isC);

i've included the details below.
thanks

-taj

---------------------------------
% ./lua 
Lua 4.1 (beta)  Copyright (C) 1994-2001 TeCGraf, PUC-Rio
> function foo() return 'this causes a core dump' end
> Thread_new(foo)
Segmentation fault (core dumped)
%
---------------------------------
#include "lua.h"
#include "lauxlib.h"

static int
lua_Thread_new(lua_State *L)
{
	lua_State *newL;
	int ref, code;

	newL = lua_newthread(L, 0);
	luaL_check_rawtype(L, 1, LUA_TFUNCTION);
	ref = luaL_ref(L, LUA_REGISTRYINDEX);
	lua_rawgeti(newL, LUA_REGISTRYINDEX, ref);
	luaL_unref(L, LUA_REGISTRYINDEX, ref);
	lua_call(newL, 0, 1);
	code = luaL_check_int(newL, 1);
	lua_close(newL);
	return 0;
}

int
lua_xxxlibopen(lua_State *L)
{
	lua_register(L, "Thread_new", lua_Thread_new);
	return 0;
}
---------------------------------
% gdb ./lua core
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
Core was generated by `./lua'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/i686/libm.so.6...done.
Loaded symbols for /lib/i686/libm.so.6
Reading symbols from /lib/i686/libc.so.6...done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0  0x08052ae8 in isLmark (ci=0x806bbf8) at ldebug.c:36
36        return (ci && ci->prev && !ci_func(ci)->c.isC);
(gdb) bt
#0  0x08052ae8 in isLmark (ci=0x806bbf8) at ldebug.c:36
#1  0x08053c8c in getfuncname (L=0x806be98, ci=0x806bbf8, name=0xbffff148) at ldebug.c:517
#2  0x0805329d in lua_getinfo (L=0x806be98, what=0x8061da0 "n", ar=0xbffff140) at ldebug.c:275
#3  0x0804a212 in luaL_argerror (L=0x806be98, narg=1, extramsg=0xbffff1c0 "number expected, got string") at lauxlib.c:37
#4  0x0804a280 in luaL_typerror (L=0x806be98, narg=1, tname=0x8069328 "number") at lauxlib.c:48
#5  0x0804a2b0 in tag_error (L=0x806be98, narg=1, tag=2) at lauxlib.c:53
#6  0x0804a4e1 in luaL_check_number (L=0x806be98, narg=1) at lauxlib.c:104
#7  0x0804963c in lua_Thread_new (L=0x80658f8) at xx.c:16
#8  0x080541a9 in callCclosure (L=0x80658f8, cl=0x806a4d8) at ldo.c:129
#9  0x080542a9 in luaD_call (L=0x80658f8, func=0x80659cc) at ldo.c:159
#10 0x0805da6c in luaV_execute (L=0x80658f8, cl=0x806a5f0, base=0x80659cc) at lvm.c:552
#11 0x080542cc in luaD_call (L=0x80658f8, func=0x80659c0) at ldo.c:159
#12 0x0805438c in f_call (L=0x80658f8, ud=0xbffff538) at ldo.c:183
#13 0x080549dd in luaD_runprotected (L=0x80658f8, f=0x8054370 <f_call>, ud=0xbffff538) at ldo.c:349
#14 0x08054403 in lua_call (L=0x80658f8, nargs=0, nresults=-1) at ldo.c:196
#15 0x080522dc in lua_dobuffer (L=0x80658f8, buff=0x806bcc0 "Thread_new(foo)\n", size=16, 
    name=0x806bcc0 "Thread_new(foo)\n") at lapi.c:487
#16 0x08052313 in lua_dostring (L=0x80658f8, str=0x806bcc0 "Thread_new(foo)\n") at lapi.c:493
#17 0x080497a3 in ldo (f=0x80522ec <lua_dostring>, name=0x806bcc0 "Thread_new(foo)\n", clear=0) at lua.c:83
#18 0x08049c21 in manual_input (version=1, prompt=1) at lua.c:214
#19 0x08049cf5 in handle_argv (argv=0xbffff8b0, toclose=0xbffff830) at lua.c:230
#20 0x0804a15d in main (argc=1, argv=0xbffff8ac) at lua.c:341
#21 0x40067177 in __libc_start_main (main=0x804a0e8 <main>, argc=1, ubp_av=0xbffff8ac, init=0x8048f84 <_init>, 
    fini=0x80619b0 <_fini>, rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffff89c) at ../sysdeps/generic/libc-start.c:129
(gdb)
---------------------------------