aboutsummaryrefslogtreecommitdiff
path: root/ldo.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Bug: Missing error status in panic functionv5.4Roberto Ierusalimschy2025-01-161-0/+1
| | | | | 'luaD_throw' may call 'luaE_resetthread', which returns an error code but clears 'L->status'; so, 'luaD_throw' should set that status again.
* Bug: Yielding in a hook stops in the wrong instructionRoberto Ierusalimschy2024-01-111-0/+4
| | | | | | | | Yielding in a hook must decrease the program counter, because it already counted an instruction that, in the end, was not executed. However, that decrement should be done only when about to restart the thread. Otherwise, inspecting the thread with the debug library shows it one instruction behind of where it really is.
* Several functions turned 'static'Roberto Ierusalimschy2023-05-221-3/+3
| | | | | Several functions that were already being used only inside their own file have been declared as 'static'.
* Corrected support for 16-bit systemsRoberto Ierusalimschy2023-03-091-9/+5
| | | | | We still need access to a 16-bit system to correctly test these changes.
* Stack reallocation done with a single reallocRoberto Ierusalimschy2022-10-311-22/+46
| | | | | | | To avoid the need of both the old and the new stack addresses valid at the same time, to correct the pointers to the stack, these pointers are changed to offsets before the reallocation and then changed back to pointers after the reallocation.
* Stack indices changed to union'sRoberto Ierusalimschy2022-10-291-63/+62
| | | | | That will allow to change pointers to offsets while reallocating the stack.
* More checks and documentation for uses of EXTRA_STACKRoberto Ierusalimschy2022-05-261-1/+6
|
* Bug: 'lua_settop' may use an invalid pointer to stackRoberto Ierusalimschy2022-05-251-6/+6
|
* 'lua_checkstack' doesn't need to check stack overflowRoberto Ierusalimschy2022-05-231-8/+7
| | | | | | 'luaD_growstack' already checks that. This commit also fixes an internal bug in 'luaD_growstack': a large 'n' could cause an arithmetic overflow when computing 'needed'.
* DetailsRoberto Ierusalimschy2022-04-011-2/+6
| | | | | Comments + manual + identation + asserts about stack limits that were not allowing the use of the full stack
* Bug: finalizers can be called with an invalid stackRoberto Ierusalimschy2021-12-151-1/+1
| | | | | The call to 'checkstackGC' can run finalizers, which will find an inconsistent CallInfo, as 'ci' is half updated at the point of call.
* Corrected bug in 'luaD_tryfuncTM'Roberto Ierusalimschy2021-11-161-1/+2
| | | | | | The pointer to the metamethod can be invalidated by a finalizer that can run during a GC in 'checkstackGCp'. (This commit also fixes a detail in the manual.) Bug introduced in commit 91673a8ec.
* Bug: C stack overflow with coroutinesRoberto Ierusalimschy2021-11-031-2/+4
| | | | | | 'coroutine.resume' did not increment counter of C calls when continuing execution after a protected error (that is, while running 'precover').
* More uniform implementation for tail callsRoberto Ierusalimschy2021-10-291-29/+52
| | | | | | | | | | | 'luaD_pretailcall' mimics 'luaD_precall', handling call metamethods and calling C functions directly. That makes the code in the interpreter loop simpler. This commit also goes back to emulating the tail call in 'luaD_precall' with a goto, as C compilers may not do proper tail calls and the C stack can overflow much sooner than the Lua stack (which grows as the metamethod is added to it).
* Removed goto's in 'luaD_precall'Roberto Ierusalimschy2021-10-181-24/+27
| | | | (plus a detail in lauxlib.h.)
* Using 'inline' in some functionsRoberto Ierusalimschy2021-09-151-4/+4
| | | | | According to ISO C, "making a function an inline function suggests that calls to the function be as fast as possible." (Not available in C89.)
* 'luaD_tryfuncTM' checks stack space by itselfRoberto Ierusalimschy2021-08-181-3/+4
|
* Undo simplification of tail calls (commit 901d760)Roberto Ierusalimschy2021-08-181-34/+32
| | | | Not that simpler and slower.
* Simplification in the parameters of 'luaD_precall'Roberto Ierusalimschy2021-06-301-10/+9
| | | | | | The parameters 'nresults' and 'delta1', in 'luaD_precall', were never meaningful simultaneously. So, they were combined in a single parameter 'retdel'.
* C functions can be tail called, tooRoberto Ierusalimschy2021-06-141-18/+25
| | | | | A tail call to a C function can have the behavior of a "real" tail call, reusing the stack frame of the caller.
* Simpler implementation for tail callsRoberto Ierusalimschy2021-06-111-24/+24
| | | | | Tail calls handled by 'luaD_precall', like regular calls, to avoid code duplication.
* Stack reallocation done in two phasesRoberto Ierusalimschy2021-02-271-7/+21
| | | | | | | | | $he stack reallocation is done in two steps (allocation + free) because the correction of the pointers pointing into the stack must be done while both addresses (the old stack and the new one) are valid. In ISO C, any pointer use after the pointer has been deallocated is undefined behavior. The compiler option '-fsanitize=pointer-subtract' (plus what it needs to work) complained about the old implementation.
* Broadening the use of branch hintsRoberto Ierusalimschy2021-02-241-12/+12
| | | | | | More uses of macros 'likely'/'unlikely' (renamed to 'l_likely'/'l_unlikely'), both in range (extended to the libraries) and in scope (extended to hooks, stack growth).
* '__close' methods can yield in the return of a C functionRoberto Ierusalimschy2021-02-121-29/+43
| | | | | | | When, inside a coroutine, a C function with to-be-closed slots return, the corresponding metamethods can yield. ('__close' metamethods called through 'lua_closeslot' still cannot yield, as there is no continuation to go when resuming.)
* New implementation for to-be-closed variablesRoberto Ierusalimschy2021-02-091-1/+1
| | | | | | | | To-be-closed variables are linked in their own list, embedded into the stack elements. (Due to alignment, this information does not change the size of the stack elements in most architectures.) This new list does not produce garbage and avoids memory errors when creating tbc variables.
* Fixed some bugs around stack reallocationRoberto Ierusalimschy2021-02-051-1/+1
| | | | Long time without using HARDSTACKTESTS...
* Optimizations for line hookRoberto Ierusalimschy2021-01-281-4/+5
| | | | | The function 'changedline' tries harder to avoid calling 'luaG_getfuncline' plus small changes in the use of 'L->oldpc'.
* Small improvements in hooksRoberto Ierusalimschy2021-01-261-9/+8
| | | | | | | | | | - 'L->top' is set once in 'luaD_hook', instead of being set in 'luaD_hookcall' and 'rethook'; - resume discard arguments when returning after an yield inside a hook (arguments may interfere with the coroutine stack); - yield inside a hook asserts it has no arguments.
* Janitorial workRoberto Ierusalimschy2021-01-251-24/+31
| | | | Comments, code details, identation.
* Correct order of return hooks vs. close metamethodsRoberto Ierusalimschy2021-01-211-9/+15
| | | | | | 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.
* Simpler handling of errors when creating tbc variablesRoberto Ierusalimschy2021-01-191-0/+1
| | | | | | 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.
* Allow yields in '__close' metamethods ater errorsRoberto Ierusalimschy2021-01-181-60/+67
| | | | | | Completes commit b07fc10e91a. '__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.
* Allow yields inside '__close' metamethodsRoberto Ierusalimschy2021-01-131-3/+3
| | | | | | | 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.
* Handles '__close' errors in coroutines in "coroutine style"Roberto Ierusalimschy2020-12-301-20/+46
| | | | | Errors in '__close' metamethods in coroutines are handled by the same logic that handles other errors, through 'recover'.
* Better error messages for calling non-callable objectsRoberto Ierusalimschy2020-12-291-1/+1
| | | | | | | 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.
* Reset thread before panickingRoberto Ierusalimschy2020-12-281-5/+1
| | | | | Before panicking, it is simpler to reset the thread instead of closing its variables and adjust the top manually.
* Cleaner handling of errors in '__close' metamethodsRoberto Ierusalimschy2020-12-281-12/+47
| | | | | Instead of protecting each individual metamethod call, protect the entire call to 'luaF_close'.
* Bug when growing a stackRoberto Ierusalimschy2020-11-081-1/+1
| | | | | | 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.)
* DetailsRoberto Ierusalimschy2020-10-301-8/+8
| | | | | | - small corrections in the manual - ldo.c: 'docall' -> 'ccall' ('docall' already used in 'lua.c') - comments
* 'recover' finish of 'luaD_pcall' should follow the originalRoberto Ierusalimschy2020-10-121-3/+3
|
* No more field 'lua_State.stacksize'Roberto Ierusalimschy2020-10-121-10/+9
| | | | | | 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.
* Avoid shrinking stacks to oftenRoberto Ierusalimschy2020-10-121-16/+38
| | | | | | 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'.
* Correct handling of 'luaV_execute' invocationsRoberto Ierusalimschy2020-10-121-11/+14
| | | | | | | | | 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.)
* Revision of stackless implementationRoberto Ierusalimschy2020-10-121-26/+26
| | | | | | - more organized handling of 'nCcalls' - comments - deprecation of 'setcstacklimit'
* Back to a stackless implementationRoberto Ierusalimschy2020-10-121-20/+31
| | | | | | | | | | | | | 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.
* Fixed bug: 'luaD_callnoyield' called twice in a rowRoberto Ierusalimschy2020-07-171-5/+4
| | | | | | | | | | | 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.)
* Fixed bug: invalid 'oldpc' when returning to a functionRoberto Ierusalimschy2020-07-171-3/+3
| | | | | | | | | | 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.
* Fixed bug: wrong stack limit when entering a coroutineRoberto Ierusalimschy2020-07-131-1/+1
| | | | | | When entering a coroutine, the computation of nCcalls added 'from->nci' to correct for preallocated CallInfos, but 'nci' includes also the Callinfos already used.
* Fixed bugs of stack reallocation x GCRoberto Ierusalimschy2020-07-071-6/+7
| | | | | | | | 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.)
* Avoid any code before locks in the APIRoberto Ierusalimschy2020-07-061-1/+2
| | | | | For consistency in the C API, avoid any initializations before callling lua_lock.