-
-
Notifications
You must be signed in to change notification settings - Fork 715
add sig_on and sig_off to avoid segfault #41264
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
base: develop
Are you sure you want to change the base?
Conversation
Refactor get and set methods to use indexing directly.
Removed illegal assignment example and related comments.
Added tests for vector assignment and index errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get() is an unsafe method, as documented. What's the point of this? Just use __getitem__, which (should be, although I didn't check) is safe
|
please see my comment in #41249 - the whole point of |
Updated the get and set methods to remove bounds checking and added signal handling.
|
In some cases, it will not cause a segfault |
|
segfaults are triggered by hardware when you are trying to access memory not allocated for your process. So you can violate the boundaries of your array sometimes, without triggering it, it is normal. I still wonder whether it's not better just to leave this |
|
I think the method is strange. like |
|
the naming is unfortunate. perhaps it should be renamed to |
But we already have get_unsafe |
|
get_unsafe is Cython only |
| PySlice_GetIndicesEx(i, d, &start, &stop, &step, &slicelength) | ||
| values = [] | ||
| for n in range(slicelength): | ||
| values.append(self.get_unsafe(start + n*step)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It use get_unsafe in _getitem_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it certainly does (it's probably the only one "real" array element raw access method). I wonder why this call is not wrapped in sig_on/sig_off - is it a bug?
@nbruin - what would you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like get is slower and with less features than __getitem__, so I suspect it can just be deprecated. In the mean time, slapping on sig_on/sig_off could be OK, but shouldn't we really just be checking bounds and raising an error? As observed, you may not get a segfault for out-of-bounds access. In that case, you'll just get a garbage value. That's even worse! The argument would usually be "but I only use this routine for in-bounds access and then it's faster". We don't seem to have the "faster" part here. So if people want faster code, they should move to __getitem__ anyway (or cython where there's a proper "unsafe").
So it doesn't seem very important what "get" does. It might just be a nuisance. Did anyone look through its blame to see where it's coming from? Sometimes old tickets give insight or it may show that there was a problem before that has somehow been resolved in a different way.
|
Documentation preview for this PR (built with commit 55e08dd; changes) is ready! 🎉 |
Fix #41249 add sig_on and sig_off to the unsafe methods`
📝 Checklist
⌛ Dependencies