Skip to content

Conversation

pengwyn
Copy link
Contributor

@pengwyn pengwyn commented Aug 24, 2022

I was noticing that large unsigned 64 ints were being converted from json into a negative python int. I think this is because the from_json is first checking if the json object is an integer, and only if that fails to check if it is an unsigned number. So I think the unsigned branch might never be hit.

I flipped the order around, and added a test to check this. One comment about that test, I'm doing a full round trip of uint64_t to python int to json to python int, as I want to compare the two python ints without any explicit casting, as that would just cast away the issue.

I actually had trouble debugging this because the default error output of pybind seems not to realise it should be trying to use 64 bit integers (long long) for the printing output and just shows -1 instead. However, the python objects themselves are fine.

Copy link
Collaborator

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

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

This is great! Thanks a lot :)

@martinRenou
Copy link
Collaborator

I think the CI issues are not related to your changes. I will try to get the CI green first in a separate PR.

@martinRenou martinRenou force-pushed the unsigned-conversion-order branch from a551111 to c2463f9 Compare August 24, 2022 12:20
@martinRenou
Copy link
Collaborator

I took the liberty to rebase your PR against the new master branch

@martinRenou martinRenou merged commit 23183c1 into pybind:master Aug 24, 2022
@pengwyn
Copy link
Contributor Author

pengwyn commented Aug 25, 2022

Fantastic! Also loving the speedy merge.

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.

2 participants