Skip to content

Commit 9778d26

Browse files
BUG: core: Don't call INCREF/DECREF on descr in NpyStringAcquireAllocator. (#31456) (#31460)
Co-authored-by: Warren Weckesser <[email protected]>
2 parents 8d8d7e5 + e0e3876 commit 9778d26

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

‎numpy/_core/src/common/raii_utils.hpp‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ class SaveThreadState
126126
//
127127
// Instead of
128128
//
129-
// Py_INCREF(descr);
130129
// npy_string_allocator *allocator = NpyString_acquire_allocator(descr);
131130
// [code that uses allocator]
132131
// NpyString_release_allocator(allocator);
133-
// Py_DECREF(descr);
134132
//
135133
// use
136134
//
@@ -141,19 +139,16 @@ class SaveThreadState
141139
//
142140
class NpyStringAcquireAllocator
143141
{
144-
PyArray_StringDTypeObject *_descr;
145142
npy_string_allocator *_allocator;
146143

147144
public:
148145

149-
NpyStringAcquireAllocator(PyArray_StringDTypeObject *descr) : _descr(descr) {
150-
Py_INCREF(_descr);
151-
_allocator = NpyString_acquire_allocator(_descr);
146+
NpyStringAcquireAllocator(PyArray_StringDTypeObject *descr) {
147+
_allocator = NpyString_acquire_allocator(descr);
152148
}
153149

154150
~NpyStringAcquireAllocator() {
155151
NpyString_release_allocator(_allocator);
156-
Py_DECREF(_descr);
157152
}
158153

159154
NpyStringAcquireAllocator(const NpyStringAcquireAllocator&) = delete;

‎numpy/_core/tests/test_stringdtype.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def test_self_casts(dtype, dtype2, strings):
260260
["this", "is", "an", "array"],
261261
["€", "", "😊"],
262262
["A¢☃€ 😊", " A☃€¢😊", "☃€😊 A¢", "😊☃A¢ €"],
263+
["short", "12345678"] * 1000,
263264
],
264265
)
265266
class TestStringLikeCasts:

0 commit comments

Comments
 (0)