-
Notifications
You must be signed in to change notification settings - Fork 782
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
Conversation
src/types/num.rs
Outdated
int_convert_128!(u128, 16, 0); | ||
|
||
#[cfg(all(feature = "num-bigint", not(Py_LIMITED_API)))] | ||
mod bitint_conversion { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
#[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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
Resolves #543.