]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.8] bpo-40052: Fix alignment issue in PyVectorcall_Function() (GH-23999) (GH-24120)
authorPetr Viktorin <encukou@gmail.com>
Tue, 12 Jan 2021 14:45:05 +0000 (15:45 +0100)
committerGitHub <noreply@github.com>
Tue, 12 Jan 2021 14:45:05 +0000 (15:45 +0100)
Co-Authored-By: Andreas Schneider <asn@cryptomilk.org>
Co-Authored-By: Antoine Pitrou <antoine@python.org>.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
(cherry picked from commit 056c08211b402b4dbc1530a9de9d00ad5309909f)
https://bugs.python.org/issue40052

Include/cpython/abstract.h
Misc/NEWS.d/next/C API/2020-03-24-09-27-10.bpo-40052.27P2KG.rst [new file with mode: 0644]
Objects/call.c

index 2ea3209bca1098f11b1a1a78e43280eea79459c9..dbfce2dc9061db3ab5d5b4b1bcae63af4a0c9c39 100644 (file)
@@ -82,14 +82,14 @@ _PyVectorcall_Function(PyObject *callable)
 {
     PyTypeObject *tp = Py_TYPE(callable);
     Py_ssize_t offset = tp->tp_vectorcall_offset;
-    vectorcallfunc *ptr;
+    vectorcallfunc ptr;
     if (!PyType_HasFeature(tp, _Py_TPFLAGS_HAVE_VECTORCALL)) {
         return NULL;
     }
     assert(PyCallable_Check(callable));
     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
diff --git a/Misc/NEWS.d/next/C API/2020-03-24-09-27-10.bpo-40052.27P2KG.rst b/Misc/NEWS.d/next/C API/2020-03-24-09-27-10.bpo-40052.27P2KG.rst
new file mode 100644 (file)
index 0000000..538488e
--- /dev/null
@@ -0,0 +1,2 @@
+Fix an alignment build warning/error in function ``PyVectorcall_Function()``.
+Patch by Andreas Schneider, Antoine Pitrou and Petr Viktorin.
index c66389854d8bf015c87fa65c5df64733ae7a3aa7..9672be01ed05904ca4b5b786defaed8082a37bac 100644 (file)
@@ -175,13 +175,14 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
 {
     /* get vectorcallfunc as in _PyVectorcall_Function, but without
      * the _Py_TPFLAGS_HAVE_VECTORCALL check */
+    vectorcallfunc func;
     Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset;
     if (offset <= 0) {
         PyErr_Format(PyExc_TypeError, "'%.200s' object does not support vectorcall",
                      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(PyExc_TypeError, "'%.200s' object does not support vectorcall",
                      Py_TYPE(callable)->tp_name);