@@ -266,7 +266,7 @@ static void serialize_object(PARROT_INTERP, SerializationWriter *writer, PMC *ob
266
266
/* Increment count of objects in the table. */
267
267
writer -> root .num_objects ++ ;
268
268
269
- /* Delegate to its serialization REPR method . */
269
+ /* Delegate to its serialization REPR function . */
270
270
writer -> writing_object = 1 ;
271
271
if (REPR (obj )-> serialize )
272
272
REPR (obj )-> serialize (interp , STABLE (obj ), OBJECT_BODY (obj ), writer );
@@ -322,6 +322,7 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
322
322
GETATTR_SerializationContext_root_stables (interp , sc , stables );
323
323
GETATTR_SerializationContext_root_objects (interp , sc , objects );
324
324
writer -> root .version = CURRENT_VERSION ;
325
+ writer -> root .sc = sc ;
325
326
writer -> stables_list = stables ;
326
327
writer -> objects_list = objects ;
327
328
writer -> root .string_heap = empty_string_heap ;
@@ -406,6 +407,24 @@ static STRING * read_string_from_heap(PARROT_INTERP, SerializationReader *reader
406
407
return VTABLE_get_string_keyed_int (interp , reader -> root .string_heap , idx );
407
408
}
408
409
410
+ /* Locates a serialization context; 0 is the current one, otherwise see the
411
+ * dependencies table. */
412
+ static PMC * locate_sc (PARROT_INTERP , SerializationReader * reader , Parrot_Int4 sc_id ) {
413
+ PMC * sc ;
414
+ if (sc_id == 0 )
415
+ return reader -> root .sc ;
416
+ sc = VTABLE_get_pmc_keyed_int (interp , reader -> root .dependent_scs , sc_id - 1 );
417
+ if (PMC_IS_NULL (sc ))
418
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
419
+ "Invalid dependencies table index encountered (index %d)" , sc_id );
420
+ return sc ;
421
+ }
422
+
423
+ /* Looks up an STable. */
424
+ static PMC * lookup_stable (PARROT_INTERP , SerializationReader * reader , Parrot_Int4 sc_id , Parrot_Int4 idx ) {
425
+ return SC_get_stable (interp , locate_sc (interp , reader , sc_id ), idx );
426
+ }
427
+
409
428
/* Checks the header looks sane and all of the places it points to make sense.
410
429
* Also disects the input string into the tables and data segments and populates
411
430
* the reader data structure more fully. */
@@ -515,8 +534,26 @@ static void deserialize_stable(PARROT_INTERP, SerializationReader *reader, INTVA
515
534
516
535
/* Deserializes a single object, along with its REPR data. */
517
536
static void deserialize_object (PARROT_INTERP , SerializationReader * reader , INTVAL i , PMC * obj ) {
518
- Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
519
- "Object deserialization not yet implemented" );
537
+ /* Calculate location of object's table row. */
538
+ char * obj_table_row = reader -> root .objects_table + i * OBJECTS_TABLE_ENTRY_SIZE ;
539
+
540
+ /* Resolve the STable. */
541
+ PMC * stable = lookup_stable (interp , reader ,
542
+ read_int32 (obj_table_row , 0 ), /* The SC in the dependencies table, + 1 */
543
+ read_int32 (obj_table_row , 4 )); /* The index in that SC */
544
+
545
+ /* Allocate the object, fiddling things so that it gets wrapped in the
546
+ * PMC we want it to. */
547
+ set_wrapping_object (obj );
548
+ STABLE_STRUCT (stable )-> REPR -> allocate (interp , STABLE_STRUCT (stable ));
549
+
550
+ /* Delegate to its deserialization REPR function. */
551
+ reader -> reading_object = 1 ;
552
+ if (REPR (obj )-> deserialize )
553
+ REPR (obj )-> deserialize (interp , STABLE (obj ), OBJECT_BODY (obj ), reader );
554
+ else
555
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
556
+ "Missing deserialize REPR function" );
520
557
}
521
558
522
559
/* Takes serialized data, an empty SerializationContext to deserialize it into
@@ -535,6 +572,7 @@ void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, STRING
535
572
GETATTR_SerializationContext_root_objects (interp , sc , objects );
536
573
reader -> stables_list = stables ;
537
574
reader -> objects_list = objects ;
575
+ reader -> root .sc = sc ;
538
576
reader -> root .string_heap = string_heap ;
539
577
reader -> root .dependent_scs = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
540
578
0 commit comments