Skip to content

Commit

Permalink
Fix autobox possibly writing to an outdated target
Browse files Browse the repository at this point in the history
Since autobox is a macro, the target argument is not evaluated at the place of
the call but in the expanded code. That happens only after allocating, so the
GC may have already moved the target frame. Avoid this by forgoing the local
variable and accessing tc->cur_frame->caller again instead as that will have
been updated.
  • Loading branch information
niner committed Jul 27, 2019
1 parent f18bfad commit 4ab1d42
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/args.c
Expand Up @@ -503,7 +503,7 @@ void MVM_args_set_result_int(MVMThreadContext *tc, MVMint64 result, MVMint32 fra
target->return_value->n64 = (MVMnum64)result;
break;
case MVM_RETURN_OBJ:
autobox(tc, target, result, int_box_type, 0, set_int, target->return_value->o);
autobox(tc, target, result, int_box_type, 0, set_int, (frameless ? tc->cur_frame : tc->cur_frame->caller)->return_value->o);
break;
default:
MVM_exception_throw_adhoc(tc, "Result return coercion from int NYI; expects type %u", target->return_type);
Expand All @@ -526,7 +526,7 @@ void MVM_args_set_result_num(MVMThreadContext *tc, MVMnum64 result, MVMint32 fra
target->return_value->i64 = (MVMint64)result;
break;
case MVM_RETURN_OBJ:
autobox(tc, target, result, num_box_type, 0, set_num, target->return_value->o);
autobox(tc, target, result, num_box_type, 0, set_num, (frameless ? tc->cur_frame : tc->cur_frame->caller)->return_value->o);
break;
default:
MVM_exception_throw_adhoc(tc, "Result return coercion from num NYI; expects type %u", target->return_type);
Expand All @@ -546,7 +546,7 @@ void MVM_args_set_result_str(MVMThreadContext *tc, MVMString *result, MVMint32 f
target->return_value->s = result;
break;
case MVM_RETURN_OBJ:
autobox(tc, target, result, str_box_type, 1, set_str, target->return_value->o);
autobox(tc, target, result, str_box_type, 1, set_str, (frameless ? tc->cur_frame : tc->cur_frame->caller)->return_value->o);
break;
default:
MVM_exception_throw_adhoc(tc, "Result return coercion from str NYI; expects type %u", target->return_type);
Expand Down

0 comments on commit 4ab1d42

Please sign in to comment.