better support for extra user space associated with a Lua state

This commit is contained in:
Roberto Ierusalimschy
2014-07-24 11:00:16 -03:00
parent 55a710545c
commit baa0e23456
4 changed files with 23 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 2.122 2014/07/18 12:17:54 roberto Exp roberto $
** $Id: lstate.c,v 2.123 2014/07/18 13:36:14 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -53,9 +53,7 @@
** thread state + extra space
*/
typedef struct LX {
#if defined(LUAI_EXTRASPACE)
char buff[LUAI_EXTRASPACE];
#endif
lu_byte extra_[LUA_EXTRASPACE];
lua_State l;
} LX;
@@ -263,6 +261,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
/* link it on list 'allgc' */
L1->next = g->allgc;
g->allgc = obj2gco(L1);
/* anchor it on L stack */
setthvalue(L, L->top, L1);
api_incr_top(L);
preinit_thread(L1, g);
@@ -270,6 +269,8 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
L1->basehookcount = L->basehookcount;
L1->hook = L->hook;
resethookcount(L1);
/* initialize L1 extra space */
memcpy(lua_getextraspace(L1), lua_getextraspace(L), LUA_EXTRASPACE);
luai_userstatethread(L, L1);
stack_init(L1, L); /* init stack */
lua_unlock(L);