-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
Silent ctypes.struct layout change from native to Windows when bitfields are used #131747
Comments
cc @encukou (you messed with bitfields recently, right?) If this is valid, we should probably mark this as a blocker. |
@ZeroIntensity I'm glad that you see it as a bug and not a feature request. I discovered it while implementing the same functionality in IronPython, and just couldn't bring myself to follow CPython in this case (normally IronPython follows what CPython does, if possible). It would be great if CPython changes this so that there are no uneecessary differences between IronPython and CPython. |
Yeah, I doubt it's intended behavior. Assuming that's correct (I wasn't part of designing or reviewing |
Hi! I have limited access to the computer & I'm writing from memory. Please verify my claims :) Yes, 3.14 has an overhaul of struct layout; look at 3.13 for the previous status quo. In both 3.13 and the current 3.14, the meaning of We could deprecate Of course, if |
To clarify (or add to the confusion) If the silent layout change was always in Python, I see it as it was always a bug that went unreported. This is not surprising since till 3.14 there far more serious problems with handling bitfields (overlapping fields, spurious padding bits inserted that did not match the compiler) so I doubt this is widely used. Even if making it an error "breaks" some existing code that just happens to work correctly, there is a trivial remedy by adding At the very least, if not an error, please make it a warning that the layout was changed and that in the future this will become GCC pragma pack, so the user better be explicit. |
Bug report
Bug description:
Python 3.14 implements a special field
_layout_
inctypes.Structure
that allows the programmer to explicitly choose the layout rules for bitfields used by either GCC/Clang or MSVC. The default layout is appropiate for the OS platform (MSVC on Windows, GCC otherwise) which is expected behaviour. It is also possible to use field_pack_
to change the layout to match the compiler. This is currently only implemented for the MSVC layout, not for GCC.The problem is that using
_pack_
on non-Windows systems silently switches the layout rules from GCC to MSVC, which is an unexpected layout by default on non-Windows systems. I propose that this case be handled as an error (NotImplementedError
) rather than the silent layout switch. The error message may contain a hint that if the MSVC layout is indeed what is intended, one need to select it explicitly by setting field_layout_
.From the Zen of Python:
Tested on 3.14a6
CPython versions tested on:
3.14
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: