@@ -77,6 +77,7 @@ External links:
77
77
78
78
#include "julia.h"
79
79
#include "julia_internal.h"
80
+ #include "julia_gcext.h"
80
81
#include "builtin_proto.h"
81
82
#include "processor.h"
82
83
#include "serialize.h"
@@ -1438,10 +1439,14 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED
1438
1439
if (dt -> layout != NULL ) {
1439
1440
size_t nf = dt -> layout -> nfields ;
1440
1441
size_t np = dt -> layout -> npointers ;
1441
- size_t fieldsize = jl_fielddesc_size (dt -> layout -> fielddesc_type );
1442
+ size_t fieldsize = 0 ;
1443
+ uint8_t is_foreign_type = dt -> layout -> fielddesc_type == 3 ;
1444
+ if (!is_foreign_type ) {
1445
+ fieldsize = jl_fielddesc_size (dt -> layout -> fielddesc_type );
1446
+ }
1442
1447
char * flddesc = (char * )dt -> layout ;
1443
1448
size_t fldsize = sizeof (jl_datatype_layout_t ) + nf * fieldsize ;
1444
- if (dt -> layout -> first_ptr != -1 )
1449
+ if (! is_foreign_type && dt -> layout -> first_ptr != -1 )
1445
1450
fldsize += np << dt -> layout -> fielddesc_type ;
1446
1451
uintptr_t layout = LLT_ALIGN (ios_pos (s -> const_data ), sizeof (void * ));
1447
1452
write_padding (s -> const_data , layout - ios_pos (s -> const_data )); // realign stream
@@ -1450,6 +1455,13 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED
1450
1455
arraylist_push (& s -> relocs_list , (void * )(reloc_offset + offsetof(jl_datatype_t , layout ))); // relocation location
1451
1456
arraylist_push (& s -> relocs_list , (void * )(((uintptr_t )ConstDataRef << RELOC_TAG_OFFSET ) + layout )); // relocation target
1452
1457
ios_write (s -> const_data , flddesc , fldsize );
1458
+ if (is_foreign_type ) {
1459
+ // make sure we have space for the extra hidden pointers
1460
+ // zero them since they will need to be re-initialized externally
1461
+ assert (fldsize == sizeof (jl_datatype_layout_t ));
1462
+ jl_fielddescdyn_t dyn = {0 , 0 };
1463
+ ios_write (s -> const_data , (char * )& dyn , sizeof (jl_fielddescdyn_t ));
1464
+ }
1453
1465
}
1454
1466
}
1455
1467
else if (jl_is_typename (v )) {
@@ -2912,6 +2924,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
2912
2924
assert (* (void * * )dt == (void * )newdt );
2913
2925
* newdt = * (jl_datatype_t * )dt ; // copy the datatype fields (except field 1, which we corrupt above)
2914
2926
newdt -> name = name ;
2927
+ assert (newdt -> layout -> fielddesc_type != 3 );
2915
2928
}
2916
2929
}
2917
2930
// we should never see these pointers again, so scramble their memory, so any attempt to look at them crashes
0 commit comments