Commit Graph

5403 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
74d99057a5 Bug: C stack overflow with coroutines
'coroutine.resume' did not increment counter of C calls when
continuing execution after a protected error (that is,
while running 'precover').
2021-11-03 15:04:18 -03:00
Roberto Ierusalimschy
1fce5bea81 More uniform implementation for tail calls
'luaD_pretailcall' mimics 'luaD_precall', handling call metamethods
and calling C functions directly. That makes the code in the
interpreter loop simpler.

This commit also goes back to emulating the tail call in 'luaD_precall'
with a goto, as C compilers may not do proper tail calls and the C
stack can overflow much sooner than the Lua stack (which grows as the
metamethod is added to it).
2021-10-29 13:41:24 -03:00
Roberto Ierusalimschy
3699446aaf Removed goto's in 'luaD_precall'
(plus a detail in lauxlib.h.)
2021-10-18 11:58:40 -03:00
Roberto Ierusalimschy
0e5071b5fb Avoid taking the address of a 'TValue' field
That structure can be packed in the future.
2021-10-11 13:52:26 -03:00
Roberto Ierusalimschy
87a9573b2e Documentation
Better explanation about the guaranties of multiple assignment in
the manual.
2021-10-11 13:49:13 -03:00
Roberto Ierusalimschy
deac067ed3 Avoid overflows when incrementing parameters in C
Any C function can receive maxinteger as an integer argument, and
therefore cannot increment it without some care (e.g., doing unsigned
arithmetic as the core does).
2021-09-22 13:10:39 -03:00
Roberto Ierusalimschy
2ff3471722 Using 'inline' in some functions
According to ISO C, "making a function an inline function suggests that
calls to the function be as fast as possible." (Not available in C89.)
2021-09-15 11:18:41 -03:00
Roberto Ierusalimschy
9db4bfed6b Revamp of format validation in 'string.format'
When calling 'sprintf', not all conversion specifiers accept all
flags; some combinations are undefined behavior.
2021-09-03 13:14:56 -03:00
Roberto Ierusalimschy
91673a8ec0 'luaD_tryfuncTM' checks stack space by itself 2021-08-18 12:05:06 -03:00
Roberto Ierusalimschy
41871f1803 Undo simplification of tail calls (commit 901d760)
Not that simpler and slower.
2021-08-18 11:21:33 -03:00
Roberto Ierusalimschy
a393ac2554 Detail in 'testes/math.lua'
Added a print with the random seeds used in the tests of 'random'.
2021-08-18 10:46:18 -03:00
Roberto Ierusalimschy
65434b4d1b Option '-l' can give a name for the global variable.
Sintax for this option now is '-l [globname=]modname'.
2021-08-16 13:57:19 -03:00
Roberto Ierusalimschy
59acd79c05 Added tests for string reuse by the scanner 2021-08-11 11:19:33 -03:00
Roberto Ierusalimschy
e2c07dcbf7 Improved documentation for 'lua_getinfo' 2021-08-11 11:18:10 -03:00
Roberto Ierusalimschy
439e45a2f6 Bug: luaL_tolstring may get confused with negative index
When object has a '__name' metafield, 'luaL_tolstring' used the
received index after pushing a string on the stack.
2021-07-22 13:48:43 -03:00
Roberto Ierusalimschy
62fb934427 Bug: Negation in 'luaV_shiftr' may overflow
Negation of an unchecked lua_Integer overflows with mininteger.
2021-07-22 13:44:53 -03:00
Roberto Ierusalimschy
8a32e0aa4a Correction on documentation of string-buffer operations
All string-buffer operations can potentially change the stack in
unspecified ways; the push/pop documentation in the manual should
reflect that.
2021-07-21 11:33:58 -03:00
Roberto Ierusalimschy
dbdc74dc55 Simplification in the parameters of 'luaD_precall'
The parameters 'nresults' and 'delta1', in 'luaD_precall', were never
meaningful simultaneously. So, they were combined in a single parameter
'retdel'.
2021-06-30 12:53:21 -03:00
Roberto Ierusalimschy
6a0dace25a Bug: 'local function' can assign to '<const>' variables 2021-06-20 15:36:36 -03:00
Roberto Ierusalimschy
04e19712a5 C functions can be tail called, too
A tail call to a C function can have the behavior of a "real" tail
call, reusing the stack frame of the caller.
2021-06-14 13:28:21 -03:00
Roberto Ierusalimschy
901d760093 Simpler implementation for tail calls
Tail calls handled by 'luaD_precall', like regular calls, to avoid
code duplication.
2021-06-11 13:41:07 -03:00
Roberto Ierusalimschy
c0ed74c1e1 Avoid the term "undefined behavior" in the manual 2021-06-09 13:24:49 -03:00
Roberto Ierusalimschy
fc6c74f100 'index2value' more robust
'index2value' accepts pseudo-indices also when called from a Lua
function, through a hook.
2021-05-24 16:48:43 -03:00
Roberto Ierusalimschy
1e6918d553 Details
- Removed unused (and trivial) definition LUA_UNSIGNEDBITS
- Alignment structure in pack/unpack moved to a narrower scope
2021-05-24 16:48:09 -03:00
Roberto Ierusalimschy
681297187e Bug: yielding in '__close' mess up number of returns
Yielding in a __close metamethod called when returning vararg results
changes the top and so messes up the number of returned values.
2021-04-16 15:41:44 -03:00
Roberto Ierusalimschy
5148954eed Align error messages for calling non-callable values
'pcall(foo)' message was "attempt to call a table value", while
'pcall(function () foo() end) message was "global 'foo' is not callable".
2021-04-12 16:50:34 -03:00
Roberto Ierusalimschy
d205f3a484 Bug: Lua source should not use C99 comments ("//") 2021-04-10 10:19:21 -03:00
Roberto Ierusalimschy
47cffdc723 Bug: tbc variables in "for" loops don't avoid tail calls 2021-04-07 14:59:26 -03:00
Roberto Ierusalimschy
36de01d988 Changes in cache for function constants
In 'lcode.c', when adding constants to the list of constants of a
function, integers represent themselves in the cache and floats
with integral values get a small delta to avoid collision with
integers. (This change avoids creating artificial addresses; the old
implementation converted integers to pointers to index the cache.)
2021-03-30 14:49:18 -03:00
Roberto Ierusalimschy
7fbe215808 New hash function for integer keys
When integer keys do not form a sequence, it is better to use all their
bits to compute their hashes. (The previous implementation was quite bad
for integer keys with common lower bits, and disastrous for integer keys
changing only in their upper 32 bits.)
2021-03-29 15:47:18 -03:00
Roberto Ierusalimschy
bf10593a3a Allow yields inside '__pairs' 2021-03-29 12:57:32 -03:00
Roberto Ierusalimschy
bef250eb8d Details
Comments and small improvements in the manual.
2021-03-29 11:47:12 -03:00
Roberto Ierusalimschy
ba81adaad9 Next release number (5.4.4) 2021-03-29 11:26:07 -03:00
Roberto Ierusalimschy
eadd8c7178 Added option LUA_NOBUILTIN
This option allows external code to avoid the use of gcc builtin macro
'__builtin_expect' in the Lua API.
2021-03-12 15:03:33 -03:00
Roberto Ierusalimschy
014daf43cb Details
Comments and order of hashing macros in 'ltable.c'.
2021-03-12 11:29:34 -03:00
Roberto Ierusalimschy
05b13651f9 File 'tracegc.lua' added to 'packtests' 2021-03-10 10:35:57 -03:00
Roberto Ierusalimschy
81c6021fb4 New implementation for 'tbclist'
- Fixes a bug, by removing dummy nodes together with the node
itself. (The previous implementation could leave dummy nodes in frames
which otherwise had no tbc variables, and therefore would not close
variables; that could leave 'tbclist' pointing higher than 'top', which
could dangle if the stack shrank.)

- Computes MAXDELTA based on the type of delta, to ease changing its
type if needed.

- Instead of 'isdummy', uses 'delta==0' to signal dummy nodes. (Dummy
nodes always have MAXDELTA for their real delta.)
2021-03-10 10:27:19 -03:00
Roberto Ierusalimschy
a7b8b27dd3 Uses of "likely" in macros active to all users
The use of 'l_likely' in auxlib macros 'luaL_argcheck' and
'luaL_argexpected' should not be restricted to Lua's own code.
For that, 'l_likely' was renamed to 'luai_likely' to be exported
to external code.
2021-03-09 12:50:59 -03:00
Roberto Ierusalimschy
511d53a826 lua_settop/lua_pop closes to-be-closed variables
The existence of 'lua_closeslot' is no reason for lua_pop not to close
to-be-closed variables too.  It is too error-prone for lua_pop not to
close tbc variables being popped from the stack.
2021-03-09 11:42:45 -03:00
Roberto Ierusalimschy
f5df7f91f7 Wrong assertion in 'getbaseline'
The assertion cannot compute 'f->abslineinfo[i]' when the initial
estimate 'i' is -1.
2021-03-05 12:10:34 -03:00
Roberto Ierusalimschy
e7803f7dbc New release number (5.4.3) 2021-03-03 09:44:20 -03:00
Roberto Ierusalimschy
b7eb21c1ef Normalization of metamethod typography in the manual 2021-03-02 13:50:00 -03:00
Roberto Ierusalimschy
cf23a93d82 Added assertions for proper use of string buffers 2021-03-02 11:39:42 -03:00
Roberto Ierusalimschy
9a2de786de Stack check in warning function for tests
The warning function using for tests need to check the stack before
pushing anything. (Warning functions are not expected to access a
Lua state, therefore they have no preallocated stack space.)
2021-03-02 11:35:40 -03:00
Roberto Ierusalimschy
5276973224 New test module 'tracegc'
New module easies the inclusion of GC tracing in individual test files.
2021-03-01 13:54:29 -03:00
Roberto Ierusalimschy
f9d857a81b Stack reallocation done in two phases
$he stack reallocation is done in two steps (allocation + free) because
the correction of the pointers pointing into the stack must be done
while both addresses (the old stack and the new one) are valid.  In ISO
C, any pointer use after the pointer has been deallocated is undefined
behavior. The compiler option '-fsanitize=pointer-subtract' (plus what
it needs to work) complained about the old implementation.
2021-02-27 12:56:09 -03:00
Roberto Ierusalimschy
1537d6680b New control for reentrancy of emergency collections
Instead of assuming that shrinking a block may be an emergency
collection, use an explicit field ('gcstopem') to stop emergency
collections while GC is working.
2021-02-26 11:41:02 -03:00
Roberto Ierusalimschy
e0260eb2d4 Bug (kind of) in 'isinstack'
The function 'isinstack' tried to work around the undefined behavior
of subtracting two pointers that do not point to the same object,
but the compiler killed to trick. (It optimizes out the safety check,
because in a correct execution it will be always true.)
2021-02-25 13:39:36 -03:00
Roberto Ierusalimschy
5205f073c5 Don't use tointegerns when luaV_tointegerns will do
Some places don't need the "fast path" macro tointegerns, either
because speed is not essential (lcode.c) or because the value is not
supposed to be an integer already (luaV_equalobj and luaG_tointerror).
Moreover, luaV_equalobj should always use F2Ieq, even if Lua is
compiled to "round to floor".
2021-02-24 12:24:42 -03:00
Roberto Ierusalimschy
31925e4cc2 Details
Added documentation and asserts that constants for arithmetic opcodes
must be numbers.
2021-02-24 11:30:46 -03:00