-
-
Couldn't load subscription status.
- Fork 33.2k
gh-131747: ctypes: Deprecate _pack_ implicitly setting _layout_ = 'ms' #133205
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
Changes from 6 commits
ade4c77
850a16f
971c779
516d563
85cee9f
8f61cae
48261f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Pending removal in Python 3.19 | ||
| ------------------------------ | ||
|
|
||
| * :mod:`ctypes`: | ||
|
|
||
| * Implicitly switching to the MSVC-compatible struct layout by setting | ||
| :attr:`~ctypes.Structure._pack_` but not :attr:`~ctypes.Structure._layout_` | ||
| on non-Windows platforms. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
| Py_TPFLAGS_DISALLOW_INSTANTIATION, | ||
| Py_TPFLAGS_IMMUTABLETYPE) | ||
| from struct import calcsize | ||
| import contextlib | ||
| from test.support import MS_WINDOWS | ||
|
|
||
|
|
||
| class StructUnionTestBase: | ||
|
|
@@ -335,6 +337,22 @@ def test_methods(self): | |
| self.assertIn("from_address", dir(type(self.cls))) | ||
| self.assertIn("in_dll", dir(type(self.cls))) | ||
|
|
||
| def test_pack_layout_switch(self): | ||
| # Setting _pack_ implicitly sets default layout to MSVC; | ||
| # this is deprecated on non-Windows platforms. | ||
| if MS_WINDOWS: | ||
| warn_context = contextlib.nullcontext() | ||
|
Comment on lines
+343
to
+344
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just skip the test on Windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to this to work everywhere (but warn only on non-Windows). |
||
| else: | ||
| warn_context = self.assertWarns(DeprecationWarning) | ||
| with warn_context: | ||
| class X(self.cls): | ||
| _pack_ = 1 | ||
| # _layout_ missing | ||
| _fields_ = [('a', c_int8, 1), ('b', c_int16, 2)] | ||
|
|
||
| # Check MSVC layout (bitfields of different types aren't combined) | ||
| self.check_sizeof(X, struct_size=3, union_size=2) | ||
|
|
||
|
|
||
| class StructureTestCase(unittest.TestCase, StructUnionTestBase): | ||
| cls = Structure | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| On non-Windows platforms, deprecate using :attr:`ctypes.Structure._pack_` to | ||
| use a Windows-compatible layout on non-Windows platforms. The layout should | ||
| be specified explicitly by setting :attr:`ctypes.Structure._layout_` to | ||
| ``'ms'``. |
Uh oh!
There was an error while loading. Please reload this page.