Berry report bug fix #106

This commit is contained in:
Stephan Hadinger 2021-06-15 20:53:49 +02:00
parent bd87afeabf
commit ec33c19dbe
2 changed files with 24 additions and 6 deletions

View File

@ -54,17 +54,22 @@ void be_initupvals(bvm *vm, bclosure *cl)
void be_upvals_close(bvm *vm, bvalue *level)
{
bupval *node = vm->upvalist, *next;
while (node && node->value >= level) {
bupval **prev = &vm->upvalist;
while (node) {
next = node->u.next;
if (!node->refcnt) {
be_free(vm, node, sizeof(bupval));
if (node->value >= level) {
if (!node->refcnt) {
be_free(vm, node, sizeof(bupval));
} else {
node->u.value = *node->value; /* move value to upvalue slot */
node->value = &node->u.value;
}
*prev = next; /* remove from linked list */
} else {
node->u.value = *node->value; /* move value to upvalue slot */
node->value = &node->u.value;
prev = &node->u.next;
}
node = next;
}
vm->upvalist = node;
}
void be_release_upvalues(bvm *vm, bclosure *cl)

View File

@ -0,0 +1,13 @@
#- test for issue #105 -#
l=[]
def tick()
var start=100
for i : 1..3
l.push(def () return [i, start] end)
end
end
tick()
assert(l[0]() == [1, 100])
assert(l[1]() == [2, 100])
assert(l[2]() == [3, 100])