From 4ab1d425e10f13586d43bcd32816840fff3899af Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Sat, 27 Jul 2019 13:28:19 +0200 Subject: [PATCH] Fix autobox possibly writing to an outdated target 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. --- src/core/args.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/args.c b/src/core/args.c index e29150e722..6c8d9cb4c9 100644 --- a/src/core/args.c +++ b/src/core/args.c @@ -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); @@ -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); @@ -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);