Skip to content

Commit 2ec73d0

Browse files
committed
Start to sketch out deserialization related state and overall algorithm.
1 parent aff34ae commit 2ec73d0

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/6model/serialization.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#define DEFAULT_STABLE_DATA_SIZE 4096
2323
#define OBJECT_SIZE_GUESS 8
2424

25+
/* ***************************************************************************
26+
* Serialization (writing related)
27+
* ***************************************************************************/
28+
2529
/* Writes an int64 into a buffer. */
2630
static void write_int64(char *buffer, size_t offset, Parrot_Int8 value) {
2731
/* XXX: Big Endian Handling! */
@@ -357,8 +361,55 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
357361
return result;
358362
}
359363

364+
365+
/* ***************************************************************************
366+
* Deserialization (reading related)
367+
* ***************************************************************************/
368+
369+
/* Checks the header looks sane and all of the places it points to make sense.
370+
* Also disects the input string into the tables and data segments and populates
371+
* the reader data structure more fully. */
372+
static void check_and_disect_input(PARROT_INTERP, SerializationReader *reader, STRING *data) {
373+
374+
}
375+
360376
/* Takes serialized data, an empty SerializationContext to deserialize it into
361377
* and a strings heap. Deserializes the data into the required objects and
362378
* STables. */
363379
void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, STRING *data) {
380+
PMC *stables = PMCNULL;
381+
PMC *objects = PMCNULL;
382+
383+
/* Create reader data structure and populate the basic bits. */
384+
SerializationReader *reader = mem_allocate_zeroed_typed(SerializationReader);
385+
GETATTR_SerializationContext_root_stables(interp, sc, stables);
386+
GETATTR_SerializationContext_root_objects(interp, sc, objects);
387+
reader->stables_list = stables;
388+
reader->objects_list = objects;
389+
reader->root.string_heap = string_heap;
390+
reader->root.dependent_scs = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
391+
392+
/* Read header and disect the data into its parts. */
393+
check_and_disect_input(interp, reader, data);
394+
395+
/* Resolve the SCs in the dependencies table. */
396+
397+
/* Disable GC at this stage; for one there's no point collecting when all
398+
* we're doing in here is allocating, but more importantly STable REPRData
399+
* may be in an inconsistent state during all of this and so we may not have
400+
* yet deserialized enough to know how to do marking/freeing. */
401+
Parrot_block_GC_mark(interp);
402+
403+
/* Stub-allocate PMCs for all STables and objects, so we know where
404+
* they will all end up. */
405+
406+
/* Deserialize STables, along with their representation data. */
407+
408+
/* Deserialize objects. */
409+
410+
/* Re-enable GC. */
411+
Parrot_unblock_GC_mark(interp);
412+
413+
/* Clear up afterwards. */
414+
mem_sys_free(reader);
364415
}

src/6model/serialization.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ typedef struct {
3838
typedef struct {
3939
/* Serialization root data. */
4040
SerializationRoot root;
41+
42+
/* The stables list and object list we're deserializing things into. */
43+
PMC *stables_list;
44+
PMC *objects_list;
45+
46+
/* Flag for if we're reading the stable data chunk or object data chunk. */
47+
char reading_object;
48+
49+
/* Current offsets for the data chunks (also correspond to the amount of
50+
* data written in to them). */
51+
Parrot_Int4 stables_data_offset;
52+
Parrot_Int4 objects_data_offset;
4153
} SerializationReader;
4254

4355
/* Represents the serialization writer and the various functions available

0 commit comments

Comments
 (0)