aboutsummaryrefslogtreecommitdiff
path: root/lfunc.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* '__close' gets no error object if there is no errorRoberto Ierusalimschy2025-02-281-12/+20
| | | | | Instead of receiving nil as a second argument, __close metamethods are called with just one argument when there are no errors.
* New type 'TStatus' for thread status/error codesRoberto Ierusalimschy2025-01-301-2/+3
|
* 'objsize' returns 'l_mem'Roberto Ierusalimschy2024-11-151-5/+5
| | | | Sums of size_t may not fit in a size_t.
* 'objsize' broke in smaller piecesRoberto Ierusalimschy2024-09-301-0/+15
|
* Added gcc option '-Wconversion'Roberto Ierusalimschy2024-07-271-7/+7
| | | | | No warnings for standard numerical types. Still pending alternative numerical types.
* Fixed buffers reuse absolute line informationRoberto Ierusalimschy2023-12-271-1/+1
|
* Added suport for Fixed BuffersRoberto Ierusalimschy2023-09-051-2/+4
| | | | | A fixed buffer keeps a binary chunk "forever", so that the program does not need to copy some of its parts when loading it.
* Field 'Proto.is_vararg' uses only one bitRoberto Ierusalimschy2023-08-301-1/+1
| | | | So that the other bits can be used for other purposes.
* Removed unused field 'UpVal.tbc'Roberto Ierusalimschy2022-11-081-3/+2
|
* Stack indices changed to union'sRoberto Ierusalimschy2022-10-291-21/+21
| | | | | That will allow to change pointers to offsets while reallocating the stack.
* Better documentation for 'multires' expressionsRoberto Ierusalimschy2022-08-191-1/+1
| | | | | | Manual has a new section explaining multires expressions, lists of expressions, and adjustments. This commit also corrects some comments in the code.
* Bug: 'lua_settop' may use an invalid pointer to stackRoberto Ierusalimschy2022-05-251-2/+3
|
* New implementation for 'tbclist'Roberto Ierusalimschy2021-03-101-11/+29
| | | | | | | | | | | | | | - Fixes a bug, by removing dummy nodes together with the node itself. (The previous implementation could leave dummy nodes in frames which otherwise had no tbc variables, and therefore would not close variables; that could leave 'tbclist' pointing higher than 'top', which could dangle if the stack shrank.) - Computes MAXDELTA based on the type of delta, to ease changing its type if needed. - Instead of 'isdummy', uses 'delta==0' to signal dummy nodes. (Dummy nodes always have MAXDELTA for their real delta.)
* New implementation for to-be-closed variablesRoberto Ierusalimschy2021-02-091-32/+34
| | | | | | | | 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-0/+2
| | | | Long time without using HARDSTACKTESTS...
* Simpler handling of errors when creating tbc variablesRoberto Ierusalimschy2021-01-191-21/+16
| | | | | | 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 inside '__close' metamethodsRoberto Ierusalimschy2021-01-131-8/+12
| | | | | | | 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.
* No need to recheck close method before calling itRoberto Ierusalimschy2020-12-291-25/+19
| | | | | | | | A to-be-closed variable is constant and it must have a close metamethod when it is created. A program has to go out of its way (e.g., by changing the variable's metamethod) to invalidate that check. So, it is not worth to test that again. If the program tampers with the metamethod, Lua will raise a regular error when attempting to call it.
* Cleaner handling of errors in '__close' metamethodsRoberto Ierusalimschy2020-12-281-53/+22
| | | | | Instead of protecting each individual metamethod call, protect the entire call to 'luaF_close'.
* Report last error in closing methodsRoberto Ierusalimschy2020-12-221-7/+3
| | | | | When there are multiple errors around closing methods, report the last error instead of the original.
* Upvalues removed from 'openupval' before being closedRoberto Ierusalimschy2020-12-211-8/+22
| | | | | | | Undo commit c220b0a5d0: '__close' is not called again in case of errors. (Upvalue is removed from the list before the call.) The common error that justified that change was C stack overflows, which are much rarer with the stackless implementation.
* DetailsRoberto Ierusalimschy2020-10-121-1/+1
| | | | | | | - 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
* Small changes in macros that change GC colorsRoberto Ierusalimschy2020-08-131-1/+1
| | | | | | | | | | | | | - 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.)
* All objects are kept 'new' in incremental GCRoberto Ierusalimschy2020-07-271-2/+3
| | | | | | 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.
* Clearer distinction between types and tagsRoberto Ierusalimschy2020-01-311-5/+5
| | | | | LUA_T* represents only types; tags (types + Variants) are represented by LUA_V* constants.
* Comments (mosty typos)Roberto Ierusalimschy2019-12-301-1/+1
|
* DetailsRoberto Ierusalimschy2019-11-181-7/+7
|
* Supressed errors in '__close' generate warningsRoberto Ierusalimschy2019-08-161-1/+5
|
* To-be-closed variables must be closed on initializationRoberto Ierusalimschy2019-07-311-17/+32
| | | | | | | | | When initializing a to-be-closed variable, check whether it has a '__close' metamethod (or is a false value) and raise an error if if it hasn't. This produces more accurate error messages. (The check before closing still need to be done: in the C API, the value is not constant; and the object may lose its '__close' metamethod during the block.)
* Do not collect open upvaluesRoberto Ierusalimschy2019-07-221-8/+7
| | | | | | | | Open upvalues are kept alive together with their corresponding stack. This change makes a simpler and safer fix to the issue in commit 440a5ee78c8, about upvalues in the list of open upvalues being collected while others are being created. (That previous fix may not be correct.)
* Fixed bug for emergency collection in upvalue creationRoberto Ierusalimschy2019-07-191-6/+8
| | | | | | | | | | | When creating an upvalue, an emergency collection can collect the previous upvalue where the new one would be linked. The following code can trigger the bug, using valgrind on Lua compiled with the -DHARDMEMTESTS option: local x; local y (function () return y end)(); (function () return x end)()
* Tag LUA_TUPVALTBC replaced by a flagRoberto Ierusalimschy2019-07-191-7/+8
| | | | | It is simpler to signal a to-be-closed upvalue with a boolean flag, instead of using a different tag.
* Small bug with stack reallocationRoberto Ierusalimschy2019-07-181-4/+3
| | | | | | | | OP_RETURN must update trap before updating stack. (Bug detected with -DHARDSTACKTESTS). Also, in 'luaF_close', do not create a variable with 'uplevel(uv)', as the stack may change and invalidate this value. (This is not a bug, but could become one if 'upl' was used again.)
* '__close' method may be called again in case of errorRoberto Ierusalimschy2019-07-161-10/+12
| | | | | | | | | An error in a closing method may be caused by a lack of resources, such as memory or stack space, and the error may free enough resources (by unwinding the stack) to allow the method to work if called again. If the closing method is already running after some error (including its own), it is not called again.
* Avoid setting the stack top below upvalues to be closedRoberto Ierusalimschy2019-07-161-0/+1
| | | | | | When leaving a scope, the new stack top should be set only after closing any upvalue, to avoid manipulating values in an "invalid" part of the stack.
* Multiple errors in '__toclose' report the first oneRoberto Ierusalimschy2019-06-051-3/+6
| | | | | | | | When there are multiple errors when closing objects, the error reported by the protected call is the first one, for two reasons: First, other errors may be caused by this one; second, the first error is handled in the original execution context, and therefore has the full traceback.
* DetailsRoberto Ierusalimschy2019-03-131-1/+2
| | | | | | | | | | Several small improvements (code style, warnings, comments, more tests), in particular: - 'lua_topointer' extended to handle strings - raises an error in 'string.format("%10q")' ('%q' with modifiers) - in the manual for 'string.format', the term "option" replaced by "conversion specifier" (the term used by the C standard)
* No more to-be-closed functionsRoberto Ierusalimschy2019-01-041-14/+10
| | | | | | | | | | | | | | | | | | | To-be-closed variables must contain objects with '__toclose' metamethods (or nil). Functions were removed for several reasons: * Functions interact badly with sandboxes. If a sandbox raises an error to interrupt a script, a to-be-closed function still can hijack control and continue running arbitrary sandboxed code. * Functions interact badly with coroutines. If a coroutine yields and is never resumed again, its to-be-closed functions will never run. To-be-closed objects, on the other hand, will still be closed, provided they have appropriate finalizers. * If you really need a function, it is easy to create a dummy object to run that function in its '__toclose' metamethod. This comit also adds closing of variables in case of panic.
* New functions 'lua_resetthread' and 'coroutine.kill'Roberto Ierusalimschy2018-12-131-8/+10
| | | | | | New functions to reset/kill a thread/coroutine, mainly (only?) to close any pending to-be-closed variable. ('lua_resetthread' also allows a thread to be reused...)
* A to-be-closed variable must have a closable value (or be nil)Roberto Ierusalimschy2018-11-291-0/+6
| | | | | | | It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.)
* Removed internal cache for closuresRoberto Ierusalimschy2018-11-011-2/+0
| | | | | | | | | | | | | | | | | | | The mechanism of "caching the last closure created for a prototype to try to reuse it the next time a closure for that prototype is created" was removed. There are several reasons: - It is hard to find a natural example where this cache has a measurable impact on performance. - Programmers already perceive closure creation as something slow, so they tend to avoid it inside hot paths. (Any case where the cache could reuse a closure can be rewritten predefining the closure in some variable and using that variable.) - The implementation was somewhat complex, due to a bad interaction with the generational collector. (Typically, new closures are new, while prototypes are old. So, the cache breaks the invariant that old objects should not point to new ones.)
* Closing methods should not interfere with returning valuesRoberto Ierusalimschy2018-10-251-31/+33
| | | | | | | | | | | | A closing method cannot be called in its own stack slot, as there may be returning values in the stack after that slot, and the call would corrupt those values. Instead, the closing method must be copied to the top of the stack to be called. Moreover, even when a function returns no value, its return istruction still has to have its position (which will set the stack top) after the local variables, otherwise a closing method might corrupt another not-yet-called closing method.
* Handling of memory errors when creating to-be-closed upvaluesRoberto Ierusalimschy2018-10-181-32/+94
|
* First "complete" implementation of to-be-closed variablesRoberto Ierusalimschy2018-10-171-3/+44
| | | | | | | Still missing: - handling of memory errors when creating upvalue (must run closing method all the same) - interaction with coroutines
* Removed extra information from RCS keyword stringsRoberto Ierusalimschy2018-08-231-1/+1
| | | | | Version numbers and dates (mostly wrong) from RCS keyword strings removed from all source files; only the file name are kept.
* new type 'StackValue' for stack elementsRoberto Ierusalimschy2017-06-291-6/+6
| | | | (we may want to put extra info there in the future)
* 'lineinfo' in prototypes saved as differences instead of absoluteRoberto Ierusalimschy2017-06-271-1/+4
| | | | | | values, so that the array can use bytes instead of ints, reducing its size. (A new array 'abslineinfo' is used when line differences do not fit in a byte.)
* bug: cannot reuse a dying upvalueRoberto Ierusalimschy2017-05-241-2/+2
|
* added 'cachemiss' field to prototype to avoid wasting time checkingRoberto Ierusalimschy2017-04-301-1/+2
| | | | hits that fail too often
* Upvalues collected like everything else (with mark-sweep) insteadRoberto Ierusalimschy2017-04-111-19/+28
| | | | of reference count (simpler and better for generational mode)