Revert "refactor: make get_local_variable_ptr accept "rb_env_t *""

This reverts commit 6d75599a1aade9f8081d0691a9da1e62a5428e95.

Updating env was actually needed in local_variable_set.
Alan Wu pointed this out to me.
This commit is contained in:
Yusuke Endoh 2025-02-20 09:32:22 +09:00
parent a27758ad4e
commit 7605d68062
Notes: git 2025-02-20 01:20:23 +00:00

12
proc.c
View File

@ -404,8 +404,9 @@ bind_eval(int argc, VALUE *argv, VALUE bindval)
}
static const VALUE *
get_local_variable_ptr(const rb_env_t *env, ID lid)
get_local_variable_ptr(const rb_env_t **envp, ID lid)
{
const rb_env_t *env = *envp;
do {
if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
if (VM_ENV_FLAGS(env->ep, VM_ENV_FLAG_ISOLATED)) {
@ -429,6 +430,7 @@ get_local_variable_ptr(const rb_env_t *env, ID lid)
}
}
*envp = env;
unsigned int last_lvar = env->env_size+VM_ENV_INDEX_LAST_LVAR
- 1 /* errinfo */;
return &env->env[last_lvar - (local_table_size - i)];
@ -436,10 +438,12 @@ get_local_variable_ptr(const rb_env_t *env, ID lid)
}
}
else {
*envp = NULL;
return NULL;
}
} while ((env = rb_vm_env_prev_env(env)) != NULL);
*envp = NULL;
return NULL;
}
@ -539,7 +543,7 @@ bind_local_variable_get(VALUE bindval, VALUE sym)
GetBindingPtr(bindval, bind);
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
if ((ptr = get_local_variable_ptr(env, lid)) != NULL) {
if ((ptr = get_local_variable_ptr(&env, lid)) != NULL) {
return *ptr;
}
@ -591,7 +595,7 @@ bind_local_variable_set(VALUE bindval, VALUE sym, VALUE val)
GetBindingPtr(bindval, bind);
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
if ((ptr = get_local_variable_ptr(env, lid)) == NULL) {
if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
/* not found. create new env */
ptr = rb_binding_add_dynavars(bindval, bind, 1, &lid);
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
@ -634,7 +638,7 @@ bind_local_variable_defined_p(VALUE bindval, VALUE sym)
GetBindingPtr(bindval, bind);
env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
return RBOOL(get_local_variable_ptr(env, lid));
return RBOOL(get_local_variable_ptr(&env, lid));
}
/*