Skip to content

[READY] Small fixes in numpy.h #2293

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
Jul 12, 2020
Merged

Conversation

@YannickJadoul
Copy link
Collaborator

PyArray_DescrNewFromType is at offset 96

How was this never noticed? This means that PyArray_DescrNewFromType is never used?

array_t constructor that takes a size and a pointer should take ssize_t.

This was changed in #782, but it seems that was a bit too enthusiast? Would you mind going over the other changes in this PR and see if more things that should not made signed now still are?

@YannickJadoul
Copy link
Collaborator

array_t constructor that takes a size and a pointer should take ssize_t.

This was changed in #782, but it seems that was a bit too enthusiast? Would you mind going over the other changes in this PR and see if more things that should not made signed now still are?

There has actually been discussion on that: #782 (review)

@bstaletic
Copy link
Collaborator Author

PyArray_DescrNewFromType is at offset 96

How was this never noticed? This means that PyArray_DescrNewFromType is never used?

It is never used. Also, the compiler has no way of warning us here because this works by grabbing a capsule, casting it to a void** and then using offsets to cast void* to function pointers. It completely side-steps any possibility for type safety.

array_t constructor that takes a size and a pointer should take ssize_t.

This was changed in #782, but it seems that was a bit too enthusiast? Would you mind going over the other changes in this PR and see if more things that should not made signed now still are?

There has actually been discussion on that: #782 (review)

Hmm... but we're geting a cast to signed anyway. That's why the warning happens.

@YannickJadoul
Copy link
Collaborator

It is never used. Also, the compiler has no way of warning us here because this works by grabbing a capsule, casting it to a void** and then using offsets to cast void* to function pointers. It completely side-steps any possibility for type safety.

Right, I thought so. Should we maybe comment out the things that aren't used (and not tested)?

Hmm... but we're geting a cast to signed anyway. That's why the warning happens.

Ah, wait, you're changing it tó ssize_t. Right, this was forgotten in the array_t, but I was looking at array. (In my defence, that's only 2 bytes difference.)

@bstaletic
Copy link
Collaborator Author

It is never used. Also, the compiler has no way of warning us here because this works by grabbing a capsule, casting it to a void** and then using offsets to cast void* to function pointers. It completely side-steps any possibility for type safety.

Right, I thought so. Should we maybe comment out the things that aren't used (and not tested)?

I'd rather drop it completely than comment it out. As this pull request shows, the more of numpy's multiarray C API we use, the worse. Should I check the rest and remove all that aren't used?

@bstaletic
Copy link
Collaborator Author

I'd rather drop it completely than comment it out. As this pull request shows, the more of numpy's multiarray C API we use, the worse. Should I check the rest and remove all that aren't used?

After a short discussion with @YannickJadoul we agreed not to touch PyArray_DescrNewFromType besides fixing the offset, because removing it would affect the ABI of py::detail::npy_api.

@wjakob
Copy link
Member

wjakob commented Jul 12, 2020

Oh gosh, good catch about the bad offset. All of these changes look good to me, please feel free to merge yourself when ready.

@YannickJadoul
Copy link
Collaborator

All is green; let's go!

@YannickJadoul YannickJadoul merged commit aa982e1 into pybind:master Jul 12, 2020
@YannickJadoul
Copy link
Collaborator

Thanks, @bstaletic!

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.

array_t constructor takes shape as size_t, not ssize_t
4 participants