Skip to content

Commit

Permalink
Use Unicode unconditionally for _winapi.CreateFile (pythonGH-114611)
Browse files Browse the repository at this point in the history
Currently it switches based on build settings, but argument clinic does not handle it correctly.
  • Loading branch information
zooba committed Jan 26, 2024
1 parent c09eae3 commit b7318a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 9 additions & 8 deletions Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
/*[clinic input]
_winapi.CreateFile -> HANDLE
file_name: LPCTSTR
file_name: LPCWSTR
desired_access: DWORD
share_mode: DWORD
security_attributes: LPSECURITY_ATTRIBUTES
Expand All @@ -462,12 +462,12 @@ _winapi.CreateFile -> HANDLE
[clinic start generated code]*/

static HANDLE
_winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
_winapi_CreateFile_impl(PyObject *module, LPCWSTR file_name,
DWORD desired_access, DWORD share_mode,
LPSECURITY_ATTRIBUTES security_attributes,
DWORD creation_disposition,
DWORD flags_and_attributes, HANDLE template_file)
/*[clinic end generated code: output=417ddcebfc5a3d53 input=6423c3e40372dbd5]*/
/*[clinic end generated code: output=818c811e5e04d550 input=1fa870ed1c2e3d69]*/
{
HANDLE handle;

Expand All @@ -478,14 +478,15 @@ _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name,
}

Py_BEGIN_ALLOW_THREADS
handle = CreateFile(file_name, desired_access,
share_mode, security_attributes,
creation_disposition,
flags_and_attributes, template_file);
handle = CreateFileW(file_name, desired_access,
share_mode, security_attributes,
creation_disposition,
flags_and_attributes, template_file);
Py_END_ALLOW_THREADS

if (handle == INVALID_HANDLE_VALUE)
if (handle == INVALID_HANDLE_VALUE) {
PyErr_SetFromWindowsErr(0);
}

return handle;
}
Expand Down
15 changes: 10 additions & 5 deletions Modules/clinic/_winapi.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7318a1

Please sign in to comment.