-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
BUG: fix integer size confusion in handling array's ndmin argument #14769
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.
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
Conversation
Did the numpy test suite pass on the machine you ran into this on? If so, can we add a test that would fail? |
The ndmin local variable was changed from an "int" to an "npy_intp" but &ndmin is passed to PyArg_ParseTupleAndKeywords against a "i" argument spec, but these integers have different sizes (well on an LP64 platform anyway). This actually works on a little endian system but fails on a big endian one. Fix this by converting the local back to an int, and being a little careful before assigning the result of PyLong_AsLong to it. Fixes numpy#14767
You mean before this change? No, not even close.
I don't think it's possible to write a test that will fail on a little endian system. I also can't think of an easy way to run CI on a big endian system. You might be able to get access to s390x via https://developer.ibm.com/linuxone (or by finding the right person inside IBM, I guess), or run some simple tests via qemu system emulation or something, |
Big endian CI can be done on POWER9 (which is ppc64); there is Integricloud for a VPS, but I'll poke some people. |
@awilfox POWER9 is ppc64le, meaning little-endian. I don't believe there are any active distributions with ppc64 (64bit big endian ports). |
That's not true; POWER9 is bi-endian. FreeBSD, Gentoo, Adélie, Void all have big endian ports that run natively on POWER9. |
While in theory big endian exists for POWER9, it is difficult to find a CI service that provides that variant. Even the gcc build farm offers only little-endian POWER9 machines. I think the only little-endian machine on that list is mips64. |
Yes, CI as a service is difficult for big endian arches, but having access to big endian machines isn't. Hope the CI situation will change some time. |
Compiler warnings and static analysis should be able to detect this issue, with lots of noise.
However, not all of them are true issues, as they depend on actual ranges of source and target values and endianness.... I wonder if it might be sufficient to cross-compile to a big-endian target with these options on to spot issues. |
I don't agree. The compiler is powerless when it comes to checking the types in |
True.... we can ask cpython to write gcc-plugin to add those in a similar fashion as printf warnings? |
That would certainly be cool The path I was considering was trying to write my own semmle QL query for LGTM.com, using their printf example to go by. |
I think I don't understand the issue correctly here: We call
and assign the result to |
Ref numpy/numpy#14769 [ci skip]
@xnox: while you're right that that's sloppy, that's not the cause of the issue. The problem is we call |
The PR in question looks ready. We can put this in and continue to look for more systematic solutions. I will merge soon unless there is more review. |
Ref numpy/numpy#14769 [ci skip]
Test failure looks unrelated, will restart it to be sure |
Something is up with azure, restarting tests doesn;t seem to work. Is there a reason not to merge this now (I let it slip before)? |
If we're fine dealing with the likely unrelated azure problem later,I see no reason not to merge |
Thanks @mwhudson |
The ndmin local variable was changed from an "int" to an "npy_intp" but
&ndmin is passed to PyArg_ParseTupleAndKeywords against a "i" argument
spec, but these integers have different sizes (well on an LP64 platform
anyway). This actually works on a little endian system but fails
on a big endian one. Fix this by converting the local back to an int,
and being a little careful before assigning the result of PyLong_AsLong to
it.
Fixes #14767