BUG: Fix undefined behaviour induced by bad __array_wrap__#8618
BUG: Fix undefined behaviour induced by bad __array_wrap__#8618mhvk merged 1 commit intonumpy:masterfrom
__array_wrap__#8618Conversation
|
Nice find! Though I think it is better just to fail, so that someone realises it is a mistake. At least, I can just imagine writing code but forgetting to return the object, and trying and trying and never getting it to work -- would be so frustrating! And since presently it does fail too, it would not introduce regressions. |
numpy/core/src/umath/ufunc_object.c
Outdated
There was a problem hiding this comment.
I think just goto fail; here (see main comment)
There was a problem hiding this comment.
It'd need a PyExc_SetString too though, right?
|
Also, once we have decided on what the path should be, a test case and an entry in the 1.12.1 release notes..... Thanks! |
Yeah, i think I agree with you, and just did it this way because that seemed like what the original author was aiming for.
also while we're at it, can we put a deprecation warning in the missing |
|
Actually, can't we just allow it to return |
|
Since it is possible to return anything at all, I think I agree |
|
p.s. As for deprecating the no-context part: definitely a different PR (since it doesn't fix any bugs, so would go in 1.13, not 1.12.1). Not completely sure it is worth it, though -- given the comparison with |
1bd2d72 to
f94e4ef
Compare
Yep, done, along with a testcase
Agreed
My concern is other bits of numpy that forget to do this check.
Is there a template I should be creating these from? |
numpy/core/tests/test_umath.py
Outdated
There was a problem hiding this comment.
Add a comment here that this is a regression check ensuring that if None is returned, it doesn't crash the system (linking back to the issue and PR; convention seems to be gh-nnnn).
numpy/core/tests/test_umath.py
Outdated
There was a problem hiding this comment.
not important here, but convention is to use context=None, since the caller does not have to put in any context. Since you need to edit anyway...
There was a problem hiding this comment.
This is not the only place where this is missing in this file, so I'll leave the others to keep this patch small
|
@charris - this PR is a bug fix for 1.12, and should presumably be mentioned in the release notes, but there is no |
|
@mhvk The merged fixes will be found by a script and added to the 1.12.1 release notes with a link to the relevant PR. Unless you think more explanation is needed that should suffice. I've created the initial release notes just in case, but you will need to rebase this to see them. |
|
OK, thanks for the clarification. In that case, @eric-wieser, I think this is ready to go in after you've made the two small changes I requested in-line (you can use |
Presumably then, I should not squash my commits? |
|
@eric-wieser - arrgghh - my astropy background, where we do not worry about the number of commits, is showing through. Since for numpy the changelog is partially generated automatically, based on commits, I guess it is indeed much bettter to just have a single commit (unless there really are different pieces to a puzzle). So, could you squash? |
|
@mhvk I'm thinking of putting the PRs in the changlog instead of commits/merges. Note that the last posted release notes contained PRs with a link. These days you can also do squash and merge and our script also picks that up. Just make sure that the summary line and commit message are appropriate and the summary line ends with |
Now `None` is treated like any other return value, rather than a command to segfault.
f4260ae to
5095f42
Compare
|
Ok, squashed |
|
Great, merging... |
|
This needs a rebase on 1.12.1, right? |
|
I think the backporting gets done in separate PRs -- @charris?? |
|
Yep, it definitely goes in a separate PR. Not sure if it's automated, in which case this needs to stay on the radar |
|
something I like to do with bugfixes intended for backporting from the beginning is to rebase them onto the merge base between the maintenance branch and the master branch. on the bugfix branch: I usually do it, but others not so it is optional. |
|
Yep, that would have been a good idea. Too late now though... |
__array_wrap__
This fixes #8507.
The semantics of
__array_wrap__are now that if the return value is None, the argument passed in is assumed as the return value.The previous semantics were to segfault.