Commit Graph

5845 Commits

Author SHA1 Message Date
Roberto I
b352217b84 Standard allocator function added to the API
That makes easier to redefine luaL_newstate.
2025-10-17 13:53:35 -03:00
Roberto I
9c66903cc5 Details
- Functions luaK_goiffalse, luaS_hash made private.
- Removed unused macro log2maxs.
2025-10-14 13:50:24 -03:00
Roberto I
30a7b93439 Two new memory tests
For external strings and for vararg tables.
2025-10-12 15:13:28 -03:00
Roberto I
7a92f3f99a Change in dumping of NULL strings
When dumping a string, adding 2 to its size may overflow a size_t for
external strings, which may not have a header. (Adding 1 is Ok, because
all strings end with a '\0' not included in their size.) The new method
for saving NULL strings code them as a repeated string, using the
reserved index 0.
2025-10-10 15:28:41 -03:00
Roberto I
3347c9d32d Initialization of too many locals break assertion
The check for limit of local variables is made after generating code to
initialize them. If there are too many local variables not initialized,
the coding of instruction OP_LOADNIL could overflow an argument.
2025-10-10 13:22:19 -03:00
Roberto I
25c54fe60e Optimization for vararg tables
A vararg table can be virtual. If the vararg table is used only as
a base in indexing expressions, the code does not need to create an
actual table for it. Instead, it compiles the indexing expressions
into direct accesses to the internal vararg data.
2025-09-24 18:33:08 -03:00
Roberto I
0cc3c9447c Small tweaks in makefile 2025-09-18 11:03:55 -03:00
Roberto I
8fb1af0e33 Varag parameter is a new kind of variable
To allow some optimizations on its use.
2025-09-17 16:07:48 -03:00
Roberto I
140b672e2e Vararg table
Not yet optimized nor documented.
2025-09-16 13:26:24 -03:00
Roberto I
9ea06e61f2 Details
- LUAMOD_API defined as 'extern "C"' in C++.
- "ANSI C" is in fact "ISO C" (comments)
- Removed option -std from makefile in testes/libs. (Easier to change
  to C++ for tests).
2025-09-05 15:36:47 -03:00
Roberto I
ffbcadfb41 In C++, 'throw' must go to the correct handler.
In C, we may have several "setjmp" nested, and the "longjmp" will go
to the one given by the corresponding "jmp_buf". In C++, a "throw"
will always go to the inner "catch". So, the "catch" must check
whether it is the recipient of the "throw" and, if not, rethrow
the exception to the outer level.
2025-09-05 15:29:15 -03:00
Roberto Ierusalimschy
0b73ed8f08 Allows LUA_32BITS to be defined externally
An external definition for LUA_32BITS can change the API, but libraries
check number-format compatibility when loading. So, any incompatible
modules will report a clear error.
2025-08-30 16:16:02 -03:00
Roberto I
f87416f1a3 Added limit to number of elements in a constructor
The reasoning in commit 519c57d5 is wrong: A sequence of nils generates
several fields with just one OP_LOADNIL.
2025-08-27 10:30:54 -03:00
Roberto I
03a3473687 'ltests.h' should not use LUAI_FUNC
LUAI_FUNC is now defined in llimits.h.
2025-08-27 10:28:31 -03:00
Roberto Ierusalimschy
9a3940380a New compile option LUA_USE_OFF_T
Allows non-Posix systems to use off_t and related functions for
file offsets.
2025-08-26 12:30:34 -03:00
Roberto Ierusalimschy
711890624f update in 'onelua.c' 2025-08-26 12:30:05 -03:00
Roberto Ierusalimschy
13d2326a23 Some definitions moved from luaconf.h to llimits.h
These definitions were in luaconf.h only because the standard libraries
need them. Now that llimits.h is included by the libraries, it offers a
more private place for these definitions.
2025-08-21 10:51:17 -03:00
Roberto I
06c5d3825f Removed code for compatibility with version 5.3 2025-08-20 16:10:54 -03:00
Roberto I
c345877e4c Better documentation for LUA_ERRERR
Not all errors in a message handler generate a LUA_ERRERR.
2025-08-20 15:29:46 -03:00
Roberto I
907d172c11 Added lock/unlock to API function 'lua_rawlen'
The call to 'luaH_getn' can change the "field" 'lenhint' of a table.
2025-08-20 15:00:53 -03:00
Roberto I
88aa4049ad Keep the order left-right in shifts
Opcodes OP_SHLI-OP_SHRI and the cases for opcodes OP_SHL-OP_SHR were
out of order.
2025-08-20 14:31:07 -03:00
Roberto I
c688b00f73 Detail in 'obj2gco'
Its check should use the type of the object, not its tag. (Change only
relevant in test mode.)
2025-08-20 14:18:12 -03:00
Roberto I
dd095677e3 Small cleaning services 2025-08-20 13:59:08 -03:00
Roberto I
53dc5a3bba Functions 'frexp'-'ldexp' back to the math library
They are basic for anything that handles the representation of
floating numbers.
2025-08-09 15:15:20 -03:00
Roberto I
5b179eaf6a Details 2025-08-09 15:08:53 -03:00
Roberto Ierusalimschy
8fddca81e7 'onelua' can use the test library
Just add -DLUA_USER_H='"ltests.h"' when compiling it.
2025-07-29 14:35:04 -03:00
Roberto Ierusalimschy
c33bb08ffe Added some casts for 32-bit machines
When both 'int' and 'l_obj' have 32 bits, an unsigned int needs a
cast to be assigned to 'l_obj'. (As long as 'l_obj' can count the
total memory used by the system, these casts should be safe.)
2025-07-29 11:50:20 -03:00
Roberto Ierusalimschy
e3716ee161 Fix in string.rep
The cast of n (number of repetitions) to size_t may truncate its value,
causing a buffer overflow later. Better to check the buffer size
using lua_Integer, as all string lengths must fit in a lua_Integer and
n already is a lua_Integer. If everything fits in MAX_SIZE, then we can
safely convert n to size_t and compute the buffer size as a size_t.

As a corner case, n can be larger than size_t if the strings being
repeated have length zero, but in this case it will be multiplied by
zero, so an overflow in the cast is irrelevant.
2025-07-23 18:12:53 -03:00
Roberto Ierusalimschy
303f415559 Randomness added to table length computation
A bad actor could fill only a few entries in a table (power of twos in
decreasing order, see tests) and produce a small table with a huge
length. If your program builds a table with external data and iterates
over its length, this behavior could be an issue.
2025-07-18 16:18:30 -03:00
Roberto Ierusalimschy
ccb8b307f1 Correction in utf8.offset
Wrong utf-8 character may have no continuation bytes.
2025-07-18 16:10:28 -03:00
Roberto Ierusalimschy
60b6599e83 Short strings can be external, too
That complicates a little object equality (and therefore table access
for long strings), but the old behavior was somewhat weird. (Short
strings, a concept otherwise absent from the manual, could not be
external.)
2025-07-15 14:40:27 -03:00
Roberto Ierusalimschy
c612685d4b lua.c doesn't use function pointers with LUA_READLINE
Bugs in macOS prevent assigning 'add_history' to 'l_addhist' without
a warning.
2025-07-09 14:43:31 -03:00
Roberto Ierusalimschy
85a3c1699c New method to unload DLLs
External strings created by DLLs may need the DLL code to be
deallocated. This implies that a DLL can only be unloaded after all
its strings were deallocated, which happen only after the run of all
finalizers. To ensure that order, we create a 'library string' to
represent each DLL and keep it locked. When this string is deallocated
(after the deallocation of any string created by the DLL) it closes its
corresponding DLL.
2025-07-09 14:40:36 -03:00
Roberto Ierusalimschy
f65d1f9e02 lua option '--' may not be followed by script 2025-07-08 15:40:59 -03:00
Roberto Ierusalimschy
942c10a5e3 Optional initialization for global declarations 2025-07-08 13:33:57 -03:00
Roberto Ierusalimschy
8485687908 Correction in definition of CIST_FRESH
The cast must be made before the shift. If int has 16 bits, the shift
would zero the value and the cast would cast 0 to 0.
2025-07-07 15:03:45 -03:00
Roberto Ierusalimschy
03d672a95c Details (comments) 2025-07-07 15:02:09 -03:00
Roberto Ierusalimschy
03bf7fdd4f Added missing casts from lua_Unsigned to size_t
size_t can be smaller than lua_Usigned.
2025-07-01 16:07:03 -03:00
Roberto Ierusalimschy
59a1adf194 LUAI_MAXSTACK defined privately
LUAI_MAXSTACK is limited to INT_MAX/2, so can use INT_MAX/2 to define
pseudo-indices (LUA_REGISTRYINDEX) in 'lua.h'. A change in the maximum
stack size does not need to change the Lua-C ABI.
2025-07-01 10:57:02 -03:00
Roberto Ierusalimschy
cfce6f4b20 Warning in loslib.c (signed-unsigned comparison) 2025-06-27 14:47:11 -03:00
Roberto Ierusalimschy
1da89da62f Manual updated to version 5.5 2025-06-27 14:46:41 -03:00
Roberto Ierusalimschy
f6c627af20 Cast added to 'add_history'
MacOS defines 'add_history' with a "wrong" type (it returns 'int'
instead of 'void').
2025-06-26 11:45:42 -03:00
Roberto Ierusalimschy
270a58c062 Application name for 'readline' is "lua", not "Lua" 2025-06-23 14:36:32 -03:00
Roberto Ierusalimschy
30531c291b Refactoring in the use of 'readline' by 'lua.c'
More common code for 'readline' loaded statically or dynamically (or
not loaded).
2025-06-23 14:00:21 -03:00
Roberto Ierusalimschy
07b009c371 No need to limit variable declarations to 250
Only local variables, which use registers, need this low limit.
2025-06-18 16:45:55 -03:00
Roberto Ierusalimschy
f711567448 Check string indices when loading binary chunk
Lua is not religious about that, but it tries to avoid crashes when
loading binary chunks.
2025-06-17 11:40:49 -03:00
Roberto Ierusalimschy
9386e49a31 New metatable in an all-weak table can fool the GC
All-weak tables are not being revisited after being visited during
propagation; if it gets a new metatable after that, the new metatable
may not be marked.
2025-06-16 16:29:32 -03:00
Roberto Ierusalimschy
8cd7ae7da0 Simpler code for 'traversetable'
Check the mode in a separate function (getmode), instead of using
comma expressions inside the 'if' condition.
2025-06-16 15:50:12 -03:00
Roberto Ierusalimschy
0cecf1ab6d Dump uses varints also for integer constants
Unlike sizes, these constants can be negative, so it encodes those
integers into unsigned integers in a way that keeps small numbers
small.
2025-06-13 14:14:50 -03:00
Roberto Ierusalimschy
e657a48ea5 The main thread cannot be closed
No thread started with pcall (instead of resume) can be closed,
because coroutine.close would not respect the expected number of
results from the protected call.
2025-06-13 14:08:38 -03:00