Skip to content

BUG: fix reference counting bug in __array_interface__ implementation#27249

Merged
seberg merged 2 commits intonumpy:mainfrom
ngoldbaum:fix-array-interface-refcount
Aug 21, 2024
Merged

BUG: fix reference counting bug in __array_interface__ implementation#27249
seberg merged 2 commits intonumpy:mainfrom
ngoldbaum:fix-array-interface-refcount

Conversation

@ngoldbaum
Copy link
Member

@seberg ran into this testing cunumeric: https://github.com/numpy/numpy/pull/26282/files#r1722321473.

Unfortunately there are no existing tests for this code path so we missed this breakage.

I tried writing an example that triggered this code path for a while this afternoon but was unable to.

@ngoldbaum ngoldbaum added the 09 - Backport-Candidate PRs tagged should be backported label Aug 19, 2024
@charris charris added this to the 2.1.1 release milestone Aug 19, 2024
Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Suggestion for a different solution, but not very important.

}
}
}
Py_DECREF(descr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just move the Py_DECREF(descr) up inside the branch where descr is defined? Outside of that branch, it is guaranteed to be NULL (similarly, the definition of new_dtype can be much closer to its use...).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now looked at the original issue, where I see @seberg also noted it should be put up: reason is that if GetStringRef returns 0, then the key was not present so descr cannot have been set.

@seberg seberg merged commit 16d6996 into numpy:main Aug 21, 2024
@seberg
Copy link
Member

seberg commented Aug 21, 2024

Thanks Nathan!

seberg added a commit to seberg/numpy that referenced this pull request Aug 21, 2024
This adds a simple regression test for the missing descr for
numpygh-27249.
charris pushed a commit to charris/numpy that referenced this pull request Aug 22, 2024
…numpy#27249)

* BUG: fix reference counting bug in __array_interface__ implementation

* MAINT: only decref if the reference is valid
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Aug 22, 2024
charris pushed a commit to charris/numpy that referenced this pull request Aug 22, 2024
This adds a simple regression test for the missing descr for
numpygh-27249.
charris pushed a commit to charris/numpy that referenced this pull request Aug 22, 2024
This adds a simple regression test for the missing descr for
numpygh-27249.
@charris charris removed this from the 2.1.1 release milestone Aug 28, 2024
ArvidJB pushed a commit to ArvidJB/numpy that referenced this pull request Nov 1, 2024
…numpy#27249)

* BUG: fix reference counting bug in __array_interface__ implementation

* MAINT: only decref if the reference is valid
ArvidJB pushed a commit to ArvidJB/numpy that referenced this pull request Nov 1, 2024
This adds a simple regression test for the missing descr for
numpygh-27249.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants