lua-users home
lua-l archive

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

Awesome! Thankyou very much. That solves it.
You are a star.

Incidentally, while testing this, it brought up a question - under
work6's new metatable functionality, should (from lua code)
setmetatable(thread,{}) work? 
It doesn't appear to on my build. Explanation and possible patch as

Without your patch below, getmetatable(thread) crashes; with the fix it
returns nil on a newly created thread (as expected); 

But setmetatable(thread,{}) asserts ("got table, expected thread") -
It appears that luaB_setmetatable does a check to make sure that the
object being set, is a table (which under work6 isn't necessary?) before
calling on to lua_setmetatable. 

If I comment out the check (line 107 of lbaselib.c, luaL_checktype(L, 1,
LUA_TTABLE);), all seems to work as expected and the metatable is set

Is this a correct fix, or have I misunderstood the problem?

-----Original Message-----
[] On Behalf Of Mike Pall
Sent: 16 June 2005 01:19
To: Lua list
Subject: Re: another crash bug in lua5.1work6


Alex Evans wrote:
> it crashes eventually in luaH_getstr() - trying to extract
> the __tostring field from the thread's metatable.

This is the same bug. The metatable pointer gets overwritten
because the G(L)->mt array is too short by one entry (the one

Change the following lines in lobject.h from:

#define NUM_TAGS        LUA_TTHREAD
#define LUA_TPROTO      (NUM_TAGS+1)
#define LUA_TUPVAL      (NUM_TAGS+2)
#define LUA_TDEADKEY    (NUM_TAGS+3)


#define NUM_TAGS        (LUA_TTHREAD+1)
#define LUA_TPROTO      NUM_TAGS
#define LUA_TUPVAL      (NUM_TAGS+1)
#define LUA_TDEADKEY    (NUM_TAGS+2)

... and recompile.