-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Conversation
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.
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); |
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.
This line is repeated now, maybe we can merge them
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.
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.
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.
You missed that descr
is still being used further down in new = ...
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.
descr is a better name than outcode anyway
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.
You missed that
descr
is still being used further down innew = ...
I'm not sure what you're implying by this? I dropped outcode
so I think desc should still be used in the new = ...
.
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.
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).
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.
Thanks, I was being silly and only making sure the count was right at the end of the function. Fixed now.
bdadea3
to
33d8176
Compare
33d8176
to
7e8c0d6
Compare
This was proposed in one of the C cleanups, I tried it out and it looked better.