Skip to content

Commit

Permalink
gh-128889: Zero out memory ctypes for generated struct layout tests (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou authored Jan 21, 2025
1 parent 4b37a6b commit 13475e0
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 74 deletions.
5 changes: 3 additions & 2 deletions Lib/test/test_ctypes/test_generated_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_generated_data(self):
- None
- reason to skip the test (str)
This does depend on the C compiler keeping padding bits zero.
This does depend on the C compiler keeping padding bits unchanged.
Common compilers seem to do so.
"""
for name, cls in TESTCASES.items():
Expand Down Expand Up @@ -696,7 +696,8 @@ def output(string):
output(' ' + line)
typename = f'{struct_or_union(cls)} {name}'
output(f"""
{typename} value = {{0}};
{typename} value;
memset(&value, 0, sizeof(value));
APPEND(PyUnicode_FromString({c_str_repr(name)}));
APPEND(PyLong_FromLong(sizeof({typename})));
APPEND(PyLong_FromLong(_Alignof({typename})));
Expand Down
Loading

0 comments on commit 13475e0

Please sign in to comment.