-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Update pystruct + array #2297
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
Update pystruct + array #2297
Conversation
|
@qingshi163 would you review this PR please? |
|
Seem like a problem if we want to pack a float but give a int. |
| make_pack_with_endianess!(i64, get_int_or_index); | ||
| make_pack_with_endianess!(u64, get_int_or_index); | ||
| make_pack_with_endianess!(f32, TryFromObject::try_from_object); | ||
| make_pack_with_endianess!(f64, TryFromObject::try_from_object); | ||
|
|
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.
CPython allows pack float format with int, float or class with float() but not a float like string. Non of our function doing exactly the job. We may need one it also can be use by array.array
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.
I think IntoPyFloat::try_from_object is correct; it accepts float, int, or anything with a __float__ method
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.
I modified it in #2309 to not accept a float string, since that's what PyFloat_AsDouble does
d601242 to
026f396
Compare
This is sort of a big lump change, and there aren't necessarily tests to prove it, since there aren't any tests in
test_struct.pythat verify the native ordering -- even though there's padding now and correct alignment/size, the tests that I unskipped aren't related to that 😞 . Still, I think this is cleaner then it was before; there's an enum for the codes now, and finding thepack()function for a code is a bit cleaner now and respects endianness/architecture