bpo-35947: Update Windows to the current version of libffi (GH-11797) · python/cpython@32119e1
@@ -729,6 +729,23 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
729729 }
730730}
731731732+#if defined(MS_WIN32) && !defined(_WIN32_WCE)
733+/*
734+Per: https://msdn.microsoft.com/en-us/library/7572ztz4.aspx
735+To be returned by value in RAX, user-defined types must have a length
736+of 1, 2, 4, 8, 16, 32, or 64 bits
737+*/
738+int can_return_struct_as_int(size_t s)
739+{
740+return s == 1 || s == 2 || s == 4;
741+}
742+743+int can_return_struct_as_sint64(size_t s)
744+{
745+return s == 8;
746+}
747+#endif
748+732749733750ffi_type *_ctypes_get_ffi_type(PyObject *obj)
734751{
@@ -778,12 +795,9 @@ static int _call_function_pointer(int flags,
778795int *space;
779796ffi_cif cif;
780797int cc;
781-#ifdef MS_WIN32
782-int delta;
783-#ifndef DONT_USE_SEH
798+#if defined(MS_WIN32) && !defined(DONT_USE_SEH)
784799DWORD dwExceptionCode = 0;
785800EXCEPTION_RECORD record;
786-#endif
787801#endif
788802/* XXX check before here */
789803if (restype == NULL) {
@@ -828,7 +842,6 @@ static int _call_function_pointer(int flags,
828842#ifndef DONT_USE_SEH
829843 __try {
830844#endif
831-delta =
832845#endif
833846ffi_call(&cif, (void *)pProc, resmem, avalues);
834847#ifdef MS_WIN32
@@ -860,35 +873,6 @@ static int _call_function_pointer(int flags,
860873return -1;
861874 }
862875#endif
863-#ifdef MS_WIN64
864-if (delta != 0) {
865-PyErr_Format(PyExc_RuntimeError,
866-"ffi_call failed with code %d",
867-delta);
868-return -1;
869- }
870-#else
871-if (delta < 0) {
872-if (flags & FUNCFLAG_CDECL)
873-PyErr_Format(PyExc_ValueError,
874-"Procedure called with not enough "
875-"arguments (%d bytes missing) "
876-"or wrong calling convention",
877--delta);
878-else
879-PyErr_Format(PyExc_ValueError,
880-"Procedure probably called with not enough "
881-"arguments (%d bytes missing)",
882--delta);
883-return -1;
884- } else if (delta > 0) {
885-PyErr_Format(PyExc_ValueError,
886-"Procedure probably called with too many "
887-"arguments (%d bytes in excess)",
888-delta);
889-return -1;
890- }
891-#endif
892876#endif
893877if ((flags & FUNCFLAG_PYTHONAPI) && PyErr_Occurred())
894878return -1;