Commit Graph

5441 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
1f81baffad Janitorial work
Comments, code details, identation.
2021-01-25 10:39:18 -03:00
Roberto Ierusalimschy
0e9254dfa0 Correct order of return hooks vs. close metamethods
The return hook should be called only after closing variables (which
are still part of the function). C functions were calling the hook
before the metamethods.
2021-01-21 10:27:22 -03:00
Roberto Ierusalimschy
6ccd24eff5 Simpler handling of errors when creating tbc variables
New field 'lua_State.ptbc' keeps to-be-closed variable until its
upvalue is created, so that it can be closed in case of a
memory-allocation error.
2021-01-19 10:03:13 -03:00
Roberto Ierusalimschy
d0f34d9137 Allow yields in '__close' metamethods ater errors
Completes commit b07fc10e91. '__close' metamethods can yield even
when they are being called due to an error. '__close' metamethods from
C functions are still not allowed to yield.
2021-01-18 11:40:45 -03:00
Roberto Ierusalimschy
825ac8eca8 Corrected documentation for 'table.sort'
The sort function must define a (strict) weak order for a correct
sorting. A partial order is not enough.
2021-01-14 13:26:55 -03:00
Roberto Ierusalimschy
b07fc10e91 Allow yields inside '__close' metamethods
Initial implementation to allow yields inside '__close' metamethods.
This current version still does not allow a '__close' metamethod
to yield when called due to an error. '__close' metamethods from
C functions also are not allowed to yield.
2021-01-13 13:54:10 -03:00
Roberto Ierusalimschy
cc1692515e New API function 'lua_closeslot'
Closing a to-be-closed variable with 'lua_settop' is too restrictive,
as it erases all slots above the variable. Moreover, it adds side
effects to 'lua_settop', which should be a fairly basic function.
2021-01-11 15:03:01 -03:00
Roberto Ierusalimschy
ce101dcaf7 Handles '__close' errors in coroutines in "coroutine style"
Errors in '__close' metamethods in coroutines are handled by the same
logic that handles other errors, through 'recover'.
2020-12-30 11:20:22 -03:00
Roberto Ierusalimschy
553b37ce4f Do not insert nil values into tables 2020-12-29 13:38:47 -03:00
Roberto Ierusalimschy
4bd10b6fe8 Better error messages for calling non-callable objects
When available, use the calling code to find a suitable name for what
was being called; this is particularly useful for errors of non-callable
metamethods. This commit also improved the debug information for
order metamethods.
2020-12-29 13:15:54 -03:00
Roberto Ierusalimschy
59e565d955 No need to recheck close method before calling it
A to-be-closed variable is constant and it must have a close metamethod
when it is created. A program has to go out of its way (e.g., by
changing the variable's metamethod) to invalidate that check. So,
it is not worth to test that again. If the program tampers with the
metamethod, Lua will raise a regular error when attempting to call it.
2020-12-29 10:23:02 -03:00
Roberto Ierusalimschy
6188f3a654 Reset thread before panicking
Before panicking, it is simpler to reset the thread instead of closing
its variables and adjust the top manually.
2020-12-28 16:34:07 -03:00
Roberto Ierusalimschy
7af27ef59d Cleaner handling of errors in '__close' metamethods
Instead of protecting each individual metamethod call, protect the
entire call to 'luaF_close'.
2020-12-28 11:40:30 -03:00
Roberto Ierusalimschy
0ceada8da9 Report last error in closing methods
When there are multiple errors around closing methods, report the
last error instead of the original.
2020-12-22 10:54:25 -03:00
Roberto Ierusalimschy
f9d29b0c44 Upvalues removed from 'openupval' before being closed
Undo commit c220b0a5d0: '__close' is not called again in case of
errors. (Upvalue is removed from the list before the call.) The
common error that justified that change was C stack overflows, which
are much rarer with the stackless implementation.
2020-12-21 15:21:45 -03:00
Roberto Ierusalimschy
409256b784 'coroutine.close'/'lua_resetthread' report original errors
Besides errors in closing methods, 'coroutine.close' and
'lua_resetthread' also consider the original error that stopped the
thread, if any.
2020-12-18 11:22:42 -03:00
Roberto Ierusalimschy
b17178b27a Cleaner handling of floats in pack/unpack 2020-12-16 11:23:51 -03:00
Roberto Ierusalimschy
e1ceea5674 Cleaner definition for macro 'ttisclosure' 2020-12-16 11:02:40 -03:00
Roberto Ierusalimschy
748d6d4e7a Review of asserts in 'ltests.c'
The module 'ltests.c' must work correctly with asserts off, too.
2020-12-08 11:54:21 -03:00
Roberto Ierusalimschy
e2ea3b31c9 Details (do not affect regular code)
* Avoids multiple definitions of 'lua_assert' in test file.
* Smaller C-stack limit in test mode.
* Note in the manual about the use of false
* Extra test for constant reuse.
2020-12-07 11:17:30 -03:00
Roberto Ierusalimschy
23051e830a Changes in the API of 'luaH_set' and related functions
Functions to set values in a table (luaH_set, luaH_newkey, etc.) receive
the new value, instead of returning a slot where to put the value.
2020-12-04 11:08:42 -03:00
Roberto Ierusalimschy
f15589f3b0 Added test cases for error messages about goto/label 2020-12-03 12:11:15 -03:00
Roberto Ierusalimschy
754ca0060f n Windows, 'popen' accepts "[rw][bt]?" as valid modes
Added the modifiers 'b' and 't' to valid modes for 'popen' in Windows.
2020-12-03 12:09:50 -03:00
Roberto Ierusalimschy
c36ced53c9 Avoid "bad programming habits" in the reference system
References were using both 0 indices and nils as values in arrays.
Both do not fit in the concept of a sequence, which is the kind
of use that guides all Lua optimizations.
2020-12-03 12:00:32 -03:00
Roberto Ierusalimschy
d41c36bf67 'lua_assert' moved from 'lualib.h' to 'lauxlib.h'
The macro is useful also in 'lauxlib.c', which does not include
'lualib.h'. Also, the definition was corrected to be "on" when
LUAI_ASSERT is defined.
2020-12-03 10:39:38 -03:00
Roberto Ierusalimschy
d9d2904f09 Details
Names in the parser and other details that do not change actual code.
2020-12-02 15:13:13 -03:00
Roberto Ierusalimschy
65d2294454 Changed access to global table in the registry
The global table is always in the array part of the registry; we can
use this fact to make its access slightly more efficient.
2020-11-26 18:23:40 -03:00
Roberto Ierusalimschy
131e3fd814 Avoid using 'signal' when 'sigaction' is available
The semantics of 'signal' varies a lot among different implementations;
'sigaction' ensures a more consistent behavior.
2020-11-24 14:41:50 -03:00
Roberto Ierusalimschy
9d067ab73b Optimization for 'n^2'
Squares are much more common than other exponentiations, and 'n*n' is
much more efficient than 'pow'.
2020-11-13 09:59:07 -03:00
Roberto Ierusalimschy
2f4162bc47 Compiler optimization back to '-O2'
Undo commit 6a10f03ff. Compiler performance is important, too.
2020-11-11 15:10:51 -03:00
Roberto Ierusalimschy
ab1aca94e8 Removed optimization for «if ... then goto»
That optimization was too complex and caused some weird traces when
debugging. The more common case «if ... then break» was kept.
2020-11-11 14:41:41 -03:00
Roberto Ierusalimschy
d282652561 Bug when growing a stack
When a stack grows, its extra area can be in use, and it becomes part
of the common area. So, the extra area must be kept correct all the
times. (Bug introduced by commit 5aa36e894f5.)
2020-11-08 11:52:26 -03:00
Roberto Ierusalimschy
58216600eb 'luaL_newstate' should not allocate extra memory
The allocation of a userdata for the state of the warn system can
cause a panic if it fails; 'luaL_ref' also can fail. This commit
re-implements the warn system so that it does not need an explicit
state. Instead, the system uses different functions to represent
the different states.
2020-11-03 16:34:36 -03:00
Roberto Ierusalimschy
94cbe46511 Details
- small corrections in the manual
- ldo.c: 'docall' -> 'ccall' ('docall' already used in 'lua.c')
- comments
2020-10-30 10:18:54 -03:00
Roberto Ierusalimschy
69b71a6919 _PROMPT can have non-string values
'get_prompt' uses 'luaL_tolstring' to convert _PROMPT or _PROMPT2
value to a string. That conversion may invoke a '__tostring'
metamethod.
2020-10-26 11:15:51 -03:00
Roberto Ierusalimschy
d742a193e5 Comments 2020-10-22 15:54:46 -03:00
Roberto Ierusalimschy
e4a38eb0e8 Fixed wrong trace of vararg functions
Trace of vararg functions was skipping an instruction when returning
from a call. (Bug introduced by commit 5d8ce05b3.)
2020-10-19 15:55:25 -03:00
Roberto Ierusalimschy
f07de22576 Fixed compiler option -DHARDSTACKTESTS to commit 5aa36e8 2020-10-19 15:43:59 -03:00
Roberto Ierusalimschy
52c8679760 Fixed bug of keys removed from tables vs 'next'
Fixed the bug that a key removed from a table might not be found
again by 'next'. (This is needed to allow keys to be removed during a
traversal.) This bug was introduced in commit 73ec04fc.
2020-10-14 15:46:58 -03:00
Roberto Ierusalimschy
849b2ecbd2 New release number (5.4.2) 2020-10-12 14:52:39 -03:00
Roberto Ierusalimschy
30528049f1 'lua_upvalueid' returns NULL on invalid upvalue index 2020-10-12 14:51:28 -03:00
Roberto Ierusalimschy
9a89fb1c9d Hash always use all characters in a long string
Hashes for long strings are computed only when they are used as keys
in a table, not a too common case. And, in that case, it is to easy to
force collisions changing only the characters which are not part of the
hash.
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
c23cc86c54 Details
- After converting a generic GCObject to a specific type ('gco2*'),
  avoid using the original GCObject (to reduce aliasing).
- Small corrections in comments in 'lopcodes.h'
- Added tests about who calls __close metamethods
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
171dcd7d74 'recover' finish of 'luaD_pcall' should follow the original 2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
5aa36e894f No more field 'lua_State.stacksize'
The stack size is derived from 'stack_last', when needed. Moreover,
the handling of stack sizes is more consistent, always excluding the
extra space except when allocating/deallocating the array.
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
9ecd446141 Avoid shrinking stacks to often
Shrink a stack only when the final stack size can be at most 2/3 the
previous size with half of its entries empty. This commit also
improves the clarity of 'luaD_growstack'.
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
fb172d0a92 No need for 'volatile' in string.pack/unpack
Type punning an address to 'char *' should be always safe.
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
0085db4596 Avoid GCs when testing stack overflow
A GC step may invoke some finalizer, which may error and emit
a warning due to stack overflfow.
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
490d42b5f8 Correct handling of 'luaV_execute' invocations
The previous stackless implementations marked all 'luaV_execute'
invocations as fresh. However, re-entering 'luaV_execute' when
resuming a coroutine should not be a fresh invocation. (It works
because 'unroll' called 'luaV_execute' for each call entry, but
it was slower than letting 'luaV_execute' finish all non-fresh
invocations.)
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
287b302acb Revision of stackless implementation
- more organized handling of 'nCcalls'
- comments
- deprecation of 'setcstacklimit'
2020-10-12 12:29:09 -03:00