Skip to content

Commit

Permalink
Make sure the frame usecapture points at is ref'd.
Browse files Browse the repository at this point in the history
We kinda got away with not doing this before, when the cur_usecapture
could never be collected. Now they can be when a thread terminates, so
protection is essential.
  • Loading branch information
jnthn committed Mar 28, 2014
1 parent 3c6e8ad commit 7d55b5a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/6model/reprs/MVMCallCapture.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
MVM_checked_free_null(ctx->body.apc);
}
}
else {
if (ctx->body.use_mode_frame)
MVM_frame_dec_ref(tc, ctx->body.use_mode_frame);
}
}

/* Gets the storage specification for this representation. */
Expand Down
4 changes: 4 additions & 0 deletions src/6model/reprs/MVMCallCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ struct MVMCallCaptureBody {
* the frame in question. For save mode, we allocate a fresh one. */
MVMArgProcContext *apc;

/* The frame the ArgProcContext lives in, if we're in use mode. This
* ensures the frame stays alive long enough. */
MVMFrame *use_mode_frame;

/* The effective MVMCallsite. This may be the original one, but in the
* event of flattening will describe the flattened outcome. */
MVMCallsite *effective_callsite;
Expand Down
7 changes: 5 additions & 2 deletions src/core/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ MVMCallsite * MVM_args_proc_to_callsite(MVMThreadContext *tc, MVMArgProcContext
/* Puts the args passed to the specified frame into the current use_capture. */
MVMObject * MVM_args_use_capture(MVMThreadContext *tc, MVMFrame *f) {
MVMCallCapture *capture = (MVMCallCapture *)tc->cur_usecapture;
capture->body.mode = MVM_CALL_CAPTURE_MODE_USE;
capture->body.apc = &f->params;
if (capture->body.use_mode_frame)
MVM_frame_dec_ref(tc, capture->body.use_mode_frame);
capture->body.mode = MVM_CALL_CAPTURE_MODE_USE;
capture->body.use_mode_frame = MVM_frame_inc_ref(tc, f);
capture->body.apc = &f->params;
capture->body.effective_callsite = MVM_args_proc_to_callsite(tc, &f->params);
return tc->cur_usecapture;
}
Expand Down

0 comments on commit 7d55b5a

Please sign in to comment.