summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-15 14:31:10 (GMT)
committerGitHub <noreply@github.com>2019-05-15 14:31:10 (GMT)
commitf24a9f3bf42709fb97b954b6dd6f90853967712e (patch)
treeafbad9c142fc9da5ed3cf3900be4d3985e592140
parent353f8d2282b1a48376f8813fd1170445a0cda873 (diff)
downloadcpython-f24a9f3bf42709fb97b954b6dd6f90853967712e.zip
cpython-f24a9f3bf42709fb97b954b6dd6f90853967712e.tar.gz
cpython-f24a9f3bf42709fb97b954b6dd6f90853967712e.tar.bz2
bpo-27987: pymalloc: align by 16bytes on 64bit platform (GH-12850) (GH-13319)
(cherry picked from commit f0be4bbb9b3cee876249c23f2ae6f38f43fa7495)
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst3
-rw-r--r--Objects/obmalloc.c6
2 files changed, 9 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst
new file mode 100644
index 0000000..b0f32a5
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst
@@ -0,0 +1,3 @@
+pymalloc returns memory blocks aligned by 16 bytes, instead of 8 bytes, on
+64-bit platforms to conform x86-64 ABI. Recent compilers assume this alignment
+more often. Patch by Inada Naoki.
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 0778c85..2067cf5 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -154,8 +154,14 @@ static int running_on_valgrind = -1;
*
* You shouldn't change this unless you know what you are doing.
*/
+
+#if SIZEOF_VOID_P > 4
+#define ALIGNMENT 16 /* must be 2^N */
+#define ALIGNMENT_SHIFT 4
+#else
#define ALIGNMENT 8 /* must be 2^N */
#define ALIGNMENT_SHIFT 3
+#endif
#define ALIGNMENT_MASK (ALIGNMENT - 1)
/* Return the number of bytes in size class I, as a uint. */