|
22 | 22 | #define DEFAULT_STABLE_DATA_SIZE 4096
|
23 | 23 | #define OBJECT_SIZE_GUESS 8
|
24 | 24 |
|
| 25 | +/* *************************************************************************** |
| 26 | + * Serialization (writing related) |
| 27 | + * ***************************************************************************/ |
| 28 | + |
25 | 29 | /* Writes an int64 into a buffer. */
|
26 | 30 | static void write_int64(char *buffer, size_t offset, Parrot_Int8 value) {
|
27 | 31 | /* XXX: Big Endian Handling! */
|
@@ -357,8 +361,55 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
|
357 | 361 | return result;
|
358 | 362 | }
|
359 | 363 |
|
| 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 | + |
360 | 376 | /* Takes serialized data, an empty SerializationContext to deserialize it into
|
361 | 377 | * and a strings heap. Deserializes the data into the required objects and
|
362 | 378 | * STables. */
|
363 | 379 | 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); |
364 | 415 | }
|
0 commit comments