Skip to content

Commit

Permalink
Merge pull request numpy#26021 from charris/backport-25950
Browse files Browse the repository at this point in the history
BUG: Fix reference leak in niche user old user dtypes
  • Loading branch information
charris committed Mar 14, 2024
2 parents f4e5508 + 856eb95 commit ceab92f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions numpy/core/src/multiarray/usertypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ PyArray_RegisterDataType(PyArray_Descr *descr)
NPY_DT_SLOTS(NPY_DTYPE(descr))->get_clear_loop = (
&npy_get_clear_void_and_legacy_user_dtype_loop);
/* Also use the void zerofill since there may be objects */
NPY_DT_SLOTS(NPY_DTYPE(descr))->get_clear_loop = (
&npy_get_zerofill_void_and_legacy_user_dtype_loop);
NPY_DT_SLOTS(NPY_DTYPE(descr))->get_fill_zero_loop = (
(get_traverse_loop_function *)&npy_get_zerofill_void_and_legacy_user_dtype_loop);
}

return typenum;
Expand Down
7 changes: 7 additions & 0 deletions numpy/core/tests/test_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,13 @@ class mytype:
# unnecessary restriction, but one that has been around forever:
assert np.dtype(mytype) == np.dtype("O")

if HAS_REFCOUNT:
# Create an array and test that memory gets cleaned up (gh-25949)
o = object()
a = np.array([o], dtype=dt)
del a
assert sys.getrefcount(o) == 2

def test_custom_structured_dtype_errors(self):
class mytype:
pass
Expand Down

0 comments on commit ceab92f

Please sign in to comment.