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

Skip to content

Commit 056c082

Browse files
encukoucryptomilkpitrou
authored
bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999)
``` 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. ``` Co-Authored-By: Andreas Schneider <[email protected]> Co-Authored-By: Antoine Pitrou <[email protected]>
1 parent 2edfc86 commit 056c082

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Include/cpython/abstract.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PyVectorcall_Function(PyObject *callable)
6363
{
6464
PyTypeObject *tp;
6565
Py_ssize_t offset;
66-
vectorcallfunc *ptr;
66+
vectorcallfunc ptr;
6767

6868
assert(callable != NULL);
6969
tp = Py_TYPE(callable);
@@ -73,8 +73,8 @@ PyVectorcall_Function(PyObject *callable)
7373
assert(PyCallable_Check(callable));
7474
offset = tp->tp_vectorcall_offset;
7575
assert(offset > 0);
76-
ptr = (vectorcallfunc *)(((char *)callable) + offset);
77-
return *ptr;
76+
memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
77+
return ptr;
7878
}
7979

8080
/* Call the callable object 'callable' with the "vectorcall" calling
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an alignment build warning/error in function ``PyVectorcall_Function()``.
2+
Patch by Andreas Schneider, Antoine Pitrou and Petr Viktorin.

Objects/call.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ PyObject *
205205
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
206206
{
207207
PyThreadState *tstate = _PyThreadState_GET();
208+
vectorcallfunc func;
208209

209210
/* get vectorcallfunc as in PyVectorcall_Function, but without
210211
* the Py_TPFLAGS_HAVE_VECTORCALL check */
@@ -215,7 +216,7 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
215216
Py_TYPE(callable)->tp_name);
216217
return NULL;
217218
}
218-
vectorcallfunc func = *(vectorcallfunc *)(((char *)callable) + offset);
219+
memcpy(&func, (char *) callable + offset, sizeof(func));
219220
if (func == NULL) {
220221
_PyErr_Format(tstate, PyExc_TypeError,
221222
"'%.200s' object does not support vectorcall",

0 commit comments

Comments
 (0)