Commit Graph

5452 Commits

Author SHA1 Message Date
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
Roberto Ierusalimschy
5d8ce05b3f Back to a stackless implementation
A "with stack" implementation gains too little in performance to be
worth all the noise from C-stack overflows.

This commit is almost a sketch, to test performance. There are several
pending stuff:

- review control of C-stack overflow and error messages;
- what to do with setcstacklimit;
- review comments;
- review unroll of Lua calls.
2020-10-12 12:29:09 -03:00
Roberto Ierusalimschy
f83de8e34e Wrong cast in 'str_unpack' 2020-09-30 15:10:12 -03:00
Roberto Ierusalimschy
9f791535cd Merge branch 'master' of https://github.com/lua/lua
Adding file README.md to local repository.
2020-09-29 10:25:50 -03:00
lhf
51c29ec0c4
Create README.md 2020-09-28 14:34:44 +00:00
Roberto Ierusalimschy
fbaf040f5e Details in the manual 2020-09-25 10:49:29 -03:00
Roberto Ierusalimschy
e51564d1be Details in comments and documentation 2020-09-16 14:57:51 -03:00
Roberto Ierusalimschy
98ec799591 Detail
Code for multi-character tokens can start right after maximum char.
2020-09-15 14:29:52 -03:00
Roberto Ierusalimschy
b6888a158b New release number (5.4.1) 2020-09-15 14:27:10 -03:00
Roberto Ierusalimschy
613513d09f Better documentation for the GC of strings in the C API
Plus some other small changes.
2020-09-09 17:28:25 -03:00
Roberto Ierusalimschy
8496112a18 Better documentation for 'lctype.h'
The old documentation said that 'ltolower' only works for alphabetic
characters. However, 'l_str2d' uses it (correctly) also on dots ('.').
2020-09-03 09:52:43 -03:00
Roberto Ierusalimschy
6bc0f13505 Fixed bug of long strings in binary chunks
When "undumping" a long string, the function 'loadVector' can call the
reader function, which can run the garbage collector, which can collect
the string being read. So, the string must be anchored during the call
to 'loadVector'.
2020-08-18 14:42:11 -03:00
Roberto Ierusalimschy
8a89da07ba Better control of gray objects
Avoid turning an object to gray except at the moment it is inserted in a
gray list or in the explicit exceptional cases such as open upvalues and
fixed strings.
2020-08-17 15:38:51 -03:00
Roberto Ierusalimschy
f849885a4b Small changes in macros that change GC colors
- Macro 'gray2black' was renamed 'nw2black' (Non-White to black), as it
was already being used on objects that could be already black.

- Macros 'white2gray' and 'black2gray' were unified in 'set2gray'; no
reason to have two macros when one will do and, again, 'black2gray' was
already being used on objects that could be already gray.

Moreover, macros 'maskcolors' and 'maskgcbits' were negated to have
ones in the described bits, instead of zeros. (This naming seems more
intuitive.)
2020-08-13 15:23:21 -03:00
Roberto Ierusalimschy
f7ce7e5faa TOUCHED2 objects are not always black
This commit fixes a bug introduced in commit 9cf3299fa. TOUCHED2
objects are always black while the mutator runs, but they can become
temporarily gray inside a minor collection (e.g., if the object is a
weak table).
2020-08-13 14:31:27 -03:00
Roberto Ierusalimschy
65141832d2 Open upvalues should be gray when entering gen. mode
Open upvalues are never black; so, when entering generational mode,
they must be colored gray, not black.
2020-08-07 14:53:38 -03:00
Roberto Ierusalimschy
f13dc59416 Better tests for gray lists
Test uses an extra bit in 'marked' to mark all elements in gray lists
and then check against elements colored gray.
2020-08-07 14:45:20 -03:00
Roberto Ierusalimschy
7c3cb71fa4 Free bit 7 of GC 'marked' field
Tables were using this bit to indicate their array sizes were real
('isrealasize'), but this bit can be useful for tests. Instead, they
can use bit 7 of their 'flag' field for that purpose. (There are only
six fast-access metamethods.) This 'flag' field only exists in tables,
so this use does not affect other types.
2020-08-07 11:21:44 -03:00
Roberto Ierusalimschy
68109afcdb Detail (in asserts)
Macro 'checkconsistency' replaced by the similar 'checkliveness".
2020-08-03 16:05:10 -03:00
Roberto Ierusalimschy
9cf3299faf Threads don't need to always go to 'grayagain'
In incremental mode, threads don't need to be visited again once
visited in the atomic phase. In generational mode (where all visits
are in the atomic phase), only old threads need to be kept in the
'grayagain' list for the next cycle.
2020-08-03 14:28:13 -03:00
Roberto Ierusalimschy
b9b554e0f6 Clearer handling of gray lists when entering generational mode
When entering generational mode, all objects are old. So, the only
objects that need to be in a gray list are threads, which can be
assigned without barriers. Changes in anything else (e.g., weak
tables) will trigger barriers that, if needed, will add the object
to a gray list.
2020-08-03 13:22:57 -03:00
Roberto Ierusalimschy
0dc5deca1c Optimization in 'markold'
OLD1 objects can be potentially anywhere in the 'allgc' list (up
to 'reallyold'), but frequently they are all after 'old1' (natural
evolution of survivals) or do not exist at all (when all objects die
young). So, instead of 'markold' starts looking for them always
from the start of 'allgc', the collector keeps an extra pointer,
'firstold1', that points to the first OLD1 object in the 'allgc' list,
or is NULL if there are no OLD1 objects in that list.
2020-07-29 17:05:47 -03:00
Roberto Ierusalimschy
b4c353434f Details
The fields 'old' and 'finobjold' were renamed 'old1' and 'finobjold1',
respectively, to make clearer the main ages of their elements.
2020-07-29 11:34:08 -03:00
Roberto Ierusalimschy
71f70df327 OLD1 ages advanced by 'markold'
Objects aged OLD1 have their ages advanced by 'markold', which has to
visit them anyway. So, the GC doesn't need to "sweep" the old1 list.
2020-07-29 09:58:25 -03:00
Roberto Ierusalimschy
663f83f647 Same changes around 'correctgraylist'
Instead of adding all tables and userdata back to the 'grayagain' list
to be checked by 'correctgraylist', the collector adds only the objects
that will remain in that list (objects aged TOUCHED1). This commit
also rewrites 'correctgraylist' with a clearer logic.
2020-07-28 15:51:07 -03:00
Roberto Ierusalimschy
ae5b5ba529 Fixed bug: line hooks in stripped functions
Line-hook handling was accessing debug info. without checking whether
it was present.
2020-07-27 13:23:05 -03:00
Roberto Ierusalimschy
a585eae6e7 Fixed bug: Negation overflow in getlocal/setlocal 2020-07-27 12:01:38 -03:00
Roberto Ierusalimschy
d2c2e32e8a All objects are kept 'new' in incremental GC
Small changes to ensure that all objects are kept 'new' in incremental
GC (except for fixed strings, which are always old) and to make that
fact clearer.
2020-07-27 11:39:42 -03:00
Roberto Ierusalimschy
8c7c9ea065 Function 'printobj' in 'ltests.c' made public
It helps to have this function available for debugging.
2020-07-27 11:24:03 -03:00
Roberto Ierusalimschy
a6da1472c0 Fixed bug: barriers cannot be active during sweep
Barriers cannot be active during sweep, even in generational mode.
(Although gen. mode is not incremental, it can hit a barrier when
deleting a thread and closing its upvalues.)  The colors of objects are
being changed during sweep and, therefore, cannot be trusted.
2020-07-27 10:26:20 -03:00
Roberto Ierusalimschy
34affe7a63 Fixed bug: 'luaD_callnoyield' called twice in a row
In luaD_callnoyield, when there is a possible stack overflow, it
zeros the number of CallInfos to force a check when calling the
function. However, if the "function" is not a function, the code will
raise an error before checking the stack. Then, the error handling calls
luaD_callnoyield again and nCcalls is decremented again, crossing the
stack redzone without raising an error. (This loop can only happens
once, because the error handler must be a function.  But once is enough
to cross the redzone.)
2020-07-17 14:54:26 -03:00
Roberto Ierusalimschy
a2195644d8 Fixed bug: invalid 'oldpc' when returning to a function
The field 'L->oldpc' is not always updated when control returns to a
function; an invalid value can seg. fault when computing 'changedline'.
(One example is an error in a finalizer; control can return to
'luaV_execute' without executing 'luaD_poscall'.) Instead of trying to
fix all possible corner cases, it seems safer to be resilient to invalid
values for 'oldpc'. Valid but wrong values at most cause an extra call
to a line hook.
2020-07-17 11:01:05 -03:00
Roberto Ierusalimschy
1ecfbfa1a1 Fixed bug: invalid mode can crash 'io.popen' 2020-07-15 16:01:03 -03:00
Roberto Ierusalimschy
e1d8770f12 Fixed bug: wrong stack limit when entering a coroutine
When entering a coroutine, the computation of nCcalls added 'from->nci'
to correct for preallocated CallInfos, but 'nci' includes also the
Callinfos already used.
2020-07-13 13:39:02 -03:00
Roberto Ierusalimschy
0f1cd0eba9 Added test for fix 127e7a6c89 2020-07-13 13:37:01 -03:00
Roberto Ierusalimschy
127e7a6c89 Fixed bug of old finalized objects in the GC
When an object aged OLD1 is finalized, it is moved from the list
'finobj' to the *beginning* of the list 'allgc'. So, this part of the
list (and not only the survival list) must be visited by 'markold'.
2020-07-10 14:13:50 -03:00
Roberto Ierusalimschy
6f5bd5072d Macro LUAI_ASSERT eases turning assertions on 2020-07-08 15:51:55 -03:00
Roberto Ierusalimschy
56ec432281 Change in macro HARDMEMTESTS for testing GC
Macro HARDMEMTESTS broke in two: HARDMEMTESTS forces a full GC cycle
at every point where the GC can run. New macro EMERGENCYGCTESTS
forces an emergency collection at every memory allocation.
2020-07-08 15:36:48 -03:00
Roberto Ierusalimschy
31b8c2d438 Fixed bug of access violation in finalizers
Errors in finalizers need a valid 'pc' to produce an error message,
even if the error is not propagated. Therefore, calls to the GC (which
may call finalizers) inside luaV_execute must save the 'pc'.
2020-07-08 12:02:56 -03:00
Roberto Ierusalimschy
eb41999461 Fixed bugs of stack reallocation x GC
Macro 'checkstackGC' was doing a GC step after resizing the stack;
the GC could shrink the stack and undo the resize. Moreover, macro
'checkstackp' also does a GC step, which could remove the preallocated
CallInfo when calling a function. (Its name has been changed to
'checkstackGCp' to emphasize that it calls the GC.)
2020-07-07 18:03:48 -03:00