Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40052: Fix alignment issue in PyVectorcall_Function() #23999

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PyVectorcall_Function(PyObject *callable)
{
PyTypeObject *tp;
Py_ssize_t offset;
vectorcallfunc *ptr;
vectorcallfunc ptr;

assert(callable != NULL);
tp = Py_TYPE(callable);
Expand All @@ -73,8 +73,8 @@ PyVectorcall_Function(PyObject *callable)
assert(PyCallable_Check(callable));
offset = tp->tp_vectorcall_offset;
assert(offset > 0);
ptr = (vectorcallfunc *)(((char *)callable) + offset);
return *ptr;
memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
return ptr;
}

/* Call the callable object 'callable' with the "vectorcall" calling
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an alignment build warning/error in function ``PyVectorcall_Function()``.
Patch by Andreas Schneider, Antoine Pitrou and Petr Viktorin.
3 changes: 2 additions & 1 deletion Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ PyObject *
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
{
PyThreadState *tstate = _PyThreadState_GET();
vectorcallfunc func;

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