diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 1317fc9a172..e9dcec6590b 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -508,7 +508,9 @@ _winapi_CreateFileMapping_impl(PyObject *module, HANDLE file_handle, Py_END_ALLOW_THREADS if (handle == NULL) { - PyErr_SetFromWindowsErrWithUnicodeFilename(0, name); + PyObject *temp = PyUnicode_FromWideChar(name, -1); + PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, 0, temp); + Py_XDECREF(temp); handle = INVALID_HANDLE_VALUE; } @@ -1405,7 +1407,9 @@ _winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access, Py_END_ALLOW_THREADS if (handle == NULL) { - PyErr_SetFromWindowsErrWithUnicodeFilename(0, name); + PyObject *temp = PyUnicode_FromWideChar(name, -1); + PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, 0, temp); + Py_XDECREF(temp); handle = INVALID_HANDLE_VALUE; }