Skip to content
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

Support conversion between num-bigint <-> Python Long #608

Merged
merged 6 commits into from
Oct 7, 2019

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Sep 28, 2019

Resolves #543.

src/types/num.rs Outdated
int_convert_128!(u128, 16, 0);

#[cfg(all(feature = "num-bigint", not(Py_LIMITED_API)))]
mod bitint_conversion {
Copy link
Member

Choose a reason for hiding this comment

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

typo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks.

src/types/num.rs Outdated
if num.is_null() {
return Err(PyErr::fetch(ob.py()));
}
let n_bytes = (ffi::_PyLong_NumBits(ob.as_ptr()) as usize - 1) / 8 + 1;
Copy link
Member

Choose a reason for hiding this comment

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

looks like this should use num, not ob...

Can _PyLong_NumBits return zero? The subtract would wrap in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like this should use num, not ob...

Wow, I didn't know that.

Can _PyLong_NumBits return zero? The subtract would wrap in that case.

Good catch, thanks.

src/types/num.rs Outdated
Comment on lines 235 to 238
#[cfg(all(not(Py_LIMITED_API), target_endian = "little"))]
int_convert_128!(i128, 16, 1);
#[cfg(not(Py_LIMITED_API))]
int_convert_bignum!(i128, 16, IS_LITTLE_ENDIAN, 1);
#[cfg(not(Py_LIMITED_API))]
int_convert_bignum!(u128, 16, IS_LITTLE_ENDIAN, 0);
int_convert_128!(u128, 16, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

i128 conversions on big-endian appears to have been inadvertently deleted

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's at line 236

Copy link
Contributor

Choose a reason for hiding this comment

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

line 236 is only enabled on little-endian systems, so it can't provide the i128 conversions on big-endian systems since it is disabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I understand.
Thank you for pointing it out!

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.

python3 int <-> num_bigint support
3 participants