Skip to content
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

BUG: Initialize the full nditer buffer in case of error #18922

Merged
merged 2 commits into from May 6, 2021

Conversation

charris
Copy link
Member

@charris charris commented May 5, 2021

Backport of #18813.

This is necessary because in some rare cases (reductions), we may
not actually use the full buffer. In that case, the cleanup-on-error
code would have to grow smart enough to handle these cases.
It seems much simpler to just always initialize the full buffers, even
if we may not end up using them.

Admittedly, the old logic might have skipped the buffer clearing
(especially the full buffer) in a fair bit of cases, but since
this is only relevant for object dtype, I assume this is fine.

@charris charris added this to the 1.20.3 release milestone May 5, 2021
seberg added 2 commits May 5, 2021 19:50
This is necessary because in some rare cases (reductions), we may
not actually use the full buffer.  In that case, the cleanup-on-error
code would have to grow smart enough to handle these cases.
It seems much simpler to just always initialize the full buffers, even
if we may not end up using them.

Admittedly, the old logic might have skipped the buffer clearing
(especially the full buffer) in a fair bit of cases, but since
this is only relevant for `object` dtype, I assume this is fine.
Buffer must always either contain NULL or valid references
(assuming the dtype supports references) in order to allow
cleanup in case of errors.

It is thus unnecessary to clear buffers before every copy, if
they contain NULL, all is fine. If they contain non-NULL, we should
also DECREF those references (so it would be incorrect as well).

Buffers thus need the memset exactly once: directly upon allcoation
(which we do now).  After this any transfer from/to the buffer needs
to ensure that the buffer is always in a good state.
@charris charris merged commit 418a855 into numpy:maintenance/1.20.x May 6, 2021
@charris charris deleted the backport-18813 branch May 7, 2021 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants