-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Segmentation fault when reversing an array enough times (Trac #466) #1064
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
Comments
@alberts wrote on 2007-03-10 Confirmed with 1.0.2.dev3572. I ran the provided code through Valgrind. After a while Valgrind crashes with:
Running under gdb, I get the following backtrace when it crashes:
|
@pv wrote on 2007-04-01 Not only does [::-1] crash, but also the following loops cause a crash:
I notice that on each iteration, some memory is reserved, and the size of the python process grows continuously while the loop is running. The following does not exhibit this behavior:
I think that the code makes numpy to generate a chain of views, unlimited in length, each referring to its parent. The bottom views are never freed before the topmost one, which causes memory hogging and everything to be freed only when the program ends. When freeing, DECREFing self->base calls array_dealloc recursively until stack overflows. If this hypothesis is correct, could the problem be fixed by walking self->base pointers upwards always when creating new views? |
@teoliphant wrote on 2007-05-11 I think the hypothesis is correct. This definitely looks like a stack-overflow. I am hesitant to walk self-base pointers upwards as there may be situations where this creates other problems. There are other ways in Python to create stack over-flows like this, so I'm not sure a lot of effort should be spent on fixing this. |
Milestone changed to |
@sebhaase wrote on 2007-05-14 Hi, -Sebastian |
@dmcooke wrote on 2007-05-14 I don't agree with the wontfix. I don't think walking the self-base pointers upwards will cause other problems: you'll get a very wide tree with the base as the root, instead of a long skinny one. Using the original base would make views always views of the original array, instead of the previous. Reopening, will assign this to me. I don't think it'll be fixed for 1.0.3, though. |
Milestone changed to |
Milestone changed to |
Milestone changed to |
@mwiebe wrote on 2011-03-23 There should be a clean API mechanism for creating views, since currently fixing this requires hand-modifying many places. One fix will be to do a separation between "arrays" and "buffers," where a buffer holds elements, and arrays are always a view into a buffer. A view into another view would end up looking into the buffer, so no chain of references could exist. |
@teoliphant wrote on 2011-03-23 I am not sure what is meant by a "clean API mechanism". I'm pretty sure that all that needs to be done is to push the reference to the original object exposing the memory instead of leaving it to the "most recent" array exposing the view. This could have been changed and it is not that difficult of a change. I dont' know what you mean by a "separation" of an array and a "buffer". An array is an example of a buffer. There are many examples of "buffers" and an array is a kind of "buffer" |
@mwiebe wrote on 2011-07-19 I've made a new function PyArray_SetBase(arr, obj), which encapsulates setting the base. This is what I meant by a clean API mechanism. I've changed the many places this was being done to use PyArray_SetBase. The NPY_ARRAY_UPDATEIFCOPY flag needed special handling, and the memmap ndarray subclass had bad assumptions about how views worked, and hopefully the way I've dealt with those is good. Anything that's not should be caught with a long testing period just like during the 1.6 release. The changes are here: |
@charris wrote on 2011-08-13 Can this be closed? |
@mwiebe wrote on 2011-08-13 The examples in the original report don't crash for me, I'll go ahead and close it. |
Milestone changed to |
Milestone changed to |
Original ticket http://projects.scipy.org/numpy/ticket/466 on 2007-03-08 by @FrancescAlted, assigned to @dmcooke.
Hi,
I'm getting a consistent seg fault by running this code:
and the output for my machine:
I need 1 million of iterations for getting the segfault, but your mileage may vary.
The text was updated successfully, but these errors were encountered: