lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote on 3/16/2017 7:55 AM:
Once a few dozens of launching my app I notice crash on start, lua
initialization.
Keeping in mind that this could be our-code issue, anyway I looked on
lua_newstate() implementation.
Here it is with my comments:

[...]

setnilvalue macro gives something like this:

[...]
	if (i_o >= L->base && i_o < L->top && !stuckref(i_o))
	{
		i_o->value.gc->gch.refCount--;			// crashed
What version of Lua are you talking about? Lua does not use reference
count and nowhere in its code you would find a 'refCount' field.
As far as I am aware, I had the only reference counted implementation of Lua 5.1 out there. It was a huge win for the games I worked on, making garbage collection blips a non-issue.

However, that implementation used a variable called 'ref' to do the calculations:

#define CommonHeader GCObject *next; GCObject* prev; lu_byte tt; lu_byte marked; unsigned short ref

There is obviously another version out there. Still, the following may help the OP. If additional consulting is needed for a reference counted version of Lua 5.1, feel free to contact me directly.

It did this in lua_newstate():

#if LUA_REFCOUNT
  setnilvalue2n(L, registry(L));
#else
  setnilvalue(registry(L));
#endif

where setnilvalue2n() was defined as:

#define setnilvalue2n(L,obj) ((obj)->tt=LUA_TNIL)

but setnilvalue() was defined as:

#define luarc_release(L,o) { TValue* i_o2 = (o); if(iscollectable(i_o2) && ((--gcvalue(i_o2)->gch.ref)<=0)) \
        {    \
            luarc_releaseobject(L,gcvalue(i_o2));    \
        }    }
#define setnilvalue(obj) { TValue *i_o=(obj); luarc_release(L, i_o); i_o->tt=LUA_TNIL; }

I have no idea what stuckref() would do.

-Josh