1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

5669 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
b4b616bdf2 Rehash reinserts elements with "lighter" functions
When reinserting elements into a table during a rehash, the code does
not need to invoke all the complexity of a full 'luaH_set':

- The table has space for all keys.
- The key cannot exist in the new hash.
- The keys are valid (not NaN nor nil).
- The keys are normalized (1.0 -> 1).
- The values cannot be nil.
- No barrier needed (the table already pointed to the key and value).
2024-12-05 17:34:08 -03:00
Roberto Ierusalimschy
bb93f04d87 Refactoring of 'luaH_newkey'
Function broke in two and some checks moved to the caller. (We may
want to call it without the checks.)
2024-12-05 14:27:58 -03:00
Roberto Ierusalimschy
975d4e0592 Fix in the definition of 'sizeLclosure'
The array at the end of a Lua closure has pointers to upvalues, not
to tagged values. This bug cannot cause any issue: The ISO C standard
requires that all pointers to structures have the same representation,
so sizeof(TValue*) must be equal to sizeof(UpVal*).
2024-12-03 10:53:46 -03:00
Roberto Ierusalimschy
04e495403b New function 'lua_printvalue' for internal debugging 2024-12-02 11:19:03 -03:00
Roberto Ierusalimschy
62afbc6bfc Details
Added two warnings to the makefile.
2024-11-29 17:39:20 -03:00
Roberto Ierusalimschy
002beeebe7 New way to keep hints for table length
Instead of using 'alimit' for keeping the size of the array and at
the same time being a hint for '#t', a table now keeps these two
values separate. The Table structure has a field 'asize' with the
size of the array, while the length hint is kept in the array itself.
That way, tables with no array part waste no space with that field.
Moreover, the space for the hint may have zero cost for small arrays,
if the array of tags plus the hint still fits in a single word.
2024-11-29 17:26:20 -03:00
Roberto Ierusalimschy
9329eeac3b Avoid an extra call to 'concretesize' in 'resizearray' 2024-11-27 18:37:29 -03:00
Roberto Ierusalimschy
682efe2678 Change to macro 'LUAI_TRY'
The call to 'f' is done by the macro, to give it more flexibility.
2024-11-25 15:47:08 -03:00
Roberto Ierusalimschy
50c7c915ee Debug information about extra arguments from __call
'debug.getinfo' can return number of extra arguments added to a call by
a chain of __call metavalues. That information is being used to improve
error messages about errors in these extra arguments.
2024-11-19 14:09:18 -03:00
Roberto Ierusalimschy
b117bdb344 Counter for length of chains of __call metamethods
This counter will allow (in a later commit) error messages to correct
argument numbers in functions called through __call metamethods.
2024-11-16 12:00:28 -03:00
Roberto Ierusalimschy
f12ce4029d More integration of 'nresults' into 'callstatus' 2024-11-15 15:25:11 -03:00
Roberto Ierusalimschy
a4762b6ffe 'objsize' returns 'l_mem'
Sums of size_t may not fit in a size_t.
2024-11-15 12:04:53 -03:00
Roberto Ierusalimschy
d4247befa1 New macro 'assert_code'
It allows code that is only used by assertions but that are not
assertions (e.g., declaration of a variable used in a later assertion).
2024-11-15 11:57:18 -03:00
Roberto Ierusalimschy
ee6a4cd1ec Ease slightly making Lua with C89 2024-11-15 11:43:32 -03:00
Roberto Ierusalimschy
8a4419b119 Dummy node has a non-nil key
That allows 'getfreepos' to treat it like a regular hash part that has
a deleted entry.
2024-11-15 10:48:52 -03:00
Roberto Ierusalimschy
9a91fe1640 Add extra size when resizing tables with deleted keys
Without this extra space, sequences of insertions/deletions (and
some other uses) can have unpexpected low performances.  See the
added tests for an example, and *Mathematical Models to Analyze Lua
Hybrid Tables and Why They Need a Fix* (Martínez, Nicaud, Rotondo;
arXiv:2208.13602v2) for detais.
2024-11-14 11:48:25 -03:00
Roberto Ierusalimschy
2491b87c10 New rule for size of array part
Array part needs 1/3 of its elements filled, instead of 1/2.
Array entries use ~1/3 the memory of hash entries, so this new rule
still ensures that array parts do not use more memory than keeping
the values in the hash, while allowing more uses of the array part,
which is more efficient than the hash.
2024-11-13 13:37:24 -03:00
Roberto Ierusalimschy
0de8191152 New structure to count keys in a table for rehashing 2024-10-28 14:15:21 -03:00
Roberto Ierusalimschy
853311e5b1 Table rehash can resize only the hash part
If there are no integer keys outside the array part, there is no
reason to resize it, saving the time to count its elements.  Moreover,
assignments to non-integer keys will not collapse a table created with
'table.create'.
2024-10-28 10:54:36 -03:00
Roberto Ierusalimschy
25a2dac2bc Always use unsigned int for indexing table-arrays 2024-10-24 15:33:25 -03:00
Roberto Ierusalimschy
e3ce88c9e8 New function 'lua_numbertostrbuff'
It converts a Lua number to a string in a buffer, without creating
a new Lua string.
2024-10-23 17:16:17 -03:00
Roberto Ierusalimschy
5ffcd458f0 Some changes in default GC parameters 2024-10-23 17:15:06 -03:00
Roberto Ierusalimschy
9b01da97e3 Small bug in 'luaE_luaE_statesize'
Plus, function was renamed to 'luaE_threadsize'.
2024-10-21 15:30:35 -03:00
Roberto Ierusalimschy
258355734d Better support in 'ltests' for tracing the GC 2024-10-21 15:18:20 -03:00
Roberto Ierusalimschy
d0815046d0 Some adjustments in transition minor->major
Plus extra comments and other details.
2024-10-18 17:10:20 -03:00
Roberto Ierusalimschy
3d54b42d59 'objsize' broke in smaller pieces 2024-09-30 14:01:42 -03:00
Roberto Ierusalimschy
e4f418f07c Local declaration in the REPL generates a warning 2024-09-27 10:00:35 -03:00
Roberto Ierusalimschy
20d42ccaae No errors in 'luaO_pushvfstring'
Any call to 'va_start' must have a corresponding call to 'va_end';
so, functions called between them (luaO_pushvfstring in particular)
cannot raise errors.
2024-09-20 15:56:39 -03:00
Roberto Ierusalimschy
70d6975018 Towards no errors in 'luaO_pushvfstring'
Any call to 'va_start' must have a corresponding call to 'va_end';
so, functions called between them (luaO_pushvfstring in particular)
cannot raise errors.
2024-09-20 12:21:11 -03:00
Roberto Ierusalimschy
00e34375ec In 'luaO_pushvfstring', all options use 'addstr2buff' 2024-09-20 10:06:06 -03:00
Roberto Ierusalimschy
45a8f1b593 Removed 'if' left from commit ddfa1fbccfe 2024-09-20 09:43:46 -03:00
Roberto Ierusalimschy
8fac494509 Avoid Microsoft warning
> warning C4334: '<<': result of 32-bit shift implicitly converted to
> 64 bits (was 64-bit shift intended?)
2024-09-19 19:09:35 -03:00
Roberto Ierusalimschy
9b72355f99 USHRT_MAX changed to SHRT_MAX
USHRT_MAX does not fit in an 'int' in 16-bit systems.
2024-09-19 19:06:16 -03:00
Roberto Ierusalimschy
ddfa1fbccf GC back to controling pace counting bytes
Memory is the resource we want to save. Still to be reviewed again.
2024-09-19 19:02:14 -03:00
Roberto Ierusalimschy
b443145ff3 Details
Fixed comments in sort partition.
2024-09-12 11:08:11 -03:00
Roberto Ierusalimschy
4901853c11 Parameter for lua_gc/LUA_GCSTEP changed to 'size_t'
'size_t' is the common type for measuring memory. 'int' can be too
small for steps.
2024-09-10 17:05:39 -03:00
Roberto Ierusalimschy
a04e0ffdb9 Rename of fields in global state that control GC
All fields in the global state that control the pace of the garbage
collector prefixed with 'GC'.
2024-09-06 14:38:39 -03:00
Roberto Ierusalimschy
007b8c7a01 Details
Identation + comments
2024-09-06 14:35:04 -03:00
Roberto Ierusalimschy
fd0e1f530d Added option for direct correction of stack pointers
The use of a pointer (not access, only for computations) after its
deallocation is forbiden in ISO C, but seems to work fine in all
platforms we are aware of. So, using that to correct stack pointers
after a stack reallocation seems safe and is much simpler than the
current implementation (first change all pointers to offsets and
then changing the offsets back to pointers). Anyway, for now that
option is disabled.
2024-08-22 11:11:00 -03:00
Roberto Ierusalimschy
75620b45ae 'lcode.c' can use 'checklimit', too 2024-08-20 15:15:23 -03:00
Roberto Ierusalimschy
3e88b72b8e A return can have at most 254 values 2024-08-19 18:39:25 -03:00
Roberto Ierusalimschy
8b752ddf14 Bug: wrong code gen. for indices with comparisons
In function 'luaK_exp2val', used to generate code for indices: Macro
'hasjumps' does not consider the case when the whole expression is a
"jump" (a test). In all other of its uses, the surrounding code ensures
that the expression cannot be VJMP.
2024-08-17 12:47:28 -03:00
Roberto Ierusalimschy
1bf4b80f1a Floats formatted with "correct" precision
Conversion float->string ensures that, for any float f,
tonumber(tostring(f)) == f, but still avoiding noise like 1.1
converting to "1.1000000000000001".
2024-08-02 15:09:30 -03:00
Roberto Ierusalimschy
4c6afbcb01 Struct 'transferinfo' moved to "lua_State"
That reduces the size of "CallInfo". Moreover, bit CIST_HOOKED from
call status is not needed. When in a hook, 'transferinfo' is always
valid, being zero when the hook is not call/return.
2024-07-30 10:16:19 -03:00
Roberto Ierusalimschy
f2206b2abe '-Wconversion' extended to all options of Lua numbers 2024-07-27 15:13:21 -03:00
Roberto Ierusalimschy
0acd55898d Added gcc option '-Wconversion'
No warnings for standard numerical types. Still pending alternative
numerical types.
2024-07-27 13:32:59 -03:00
Roberto Ierusalimschy
15231d4fb2 'nresults' moved into 'callstatus'
That gives us more free bits in 'callstatus', for future use.
2024-07-21 14:56:59 -03:00
Roberto Ierusalimschy
f407b3c4a1 Using CIST_CLSRET instead of trick with 'nresults'
The callstatus flag CIST_CLSRET is used in all tests for the
presence of variables to be closed in C functions.
2024-07-19 17:34:22 -03:00
Roberto Ierusalimschy
a546138d15 Explicit limit for number of results in a call
The parameter 'nresults' in 'lua_call' and similar functions has a
limit of 250. It already had an undocumented (and unchecked) limit of
SHRT_MAX, but it is seldom larger than 2.
2024-07-18 14:44:40 -03:00
Roberto Ierusalimschy
cd4de92762 Maximum stack size may not fit in unsigned short
Therefore, fields ftransfer/ntransfer in lua_Debug must have type
'int'. (Maximum stack size must fit in an 'int'.) Also, this commit
adds check that maximum stack size respects size_t for size in bytes.
2024-07-16 11:33:30 -03:00