16
16
#define CURRENT_VERSION 1
17
17
18
18
/* Various sizes (in bytes). */
19
- #define HEADER_SIZE 4 * 11
19
+ #define HEADER_SIZE 4 * 14
20
20
#define DEP_TABLE_ENTRY_SIZE 8
21
21
#define STABLES_TABLE_ENTRY_SIZE 8
22
22
#define OBJECTS_TABLE_ENTRY_SIZE 16
23
23
#define CLOSURES_TABLE_ENTRY_SIZE 12
24
+ #define CONTEXTS_TABLE_ENTRY_SIZE 12
24
25
25
26
/* Some guesses. */
26
27
#define DEFAULT_STABLE_DATA_SIZE 4096
27
28
#define STABLES_TABLE_ENTRIES_GUESS 16
28
29
#define OBJECT_SIZE_GUESS 8
29
30
#define CLOSURES_TABLE_ENTRIES_GUESS 16
31
+ #define CONTEXTS_TABLE_ENTRIES_GUESS 4
32
+ #define DEFAULT_CONTEXTS_DATA_SIZE 1024
30
33
31
34
/* Possible reference types we can serialize. */
32
35
#define REFVAR_NULL 1
@@ -452,6 +455,8 @@ static STRING * concatenate_outputs(PARROT_INTERP, SerializationWriter *writer)
452
455
output_size += writer -> root .num_objects * OBJECTS_TABLE_ENTRY_SIZE ;
453
456
output_size += writer -> objects_data_offset ;
454
457
output_size += writer -> root .num_closures * CLOSURES_TABLE_ENTRY_SIZE ;
458
+ output_size += writer -> root .num_contexts * CONTEXTS_TABLE_ENTRY_SIZE ;
459
+ output_size += writer -> contexts_data_offset ;
455
460
456
461
/* Allocate a buffer that size. */
457
462
output = mem_sys_allocate (output_size );
@@ -500,6 +505,19 @@ static STRING * concatenate_outputs(PARROT_INTERP, SerializationWriter *writer)
500
505
writer -> root .num_closures * CLOSURES_TABLE_ENTRY_SIZE );
501
506
offset += writer -> root .num_closures * CLOSURES_TABLE_ENTRY_SIZE ;
502
507
508
+ /* Put contexts table in place, and set location/rows in header. */
509
+ write_int32 (output , 44 , offset );
510
+ write_int32 (output , 48 , writer -> root .num_contexts );
511
+ memcpy (output + offset , writer -> root .contexts_table ,
512
+ writer -> root .num_contexts * CONTEXTS_TABLE_ENTRY_SIZE );
513
+ offset += writer -> root .num_contexts * CONTEXTS_TABLE_ENTRY_SIZE ;
514
+
515
+ /* Put contexts data in place. */
516
+ write_int32 (output , 52 , offset );
517
+ memcpy (output + offset , writer -> root .contexts_data ,
518
+ writer -> contexts_data_offset );
519
+ offset += writer -> contexts_data_offset ;
520
+
503
521
/* Sanity check. */
504
522
if (offset != output_size )
505
523
Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
@@ -653,6 +671,7 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
653
671
writer -> stables_list = stables ;
654
672
writer -> objects_list = objects ;
655
673
writer -> codes_list = codes ;
674
+ writer -> contexts_list = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
656
675
writer -> root .string_heap = empty_string_heap ;
657
676
writer -> root .dependent_scs = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
658
677
@@ -669,6 +688,10 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
669
688
writer -> root .objects_data = mem_sys_allocate (writer -> objects_data_alloc );
670
689
writer -> closures_table_alloc = CLOSURES_TABLE_ENTRY_SIZE * CLOSURES_TABLE_ENTRIES_GUESS ;
671
690
writer -> root .closures_table = mem_sys_allocate (writer -> closures_table_alloc );
691
+ writer -> contexts_table_alloc = CONTEXTS_TABLE_ENTRY_SIZE * CONTEXTS_TABLE_ENTRIES_GUESS ;
692
+ writer -> root .contexts_table = mem_sys_allocate (writer -> contexts_table_alloc );
693
+ writer -> contexts_data_alloc = DEFAULT_CONTEXTS_DATA_SIZE ;
694
+ writer -> root .contexts_data = mem_sys_allocate (writer -> contexts_data_alloc );
672
695
673
696
/* Populate write functions table. */
674
697
writer -> write_int = write_int_func ;
@@ -1032,7 +1055,7 @@ static void check_and_disect_input(PARROT_INTERP, SerializationReader *reader, S
1032
1055
Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
1033
1056
"Corruption detected (objects data starts after end of data)" );
1034
1057
1035
- /* Get size and location of STables table. */
1058
+ /* Get size and location of closures table. */
1036
1059
reader -> root .closures_table = data + read_int32 (data , 36 );
1037
1060
reader -> root .num_closures = read_int32 (data , 40 );
1038
1061
if (reader -> root .closures_table < prov_pos )
@@ -1043,9 +1066,31 @@ static void check_and_disect_input(PARROT_INTERP, SerializationReader *reader, S
1043
1066
Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
1044
1067
"Corruption detected (Closures table overruns end of data)" );
1045
1068
1069
+ /* Get size and location of contexts table. */
1070
+ reader -> root .contexts_table = data + read_int32 (data , 44 );
1071
+ reader -> root .num_contexts = read_int32 (data , 48 );
1072
+ if (reader -> root .contexts_table < prov_pos )
1073
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
1074
+ "Corruption detected (contexts table starts before closures table ends)" );
1075
+ prov_pos = reader -> root .contexts_table + reader -> root .num_contexts * CONTEXTS_TABLE_ENTRY_SIZE ;
1076
+ if (prov_pos > data_end )
1077
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
1078
+ "Corruption detected (contexts table overruns end of data)" );
1079
+
1080
+ /* Get location of contexts data. */
1081
+ reader -> root .contexts_data = data + read_int32 (data , 52 );
1082
+ if (reader -> root .contexts_data < prov_pos )
1083
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
1084
+ "Corruption detected (contexts data starts before contexts table ends)" );
1085
+ prov_pos = reader -> root .contexts_data ;
1086
+ if (prov_pos > data_end )
1087
+ Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
1088
+ "Corruption detected (contexts data starts after end of data)" );
1089
+
1046
1090
/* Set reading limits for data chunks. */
1047
1091
reader -> stables_data_end = reader -> root .objects_table ;
1048
1092
reader -> objects_data_end = reader -> root .closures_table ;
1093
+ reader -> contexts_data_end = data_end ;
1049
1094
}
1050
1095
1051
1096
/* Goes through the dependencies table and resolves the dependencies that it
@@ -1185,6 +1230,7 @@ void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, PMC *st
1185
1230
GETATTR_SerializationContext_root_objects (interp , sc , objects );
1186
1231
reader -> stables_list = stables ;
1187
1232
reader -> objects_list = objects ;
1233
+ reader -> contexts_list = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
1188
1234
reader -> root .sc = sc ;
1189
1235
reader -> root .string_heap = string_heap ;
1190
1236
reader -> root .dependent_scs = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
0 commit comments