@@ -196,7 +196,9 @@ is_short_string(const npy_packed_static_string *s)
196196{
197197 unsigned char high_byte =
198198 ((_npy_static_string_u * )s )-> direct_buffer .flags_and_size ;
199- return (high_byte & NPY_STRING_SHORT ) == NPY_STRING_SHORT ;
199+ int has_short_flag = (high_byte & NPY_STRING_SHORT );
200+ int has_on_heap_flag = (high_byte & NPY_STRING_ON_HEAP );
201+ return has_short_flag && !has_on_heap_flag ;
200202}
201203
202204int
@@ -288,11 +290,13 @@ heap_or_arena_allocate(npy_string_allocator *allocator,
288290 }
289291 }
290292 else if (* flags & NPY_STRING_SHORT ) {
291- // have to heap allocate this leaves the NPY_STRING_SHORT flag set to
292- // indicate that there is no room in the arena buffer for strings in
293- // this entry, avoiding possible reallocation of the entire arena
294- // buffer when writing to a single string
295- * flags &= NPY_STRING_ON_HEAP ;
293+ // Have to heap allocate since there isn't a preexisting
294+ // allocation. This leaves the NPY_STRING_SHORT flag set to indicate
295+ // that there is no room in the arena buffer for strings in this
296+ // entry, avoiding possible reallocation of the entire arena buffer
297+ // when writing to a single string
298+ * flags |= NPY_STRING_ON_HEAP ;
299+ * on_heap = 1 ;
296300 return allocator -> malloc (sizeof (char ) * size );
297301 }
298302 // string isn't previously allocated, so add to existing arena allocation
0 commit comments