Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6f4de5

Browse files
committed
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 <[email protected]>
1 parent e0b8101 commit e6f4de5

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Include/cpython/abstract.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ PyVectorcall_Function(PyObject *callable)
6767
{
6868
PyTypeObject *tp;
6969
Py_ssize_t offset;
70-
vectorcallfunc *ptr;
70+
union {
71+
char *data;
72+
vectorcallfunc *ptr;
73+
} vc;
7174

7275
assert(callable != NULL);
7376
tp = Py_TYPE(callable);
@@ -77,8 +80,8 @@ PyVectorcall_Function(PyObject *callable)
7780
assert(PyCallable_Check(callable));
7881
offset = tp->tp_vectorcall_offset;
7982
assert(offset > 0);
80-
ptr = (vectorcallfunc *)(((char *)callable) + offset);
81-
return *ptr;
83+
vc.data = (char *)callable + offset;
84+
return *vc.ptr;
8285
}
8386

8487
/* Call the callable object 'callable' with the "vectorcall" calling
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an alignment build warning/error in function ``PyVectorcall_Function()`` publicly exposed by ``abstract.h``.

Objects/call.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ PyObject *
205205
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
206206
{
207207
PyThreadState *tstate = _PyThreadState_GET();
208+
union {
209+
char *data;
210+
vectorcallfunc *ptr;
211+
} vc;
208212

209213
/* get vectorcallfunc as in PyVectorcall_Function, but without
210214
* the Py_TPFLAGS_HAVE_VECTORCALL check */
@@ -215,7 +219,8 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
215219
Py_TYPE(callable)->tp_name);
216220
return NULL;
217221
}
218-
vectorcallfunc func = *(vectorcallfunc *)(((char *)callable) + offset);
222+
vc.data = (char *)callable + offset;
223+
vectorcallfunc func = *vc.ptr;
219224
if (func == NULL) {
220225
_PyErr_Format(tstate, PyExc_TypeError,
221226
"'%.200s' object does not support vectorcall",

0 commit comments

Comments
 (0)