Lua stack state during 'lua_load'
Jure Bagić <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <aeR7TzkxkNcNZ8gs@archlinux> |
Reference manual for 'lua_load' says: > The function lua_dump fully preserves the Lua stack > through the calls to the writer function, > except that it may push some values for internal use > before the first call, > and it restores the stack size to its original size > after the last call. How about the 'kcache' table that is pushed each time new function is being parsed (see 'open_func' in lparser.c). Now the reader cannot assume that the Lua stack is fully preserved as it might of pushed a new 'kcache' table. This assumption would break C code that interacts with Lua stack while loading chunks in text mode; loading of binary chunks looks ok, I guess the only changes here were the addition of PF_FIXED and new external strings (no new stack anchors). Updating docs is easy fix, trying to preserve stack with the addition of 'kcache' table not so easy fix. I do have 2 fixes. Storing 'kcache' table not on stack but in the scanner table or (worse option in my opinion) storing the 'kcache' tables in the 'mainfunc' 'kcache' table. Storing 'kcache' in scanner table is faster (less checks), requires one less stack slot and less code. The parser would reserve one stack slot above the scanner table that would be kept as nil. It would act as temporary anchor for 'kcache' table before the 'kcache' is inserted into the scanner table (the table itself is a key). When in 'close_func', before the GC check the 'kcache' would be removed from the scanner table (set to nil). If using 'kcache' table of the 'mainfunc' to store other 'kcache' tables, there would be additional check in 'end_func' > if (fs->prev != NULL) > -- remove 'kcache' from the main 'kcache' not only that, there would be need for additional stack slot, the temporary anchor + the slot for 'mainfunc' 'kcache' table, and it would also require pointer to the 'mainfunc' 'kcache' table. -- Jure -- You received this message because you are subscribed to the Google Groups "lua-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/lua-l/aeR7TzkxkNcNZ8gs%40archlinux.
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTilOnPIAgk+VLLAS+FaQJ4QtXaNQUCaeSGaAAKCRCFaQJ4QtXa Nbm+AQDNtMzBNNpNyWryoFkdR6ukWR76a+eiRsFeyQsYKrW/YwEAmRW/vAH/IXBv ZafkkTJr6PoMzesIsQtVAfHe2vxjsQM= =0E10 -----END PGP SIGNATURE-----