@@ -435,7 +435,7 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
435
435
{
436
436
if (a -> flags .how == 3 && a -> offset == 0 && a -> elsize == 1 &&
437
437
(jl_array_ndims (a ) != 1 ||
438
- !( a -> maxsize + sizeof (void * )+1 > GC_MAX_SZCLASS && jl_array_nrows ( a ) + sizeof (void * )+ 1 <= GC_MAX_SZCLASS ))) {
438
+ (( a -> maxsize + sizeof (void * ) + 1 <= GC_MAX_SZCLASS ) == ( jl_array_len ( a ) + sizeof (void * ) + 1 <= GC_MAX_SZCLASS ) ))) {
439
439
jl_value_t * o = jl_array_data_owner (a );
440
440
if (jl_is_string (o )) {
441
441
a -> flags .isshared = 1 ;
@@ -616,7 +616,8 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
616
616
nbytes ++ ;
617
617
oldnbytes ++ ;
618
618
}
619
- if (!a -> flags .ptrarray && jl_is_uniontype (jl_tparam0 (jl_typeof (a )))) {
619
+ int is_discriminated_union = !a -> flags .ptrarray && jl_is_uniontype (jl_tparam0 (jl_typeof (a )));
620
+ if (is_discriminated_union ) {
620
621
nbytes += newlen ;
621
622
oldnbytes += oldlen ;
622
623
}
@@ -627,15 +628,15 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
627
628
a -> data = jl_gc_managed_realloc (olddata , nbytes , oldnbytes ,
628
629
a -> flags .isaligned , (jl_value_t * )a );
629
630
}
630
- else if (a -> flags .how == 3 && jl_is_string (jl_array_data_owner (a ))) {
631
+ else if (a -> flags .how == 3 && jl_is_string (jl_array_data_owner (a )) && ! is_discriminated_union ) {
631
632
// if data is in a String, keep it that way
632
633
jl_value_t * s ;
633
634
if (a -> flags .isshared ) {
634
- s = jl_alloc_string (nbytes );
635
+ s = jl_alloc_string (nbytes - ( elsz == 1 ) );
635
636
newbuf = 1 ;
636
637
}
637
638
else {
638
- s = jl_gc_realloc_string (jl_array_data_owner (a ), nbytes );
639
+ s = jl_gc_realloc_string (jl_array_data_owner (a ), nbytes - ( elsz == 1 ) );
639
640
}
640
641
jl_array_data_owner (a ) = s ;
641
642
jl_gc_wb (a , s );
0 commit comments