Skip to content

Commit

Permalink
Always restore serialization reader state after deserializing
Browse files Browse the repository at this point in the history
We already did this for other deserialization types. This extends coverage to
objects and method caches as well, so it should now be safe to deserialize
anything without losing the reader's position.
  • Loading branch information
niner committed Oct 29, 2020
1 parent af9ebff commit ffc8a26
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/6model/serialization.c
Expand Up @@ -2812,6 +2812,10 @@ static void deserialize_object(MVMThreadContext *tc, MVMSerializationReader *rea
/* Calculate location of object's table row. */
char *obj_table_row = reader->root.objects_table + i * OBJECTS_TABLE_ENTRY_SIZE;

char **orig_read_buffer = reader->cur_read_buffer;
MVMint32 *orig_read_offset = reader->cur_read_offset;
char **orig_read_end = reader->cur_read_end;

/* Set current read buffer to the correct thing. */
reader->cur_read_buffer = &(reader->root.objects_data);
reader->cur_read_offset = &(reader->objects_data_offset);
Expand All @@ -2826,6 +2830,10 @@ static void deserialize_object(MVMThreadContext *tc, MVMSerializationReader *rea
fail_deserialize(tc, NULL, reader, "Missing deserialize REPR function for %s (%s)",
REPR(obj)->name, MVM_6model_get_debug_name(tc, obj));
reader->current_object = NULL;

reader->cur_read_buffer = orig_read_buffer;
reader->cur_read_offset = orig_read_offset;
reader->cur_read_end = orig_read_end;
}
}

Expand Down Expand Up @@ -3018,6 +3026,10 @@ void MVM_serialization_finish_deserialize_method_cache(MVMThreadContext *tc, MVM
if (st->method_cache_sc) {
MVMObject *cache;

char **orig_read_buffer = sr->cur_read_buffer;
MVMint32 *orig_read_offset = sr->cur_read_offset;
char **orig_read_end = sr->cur_read_end;

/* Set reader's position. */
sr->stables_data_offset = st->method_cache_offset;
sr->cur_read_buffer = &(sr->root.stables_data);
Expand All @@ -3039,6 +3051,10 @@ void MVM_serialization_finish_deserialize_method_cache(MVMThreadContext *tc, MVM
MVM_gc_allocate_gen2_default_clear(tc);
sr->working--;
st->method_cache_sc = NULL;

sr->cur_read_buffer = orig_read_buffer;
sr->cur_read_offset = orig_read_offset;
sr->cur_read_end = orig_read_end;
}
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)sc->body->mutex);
}
Expand Down

0 comments on commit ffc8a26

Please sign in to comment.