mirror of https://github.com/rusefi/lua.git
Finalizers must be callable
Non-function __gc metamethods are not ignored; if present, the metamethod will be called even if it is not a function.
This commit is contained in:
parent
b56d4e570a
commit
8fa4f1380b
2
lgc.c
2
lgc.c
|
@ -832,7 +832,7 @@ static void GCTM (lua_State *L) {
|
||||||
lua_assert(!g->gcemergency);
|
lua_assert(!g->gcemergency);
|
||||||
setgcovalue(L, &v, udata2finalize(g));
|
setgcovalue(L, &v, udata2finalize(g));
|
||||||
tm = luaT_gettmbyobj(L, &v, TM_GC);
|
tm = luaT_gettmbyobj(L, &v, TM_GC);
|
||||||
if (ttisfunction(tm)) { /* is the finalizer a function? */
|
if (!notm(tm)) { /* is there a finalizer? */
|
||||||
int status;
|
int status;
|
||||||
lu_byte oldah = L->allowhook;
|
lu_byte oldah = L->allowhook;
|
||||||
int running = g->gcrunning;
|
int running = g->gcrunning;
|
||||||
|
|
|
@ -689,10 +689,8 @@ After the collection,
|
||||||
Lua goes through that list.
|
Lua goes through that list.
|
||||||
For each object in the list,
|
For each object in the list,
|
||||||
it checks the object's @idx{__gc} metamethod:
|
it checks the object's @idx{__gc} metamethod:
|
||||||
If it is a function,
|
If it is present,
|
||||||
Lua calls it with the object as its single argument;
|
Lua calls it with the object as its single argument.
|
||||||
if the metamethod is not a function,
|
|
||||||
Lua simply ignores it.
|
|
||||||
|
|
||||||
At the end of each garbage-collection cycle,
|
At the end of each garbage-collection cycle,
|
||||||
the finalizers for objects are called in
|
the finalizers for objects are called in
|
||||||
|
@ -726,6 +724,9 @@ these marks have no effect.
|
||||||
|
|
||||||
Finalizers cannot yield.
|
Finalizers cannot yield.
|
||||||
|
|
||||||
|
Any error while running a finalizer generates a warning;
|
||||||
|
it is not propagated.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@sect3{weak-table| @title{Weak Tables}
|
@sect3{weak-table| @title{Weak Tables}
|
||||||
|
@ -7279,6 +7280,11 @@ that is,
|
||||||
with maximum alignment of 1 (no alignment)
|
with maximum alignment of 1 (no alignment)
|
||||||
and native endianness.
|
and native endianness.
|
||||||
|
|
||||||
|
Native endianness assumes that the whole system is
|
||||||
|
either big or little endian.
|
||||||
|
The packing functions will not emulate correctly the behavior
|
||||||
|
of mixed-endian formats.
|
||||||
|
|
||||||
Alignment works as follows:
|
Alignment works as follows:
|
||||||
For each option,
|
For each option,
|
||||||
the format gets extra padding until the data starts
|
the format gets extra padding until the data starts
|
||||||
|
@ -7288,6 +7294,7 @@ this minimum must be a power of 2.
|
||||||
Options @St{c} and @St{z} are not aligned;
|
Options @St{c} and @St{z} are not aligned;
|
||||||
option @St{s} follows the alignment of its starting integer.
|
option @St{s} follows the alignment of its starting integer.
|
||||||
|
|
||||||
|
|
||||||
All padding is filled with zeros by @Lid{string.pack}
|
All padding is filled with zeros by @Lid{string.pack}
|
||||||
(and ignored by @Lid{string.unpack}).
|
(and ignored by @Lid{string.unpack}).
|
||||||
|
|
||||||
|
@ -8720,6 +8727,14 @@ name is visible, even if this other label is declared in an enclosing
|
||||||
block.
|
block.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@item{
|
||||||
|
When finalizing an object,
|
||||||
|
Lua does not ignore @idx{__gc} metamethods that are not functions.
|
||||||
|
Any value will be called, if present.
|
||||||
|
(Non-callable values will generate a warning,
|
||||||
|
like any other error when calling a finalizer.)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue