Skip to content

Commit 7605d68

Browse files
committed
Revert "refactor: make get_local_variable_ptr accept "rb_env_t *""
This reverts commit 6d75599. Updating env was actually needed in local_variable_set. Alan Wu pointed this out to me.
1 parent a27758a commit 7605d68

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

proc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,9 @@ bind_eval(int argc, VALUE *argv, VALUE bindval)
404404
}
405405

406406
static const VALUE *
407-
get_local_variable_ptr(const rb_env_t *env, ID lid)
407+
get_local_variable_ptr(const rb_env_t **envp, ID lid)
408408
{
409+
const rb_env_t *env = *envp;
409410
do {
410411
if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
411412
if (VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_ISOLATED)) {
@@ -429,17 +430,20 @@ get_local_variable_ptr(const rb_env_t *env, ID lid)
429430
}
430431
}
431432

433+
*envp = env;
432434
unsigned int last_lvar = env->env_size+VM_ENV_INDEX_LAST_LVAR
433435
- 1 /* errinfo */;
434436
return &env->env[last_lvar - (local_table_size - i)];
435437
}
436438
}
437439
}
438440
else {
441+
*envp = NULL;
439442
return NULL;
440443
}
441444
} while ((env = rb_vm_env_prev_env(env)) != NULL);
442445

446+
*envp = NULL;
443447
return NULL;
444448
}
445449

@@ -539,7 +543,7 @@ bind_local_variable_get(VALUE bindval, VALUE sym)
539543
GetBindingPtr(bindval, bind);
540544

541545
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
542-
if ((ptr = get_local_variable_ptr(env, lid)) != NULL) {
546+
if ((ptr = get_local_variable_ptr(&env, lid)) != NULL) {
543547
return *ptr;
544548
}
545549

@@ -591,7 +595,7 @@ bind_local_variable_set(VALUE bindval, VALUE sym, VALUE val)
591595

592596
GetBindingPtr(bindval, bind);
593597
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
594-
if ((ptr = get_local_variable_ptr(env, lid)) == NULL) {
598+
if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
595599
/* not found. create new env */
596600
ptr = rb_binding_add_dynavars(bindval, bind, 1, &lid);
597601
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
@@ -634,7 +638,7 @@ bind_local_variable_defined_p(VALUE bindval, VALUE sym)
634638

635639
GetBindingPtr(bindval, bind);
636640
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
637-
return RBOOL(get_local_variable_ptr(env, lid));
641+
return RBOOL(get_local_variable_ptr(&env, lid));
638642
}
639643

640644
/*

0 commit comments

Comments
 (0)