Skip to content

Commit 10e2455

Browse files
authored
dump: ensure Array eltype layout is initialized early (#37594)
Deserializing an array needs to examine the element type (tparam0) layout. Usually we know the layout of a DataType is initialized early (when present). This also ensures that the path to it is initialized (for our case where it may be inline allocated with interior pointers).
1 parent 9ffc703 commit 10e2455

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/datatype.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
9797
t->isinlinealloc = 0;
9898
t->has_concrete_subtype = 1;
9999
t->cached_by_hash = 0;
100+
t->name = NULL;
101+
t->super = NULL;
102+
t->parameters = NULL;
100103
t->layout = NULL;
101104
t->names = NULL;
102105
t->types = NULL;

src/dump.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ static jl_value_t *jl_deserialize_value(jl_serializer_state *s, jl_value_t **loc
11391139

11401140
static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_value_t **loc) JL_GC_DISABLED
11411141
{
1142+
assert(pos == backref_list.len - 1 && "nothing should have been deserialized since assigning pos");
11421143
int tag = read_uint8(s->s);
11431144
if (tag == 6 || tag == 7) {
11441145
jl_typename_t *name = (jl_typename_t*)jl_deserialize_value(s, NULL);
@@ -1154,18 +1155,17 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v
11541155
backref_list.items[pos] = dtv;
11551156
return dtv;
11561157
}
1157-
size_t size = read_int32(s->s);
1158-
uint8_t flags = read_uint8(s->s);
1159-
uint8_t memflags = read_uint8(s->s);
1160-
jl_datatype_t *dt = NULL;
1161-
if (tag == 0 || tag == 5 || tag == 10 || tag == 11 || tag == 12)
1162-
dt = jl_new_uninitialized_datatype();
1163-
else {
1158+
if (!(tag == 0 || tag == 5 || tag == 10 || tag == 11 || tag == 12)) {
11641159
assert(0 && "corrupt deserialization state");
11651160
abort();
11661161
}
1167-
assert(pos == backref_list.len - 1 && "nothing should have been deserialized since assigning pos");
1162+
jl_datatype_t *dt = jl_new_uninitialized_datatype();
11681163
backref_list.items[pos] = dt;
1164+
if (loc != NULL && loc != HT_NOTFOUND)
1165+
*loc = (jl_value_t*)dt;
1166+
size_t size = read_int32(s->s);
1167+
uint8_t flags = read_uint8(s->s);
1168+
uint8_t memflags = read_uint8(s->s);
11691169
dt->size = size;
11701170
dt->abstract = flags & 1;
11711171
dt->mutabl = (flags >> 1) & 1;
@@ -1179,11 +1179,6 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v
11791179
dt->isinlinealloc = (memflags >> 5) & 1;
11801180
dt->has_concrete_subtype = (memflags >> 6) & 1;
11811181
dt->cached_by_hash = (memflags >> 7) & 1;
1182-
dt->types = NULL;
1183-
dt->parameters = NULL;
1184-
dt->name = NULL;
1185-
dt->super = NULL;
1186-
dt->layout = NULL;
11871182
if (!dt->abstract)
11881183
dt->ninitialized = read_uint16(s->s);
11891184
else
@@ -1247,14 +1242,16 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v
12471242
return (jl_value_t*)dt;
12481243
}
12491244

1250-
static jl_value_t *jl_deserialize_value_svec(jl_serializer_state *s, uint8_t tag) JL_GC_DISABLED
1245+
static jl_value_t *jl_deserialize_value_svec(jl_serializer_state *s, uint8_t tag, jl_value_t **loc) JL_GC_DISABLED
12511246
{
12521247
size_t i, len;
12531248
if (tag == TAG_SVEC)
12541249
len = read_uint8(s->s);
12551250
else
12561251
len = read_int32(s->s);
1257-
jl_svec_t *sv = jl_alloc_svec_uninit(len);
1252+
jl_svec_t *sv = jl_alloc_svec(len);
1253+
if (loc != NULL)
1254+
*loc = (jl_value_t*)sv;
12581255
arraylist_push(&backref_list, (jl_value_t*)sv);
12591256
jl_value_t **data = jl_svec_data(sv);
12601257
for (i = 0; i < len; i++) {
@@ -1689,7 +1686,7 @@ static jl_value_t *jl_deserialize_value(jl_serializer_state *s, jl_value_t **loc
16891686
}
16901687
return (jl_value_t*)bp;
16911688
case TAG_SVEC: JL_FALLTHROUGH; case TAG_LONG_SVEC:
1692-
return jl_deserialize_value_svec(s, tag);
1689+
return jl_deserialize_value_svec(s, tag, loc);
16931690
case TAG_COMMONSYM:
16941691
return deser_symbols[read_uint8(s->s)];
16951692
case TAG_SYMBOL: JL_FALLTHROUGH; case TAG_LONG_SYMBOL:

0 commit comments

Comments
 (0)