https://github.com/python/cpython/commit/1c4b34c6cb851334c813647a2a7db77ecee20b7a
commit: 1c4b34c6cb851334c813647a2a7db77ecee20b7a
branch: main
author: Max Bachmann <[email protected]>
committer: zooba <[email protected]>
date: 2025-05-15T11:50:46Z
summary:
gh-134041: Make _winapi functions compatible with non-desktop API partitions
(GH-134042)
files:
M Modules/_winapi.c
M Modules/clinic/_winapi.c.h
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 02817e09b936f3..0dea8d5ef172f9 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -1573,6 +1573,7 @@ static PyObject *
_winapi_GetLongPathName_impl(PyObject *module, LPCWSTR path)
/*[clinic end generated code: output=c4774b080275a2d0 input=9872e211e3a4a88f]*/
{
+#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)
DWORD cchBuffer;
PyObject *result = NULL;
@@ -1596,6 +1597,9 @@ _winapi_GetLongPathName_impl(PyObject *module, LPCWSTR
path)
PyErr_SetFromWindowsErr(0);
}
return result;
+#else
+ return PyUnicode_FromWideChar(path, -1);
+#endif
}
/*[clinic input]
@@ -1632,6 +1636,8 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE
module_handle)
return PyUnicode_FromWideChar(filename, wcslen(filename));
}
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+
/*[clinic input]
_winapi.GetShortPathName
@@ -1674,6 +1680,8 @@ _winapi_GetShortPathName_impl(PyObject *module, LPCWSTR
path)
return result;
}
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
+
/*[clinic input]
_winapi.GetStdHandle -> HANDLE
@@ -2883,6 +2891,7 @@ _winapi_NeedCurrentDirectoryForExePath_impl(PyObject
*module,
LPCWSTR exe_name)
/*[clinic end generated code: output=a65ec879502b58fc input=972aac88a1ec2f00]*/
{
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
BOOL result;
Py_BEGIN_ALLOW_THREADS
@@ -2890,6 +2899,9 @@ _winapi_NeedCurrentDirectoryForExePath_impl(PyObject
*module,
Py_END_ALLOW_THREADS
return result;
+#else
+ return TRUE;
+#endif
}
diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h
index f8b623fca082d2..b0fc1f1a89b760 100644
--- a/Modules/clinic/_winapi.c.h
+++ b/Modules/clinic/_winapi.c.h
@@ -857,6 +857,8 @@ _winapi_GetModuleFileName(PyObject *module, PyObject *arg)
return return_value;
}
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
PyDoc_STRVAR(_winapi_GetShortPathName__doc__,
"GetShortPathName($module, /, path)\n"
"--\n"
@@ -930,6 +932,8 @@ _winapi_GetShortPathName(PyObject *module, PyObject *const
*args, Py_ssize_t nar
return return_value;
}
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
"GetStdHandle($module, std_handle, /)\n"
"--\n"
@@ -2161,4 +2165,8 @@ _winapi_CopyFile2(PyObject *module, PyObject *const
*args, Py_ssize_t nargs, PyO
return return_value;
}
-/*[clinic end generated code: output=6cd07628af447d0a input=a9049054013a1b77]*/
+
+#ifndef _WINAPI_GETSHORTPATHNAME_METHODDEF
+ #define _WINAPI_GETSHORTPATHNAME_METHODDEF
+#endif /* !defined(_WINAPI_GETSHORTPATHNAME_METHODDEF) */
+/*[clinic end generated code: output=ede63eaaf63aa7e6 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]