5722 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
3dd8ea54da Order change in 'pushfuncname'
'pushglobalfuncname' can be quite slow (as it traverses all globals and
all loaded modules), so try first to get a name from the code.
2025-04-03 15:31:22 -03:00
Roberto Ierusalimschy
620f49a7aa Tiny refactoring in io.flush 2025-04-03 12:56:52 -03:00
Roberto Ierusalimschy
3f4f28010a io.write returns number of written bytes on error 2025-04-03 11:32:49 -03:00
Roberto Ierusalimschy
93e347b519 Corrections of stack addresses back to strict mode
It can be a little slower, but only for quite large stacks and moreover
stack reallocation is not a common operation.  With no strong contrary
reason, it is better to follow the standard.
2025-04-01 10:41:25 -03:00
Roberto Ierusalimschy
f4123b2fc2 Growth factor of 1.5 for stack and lexical buffer 2025-03-31 13:44:41 -03:00
Roberto Ierusalimschy
37a1b72706 Small optimization in 'project' from math.random
When computing the Mersenne number, instead of spreading 1's a fixed
number of times (with shifts of 1, 2, 4, 8, 16, and 32), spread only
until the number becomes a Mersenne number.
2025-03-27 15:22:40 -03:00
Roberto Ierusalimschy
ef5d171cc8 New macro 'l_numbits' 2025-03-27 12:38:29 -03:00
Roberto Ierusalimschy
b0f3df16a4 Addition in math.random can overflow
To avoid complains from some tools, the addition when computing
math.random(n,m), which is computed as n + random(0, m - n), should
use unsigned integers.
2025-03-25 11:43:03 -03:00
Roberto Ierusalimschy
cad5a4fdbb Details
Small changes in test library:
- execute mode added to 'all.lua';
- more information about subtypes (tags) when printing a stack.
2025-03-24 15:23:55 -03:00
Roberto Ierusalimschy
fdbb4c2341 Detail in the manual 2025-03-17 16:05:47 -03:00
Roberto Ierusalimschy
921832be8d New function 'resetCI'
New function 'resetCI' resets the CallInfo list of a thread, ensuring
a proper state when creating a new thread, closing a thread, or
closing a state, so that we can run code after that. (When closing a
thread, we need to run its __close metamethods; when closing a
state, we need to run its __close metamethods and its finalizers.)
2025-03-17 14:32:08 -03:00
Roberto Ierusalimschy
205f9aa67b New function 'printallstack' in test library 2025-03-17 14:30:43 -03:00
Roberto Ierusalimschy
94d38560c3 Wrong error message when using "_ENV" fields
The string "_ENV" is erroneously identified as a variable _ENV,
so that results from a field is classified as a global.
2025-03-14 15:16:09 -03:00
Roberto Ierusalimschy
c2dc6e8e94 Missing GC barrier in 'luaV_finishset' 2025-03-14 12:37:19 -03:00
Roberto Ierusalimschy
22974326ca Use after free in 'luaV_finishset'
If a metatable is a weak table, its __newindex field could be collected
by an emergency collection while being used in 'luaV_finishset'. (This
bug has similarities with bug 5.3.2-1, fixed in commit a272fa66.)
2025-03-13 15:30:52 -03:00
Roberto Ierusalimschy
c931d86e98 'luaD_seterrorobj' should not raise errors
This function can be called unprotected, so it should not raise any
kind of errors. (It could raise a memory-allocation error when creating
a message).
2025-03-12 15:51:16 -03:00
Roberto Ierusalimschy
d9e0f64a5d Small changes in the manual 2025-03-12 15:45:39 -03:00
Roberto Ierusalimschy
ab66652b32 Removed copyright notice from 'testes/all.lua'
All test files refer to the main copyright notice in 'lua.h'.
2025-03-12 14:00:58 -03:00
Roberto Ierusalimschy
4398e488e6 New test file 'memerr.lua'
Tests for memory-allocation errors moved from 'api.lua' to this new
file, as 'api.lua' was already too big. (Besides, these tests have
nothing to do with the API.)
2025-03-12 13:52:35 -03:00
Roberto Ierusalimschy
808976bb59 Small correction in 'traverseweakvalue'
After a weak table is traversed in the atomic phase, if it does not
have white values ('hasclears') it does not need to be retraversed
again. (Comments were correct, but code did not agree with them.)
2025-03-12 12:35:36 -03:00
Roberto Ierusalimschy
b5b1995f29 Checks for type 'int' added to binary header
The structure 'AbsLineInfo' is hard-dumped into binary chunks, and
it comprises two 'int' fields.
2025-03-10 15:21:32 -03:00
Roberto Ierusalimschy
cb88c1cd5d Detail
Added macro LUA_FAILISFALSE to make easier to change the fail value
from nil to false.
2025-02-28 15:48:45 -03:00
Roberto Ierusalimschy
ee99452158 Error object cannot be nil
Lua will change a nil as error object to a string message, so that it
never reports an error with nil as the error object.
2025-02-28 14:53:58 -03:00
Roberto Ierusalimschy
127a8e80fe '__close' gets no error object if there is no error
Instead of receiving nil as a second argument, __close metamethods are
called with just one argument when there are no errors.
2025-02-28 10:10:27 -03:00
Roberto Ierusalimschy
f9e35627ed 'lua_State.nci' must be an integer
Lua can easily overflow an unsigned short counting nested calls.
(The limit to this value is the maximum stack size, LUAI_MAXSTACK,
which is currently 1e6.)
2025-02-26 11:31:10 -03:00
Roberto Ierusalimschy
ceac82f78b Details
Comments, small changes in the manual, an extra test for errors in
error handling, small changes in tests.
2025-02-26 11:29:54 -03:00
Roberto Ierusalimschy
e5f4927a0b Array sizes in undump changed from unsigned to int
Array sizes are always int and are dumped as int, so there is no reason
to read them back as unsigned.
2025-02-20 10:09:04 -03:00
Roberto Ierusalimschy
cd38fe8cf3 Added macro LUAI_STRICT_ADDRESS
By default, the code assumes it is safe to use a dealocated pointer
as long as the code does not access it.
2025-02-18 17:02:32 -03:00
Roberto Ierusalimschy
fa1382b5cd Main thread is a regular field of global_State
They were already allocated as a single block, so there is no need
for the global_State to point to its main thread.
2025-01-31 13:51:38 -03:00
Roberto Ierusalimschy
d1e677c52b New type 'TStatus' for thread status/error codes 2025-01-30 11:41:39 -03:00
Roberto Ierusalimschy
f7439112a5 Details (in test library)
- Added support for negative stack indices in the "C interpreter"
- Improved format when printing values
2025-01-29 14:47:06 -03:00
Roberto Ierusalimschy
39a14ea7d7 CallInfo bit CIST_CLSRET broken in two
Since commit f407b3c4a, it was being used for two distinct (and
incompatible) meanings:
A: Function has TBC variables (now bit CIST_TBC)
B: Interpreter is closing TBC variables (original bit CIST_CLSRET)

B implies A, but A does not imply B.
2025-01-28 11:45:45 -03:00
Roberto Ierusalimschy
c4e7cdb541 Renaming two new functions
'lua_numbertostrbuff' -> 'lua_numbertocstring'
'lua_pushextlstring' -> 'lua_pushexternalstring'
2025-01-27 16:09:55 -03:00
Roberto Ierusalimschy
7d7ae8781e Parameters for 'lua_createtable' back to int
Tables don't accept sizes larger than int.
2025-01-21 13:33:59 -03:00
Roberto Ierusalimschy
724012d3d0 Small change in macro 'isvalid'
The "faster way" to check whether a value is not 'nilvalue' is not
faster. (Both forms entail one memory access.)
2025-01-16 16:11:49 -03:00
Roberto Ierusalimschy
664bda02ba fixing 'lua_status' in panic.
'luaD_throw' may call 'luaE_resetthread', which returns an error code
but clears 'L->status'; so, 'luaD_throw' should set that status again.
2025-01-16 16:07:39 -03:00
Roberto Ierusalimschy
2d8d5c74b5 Details
New year (2024->2025), typos in comments
2025-01-16 11:51:16 -03:00
Roberto Ierusalimschy
3cdd49c94a Fixed conversion warnings from clang
Plus some other details. (Option '-Wuninitialized' was removed from
the makefile because it is already enabled by -Wall.)
2025-01-14 16:24:46 -03:00
Roberto Ierusalimschy
10e931da82 Error "break outside loop" made a syntax error
Syntax errors are easier to handle than semantic errors.
2025-01-13 11:23:07 -03:00
Roberto Ierusalimschy
4b107a8776 Details in lparser.c
Added comments so that all braces pair correctly. (The parser has
several instances of unmatched braces as characters ('{' or '}'), which
hinders matching regular braces in the code.)
2025-01-10 15:27:17 -03:00
Roberto Ierusalimschy
429761d7d2 New optimization option for testing
Using gcc's option '-Og' (instead of '-O0') for testing/debugging.
2025-01-10 15:14:01 -03:00
Roberto Ierusalimschy
915c29f8bd Improvements in the manual
Plus details
2025-01-10 15:11:54 -03:00
Roberto Ierusalimschy
7ca3c40b50 Another way to compile goto's
The compilation of a goto or a label just create an entry and generate
boilerplate code for the gotos. As we don't know yet whether it needs a
CLOSE, we code a jump followed by a CLOSE, which is then dead code.

When a block ends (and then we know for sure whether there are variables
that need to be closed), we check the goto's against the labels of that
block. When closing a goto against a label, if it needs a CLOSE, the
compiler swaps the order of the jump and the CLOSE, making the CLOSE
active.
2025-01-10 13:54:51 -03:00
Roberto Ierusalimschy
8a3a49250c Detail
Small improvement in line-tracing for internal debugging.
2025-01-06 14:44:06 -03:00
Roberto Ierusalimschy
1ec251e091 Detail (debugging aid)
When compiling with option HARDMEMTESTS, every creation of a new key
in a table forces an emergency GC.
2025-01-06 12:41:39 -03:00
Roberto Ierusalimschy
5894ca7b95 Scanner doesn't need to anchor reserved words 2024-12-30 16:53:51 -03:00
Roberto Ierusalimschy
abf8b1cd4a Small optimization in 'luaH_psetshortstr'
Do not optimize only for table updates (key already present).
Creation of new short keys in new tables can be quite common in
programs that create lots of small tables, for instance with
constructors like {x=e1,y=e2}.
2024-12-28 15:05:01 -03:00
Roberto Ierusalimschy
2a307f898b When parser reuses constants, only floats can collide
Ensure that float constants never use integer keys, so that only
floats can collide in 'k2proto'.
2024-12-28 15:03:48 -03:00
Roberto Ierusalimschy
f81d0bbd4f Detail in 'luaD_inctop'
Protect stack top before possible stack reallocation. (In the current
implementation, a stack reallocation cannot call an emergency
collection, so there is no bug, but it is safer not to depend on that.)
2024-12-17 13:36:12 -03:00
Roberto Ierusalimschy
1c40ff9faa Scanner and parser use different tables for constants
Moreover, each function being parsed has its own table.

The code is cleaner when each table is used for one specific purpose:
The scanner uses its table to anchor and unify strings, mapping strings
to themselves; the parser uses it to reuse constants in the code,
mapping constants to their indices in the constant table. A different
table for each task avoids false collisions.
2024-12-17 11:23:22 -03:00