Skip to content

Commit 5308279

Browse files
committed
Deserialize RPAs with their object ownership. This seems to fix the leak that saw parametric roles and pre-comp sometimes interact badly.
1 parent 3ab8ab1 commit 5308279

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/6model/serialization.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "pmc_serializationcontext.h"
1212
#include "pmc_nqplexinfo.h"
1313
#include "pmc_ownedhash.h"
14+
#include "pmc_ownedresizablepmcarray.h"
1415
#include "pmc/pmc_sub.h"
1516
#include "base64.h"
1617

@@ -56,6 +57,7 @@ static INTVAL nqp_lexpad_id = 0;
5657
static INTVAL perl6_lexpad_id = 0;
5758
static INTVAL ctmthunk_id = 0;
5859
static INTVAL ownedhash_id = 0;
60+
static INTVAL ownedrpa_id = 0;
5961

6062
/* ***************************************************************************
6163
* Serialization (writing related)
@@ -459,6 +461,9 @@ void write_ref_func(PARROT_INTERP, SerializationWriter *writer, PMC *ref) {
459461
else if (ref->vtable->base_type == enum_class_ResizablePMCArray) {
460462
discrim = REFVAR_VM_ARR_VAR;
461463
}
464+
else if (ref->vtable->base_type == ownedrpa_id) {
465+
discrim = REFVAR_VM_ARR_VAR;
466+
}
462467
else if (ref->vtable->base_type == enum_class_ResizableIntegerArray) {
463468
discrim = REFVAR_VM_ARR_INT;
464469
}
@@ -984,6 +989,7 @@ STRING * Serialization_serialize(PARROT_INTERP, PMC *sc, PMC *empty_string_heap)
984989
perl6_lexpad_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "Perl6LexInfo", 0));
985990
ctmthunk_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "CTMThunk", 0));
986991
ownedhash_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "OwnedHash", 0));
992+
ownedrpa_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "OwnedResizablePMCArray", 0));
987993

988994
/* Initialize string heap so first entry is the NULL string. */
989995
VTABLE_push_string(interp, empty_string_heap, STRINGNULL);
@@ -1123,7 +1129,7 @@ PMC * read_obj_ref(PARROT_INTERP, SerializationReader *reader) {
11231129
/* Reads in an array of variant references. */
11241130
PMC * read_ref_func(PARROT_INTERP, SerializationReader *reader);
11251131
static PMC * read_array_var(PARROT_INTERP, SerializationReader *reader) {
1126-
PMC *result = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
1132+
PMC *result = Parrot_pmc_new(interp, ownedrpa_id);
11271133
Parrot_Int4 elems, i;
11281134

11291135
/* Read the element count. */
@@ -1135,6 +1141,9 @@ static PMC * read_array_var(PARROT_INTERP, SerializationReader *reader) {
11351141
for (i = 0; i < elems; i++)
11361142
VTABLE_set_pmc_keyed_int(interp, result, i, read_ref_func(interp, reader));
11371143

1144+
/* Set the owner. */
1145+
PARROT_OWNEDRESIZABLEPMCARRAY(result)->owner = reader->cur_object;
1146+
11381147
return result;
11391148
}
11401149

@@ -1735,6 +1744,7 @@ void Serialization_deserialize(PARROT_INTERP, PMC *sc, PMC *string_heap, PMC *st
17351744
/* Other init. */
17361745
smo_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
17371746
ownedhash_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "OwnedHash", 0));
1747+
ownedrpa_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "OwnedResizablePMCArray", 0));
17381748

17391749
/* Read header and disect the data into its parts. */
17401750
check_and_disect_input(interp, reader, data);

0 commit comments

Comments
 (0)