diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 2eb708e9073e91..b37b8e0847d0a1 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -502,7 +502,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; } @@ -1379,7 +1381,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; }