@@ -196,7 +196,9 @@ is_short_string(const npy_packed_static_string *s)
196
196
{
197
197
unsigned char high_byte =
198
198
((_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 ;
200
202
}
201
203
202
204
int
@@ -288,11 +290,13 @@ heap_or_arena_allocate(npy_string_allocator *allocator,
288
290
}
289
291
}
290
292
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 ;
296
300
return allocator -> malloc (sizeof (char ) * size );
297
301
}
298
302
// string isn't previously allocated, so add to existing arena allocation
0 commit comments