Stack reallocation done with a single realloc

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.
This commit is contained in:
Roberto Ierusalimschy
2022-10-31 15:06:20 -03:00
parent 413a393e62
commit ee645472eb
2 changed files with 52 additions and 22 deletions

View File

@@ -158,8 +158,13 @@ typedef union StackValue {
typedef StackValue *StkId;
/*
** When reallocating the stack, change all pointers to the stack into
** proper offsets.
*/
typedef union {
StkId p; /* actual pointer */
ptrdiff_t offset; /* used while the stack is being reallocated */
} StkIdRel;
@@ -626,6 +631,7 @@ typedef struct UpVal {
lu_byte tbc; /* true if it represents a to-be-closed variable */
union {
TValue *p; /* points to stack or to its own value */
ptrdiff_t offset; /* used while the stack is being reallocated */
} v;
union {
struct { /* (when open) */