Skip to content

Commit 1b85f4e

Browse files
bpo-27987: pymalloc: align by 16bytes on 64bit platform (GH-12850)
(cherry picked from commit f0be4bb) Co-authored-by: Inada Naoki <[email protected]>
1 parent 2156fec commit 1b85f4e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pymalloc returns memory blocks aligned by 16 bytes, instead of 8 bytes, on
2+
64-bit platforms to conform x86-64 ABI. Recent compilers assume this alignment
3+
more often. Patch by Inada Naoki.

Objects/obmalloc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,14 @@ static int running_on_valgrind = -1;
788788
*
789789
* You shouldn't change this unless you know what you are doing.
790790
*/
791+
792+
#if SIZEOF_VOID_P > 4
793+
#define ALIGNMENT 16 /* must be 2^N */
794+
#define ALIGNMENT_SHIFT 4
795+
#else
791796
#define ALIGNMENT 8 /* must be 2^N */
792797
#define ALIGNMENT_SHIFT 3
798+
#endif
793799

794800
/* Return the number of bytes in size class I, as a uint. */
795801
#define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT)

0 commit comments

Comments
 (0)