Skip to content

BUG: fix np.resize refchk on python 3.14#30278

Merged
seberg merged 2 commits into
numpy:mainfrom
ngoldbaum:fix-resize-check
Nov 22, 2025
Merged

BUG: fix np.resize refchk on python 3.14#30278
seberg merged 2 commits into
numpy:mainfrom
ngoldbaum:fix-resize-check

Conversation

@ngoldbaum

Copy link
Copy Markdown
Member

Fixes #30265

@ngoldbaum ngoldbaum added the 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) label Nov 21, 2025
@ngoldbaum ngoldbaum added this to the 2.4.0 release milestone Nov 21, 2025
@seberg

seberg commented Nov 21, 2025

Copy link
Copy Markdown
Member

Hmmmpf, this doesn't seem to work on older versions, I guess because the method call is passed a new reference (i.e. it was refcount > 2).
Maybe on 3.14 it actually works out in the end (not sure from the tests), because this shouldn't need a new reference in theory as we don't need a bound method.


Oh well, if there is a simple solution great, if not... then too bad but OK, it's not the end of the world if this is just a best effort and I am not worried about the pattern in the issue, just thought there might be more.

@ngoldbaum

Copy link
Copy Markdown
Member Author

The fix ended up being to make the code python-version-dependent and avoid the definition in the compat header. The 2 references used to include a reference from the Python stack, but that's elided in 3.14, so there's only one reference.

@seberg

seberg commented Nov 22, 2025

Copy link
Copy Markdown
Member

Thanks Nathan, makes sense that it changed in 3.14, seems to work so let's put it in!

@seberg seberg merged commit 0957720 into numpy:main Nov 22, 2025
74 checks passed
cakedev0 pushed a commit to cakedev0/numpy that referenced this pull request Dec 5, 2025
Use new API on Python 3.14 for unique reference check (as it changed and for free-threading).
On older Python's there is an additional reference on the stack for the method call, though.

Fixes numpygh-30265
IndifferentArea pushed a commit to IndifferentArea/numpy that referenced this pull request Dec 7, 2025
Use new API on Python 3.14 for unique reference check (as it changed and for free-threading).
On older Python's there is an additional reference on the stack for the method call, though.

Fixes numpygh-30265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: ndarray.resize doesn't detect aliasing in python 3.14

2 participants