Skip to content

np.zeros(10, dtype=[]) calls malloc(0) #13645

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

Closed
eric-wieser opened this issue May 27, 2019 · 3 comments
Closed

np.zeros(10, dtype=[]) calls malloc(0) #13645

eric-wieser opened this issue May 27, 2019 · 3 comments

Comments

@eric-wieser
Copy link
Member

... and malloc(0) is implementation-defined. This works fine on my machine, but may throw an exception on other machines.

This happens via PyDataMem_NEW, so we at least have a point we can intercept this. We should probably do one of:

  • Ensure that PyDataMem_NEW(0) is never called (and perhaps make it fail on all platforms to make this detectable)
  • Special-case PyDataMem_NEW(0) to mean PyDataMem_NEW(1), so that it the allocation always succeeds
  • Do the above conditionally on feature-detection of malloc(0) == NULL performed in configtest, to avoid the cost of the conditional on platforms with the version of malloc which is convenient for us.

There are probably a few places where there is a similar problem with PyDataMem_RENEW(ptr, 0), except that does the wrong thing on all platforms

@mattip
Copy link
Member

mattip commented Jun 11, 2019

Closing, fixed by #13691 which both asserts !=0 and fixes all the places it could be called.

@mattip mattip closed this as completed Jun 11, 2019
@eric-wieser
Copy link
Member Author

We probably want to add a test for this somewhere, since that PR does not.

@mattip
Copy link
Member

mattip commented Jun 11, 2019

All the code paths in the PR show 100% coverage, implying they are tested, which is why I did not require additional tests before merging. Although one more test could not hurt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants