https://github.com/python/cpython/commit/74bd566f70f14959a7752388eb2f24cfeb6cf4e4
commit: 74bd566f70f14959a7752388eb2f24cfeb6cf4e4
branch: 3.12
author: Steve Dower <[email protected]>
committer: zooba <[email protected]>
date: 2024-01-26T17:53:46Z
summary:
Use Unicode unconditionally for _winapi.CreateFile (GH-114611)
Currently it switches based on build settings, but argument clinic does not
handle it correctly.
files:
M Modules/_winapi.c
M Modules/clinic/_winapi.c.h
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index bcb003f8216dd4..2784a815696851 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -439,7 +439,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
@@ -450,12 +450,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;
@@ -466,14 +466,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;
}
diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h
index 1394a8fcffd9f6..5b87b24246fd4f 100644
--- a/Modules/clinic/_winapi.c.h
+++ b/Modules/clinic/_winapi.c.h
@@ -161,7 +161,7 @@ PyDoc_STRVAR(_winapi_CreateFile__doc__,
{"CreateFile", _PyCFunction_CAST(_winapi_CreateFile), METH_FASTCALL,
_winapi_CreateFile__doc__},
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,
@@ -171,7 +171,7 @@ static PyObject *
_winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
- LPCTSTR file_name;
+ LPCWSTR file_name = NULL;
DWORD desired_access;
DWORD share_mode;
LPSECURITY_ATTRIBUTES security_attributes;
@@ -180,8 +180,8 @@ _winapi_CreateFile(PyObject *module, PyObject *const *args,
Py_ssize_t nargs)
HANDLE template_file;
HANDLE _return_value;
- if (!_PyArg_ParseStack(args, nargs, "skk" F_POINTER "kk" F_HANDLE
":CreateFile",
- &file_name, &desired_access, &share_mode, &security_attributes,
&creation_disposition, &flags_and_attributes, &template_file)) {
+ if (!_PyArg_ParseStack(args, nargs, "O&kk" F_POINTER "kk" F_HANDLE
":CreateFile",
+ _PyUnicode_WideCharString_Converter, &file_name, &desired_access,
&share_mode, &security_attributes, &creation_disposition,
&flags_and_attributes, &template_file)) {
goto exit;
}
_return_value = _winapi_CreateFile_impl(module, file_name, desired_access,
share_mode, security_attributes, creation_disposition, flags_and_attributes,
template_file);
@@ -194,6 +194,9 @@ _winapi_CreateFile(PyObject *module, PyObject *const *args,
Py_ssize_t nargs)
return_value = HANDLE_TO_PYNUM(_return_value);
exit:
+ /* Cleanup for file_name */
+ PyMem_Free((void *)file_name);
+
return return_value;
}
@@ -1479,4 +1482,4 @@ _winapi_CopyFile2(PyObject *module, PyObject *const
*args, Py_ssize_t nargs, PyO
return return_value;
}
-/*[clinic end generated code: output=9d43ae4bdbe1126a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a1f20d03c363db1d input=a9049054013a1b77]*/
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]