Skip to content

Commit 2c18e99

Browse files
maleadtKristofferC
authored andcommitted
Don't read trailing datatype layout bytes when first_ptr==-1.
1 parent 0450748 commit 2c18e99

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/dump.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,10 @@ static void jl_serialize_datatype(jl_serializer_state *s, jl_datatype_t *dt) JL_
403403
uint32_t np = dt->layout->npointers;
404404
size_t fieldsize = jl_fielddesc_size(dt->layout->fielddesc_type);
405405
ios_write(s->s, (const char*)dt->layout, sizeof(*dt->layout));
406-
ios_write(s->s, (const char*)(dt->layout + 1), nf * fieldsize + (np << dt->layout->fielddesc_type));
406+
size_t fldsize = nf * fieldsize;
407+
if (dt->layout->first_ptr != -1)
408+
fldsize += np << dt->layout->fielddesc_type;
409+
ios_write(s->s, (const char*)(dt->layout + 1), fldsize);
407410
}
408411
}
409412

@@ -1484,11 +1487,14 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v
14841487
uint32_t np = buffer.npointers;
14851488
uint8_t fielddesc_type = buffer.fielddesc_type;
14861489
size_t fielddesc_size = nf > 0 ? jl_fielddesc_size(fielddesc_type) : 0;
1490+
size_t fldsize = nf * fielddesc_size;
1491+
if (buffer.first_ptr != -1)
1492+
fldsize += np << fielddesc_type;
14871493
jl_datatype_layout_t *layout = (jl_datatype_layout_t*)jl_gc_perm_alloc(
1488-
sizeof(jl_datatype_layout_t) + nf * fielddesc_size + (np << fielddesc_type),
1494+
sizeof(jl_datatype_layout_t) + fldsize,
14891495
0, 4, 0);
14901496
*layout = buffer;
1491-
ios_read(s->s, (char*)(layout + 1), nf * fielddesc_size + (np << fielddesc_type));
1497+
ios_read(s->s, (char*)(layout + 1), fldsize);
14921498
dt->layout = layout;
14931499
}
14941500
}

src/staticdata.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,9 @@ static void jl_write_values(jl_serializer_state *s)
871871
size_t np = dt->layout->npointers;
872872
size_t fieldsize = jl_fielddesc_size(dt->layout->fielddesc_type);
873873
char *flddesc = (char*)dt->layout;
874-
size_t fldsize = sizeof(jl_datatype_layout_t) + nf * fieldsize + (np << dt->layout->fielddesc_type);
874+
size_t fldsize = sizeof(jl_datatype_layout_t) + nf * fieldsize;
875+
if (dt->layout->first_ptr != -1)
876+
fldsize += np << dt->layout->fielddesc_type;
875877
uintptr_t layout = LLT_ALIGN(ios_pos(s->const_data), sizeof(void*));
876878
write_padding(s->const_data, layout - ios_pos(s->const_data)); // realign stream
877879
newdt->layout = NULL; // relocation offset

0 commit comments

Comments
 (0)