-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-81368: Update PyCField_get_size #14647
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
base: main
Are you sure you want to change the base?
Conversation
It's not clear to me that this is the right fix. With this change, it's now impossible to get the bit offset of a struct field. |
Getting offset should be use https://github.com/python/cpython/blob/master/Modules/_ctypes/cfield.c#L254 |
Misc/NEWS.d/next/Core and Builtins/2019-07-08-17-11-20.bpo-37187.-KLvmv.rst
Outdated
Show resolved
Hide resolved
What if I want the bit offset and not the byte offset? Consider: class S(ctypes.Structure):
_fields_ = [
('a', ctypes.c_uint8),
('b', ctypes.c_uint8, 6),
('c', ctypes.c_uint8, 2),
] Previously, I could do: >>> S.c.size >> 16 # number of bits
2
>>> S.c.size & 0xFFFF # bit offset
6
>>> S.c.offset # byte offset
1 Obviously this API didn't make much sense from the current documentation, but it was at least possible to extract this information. How would I calculate those three values with your patch? |
en, I think it should be a inner behavior. Why the user should know this detail? |
https://bugs.python.org/issue37187