Skip to content

Conversation

@seberg
Copy link
Member

@seberg seberg commented Feb 25, 2023

Some void dtypes think they contain objects but don't. Instead of playing whack-a-mole to see if that can be fixed, simply make the clearing a no-op here for them.
User dtypes are weirder, it should be OK to pass through.

Fixes the error message and use write-unraisable.

Closes gh-23277

Some void dtypes think they contain objects but don't.  Instead
of playing whack-a-mole to see if that can be fixed, simply make
the clearing a no-op here for them.
User dtypes are weirder, it should be OK to pass through.

Fixes the error message and use write-unraisable.

Closes numpygh-23277
Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

/* Free any internal references */
if (PyDataType_REFCHK(fa->descr)) {
PyArray_ClearArray(self);
if (PyArray_ClearArray(self) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to check I understand: to write a test for this, one would have to have a clearing function that actually misbehaves, correct? And the actual array object here is no longer accessible, hence NULL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it shouldn't be possible to reach this, but without the fix, you do.

}
else if (dtype->type_num == NPY_VOID) {
/*
* Void dtypes can have "ghosts" of objects marking the dtype because
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a separate issue to remind us to fix this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, we have been slowly chipping away at it. Some places still copy the whole data, until that is changed this is necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One point is, that so long we allow you to view a structured array as a bytes/unstructured void, this has to stay in place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess that makes sense - actually quite a mess if there is an object underneath. But, for another time!

@charris charris merged commit a6d8b30 into numpy:main Feb 25, 2023
@charris
Copy link
Member

charris commented Feb 25, 2023

Thanks Sebastian.

@seberg seberg deleted the issue-23277 branch February 25, 2023 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: clearing of array data too aggressive after gh-22924

3 participants