Skip to content

Commit f66b8d7

Browse files
methanemcepl
authored andcommitted
align allocations and PyGC_Head to 16 bytes on 64-bit platforms
Combination of two upstream commits: - gh#python/cpython@1b85f4e (3.7.17) - gh#python/cpython@8766cb7 (3.7.17) Fixes: bpo#27987 Fixes: rh#1923658 Patch: align-allocations-PyGC_Head.patch
1 parent 5be3512 commit f66b8d7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Include/objimpl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ typedef union _gc_head {
255255
union _gc_head *gc_prev;
256256
Py_ssize_t gc_refs;
257257
} gc;
258-
double dummy; /* force worst-case alignment */
258+
long double dummy; /* force worst-case alignment */
259+
// malloc returns memory block aligned for any built-in types and
260+
// long double is the largest standard C type.
261+
// On amd64 linux, long double requires 16 byte alignment.
262+
// See bpo-27987 for more discussion.
259263
} PyGC_Head;
260264

261265
extern PyGC_Head *_PyGC_generation0;

Objects/obmalloc.c

+6
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,14 @@ static int running_on_valgrind = -1;
650650
*
651651
* You shouldn't change this unless you know what you are doing.
652652
*/
653+
654+
#if SIZEOF_VOID_P > 4
655+
#define ALIGNMENT 16 /* must be 2^N */
656+
#define ALIGNMENT_SHIFT 4
657+
#else
653658
#define ALIGNMENT 8 /* must be 2^N */
654659
#define ALIGNMENT_SHIFT 3
660+
#endif
655661

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

0 commit comments

Comments
 (0)