Skip to content

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

Merged
merged 3 commits into from
Oct 27, 2020
Merged

Update pystruct + array #2297

merged 3 commits into from
Oct 27, 2020

Conversation

coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Oct 20, 2020

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.py that 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 the pack() function for a code is a bit cleaner now and respects endianness/architecture

@youknowone
Copy link
Member

youknowone commented Oct 26, 2020

@qingshi163 would you review this PR please?

@qingshi163
Copy link
Contributor

Seem like a problem if we want to pack a float but give a int.

import struct
struct.pack('f', 10)

Comment on lines 557 to 569
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);

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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

@coolreader18 coolreader18 force-pushed the coolreader18/rework-pystruct branch from d601242 to 026f396 Compare October 26, 2020 17:14
@coolreader18 coolreader18 merged commit 3c9ad23 into master Oct 27, 2020
@coolreader18 coolreader18 deleted the coolreader18/rework-pystruct branch November 7, 2020 21:44
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.

3 participants