Skip to content

Commit 0c9e400

Browse files
committed
fix handling for heap strings that were short strings
1 parent 8dfb789 commit 0c9e400

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

stringdtype/stringdtype/src/static_string.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

202204
int
@@ -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

Comments
 (0)