Skip to content

Commit

Permalink
Fix illegal GC-violating call to jl_subtype in static_show
Browse files Browse the repository at this point in the history
Implement custom iterative check via `->super`
  • Loading branch information
NHDaly committed Nov 13, 2020
1 parent 8f54d34 commit 2e5f22c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,19 @@ static size_t jl_static_show_x_sym_escaped(JL_STREAM *out, jl_sym_t *name) JL_NO
return n;
}

// `jl_static_show()` cannot call `jl_subtype()`, for the GC reasons
// explained in the comment on `jl_static_show_x_()`, below.
// This function checks if `vt <: Function` without triggering GC.
static int jl_static_is_function_(jl_datatype_t *vt) {

This comment has been minimized.

Copy link
@Keno

Keno Nov 13, 2020

Member

JL_NOTSAFEPOINT

while (vt != jl_any_type) {
if (vt == jl_function_type) {
return 1;
}
vt = vt->super;
}
return 0;
}

// `v` might be pointing to a field inlined in a structure therefore
// `jl_typeof(v)` may not be the same with `vt` and only `vt` should be
// used to determine the type of the value.
Expand Down Expand Up @@ -999,7 +1012,7 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
n += jl_static_show_x(out, *(jl_value_t**)v, depth);
n += jl_printf(out, ")");
}
else if (jl_function_type && jl_subtype(vt, (jl_value_t*)jl_function_type)) {
else if (jl_function_type && jl_static_is_function_(vt)) {

This comment has been minimized.

Copy link
@Keno

Keno Nov 13, 2020

Member

Just put the check for jl_function_type into jl_static_is_function_?

This comment has been minimized.

Copy link
@NHDaly

NHDaly Nov 13, 2020

Author Member

Yeah, thanks. I avoided that at first because my first implementation of jl_static_is_function_ was recursive, and i didn't want to unnecessarily duplicate the check on jl_function_type. 👍 Thanks! :)

// v is function instance (an instance of a Function type).
jl_datatype_t *dv = (jl_datatype_t*)vt;
jl_sym_t *sym = dv->name->mt->name;
Expand Down

0 comments on commit 2e5f22c

Please sign in to comment.