mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
GH-75586: Make shutil.which() on Windows more consistent with the OS (GH-103179)
This commit is contained in:
parent
f184abbdc9
commit
935aa45235
7 changed files with 233 additions and 54 deletions
|
|
@ -2054,6 +2054,26 @@ _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
|
|||
#undef CB_TYPE
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_winapi.NeedCurrentDirectoryForExePath -> bool
|
||||
|
||||
exe_name: LPCWSTR
|
||||
/
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
|
||||
LPCWSTR exe_name)
|
||||
/*[clinic end generated code: output=a65ec879502b58fc input=972aac88a1ec2f00]*/
|
||||
{
|
||||
BOOL result;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
result = NeedCurrentDirectoryForExePathW(exe_name);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static PyMethodDef winapi_functions[] = {
|
||||
_WINAPI_CLOSEHANDLE_METHODDEF
|
||||
|
|
@ -2089,6 +2109,7 @@ static PyMethodDef winapi_functions[] = {
|
|||
_WINAPI_GETACP_METHODDEF
|
||||
_WINAPI_GETFILETYPE_METHODDEF
|
||||
_WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF
|
||||
_WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
|||
42
Modules/clinic/_winapi.c.h
generated
42
Modules/clinic/_winapi.c.h
generated
|
|
@ -1371,4 +1371,44 @@ _winapi__mimetypes_read_windows_registry(PyObject *module, PyObject *const *args
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=edb1a9d1bbfd6394 input=a9049054013a1b77]*/
|
||||
|
||||
PyDoc_STRVAR(_winapi_NeedCurrentDirectoryForExePath__doc__,
|
||||
"NeedCurrentDirectoryForExePath($module, exe_name, /)\n"
|
||||
"--\n"
|
||||
"\n");
|
||||
|
||||
#define _WINAPI_NEEDCURRENTDIRECTORYFOREXEPATH_METHODDEF \
|
||||
{"NeedCurrentDirectoryForExePath", (PyCFunction)_winapi_NeedCurrentDirectoryForExePath, METH_O, _winapi_NeedCurrentDirectoryForExePath__doc__},
|
||||
|
||||
static int
|
||||
_winapi_NeedCurrentDirectoryForExePath_impl(PyObject *module,
|
||||
LPCWSTR exe_name);
|
||||
|
||||
static PyObject *
|
||||
_winapi_NeedCurrentDirectoryForExePath(PyObject *module, PyObject *arg)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
LPCWSTR exe_name = NULL;
|
||||
int _return_value;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("NeedCurrentDirectoryForExePath", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
exe_name = PyUnicode_AsWideCharString(arg, NULL);
|
||||
if (exe_name == NULL) {
|
||||
goto exit;
|
||||
}
|
||||
_return_value = _winapi_NeedCurrentDirectoryForExePath_impl(module, exe_name);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = PyBool_FromLong((long)_return_value);
|
||||
|
||||
exit:
|
||||
/* Cleanup for exe_name */
|
||||
PyMem_Free((void *)exe_name);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=96ea65ece7912d0a input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue