python39/bsc1167501-invalid-alignment.patch

77 lines
2.8 KiB
Diff

From e6f4de57ffd175870e513ffa387fa6e7eaaeaed2 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Tue, 24 Mar 2020 07:55:00 +0100
Subject: [PATCH] bpo-40052: Fix alignment issue in PyVectorcall_Function()
In file included from /usr/include/python3.8/Python.h:147:
In file included from /usr/include/python3.8/abstract.h:837:
/usr/include/python3.8/cpython/abstract.h:91:11: error: cast from 'char *' to 'vectorcallfunc *'
(aka 'struct _object *(**)(struct _object *, struct _object *const *, unsigned long, struct _object *)')
increases required alignment from 1 to 8 [-Werror,-Wcast-align]
ptr = (vectorcallfunc*)(((char *)callable) + offset);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
---
Include/cpython/abstract.h | 9 ++++++---
.../next/C API/2020-03-24-09-27-10.bpo-40052.27P2KG.rst | 1 +
Objects/call.c | 7 ++++++-
3 files changed, 13 insertions(+), 4 deletions(-)
create mode 100644 Misc/NEWS.d/next/C API/2020-03-24-09-27-10.bpo-40052.27P2KG.rst
--- a/Include/cpython/abstract.h
+++ b/Include/cpython/abstract.h
@@ -67,7 +67,10 @@ PyVectorcall_Function(PyObject *callable
{
PyTypeObject *tp;
Py_ssize_t offset;
- vectorcallfunc *ptr;
+ union {
+ char *data;
+ vectorcallfunc *ptr;
+ } vc;
assert(callable != NULL);
tp = Py_TYPE(callable);
@@ -77,8 +80,8 @@ PyVectorcall_Function(PyObject *callable
assert(PyCallable_Check(callable));
offset = tp->tp_vectorcall_offset;
assert(offset > 0);
- ptr = (vectorcallfunc *)(((char *)callable) + offset);
- return *ptr;
+ vc.data = (char *)callable + offset;
+ return *vc.ptr;
}
/* Call the callable object 'callable' with the "vectorcall" calling
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -205,6 +205,10 @@ PyObject *
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
{
PyThreadState *tstate = _PyThreadState_GET();
+ union {
+ char *data;
+ vectorcallfunc *ptr;
+ } vc;
/* get vectorcallfunc as in PyVectorcall_Function, but without
* the Py_TPFLAGS_HAVE_VECTORCALL check */
@@ -215,7 +219,8 @@ PyVectorcall_Call(PyObject *callable, Py
Py_TYPE(callable)->tp_name);
return NULL;
}
- vectorcallfunc func = *(vectorcallfunc *)(((char *)callable) + offset);
+ vc.data = (char *)callable + offset;
+ vectorcallfunc func = *vc.ptr;
if (func == NULL) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object does not support vectorcall",
--- /dev/null
+++ b/Misc/NEWS.d/next/C
@@ -0,0 +1 @@
+Fix an alignment build warning/error in function ``PyVectorcall_Function()`` publicly exposed by ``abstract.h``.
\ No newline at end of file