File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import os
1313import re
1414import stat
15+ import struct
1516import sys
1617import sysconfig
1718import textwrap
@@ -899,16 +900,28 @@ def expected_failure_if_gil_disabled():
899900 _header = 'PHBBInP'
900901else :
901902 _header = 'nP'
902- _align = '0n'
903903_vheader = _header + 'n'
904904
905+ def _align (fmt ):
906+ """Pad the struct the way a C compiler does.
907+
908+ C alignment pads the struct total size so that arrays keep the largest
909+ alignment element aligned in an array.
910+ """
911+ align = '0n'
912+ if 'q' in fmt or 'Q' in fmt :
913+ align = '0q'
914+ if 'd' in fmt :
915+ align = '0d'
916+ return align
917+
905918def calcobjsize (fmt ):
906- import struct
907- return struct .calcsize (_header + fmt + _align )
919+ whole_fmt = _header + fmt
920+ return struct .calcsize (whole_fmt + _align ( whole_fmt ) )
908921
909922def calcvobjsize (fmt ):
910- import struct
911- return struct .calcsize (_vheader + fmt + _align )
923+ whole_fmt = _vheader + fmt
924+ return struct .calcsize (whole_fmt + _align ( whole_fmt ) )
912925
913926
914927_TPFLAGS_STATIC_BUILTIN = 1 << 1
You can’t perform that action at this time.
0 commit comments