GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: fix choose refcount leak by charris · Pull Request #24328 · numpy/numpy

BUG: fix choose refcount leak #24328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
charris merged 6 commits into numpy:maintenance/1.26.x from charris:backport-24188
Aug 3, 2023

Uh oh!

There was an error while loading. Please reload this page.

Merged

BUG: fix choose refcount leak #24328

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
ec9c025
BUG: fix choose refcount leak
tylerjereddy Jul 15, 2023
6e41cd6
BUG: PR 24188 revisions
tylerjereddy Jul 18, 2023
fbf8dbc
MAINT: PR 24188 revisions
tylerjereddy Jul 25, 2023
e4b880e
MAINT: Use explicit copy path in choose based on refcheck
seberg Jul 31, 2023
1c22bf7
BUG: Remove unnecessary (and now also segfaulting) iterator creation
seberg Jul 31, 2023
87a93ef
ENH: Use `memcpy` and swap order
seberg Jul 31, 2023
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
BUG: fix choose refcount leak
* Fixes #22683

* use `copyswap` to avoid the reference count leaking
reported above when `np.choose` is used with `out`

* my impression from the ticket is that Sebastian doesn't
think `copyswap` is a perfect solution, but may suffice
short-term?
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@tylerjereddy @charris
tylerjereddy authored and charris committed Aug 3, 2023
commit ec9c0252db71dce8e738d0e2209c5b72156724e8

There are no files selected for viewing

8 changes: 5 additions & 3 deletions 8 numpy/core/src/multiarray/item_selection.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,8 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
{
PyArrayObject *obj = NULL;
PyArray_Descr *dtype;
int n, elsize;
PyArray_CopySwapFunc *copyswap;
int n, elsize, swap;
npy_intp i;
char *ret_data;
PyArrayObject **mps, *ap;
Expand Down Expand Up @@ -1042,6 +1043,8 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
}
elsize = PyArray_DESCR(obj)->elsize;
ret_data = PyArray_DATA(obj);
copyswap = dtype->f->copyswap;
swap = !PyArray_ISNBO(dtype->byteorder);

while (PyArray_MultiIter_NOTDONE(multi)) {
mi = *((npy_intp *)PyArray_MultiIter_DATA(multi, n));
Expand Down Expand Up @@ -1074,12 +1077,11 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
break;
}
}
memmove(ret_data, PyArray_MultiIter_DATA(multi, mi), elsize);
copyswap(ret_data, PyArray_MultiIter_DATA(multi, mi), swap, NULL);
ret_data += elsize;
PyArray_MultiIter_NEXT(multi);
}

PyArray_INCREF(obj);
Py_DECREF(multi);
for (i = 0; i < n; i++) {
Py_XDECREF(mps[i]);
Expand Down
10 changes: 10 additions & 0 deletions 10 numpy/core/tests/test_multiarray.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10031,3 +10031,13 @@ def test_argsort_int(N, dtype):
arr = rnd.randint(low=minv, high=maxv, size=N, dtype=dtype)
arr[N-1] = maxv
assert_arg_sorted(arr, np.argsort(arr, kind='quick'))


@pytest.mark.skipif(not HAS_REFCOUNT, reason="Python lacks refcounts")
def test_gh_22683():
a = np.ones(10000, dtype=object)
refc_start = sys.getrefcount(1)
np.choose(np.zeros(10000, dtype=int), [a], out=a)
np.choose(np.zeros(10000, dtype=int), [a], out=a)
refc_end = sys.getrefcount(1)
assert refc_end - refc_start < 10
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.