MAINT: Shrink the size of memory allocations to 1 bytes for arrays with size == 0.#15788
MAINT: Shrink the size of memory allocations to 1 bytes for arrays with size == 0.#15788eric-wieser wants to merge 1 commit intonumpy:mainfrom
size == 0.#15788Conversation
…th `size == 0`. In order to avoid undefined behavior, we need to ensure the generated strides are all zero.
c003daf to
c858e66
Compare
|
Test failure is the same as #15789 |
|
I think this also needs to disallow changing the strides when Could maybe add the test from 912aedd with a |
| int i; | ||
|
|
||
| #if NPY_RELAXED_STRIDES_CHECKING | ||
| npy_bool empty = 0; |
There was a problem hiding this comment.
Do we use NP_TRUE and NPY_FALSE with npy_bool?
There was a problem hiding this comment.
I wonder if we can just replace everything with bool now that we require C99... Obviously not in this patch.
|
Regarding --- numpy\core\src\common\mem_overlap.c Tue Aug 20 01:12:25 2019
+++ numpy\core\src\common\mem_overlap.c Sat Mar 21 18:46:06 2020
@@ -666,10 +666,7 @@
for (i = 0; i < nd; i++) {
if (dims[i] == 0) {
- /* If the array size is zero, return an empty range */
- *lower_offset = 0;
- *upper_offset = 0;
- return;
+ continue;
}
/* Expand either upwards or downwards depending on stride */
max_axis_offset = strides[i] * (dims[i] - 1); |
|
I was thinking more of disallowing assignment of anything but 0 to strides. Currently this succeeds: |
|
@eric-wieser any thoughts on moving this forward? The "uhoh" messages are annoying. |
|
Why did we close this instead of merging it? Was something important missing or was it a matter of this fix exposing yet another already-problematic API? |
|
I think it was just closed as part of trying to close a few stalled PRs, just reopen if you like. We removed Maybe this can now be simplified to just memsetting strides to 0? I suppose there might be some (weird) ways to abuse run into the UB still, OTOH, I still doubt that the UB matters in practice usually. |
|
Yeah, I think @charris made the reasonable decision to close out all my stalled PRs, as I haven't found much time in the last year or so to pick them back up again |
Alternative to #15780.
In order to avoid undefined behavior, we need to ensure the generated strides are all zero.