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.
  • Loading branch information
Keno committed Jul 14, 2020
1 parent 23c9e0f commit d778a3d
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 @@ -98,6 +98,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 @@ -554,7 +556,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 @@ -1179,7 +1179,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 @@ -1416,7 +1416,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 @@ -1912,7 +1911,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 @@ -1931,7 +1929,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 @@ -1951,7 +1948,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 = 5;
Expand All @@ -1964,7 +1960,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 @@ -1978,7 +1973,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 d778a3d

Please sign in to comment.