Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Fix string to uint64 conversion on 32-bit platforms. #4577

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
wants to merge 1 commit into from

Conversation

abalkin
Copy link
Contributor

@abalkin abalkin commented Apr 2, 2014

Fixes #4575.

@juliantaylor
Copy link
Contributor

this will fail if strtoll is not available, which is allegedly the case on windows.
it would be better to use PyLong_FromString assuming we have the GIL in this function

there is also duplicate of the bug somewhere in the tracker

@juliantaylor
Copy link
Contributor

there seems to be _strtoi64, _strtoui64 on windows, no idea which version of VS it requires

@abalkin
Copy link
Contributor Author

abalkin commented Apr 2, 2014

I wonder if this behavior is correct:

>>> numpy.fromstring('18446744073709551616', sep=' ', dtype='uint64')
array([18446744073709551615], dtype=uint64)
>>> numpy.fromstring('-18446744073709551616', sep=' ', dtype='uint64')
array([0], dtype=uint64)

Shouldn't overflow/underflow generate at least a warning?

@juliantaylor
Copy link
Contributor

yes if its possible via the api it should at least warn, maybe even an error as this is not a computation but IO

@@ -1498,6 +1498,18 @@ BOOL_scan(FILE *fp, npy_bool *ip, void *NPY_UNUSED(ignore),
*****************************************************************************
*/

static long long
PyOS_strtoll(const char *str, char **endptr, int base)
Copy link
Member

Choose a reason for hiding this comment

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

These functions aren't part of the Python c-api and should not be prefaced PyOS.

@juliantaylor
Copy link
Contributor

I'll take this over, might be useful for 1.9

@juliantaylor
Copy link
Contributor

see #4712
I haven't added overflow handling which is probably useful if you still want to have a go at it.

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

Successfully merging this pull request may close these issues.

numpy.fromstring unable to parse values > 2^32 on 32 bit arch
3 participants