Skip to content

Commit

Permalink
Move instance initialization into jl_uninitialized_datatype
Browse files Browse the repository at this point in the history
Otherwise it's illegal to hold onto this object without having
set ->instance, which is just asking for crashes. Fixes #36649.

(cherry picked from commit d778a3d)
  • Loading branch information
Keno authored and JeffBezanson committed Jul 21, 2020
1 parent 73da74e commit 8ac1a3a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
t->has_concrete_subtype = 1;
t->layout = NULL;
t->names = NULL;
t->types = NULL;
t->instance = NULL;
return t;
}

Expand Down Expand Up @@ -553,7 +555,6 @@ JL_DLLEXPORT jl_datatype_t *jl_new_datatype(
t->abstract = abstract;
t->mutabl = mutabl;
t->ninitialized = ninitialized;
t->instance = NULL;
t->size = 0;

t->name = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,6 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v
assert(pos == backref_list.len - 1 && "nothing should have been deserialized since assigning pos");
backref_list.items[pos] = dt;
dt->size = size;
dt->instance = NULL;
dt->abstract = flags & 1;
dt->mutabl = (flags >> 1) & 1;
int has_layout = (flags >> 2) & 1;
Expand Down
6 changes: 0 additions & 6 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,6 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value
}
ndt->mutabl = dt->mutabl;
ndt->abstract = dt->abstract;
ndt->instance = NULL;
ndt->size = 0;
jl_precompute_memoized_dt(ndt, cacheable);
if (istuple)
Expand Down Expand Up @@ -1771,7 +1770,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_any_type, jl_any_type, jl_any_type, jl_any_type,
jl_any_type, jl_any_type, jl_any_type, jl_any_type,
jl_any_type);
jl_datatype_type->instance = NULL;
jl_datatype_type->abstract = 0;
// NOTE: types are not actually mutable, but we want to ensure they are heap-allocated with stable addresses
jl_datatype_type->mutabl = 1;
Expand All @@ -1790,7 +1788,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_typename_type->types = jl_svec(9, jl_symbol_type, jl_any_type, jl_simplevector_type,
jl_type_type, jl_simplevector_type, jl_simplevector_type,
jl_any_type, jl_any_type, jl_any_type);
jl_typename_type->instance = NULL;
jl_typename_type->abstract = 0;
jl_typename_type->mutabl = 1;
jl_typename_type->ninitialized = 2;
Expand All @@ -1809,7 +1806,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_any_type, jl_any_type/*module*/,
jl_any_type/*any vector*/, jl_any_type/*long*/, jl_any_type/*int32*/,
jl_any_type/*uint8*/, jl_any_type/*uint8*/);
jl_methtable_type->instance = NULL;
jl_methtable_type->abstract = 0;
jl_methtable_type->mutabl = 1;
jl_methtable_type->ninitialized = 4;
Expand All @@ -1822,7 +1818,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_symbol_type->parameters = jl_emptysvec;
jl_symbol_type->name->names = jl_emptysvec;
jl_symbol_type->types = jl_emptysvec;
jl_symbol_type->instance = NULL;
jl_symbol_type->size = 0;
jl_symbol_type->abstract = 0;
jl_symbol_type->mutabl = 1;
Expand All @@ -1836,7 +1831,6 @@ void jl_init_types(void) JL_GC_DISABLED
jl_simplevector_type->parameters = jl_emptysvec;
jl_simplevector_type->name->names = jl_emptysvec;
jl_simplevector_type->types = jl_emptysvec;
jl_simplevector_type->instance = NULL;
jl_simplevector_type->abstract = 0;
jl_simplevector_type->mutabl = 1;
jl_simplevector_type->ninitialized = 0;
Expand Down

0 comments on commit 8ac1a3a

Please sign in to comment.