@@ -75,7 +75,7 @@ size_t jl_arr_xtralloc_limit = 0;
75
75
#define MAXINTVAL (((size_t)-1)>>1)
76
76
77
77
static jl_array_t * _new_array_ (jl_value_t * atype , uint32_t ndims , size_t * dims ,
78
- int isunboxed , int hasptr , int isunion , int elsz )
78
+ int8_t isunboxed , int8_t hasptr , int8_t isunion , int8_t zeroinit , int elsz )
79
79
{
80
80
jl_ptls_t ptls = jl_get_ptls_states ();
81
81
size_t i , tot , nel = 1 ;
@@ -123,8 +123,6 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
123
123
// No allocation or safepoint allowed after this
124
124
a -> flags .how = 0 ;
125
125
data = (char * )a + doffs ;
126
- if (tot > 0 && (!isunboxed || hasptr || isunion )) // TODO: check for zeroinit
127
- memset (data , 0 , tot );
128
126
}
129
127
else {
130
128
tsz = JL_ARRAY_ALIGN (tsz , JL_CACHE_BYTE_ALIGNMENT ); // align whole object
@@ -135,12 +133,11 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
135
133
// No allocation or safepoint allowed after this
136
134
a -> flags .how = 2 ;
137
135
jl_gc_track_malloced_array (ptls , a );
138
- if (tot > 0 && (!isunboxed || hasptr || isunion )) // TODO: check for zeroinit
139
- // need to zero out isbits union array selector bytes to ensure a valid type index
140
- memset (data , 0 , tot );
141
136
}
142
137
a -> flags .pooled = tsz <= GC_MAX_SZCLASS ;
143
138
139
+ if (zeroinit )
140
+ memset (data , 0 , tot );
144
141
a -> data = data ;
145
142
if (JL_ARRAY_IMPL_NUL && elsz == 1 )
146
143
((char * )data )[tot - 1 ] = '\0' ;
@@ -186,14 +183,15 @@ static inline jl_array_t *_new_array(jl_value_t *atype, uint32_t ndims, size_t *
186
183
else {
187
184
elsz = LLT_ALIGN (elsz , al );
188
185
}
186
+ int zi = !isunboxed || hasptr || isunion || (jl_is_datatype (eltype ) && ((jl_datatype_t * )eltype )-> zeroinit );
189
187
190
- return _new_array_ (atype , ndims , dims , isunboxed , hasptr , isunion , elsz );
188
+ return _new_array_ (atype , ndims , dims , isunboxed , hasptr , isunion , zi , elsz );
191
189
}
192
190
193
191
jl_array_t * jl_new_array_for_deserialization (jl_value_t * atype , uint32_t ndims , size_t * dims ,
194
192
int isunboxed , int hasptr , int isunion , int elsz )
195
193
{
196
- return _new_array_ (atype , ndims , dims , isunboxed , hasptr , isunion , elsz );
194
+ return _new_array_ (atype , ndims , dims , isunboxed , hasptr , isunion , 0 , elsz );
197
195
}
198
196
199
197
#ifndef JL_NDEBUG
@@ -784,7 +782,7 @@ STATIC_INLINE void jl_array_grow_at_beg(jl_array_t *a, size_t idx, size_t inc,
784
782
char * data = (char * )a -> data ;
785
783
char * newdata ;
786
784
char * typetagdata ;
787
- char * newtypetagdata ;
785
+ char * newtypetagdata = NULL ;
788
786
int isbitsunion = jl_array_isbitsunion (a );
789
787
if (isbitsunion ) typetagdata = jl_array_typetagdata (a );
790
788
if (a -> offset >= inc ) {
@@ -864,10 +862,10 @@ STATIC_INLINE void jl_array_grow_at_beg(jl_array_t *a, size_t idx, size_t inc,
864
862
#endif
865
863
a -> nrows = newnrows ;
866
864
a -> data = newdata ;
867
- if (a -> flags . ptrarray || a -> flags . hasptr ) { // TODO: check for zeroinit
865
+ if (jl_is_array_zeroinit ( a )) {
868
866
memset (newdata + idx * elsz , 0 , nbinc );
869
867
}
870
- else if (isbitsunion ) {
868
+ if (newtypetagdata ) {
871
869
memset (newtypetagdata + idx , 0 , inc );
872
870
}
873
871
}
@@ -945,7 +943,7 @@ STATIC_INLINE void jl_array_grow_at_end(jl_array_t *a, size_t idx,
945
943
a -> length = newnrows ;
946
944
#endif
947
945
a -> nrows = newnrows ;
948
- if (a -> flags . ptrarray || a -> flags . hasptr ) { // TODO: check for zeroinit
946
+ if (jl_is_array_zeroinit ( a )) {
949
947
memset (data + idx * elsz , 0 , inc * elsz );
950
948
}
951
949
}
@@ -1201,7 +1199,7 @@ JL_DLLEXPORT jl_array_t *jl_array_copy(jl_array_t *ary)
1201
1199
int isunion = jl_is_uniontype (jl_tparam0 (jl_typeof (ary )));
1202
1200
jl_array_t * new_ary = _new_array_ (jl_typeof (ary ), jl_array_ndims (ary ),
1203
1201
& ary -> nrows , !ary -> flags .ptrarray ,
1204
- ary -> flags .hasptr , isunion , elsz );
1202
+ ary -> flags .hasptr , isunion , 0 , elsz );
1205
1203
memcpy (new_ary -> data , ary -> data , len * elsz );
1206
1204
// ensure isbits union arrays copy their selector bytes correctly
1207
1205
if (jl_array_isbitsunion (ary ))
0 commit comments