8000 MAINT: Inline gentype_getreadbuf by sethtroisi · Pull Request #15422 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Inline gentype_getreadbuf #15422

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

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Conversation

sethtroisi
Copy link
Contributor

This was proposed in one of the C cleanups, I tried it out and it looked better.

Copy link
Member
@seberg seberg left a comment

Choose a reason for hiding this comment

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

I am OK with just putting it in as is but if you have time, happy to reduce things a bit more even. I am curious if we can somehow remove that whole Malloc+free block, since we are handling a new object we are creating anyway, it is fine to byteswap in-place. But I am a bit worried of missing a corner case.

PyArray_Descr *outcode = PyArray_DescrFromScalar(self);
data = (void *)scalar_value(self, outcode);
Py_DECREF(outcode);

descr = PyArray_DescrFromScalar(self);
Copy link
Member

Choose a reason for hiding this comment

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

This line is repeated now, maybe we can merge them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm less comfortable in python c code, and I consolidated two Py_DECREF to one place which felt better but made me question why they were seperated before. Can you give my update a through inspection.

Copy link
Member

Choose a reason for hiding this comment

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

You missed that descr is still being used further down in new = ...

Copy link
Member

Choose a reason for hiding this comment

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

descr is a better name than outcode anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You missed that descr is still being used further down in new = ...

I'm not sure what you're implying by this? I dropped outcode so I think desc should still be used in the new = ....

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but as long as you are using descr you must hold a reference to it. If you call DECREF you lose that reference (i.e. if you wanted to be super clean, at least in this case, you might even do descr = NULL or similar incarnations to point out that it is not anymore valid to use).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I was being silly and only making sure the count was right at the end of the function. Fixed now.

@seberg seberg merged commit 9b7e890 into numpy:master Jan 24, 2020
@sethtroisi sethtroisi deleted the buff_cleanup branch January 27, 2020 19:29
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.

4 participants
0