2015-05-13 03:22:54 -03:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-08-11 18:25:49 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2023-08-31 18:42:34 -03:00
|
|
|
# include "pycore_gc.h" // PyGC_Head
|
|
|
|
# include "pycore_runtime.h" // _Py_ID()
|
2022-08-11 18:25:49 -03:00
|
|
|
#endif
|
2023-08-31 18:42:34 -03:00
|
|
|
#include "pycore_long.h" // _PyLong_Size_t_Converter()
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__,
|
|
|
|
"GetOverlappedResult($self, wait, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OVERLAPPED_GETOVERLAPPEDRESULT_METHODDEF \
|
|
|
|
{"GetOverlappedResult", (PyCFunction)_winapi_Overlapped_GetOverlappedResult, METH_O, _winapi_Overlapped_GetOverlappedResult__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_Overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
int wait;
|
|
|
|
|
2018-12-25 07:23:47 -04:00
|
|
|
wait = PyObject_IsTrue(arg);
|
|
|
|
if (wait < 0) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_Overlapped_GetOverlappedResult_impl(self, wait);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_Overlapped_getbuffer__doc__,
|
|
|
|
"getbuffer($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF \
|
|
|
|
{"getbuffer", (PyCFunction)_winapi_Overlapped_getbuffer, METH_NOARGS, _winapi_Overlapped_getbuffer__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_Overlapped_getbuffer_impl(OverlappedObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_Overlapped_getbuffer(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return _winapi_Overlapped_getbuffer_impl(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_Overlapped_cancel__doc__,
|
|
|
|
"cancel($self, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OVERLAPPED_CANCEL_METHODDEF \
|
|
|
|
{"cancel", (PyCFunction)_winapi_Overlapped_cancel, METH_NOARGS, _winapi_Overlapped_cancel__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_Overlapped_cancel_impl(OverlappedObject *self);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_Overlapped_cancel(OverlappedObject *self, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return _winapi_Overlapped_cancel_impl(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_CloseHandle__doc__,
|
|
|
|
"CloseHandle($module, handle, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Close handle.");
|
|
|
|
|
|
|
|
#define _WINAPI_CLOSEHANDLE_METHODDEF \
|
|
|
|
{"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_CloseHandle_impl(PyObject *module, HANDLE handle);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_CloseHandle(PyObject *module, PyObject *arg)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE handle;
|
|
|
|
|
2016-06-09 10:16:06 -03:00
|
|
|
if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_CloseHandle_impl(module, handle);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__,
|
|
|
|
"ConnectNamedPipe($module, /, handle, overlapped=False)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CONNECTNAMEDPIPE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"ConnectNamedPipe", _PyCFunction_CAST(_winapi_ConnectNamedPipe), METH_FASTCALL|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle,
|
2015-05-13 12:58:35 -03:00
|
|
|
int use_overlapped);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_ConnectNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 2
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(handle), &_Py_ID(overlapped), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2016-08-14 04:52:18 -03:00
|
|
|
static const char * const _keywords[] = {"handle", "overlapped", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
2022-12-03 15:52:21 -04:00
|
|
|
.format = "" F_HANDLE "|p:ConnectNamedPipe",
|
2022-08-11 18:25:49 -03:00
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2015-05-13 03:22:54 -03:00
|
|
|
HANDLE handle;
|
|
|
|
int use_overlapped = 0;
|
|
|
|
|
2017-01-16 20:29:01 -04:00
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
2016-06-09 10:16:06 -03:00
|
|
|
&handle, &use_overlapped)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-02-12 20:28:35 -04:00
|
|
|
PyDoc_STRVAR(_winapi_CreateEventW__doc__,
|
|
|
|
"CreateEventW($module, /, security_attributes, manual_reset,\n"
|
|
|
|
" initial_state, name)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEEVENTW_METHODDEF \
|
|
|
|
{"CreateEventW", _PyCFunction_CAST(_winapi_CreateEventW), METH_FASTCALL|METH_KEYWORDS, _winapi_CreateEventW__doc__},
|
|
|
|
|
|
|
|
static HANDLE
|
|
|
|
_winapi_CreateEventW_impl(PyObject *module,
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes,
|
|
|
|
BOOL manual_reset, BOOL initial_state,
|
|
|
|
LPCWSTR name);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_CreateEventW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 4
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(security_attributes), &_Py_ID(manual_reset), &_Py_ID(initial_state), &_Py_ID(name), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"security_attributes", "manual_reset", "initial_state", "name", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "" F_POINTER "iiO&:CreateEventW",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes;
|
|
|
|
BOOL manual_reset;
|
|
|
|
BOOL initial_state;
|
|
|
|
LPCWSTR name = NULL;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&security_attributes, &manual_reset, &initial_state, _PyUnicode_WideCharString_Opt_Converter, &name)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_CreateEventW_impl(module, security_attributes, manual_reset, initial_state, name);
|
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_CreateFile__doc__,
|
|
|
|
"CreateFile($module, file_name, desired_access, share_mode,\n"
|
|
|
|
" security_attributes, creation_disposition,\n"
|
|
|
|
" flags_and_attributes, template_file, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEFILE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"CreateFile", _PyCFunction_CAST(_winapi_CreateFile), METH_FASTCALL, _winapi_CreateFile__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static HANDLE
|
2024-01-26 13:27:29 -04:00
|
|
|
_winapi_CreateFile_impl(PyObject *module, LPCWSTR file_name,
|
2015-05-13 12:58:35 -03:00
|
|
|
DWORD desired_access, DWORD share_mode,
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes,
|
|
|
|
DWORD creation_disposition,
|
|
|
|
DWORD flags_and_attributes, HANDLE template_file);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_CreateFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2024-01-26 13:27:29 -04:00
|
|
|
LPCWSTR file_name = NULL;
|
2015-05-13 03:22:54 -03:00
|
|
|
DWORD desired_access;
|
|
|
|
DWORD share_mode;
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes;
|
|
|
|
DWORD creation_disposition;
|
|
|
|
DWORD flags_and_attributes;
|
|
|
|
HANDLE template_file;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
2024-01-26 13:27:29 -04:00
|
|
|
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)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
2015-05-13 03:22:54 -03:00
|
|
|
Py_RETURN_NONE;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
2024-01-26 13:27:29 -04:00
|
|
|
/* Cleanup for file_name */
|
|
|
|
PyMem_Free((void *)file_name);
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:08:16 -04:00
|
|
|
PyDoc_STRVAR(_winapi_CreateFileMapping__doc__,
|
|
|
|
"CreateFileMapping($module, file_handle, security_attributes, protect,\n"
|
|
|
|
" max_size_high, max_size_low, name, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEFILEMAPPING_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"CreateFileMapping", _PyCFunction_CAST(_winapi_CreateFileMapping), METH_FASTCALL, _winapi_CreateFileMapping__doc__},
|
2019-02-24 00:08:16 -04:00
|
|
|
|
|
|
|
static HANDLE
|
|
|
|
_winapi_CreateFileMapping_impl(PyObject *module, HANDLE file_handle,
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes,
|
|
|
|
DWORD protect, DWORD max_size_high,
|
|
|
|
DWORD max_size_low, LPCWSTR name);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_CreateFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE file_handle;
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes;
|
|
|
|
DWORD protect;
|
|
|
|
DWORD max_size_high;
|
|
|
|
DWORD max_size_low;
|
2022-10-03 04:42:54 -03:00
|
|
|
LPCWSTR name = NULL;
|
2019-02-24 00:08:16 -04:00
|
|
|
HANDLE _return_value;
|
|
|
|
|
2020-07-10 17:26:06 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_POINTER "kkkO&:CreateFileMapping",
|
|
|
|
&file_handle, &security_attributes, &protect, &max_size_high, &max_size_low, _PyUnicode_WideCharString_Converter, &name)) {
|
2019-02-24 00:08:16 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_CreateFileMapping_impl(module, file_handle, security_attributes, protect, max_size_high, max_size_low, name);
|
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
2020-07-10 17:26:06 -03:00
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
2019-02-24 00:08:16 -04:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_CreateJunction__doc__,
|
|
|
|
"CreateJunction($module, src_path, dst_path, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEJUNCTION_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"CreateJunction", _PyCFunction_CAST(_winapi_CreateJunction), METH_FASTCALL, _winapi_CreateJunction__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2020-07-10 17:26:06 -03:00
|
|
|
_winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
|
|
|
|
LPCWSTR dst_path);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_CreateJunction(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-10-03 04:42:54 -03:00
|
|
|
LPCWSTR src_path = NULL;
|
|
|
|
LPCWSTR dst_path = NULL;
|
2015-05-13 03:22:54 -03:00
|
|
|
|
2020-07-10 17:26:06 -03:00
|
|
|
if (!_PyArg_CheckPositional("CreateJunction", nargs, 2, 2)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(args[0])) {
|
|
|
|
_PyArg_BadArgument("CreateJunction", "argument 1", "str", args[0]);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
src_path = PyUnicode_AsWideCharString(args[0], NULL);
|
|
|
|
if (src_path == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(args[1])) {
|
|
|
|
_PyArg_BadArgument("CreateJunction", "argument 2", "str", args[1]);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
dst_path = PyUnicode_AsWideCharString(args[1], NULL);
|
|
|
|
if (dst_path == NULL) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_CreateJunction_impl(module, src_path, dst_path);
|
|
|
|
|
|
|
|
exit:
|
2020-07-10 17:26:06 -03:00
|
|
|
/* Cleanup for src_path */
|
|
|
|
PyMem_Free((void *)src_path);
|
|
|
|
/* Cleanup for dst_path */
|
|
|
|
PyMem_Free((void *)dst_path);
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-02-12 20:28:35 -04:00
|
|
|
PyDoc_STRVAR(_winapi_CreateMutexW__doc__,
|
|
|
|
"CreateMutexW($module, /, security_attributes, initial_owner, name)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEMUTEXW_METHODDEF \
|
|
|
|
{"CreateMutexW", _PyCFunction_CAST(_winapi_CreateMutexW), METH_FASTCALL|METH_KEYWORDS, _winapi_CreateMutexW__doc__},
|
|
|
|
|
|
|
|
static HANDLE
|
|
|
|
_winapi_CreateMutexW_impl(PyObject *module,
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes,
|
|
|
|
BOOL initial_owner, LPCWSTR name);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_CreateMutexW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 3
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(security_attributes), &_Py_ID(initial_owner), &_Py_ID(name), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"security_attributes", "initial_owner", "name", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "" F_POINTER "iO&:CreateMutexW",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes;
|
|
|
|
BOOL initial_owner;
|
|
|
|
LPCWSTR name = NULL;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&security_attributes, &initial_owner, _PyUnicode_WideCharString_Opt_Converter, &name)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_CreateMutexW_impl(module, security_attributes, initial_owner, name);
|
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__,
|
|
|
|
"CreateNamedPipe($module, name, open_mode, pipe_mode, max_instances,\n"
|
|
|
|
" out_buffer_size, in_buffer_size, default_timeout,\n"
|
|
|
|
" security_attributes, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATENAMEDPIPE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"CreateNamedPipe", _PyCFunction_CAST(_winapi_CreateNamedPipe), METH_FASTCALL, _winapi_CreateNamedPipe__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static HANDLE
|
2024-05-29 12:51:09 -03:00
|
|
|
_winapi_CreateNamedPipe_impl(PyObject *module, LPCWSTR name, DWORD open_mode,
|
2016-07-07 11:35:15 -03:00
|
|
|
DWORD pipe_mode, DWORD max_instances,
|
|
|
|
DWORD out_buffer_size, DWORD in_buffer_size,
|
|
|
|
DWORD default_timeout,
|
2015-05-13 12:58:35 -03:00
|
|
|
LPSECURITY_ATTRIBUTES security_attributes);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_CreateNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2024-05-29 12:51:09 -03:00
|
|
|
LPCWSTR name = NULL;
|
2015-05-13 03:22:54 -03:00
|
|
|
DWORD open_mode;
|
|
|
|
DWORD pipe_mode;
|
|
|
|
DWORD max_instances;
|
|
|
|
DWORD out_buffer_size;
|
|
|
|
DWORD in_buffer_size;
|
|
|
|
DWORD default_timeout;
|
|
|
|
LPSECURITY_ATTRIBUTES security_attributes;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
2024-05-29 12:51:09 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "O&kkkkkk" F_POINTER ":CreateNamedPipe",
|
|
|
|
_PyUnicode_WideCharString_Converter, &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
2015-05-13 03:22:54 -03:00
|
|
|
Py_RETURN_NONE;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
2024-05-29 12:51:09 -03:00
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_CreatePipe__doc__,
|
|
|
|
"CreatePipe($module, pipe_attrs, size, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Create an anonymous pipe.\n"
|
|
|
|
"\n"
|
|
|
|
" pipe_attrs\n"
|
|
|
|
" Ignored internally, can be None.\n"
|
|
|
|
"\n"
|
|
|
|
"Returns a 2-tuple of handles, to the read and write ends of the pipe.");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEPIPE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"CreatePipe", _PyCFunction_CAST(_winapi_CreatePipe), METH_FASTCALL, _winapi_CreatePipe__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_CreatePipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *pipe_attrs;
|
|
|
|
DWORD size;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "Ok:CreatePipe",
|
|
|
|
&pipe_attrs, &size)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_CreatePipe_impl(module, pipe_attrs, size);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_CreateProcess__doc__,
|
|
|
|
"CreateProcess($module, application_name, command_line, proc_attrs,\n"
|
|
|
|
" thread_attrs, inherit_handles, creation_flags,\n"
|
|
|
|
" env_mapping, current_directory, startup_info, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Create a new process and its primary thread.\n"
|
|
|
|
"\n"
|
2018-12-14 04:30:51 -04:00
|
|
|
" command_line\n"
|
|
|
|
" Can be str or None\n"
|
2015-05-13 03:22:54 -03:00
|
|
|
" proc_attrs\n"
|
|
|
|
" Ignored internally, can be None.\n"
|
|
|
|
" thread_attrs\n"
|
|
|
|
" Ignored internally, can be None.\n"
|
|
|
|
"\n"
|
|
|
|
"The return value is a tuple of the process handle, thread handle,\n"
|
|
|
|
"process ID, and thread ID.");
|
|
|
|
|
|
|
|
#define _WINAPI_CREATEPROCESS_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"CreateProcess", _PyCFunction_CAST(_winapi_CreateProcess), METH_FASTCALL, _winapi_CreateProcess__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2023-05-31 14:52:33 -03:00
|
|
|
_winapi_CreateProcess_impl(PyObject *module, const wchar_t *application_name,
|
2018-12-14 04:30:51 -04:00
|
|
|
PyObject *command_line, PyObject *proc_attrs,
|
2015-05-13 12:58:35 -03:00
|
|
|
PyObject *thread_attrs, BOOL inherit_handles,
|
|
|
|
DWORD creation_flags, PyObject *env_mapping,
|
2023-05-31 14:52:33 -03:00
|
|
|
const wchar_t *current_directory,
|
2015-05-13 12:58:35 -03:00
|
|
|
PyObject *startup_info);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_CreateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2023-05-31 14:52:33 -03:00
|
|
|
const wchar_t *application_name = NULL;
|
2018-12-14 04:30:51 -04:00
|
|
|
PyObject *command_line;
|
2015-05-13 03:22:54 -03:00
|
|
|
PyObject *proc_attrs;
|
|
|
|
PyObject *thread_attrs;
|
|
|
|
BOOL inherit_handles;
|
|
|
|
DWORD creation_flags;
|
|
|
|
PyObject *env_mapping;
|
2023-05-31 14:52:33 -03:00
|
|
|
const wchar_t *current_directory = NULL;
|
2015-05-13 03:22:54 -03:00
|
|
|
PyObject *startup_info;
|
|
|
|
|
2020-06-30 03:03:15 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "O&OOOikOO&O:CreateProcess",
|
|
|
|
_PyUnicode_WideCharString_Opt_Converter, &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, _PyUnicode_WideCharString_Opt_Converter, ¤t_directory, &startup_info)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_CreateProcess_impl(module, application_name, command_line, proc_attrs, thread_attrs, inherit_handles, creation_flags, env_mapping, current_directory, startup_info);
|
|
|
|
|
|
|
|
exit:
|
2020-06-30 03:03:15 -03:00
|
|
|
/* Cleanup for application_name */
|
|
|
|
PyMem_Free((void *)application_name);
|
|
|
|
/* Cleanup for current_directory */
|
|
|
|
PyMem_Free((void *)current_directory);
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_DuplicateHandle__doc__,
|
|
|
|
"DuplicateHandle($module, source_process_handle, source_handle,\n"
|
|
|
|
" target_process_handle, desired_access, inherit_handle,\n"
|
|
|
|
" options=0, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a duplicate handle object.\n"
|
|
|
|
"\n"
|
|
|
|
"The duplicate handle refers to the same object as the original\n"
|
|
|
|
"handle. Therefore, any changes to the object are reflected\n"
|
|
|
|
"through both handles.");
|
|
|
|
|
|
|
|
#define _WINAPI_DUPLICATEHANDLE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"DuplicateHandle", _PyCFunction_CAST(_winapi_DuplicateHandle), METH_FASTCALL, _winapi_DuplicateHandle__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static HANDLE
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle,
|
2015-05-13 12:58:35 -03:00
|
|
|
HANDLE source_handle,
|
|
|
|
HANDLE target_process_handle,
|
|
|
|
DWORD desired_access, BOOL inherit_handle,
|
|
|
|
DWORD options);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_DuplicateHandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE source_process_handle;
|
|
|
|
HANDLE source_handle;
|
|
|
|
HANDLE target_process_handle;
|
|
|
|
DWORD desired_access;
|
|
|
|
BOOL inherit_handle;
|
|
|
|
DWORD options = 0;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle",
|
|
|
|
&source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
2015-05-13 03:22:54 -03:00
|
|
|
Py_RETURN_NONE;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_ExitProcess__doc__,
|
|
|
|
"ExitProcess($module, ExitCode, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_EXITPROCESS_METHODDEF \
|
|
|
|
{"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_ExitProcess_impl(PyObject *module, UINT ExitCode);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_ExitProcess(PyObject *module, PyObject *arg)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
UINT ExitCode;
|
|
|
|
|
2016-06-09 10:16:06 -03:00
|
|
|
if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_ExitProcess_impl(module, ExitCode);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__,
|
|
|
|
"GetCurrentProcess($module, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a handle object for the current process.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETCURRENTPROCESS_METHODDEF \
|
|
|
|
{"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__},
|
|
|
|
|
|
|
|
static HANDLE
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetCurrentProcess_impl(PyObject *module);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored))
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
|
|
|
_return_value = _winapi_GetCurrentProcess_impl(module);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
2015-05-13 03:22:54 -03:00
|
|
|
Py_RETURN_NONE;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__,
|
|
|
|
"GetExitCodeProcess($module, process, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the termination status of the specified process.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETEXITCODEPROCESS_METHODDEF \
|
|
|
|
{"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__},
|
|
|
|
|
|
|
|
static DWORD
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetExitCodeProcess(PyObject *module, PyObject *arg)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE process;
|
|
|
|
DWORD _return_value;
|
|
|
|
|
2016-06-09 10:16:06 -03:00
|
|
|
if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_GetExitCodeProcess_impl(module, process);
|
2017-10-24 20:53:32 -03:00
|
|
|
if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2023-10-20 12:08:41 -03:00
|
|
|
return_value = PyLong_FromUnsignedLong(_return_value);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_GetLastError__doc__,
|
|
|
|
"GetLastError($module, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_GETLASTERROR_METHODDEF \
|
|
|
|
{"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__},
|
|
|
|
|
|
|
|
static DWORD
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetLastError_impl(PyObject *module);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored))
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
DWORD _return_value;
|
|
|
|
|
|
|
|
_return_value = _winapi_GetLastError_impl(module);
|
2017-10-24 20:53:32 -03:00
|
|
|
if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2023-10-20 12:08:41 -03:00
|
|
|
return_value = PyLong_FromUnsignedLong(_return_value);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-04-15 11:36:06 -03:00
|
|
|
PyDoc_STRVAR(_winapi_GetLongPathName__doc__,
|
|
|
|
"GetLongPathName($module, /, path)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the long version of the provided path.\n"
|
|
|
|
"\n"
|
|
|
|
"If the path is already in its long form, returns the same value.\n"
|
|
|
|
"\n"
|
|
|
|
"The path must already be a \'str\'. If the type is not known, use\n"
|
|
|
|
"os.fsdecode before calling this function.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETLONGPATHNAME_METHODDEF \
|
|
|
|
{"GetLongPathName", _PyCFunction_CAST(_winapi_GetLongPathName), METH_FASTCALL|METH_KEYWORDS, _winapi_GetLongPathName__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetLongPathName_impl(PyObject *module, LPCWSTR path);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetLongPathName(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 1
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(path), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"path", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "GetLongPathName",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
PyObject *argsbuf[1];
|
|
|
|
LPCWSTR path = NULL;
|
|
|
|
|
2024-11-08 08:23:50 -04:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
|
|
|
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
2024-04-15 11:36:06 -03:00
|
|
|
if (!args) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(args[0])) {
|
|
|
|
_PyArg_BadArgument("GetLongPathName", "argument 'path'", "str", args[0]);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
path = PyUnicode_AsWideCharString(args[0], NULL);
|
|
|
|
if (path == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_GetLongPathName_impl(module, path);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for path */
|
|
|
|
PyMem_Free((void *)path);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_GetModuleFileName__doc__,
|
|
|
|
"GetModuleFileName($module, module_handle, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the fully-qualified path for the file that contains module.\n"
|
|
|
|
"\n"
|
|
|
|
"The module must have been loaded by the current process.\n"
|
|
|
|
"\n"
|
|
|
|
"The module parameter should be a handle to the loaded module\n"
|
|
|
|
"whose path is being requested. If this parameter is 0,\n"
|
|
|
|
"GetModuleFileName retrieves the path of the executable file\n"
|
|
|
|
"of the current process.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETMODULEFILENAME_METHODDEF \
|
|
|
|
{"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetModuleFileName(PyObject *module, PyObject *arg)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HMODULE module_handle;
|
|
|
|
|
2016-06-09 10:16:06 -03:00
|
|
|
if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_GetModuleFileName_impl(module, module_handle);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-04-15 11:36:06 -03:00
|
|
|
PyDoc_STRVAR(_winapi_GetShortPathName__doc__,
|
|
|
|
"GetShortPathName($module, /, path)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the short version of the provided path.\n"
|
|
|
|
"\n"
|
|
|
|
"If the path is already in its short form, returns the same value.\n"
|
|
|
|
"\n"
|
|
|
|
"The path must already be a \'str\'. If the type is not known, use\n"
|
|
|
|
"os.fsdecode before calling this function.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETSHORTPATHNAME_METHODDEF \
|
|
|
|
{"GetShortPathName", _PyCFunction_CAST(_winapi_GetShortPathName), METH_FASTCALL|METH_KEYWORDS, _winapi_GetShortPathName__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetShortPathName_impl(PyObject *module, LPCWSTR path);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetShortPathName(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 1
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(path), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"path", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "GetShortPathName",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
PyObject *argsbuf[1];
|
|
|
|
LPCWSTR path = NULL;
|
|
|
|
|
2024-11-08 08:23:50 -04:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
|
|
|
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
2024-04-15 11:36:06 -03:00
|
|
|
if (!args) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(args[0])) {
|
|
|
|
_PyArg_BadArgument("GetShortPathName", "argument 'path'", "str", args[0]);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
path = PyUnicode_AsWideCharString(args[0], NULL);
|
|
|
|
if (path == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_GetShortPathName_impl(module, path);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for path */
|
|
|
|
PyMem_Free((void *)path);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_GetStdHandle__doc__,
|
|
|
|
"GetStdHandle($module, std_handle, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return a handle to the specified standard device.\n"
|
|
|
|
"\n"
|
|
|
|
" std_handle\n"
|
|
|
|
" One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n"
|
|
|
|
"\n"
|
|
|
|
"The integer associated with the handle object is returned.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETSTDHANDLE_METHODDEF \
|
|
|
|
{"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__},
|
|
|
|
|
|
|
|
static HANDLE
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetStdHandle(PyObject *module, PyObject *arg)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
DWORD std_handle;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
2016-06-09 10:16:06 -03:00
|
|
|
if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_GetStdHandle_impl(module, std_handle);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
2015-05-13 03:22:54 -03:00
|
|
|
Py_RETURN_NONE;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_GetVersion__doc__,
|
|
|
|
"GetVersion($module, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Return the version number of the current operating system.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETVERSION_METHODDEF \
|
|
|
|
{"GetVersion", (PyCFunction)_winapi_GetVersion, METH_NOARGS, _winapi_GetVersion__doc__},
|
|
|
|
|
|
|
|
static long
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetVersion_impl(PyObject *module);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_GetVersion(PyObject *module, PyObject *Py_UNUSED(ignored))
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
long _return_value;
|
|
|
|
|
|
|
|
_return_value = _winapi_GetVersion_impl(module);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = PyLong_FromLong(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:08:16 -04:00
|
|
|
PyDoc_STRVAR(_winapi_MapViewOfFile__doc__,
|
|
|
|
"MapViewOfFile($module, file_map, desired_access, file_offset_high,\n"
|
|
|
|
" file_offset_low, number_bytes, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_MAPVIEWOFFILE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"MapViewOfFile", _PyCFunction_CAST(_winapi_MapViewOfFile), METH_FASTCALL, _winapi_MapViewOfFile__doc__},
|
2019-02-24 00:08:16 -04:00
|
|
|
|
|
|
|
static LPVOID
|
|
|
|
_winapi_MapViewOfFile_impl(PyObject *module, HANDLE file_map,
|
|
|
|
DWORD desired_access, DWORD file_offset_high,
|
|
|
|
DWORD file_offset_low, size_t number_bytes);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_MapViewOfFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE file_map;
|
|
|
|
DWORD desired_access;
|
|
|
|
DWORD file_offset_high;
|
|
|
|
DWORD file_offset_low;
|
|
|
|
size_t number_bytes;
|
|
|
|
LPVOID _return_value;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "kkkO&:MapViewOfFile",
|
|
|
|
&file_map, &desired_access, &file_offset_high, &file_offset_low, _PyLong_Size_t_Converter, &number_bytes)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_MapViewOfFile_impl(module, file_map, desired_access, file_offset_high, file_offset_low, number_bytes);
|
|
|
|
if ((_return_value == NULL) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2022-11-25 13:39:48 -04:00
|
|
|
PyDoc_STRVAR(_winapi_UnmapViewOfFile__doc__,
|
|
|
|
"UnmapViewOfFile($module, address, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_UNMAPVIEWOFFILE_METHODDEF \
|
|
|
|
{"UnmapViewOfFile", (PyCFunction)_winapi_UnmapViewOfFile, METH_O, _winapi_UnmapViewOfFile__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_UnmapViewOfFile_impl(PyObject *module, LPCVOID address);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_UnmapViewOfFile(PyObject *module, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
LPCVOID address;
|
|
|
|
|
|
|
|
if (!PyArg_Parse(arg, "" F_POINTER ":UnmapViewOfFile", &address)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_UnmapViewOfFile_impl(module, address);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-02-12 20:28:35 -04:00
|
|
|
PyDoc_STRVAR(_winapi_OpenEventW__doc__,
|
|
|
|
"OpenEventW($module, /, desired_access, inherit_handle, name)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OPENEVENTW_METHODDEF \
|
|
|
|
{"OpenEventW", _PyCFunction_CAST(_winapi_OpenEventW), METH_FASTCALL|METH_KEYWORDS, _winapi_OpenEventW__doc__},
|
|
|
|
|
|
|
|
static HANDLE
|
|
|
|
_winapi_OpenEventW_impl(PyObject *module, DWORD desired_access,
|
|
|
|
BOOL inherit_handle, LPCWSTR name);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_OpenEventW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 3
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(desired_access), &_Py_ID(inherit_handle), &_Py_ID(name), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"desired_access", "inherit_handle", "name", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "kiO&:OpenEventW",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
DWORD desired_access;
|
|
|
|
BOOL inherit_handle;
|
|
|
|
LPCWSTR name = NULL;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_OpenEventW_impl(module, desired_access, inherit_handle, name);
|
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_OpenMutexW__doc__,
|
|
|
|
"OpenMutexW($module, /, desired_access, inherit_handle, name)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OPENMUTEXW_METHODDEF \
|
|
|
|
{"OpenMutexW", _PyCFunction_CAST(_winapi_OpenMutexW), METH_FASTCALL|METH_KEYWORDS, _winapi_OpenMutexW__doc__},
|
|
|
|
|
|
|
|
static HANDLE
|
|
|
|
_winapi_OpenMutexW_impl(PyObject *module, DWORD desired_access,
|
|
|
|
BOOL inherit_handle, LPCWSTR name);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_OpenMutexW(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 3
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(desired_access), &_Py_ID(inherit_handle), &_Py_ID(name), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"desired_access", "inherit_handle", "name", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "kiO&:OpenMutexW",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
DWORD desired_access;
|
|
|
|
BOOL inherit_handle;
|
|
|
|
LPCWSTR name = NULL;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_OpenMutexW_impl(module, desired_access, inherit_handle, name);
|
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:08:16 -04:00
|
|
|
PyDoc_STRVAR(_winapi_OpenFileMapping__doc__,
|
|
|
|
"OpenFileMapping($module, desired_access, inherit_handle, name, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OPENFILEMAPPING_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"OpenFileMapping", _PyCFunction_CAST(_winapi_OpenFileMapping), METH_FASTCALL, _winapi_OpenFileMapping__doc__},
|
2019-02-24 00:08:16 -04:00
|
|
|
|
|
|
|
static HANDLE
|
|
|
|
_winapi_OpenFileMapping_impl(PyObject *module, DWORD desired_access,
|
|
|
|
BOOL inherit_handle, LPCWSTR name);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_OpenFileMapping(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
DWORD desired_access;
|
|
|
|
BOOL inherit_handle;
|
2022-10-03 04:42:54 -03:00
|
|
|
LPCWSTR name = NULL;
|
2019-02-24 00:08:16 -04:00
|
|
|
HANDLE _return_value;
|
|
|
|
|
2020-07-10 17:26:06 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "kiO&:OpenFileMapping",
|
|
|
|
&desired_access, &inherit_handle, _PyUnicode_WideCharString_Converter, &name)) {
|
2019-02-24 00:08:16 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_OpenFileMapping_impl(module, desired_access, inherit_handle, name);
|
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
2020-07-10 17:26:06 -03:00
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
2019-02-24 00:08:16 -04:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_OpenProcess__doc__,
|
|
|
|
"OpenProcess($module, desired_access, inherit_handle, process_id, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_OPENPROCESS_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"OpenProcess", _PyCFunction_CAST(_winapi_OpenProcess), METH_FASTCALL, _winapi_OpenProcess__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static HANDLE
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_OpenProcess_impl(PyObject *module, DWORD desired_access,
|
2015-05-13 12:58:35 -03:00
|
|
|
BOOL inherit_handle, DWORD process_id);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_OpenProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
DWORD desired_access;
|
|
|
|
BOOL inherit_handle;
|
|
|
|
DWORD process_id;
|
|
|
|
HANDLE _return_value;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "kik:OpenProcess",
|
|
|
|
&desired_access, &inherit_handle, &process_id)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
|
|
|
if (_return_value == NULL) {
|
2015-05-13 03:22:54 -03:00
|
|
|
Py_RETURN_NONE;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = HANDLE_TO_PYNUM(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__,
|
|
|
|
"PeekNamedPipe($module, handle, size=0, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_PEEKNAMEDPIPE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"PeekNamedPipe", _PyCFunction_CAST(_winapi_PeekNamedPipe), METH_FASTCALL, _winapi_PeekNamedPipe__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_PeekNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE handle;
|
|
|
|
int size = 0;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "|i:PeekNamedPipe",
|
|
|
|
&handle, &size)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_PeekNamedPipe_impl(module, handle, size);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2022-06-06 20:47:27 -03:00
|
|
|
PyDoc_STRVAR(_winapi_LCMapStringEx__doc__,
|
|
|
|
"LCMapStringEx($module, /, locale, flags, src)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_LCMAPSTRINGEX_METHODDEF \
|
|
|
|
{"LCMapStringEx", _PyCFunction_CAST(_winapi_LCMapStringEx), METH_FASTCALL|METH_KEYWORDS, _winapi_LCMapStringEx__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_LCMapStringEx_impl(PyObject *module, LPCWSTR locale, DWORD flags,
|
2023-08-11 15:13:46 -03:00
|
|
|
PyObject *src);
|
2022-06-06 20:47:27 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_LCMapStringEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 3
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(locale), &_Py_ID(flags), &_Py_ID(src), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-06-06 20:47:27 -03:00
|
|
|
static const char * const _keywords[] = {"locale", "flags", "src", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
2023-08-11 15:13:46 -03:00
|
|
|
.format = "O&kU:LCMapStringEx",
|
2022-08-11 18:25:49 -03:00
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2022-10-03 04:42:54 -03:00
|
|
|
LPCWSTR locale = NULL;
|
2022-06-06 20:47:27 -03:00
|
|
|
DWORD flags;
|
2023-08-11 15:13:46 -03:00
|
|
|
PyObject *src;
|
2022-06-06 20:47:27 -03:00
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
2023-08-11 15:13:46 -03:00
|
|
|
_PyUnicode_WideCharString_Converter, &locale, &flags, &src)) {
|
2022-06-06 20:47:27 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_LCMapStringEx_impl(module, locale, flags, src);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for locale */
|
|
|
|
PyMem_Free((void *)locale);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_ReadFile__doc__,
|
|
|
|
"ReadFile($module, /, handle, size, overlapped=False)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_READFILE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"ReadFile", _PyCFunction_CAST(_winapi_ReadFile), METH_FASTCALL|METH_KEYWORDS, _winapi_ReadFile__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2018-09-04 13:10:28 -03:00
|
|
|
_winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size,
|
2015-05-13 12:58:35 -03:00
|
|
|
int use_overlapped);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_ReadFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 3
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(handle), &_Py_ID(size), &_Py_ID(overlapped), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2016-08-14 04:52:18 -03:00
|
|
|
static const char * const _keywords[] = {"handle", "size", "overlapped", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
2022-12-03 15:52:21 -04:00
|
|
|
.format = "" F_HANDLE "k|p:ReadFile",
|
2022-08-11 18:25:49 -03:00
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2015-05-13 03:22:54 -03:00
|
|
|
HANDLE handle;
|
2018-09-04 13:10:28 -03:00
|
|
|
DWORD size;
|
2015-05-13 03:22:54 -03:00
|
|
|
int use_overlapped = 0;
|
|
|
|
|
2017-01-16 20:29:01 -04:00
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
2016-06-09 10:16:06 -03:00
|
|
|
&handle, &size, &use_overlapped)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-02-12 20:28:35 -04:00
|
|
|
PyDoc_STRVAR(_winapi_ReleaseMutex__doc__,
|
|
|
|
"ReleaseMutex($module, /, mutex)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_RELEASEMUTEX_METHODDEF \
|
|
|
|
{"ReleaseMutex", _PyCFunction_CAST(_winapi_ReleaseMutex), METH_FASTCALL|METH_KEYWORDS, _winapi_ReleaseMutex__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_ReleaseMutex_impl(PyObject *module, HANDLE mutex);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_ReleaseMutex(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 1
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(mutex), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"mutex", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "" F_HANDLE ":ReleaseMutex",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
HANDLE mutex;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&mutex)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_ReleaseMutex_impl(module, mutex);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_ResetEvent__doc__,
|
|
|
|
"ResetEvent($module, /, event)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_RESETEVENT_METHODDEF \
|
|
|
|
{"ResetEvent", _PyCFunction_CAST(_winapi_ResetEvent), METH_FASTCALL|METH_KEYWORDS, _winapi_ResetEvent__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_ResetEvent_impl(PyObject *module, HANDLE event);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_ResetEvent(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 1
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(event), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"event", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "" F_HANDLE ":ResetEvent",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
HANDLE event;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&event)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_ResetEvent_impl(module, event);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_SetEvent__doc__,
|
|
|
|
"SetEvent($module, /, event)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_SETEVENT_METHODDEF \
|
|
|
|
{"SetEvent", _PyCFunction_CAST(_winapi_SetEvent), METH_FASTCALL|METH_KEYWORDS, _winapi_SetEvent__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_SetEvent_impl(PyObject *module, HANDLE event);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_SetEvent(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 1
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(event), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"event", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "" F_HANDLE ":SetEvent",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
HANDLE event;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&event)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_SetEvent_impl(module, event);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__,
|
|
|
|
"SetNamedPipeHandleState($module, named_pipe, mode,\n"
|
|
|
|
" max_collection_count, collect_data_timeout, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"SetNamedPipeHandleState", _PyCFunction_CAST(_winapi_SetNamedPipeHandleState), METH_FASTCALL, _winapi_SetNamedPipeHandleState__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe,
|
2015-05-13 12:58:35 -03:00
|
|
|
PyObject *mode,
|
|
|
|
PyObject *max_collection_count,
|
|
|
|
PyObject *collect_data_timeout);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_SetNamedPipeHandleState(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE named_pipe;
|
|
|
|
PyObject *mode;
|
|
|
|
PyObject *max_collection_count;
|
|
|
|
PyObject *collect_data_timeout;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "OOO:SetNamedPipeHandleState",
|
|
|
|
&named_pipe, &mode, &max_collection_count, &collect_data_timeout)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_SetNamedPipeHandleState_impl(module, named_pipe, mode, max_collection_count, collect_data_timeout);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_TerminateProcess__doc__,
|
|
|
|
"TerminateProcess($module, handle, exit_code, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Terminate the specified process and all of its threads.");
|
|
|
|
|
|
|
|
#define _WINAPI_TERMINATEPROCESS_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"TerminateProcess", _PyCFunction_CAST(_winapi_TerminateProcess), METH_FASTCALL, _winapi_TerminateProcess__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_TerminateProcess_impl(PyObject *module, HANDLE handle,
|
2015-05-13 12:58:35 -03:00
|
|
|
UINT exit_code);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_TerminateProcess(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE handle;
|
|
|
|
UINT exit_code;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "I:TerminateProcess",
|
|
|
|
&handle, &exit_code)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_TerminateProcess_impl(module, handle, exit_code);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:08:16 -04:00
|
|
|
PyDoc_STRVAR(_winapi_VirtualQuerySize__doc__,
|
|
|
|
"VirtualQuerySize($module, address, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_VIRTUALQUERYSIZE_METHODDEF \
|
|
|
|
{"VirtualQuerySize", (PyCFunction)_winapi_VirtualQuerySize, METH_O, _winapi_VirtualQuerySize__doc__},
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
_winapi_VirtualQuerySize_impl(PyObject *module, LPCVOID address);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_VirtualQuerySize(PyObject *module, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
LPCVOID address;
|
|
|
|
size_t _return_value;
|
|
|
|
|
|
|
|
if (!PyArg_Parse(arg, "" F_POINTER ":VirtualQuerySize", &address)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_VirtualQuerySize_impl(module, address);
|
|
|
|
if ((_return_value == (size_t)-1) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = PyLong_FromSize_t(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__,
|
|
|
|
"WaitNamedPipe($module, name, timeout, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_WAITNAMEDPIPE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"WaitNamedPipe", _PyCFunction_CAST(_winapi_WaitNamedPipe), METH_FASTCALL, _winapi_WaitNamedPipe__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2024-05-29 12:51:09 -03:00
|
|
|
_winapi_WaitNamedPipe_impl(PyObject *module, LPCWSTR name, DWORD timeout);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_WaitNamedPipe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2024-05-29 12:51:09 -03:00
|
|
|
LPCWSTR name = NULL;
|
2015-05-13 03:22:54 -03:00
|
|
|
DWORD timeout;
|
|
|
|
|
2024-05-29 12:51:09 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "O&k:WaitNamedPipe",
|
|
|
|
_PyUnicode_WideCharString_Converter, &name, &timeout)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_WaitNamedPipe_impl(module, name, timeout);
|
|
|
|
|
|
|
|
exit:
|
2024-05-29 12:51:09 -03:00
|
|
|
/* Cleanup for name */
|
|
|
|
PyMem_Free((void *)name);
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2024-02-12 20:28:35 -04:00
|
|
|
PyDoc_STRVAR(_winapi_BatchedWaitForMultipleObjects__doc__,
|
|
|
|
"BatchedWaitForMultipleObjects($module, /, handle_seq, wait_all,\n"
|
|
|
|
" milliseconds=_winapi.INFINITE)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Supports a larger number of handles than WaitForMultipleObjects\n"
|
|
|
|
"\n"
|
|
|
|
"Note that the handles may be waited on other threads, which could cause\n"
|
|
|
|
"issues for objects like mutexes that become associated with the thread\n"
|
|
|
|
"that was waiting for them. Objects may also be left signalled, even if\n"
|
|
|
|
"the wait fails.\n"
|
|
|
|
"\n"
|
|
|
|
"It is recommended to use WaitForMultipleObjects whenever possible, and\n"
|
|
|
|
"only switch to BatchedWaitForMultipleObjects for scenarios where you\n"
|
|
|
|
"control all the handles involved, such as your own thread pool or\n"
|
|
|
|
"files, and all wait objects are left unmodified by a wait (for example,\n"
|
|
|
|
"manual reset events, threads, and files/pipes).\n"
|
|
|
|
"\n"
|
|
|
|
"Overlapped handles returned from this module use manual reset events.");
|
|
|
|
|
|
|
|
#define _WINAPI_BATCHEDWAITFORMULTIPLEOBJECTS_METHODDEF \
|
|
|
|
{"BatchedWaitForMultipleObjects", _PyCFunction_CAST(_winapi_BatchedWaitForMultipleObjects), METH_FASTCALL|METH_KEYWORDS, _winapi_BatchedWaitForMultipleObjects__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_BatchedWaitForMultipleObjects_impl(PyObject *module,
|
|
|
|
PyObject *handle_seq,
|
|
|
|
BOOL wait_all, DWORD milliseconds);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_BatchedWaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 3
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(handle_seq), &_Py_ID(wait_all), &_Py_ID(milliseconds), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"handle_seq", "wait_all", "milliseconds", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "Oi|k:BatchedWaitForMultipleObjects",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
PyObject *handle_seq;
|
|
|
|
BOOL wait_all;
|
|
|
|
DWORD milliseconds = INFINITE;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&handle_seq, &wait_all, &milliseconds)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_BatchedWaitForMultipleObjects_impl(module, handle_seq, wait_all, milliseconds);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:22:54 -03:00
|
|
|
PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__,
|
|
|
|
"WaitForMultipleObjects($module, handle_seq, wait_flag,\n"
|
|
|
|
" milliseconds=_winapi.INFINITE, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"WaitForMultipleObjects", _PyCFunction_CAST(_winapi_WaitForMultipleObjects), METH_FASTCALL, _winapi_WaitForMultipleObjects__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq,
|
|
|
|
BOOL wait_flag, DWORD milliseconds);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_WaitForMultipleObjects(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *handle_seq;
|
|
|
|
BOOL wait_flag;
|
|
|
|
DWORD milliseconds = INFINITE;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "Oi|k:WaitForMultipleObjects",
|
|
|
|
&handle_seq, &wait_flag, &milliseconds)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_WaitForMultipleObjects_impl(module, handle_seq, wait_flag, milliseconds);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__,
|
|
|
|
"WaitForSingleObject($module, handle, milliseconds, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Wait for a single object.\n"
|
|
|
|
"\n"
|
|
|
|
"Wait until the specified object is in the signaled state or\n"
|
|
|
|
"the time-out interval elapses. The timeout value is specified\n"
|
|
|
|
"in milliseconds.");
|
|
|
|
|
|
|
|
#define _WINAPI_WAITFORSINGLEOBJECT_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"WaitForSingleObject", _PyCFunction_CAST(_winapi_WaitForSingleObject), METH_FASTCALL, _winapi_WaitForSingleObject__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static long
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle,
|
2015-05-13 12:58:35 -03:00
|
|
|
DWORD milliseconds);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_WaitForSingleObject(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
HANDLE handle;
|
|
|
|
DWORD milliseconds;
|
|
|
|
long _return_value;
|
|
|
|
|
2017-06-10 01:51:48 -03:00
|
|
|
if (!_PyArg_ParseStack(args, nargs, "" F_HANDLE "k:WaitForSingleObject",
|
|
|
|
&handle, &milliseconds)) {
|
2017-01-16 20:35:17 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
_return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds);
|
2016-06-09 10:16:06 -03:00
|
|
|
if ((_return_value == -1) && PyErr_Occurred()) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = PyLong_FromLong(_return_value);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_WriteFile__doc__,
|
|
|
|
"WriteFile($module, /, handle, buffer, overlapped=False)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_WRITEFILE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"WriteFile", _PyCFunction_CAST(_winapi_WriteFile), METH_FASTCALL|METH_KEYWORDS, _winapi_WriteFile__doc__},
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2016-07-07 11:35:15 -03:00
|
|
|
_winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer,
|
2015-05-13 12:58:35 -03:00
|
|
|
int use_overlapped);
|
2015-05-13 03:22:54 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2017-12-15 07:11:11 -04:00
|
|
|
_winapi_WriteFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
2015-05-13 03:22:54 -03:00
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 3
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(handle), &_Py_ID(buffer), &_Py_ID(overlapped), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2016-08-14 04:52:18 -03:00
|
|
|
static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
2022-12-03 15:52:21 -04:00
|
|
|
.format = "" F_HANDLE "O|p:WriteFile",
|
2022-08-11 18:25:49 -03:00
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2015-05-13 03:22:54 -03:00
|
|
|
HANDLE handle;
|
|
|
|
PyObject *buffer;
|
|
|
|
int use_overlapped = 0;
|
|
|
|
|
2017-01-16 20:29:01 -04:00
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
2016-06-09 10:16:06 -03:00
|
|
|
&handle, &buffer, &use_overlapped)) {
|
2015-05-13 03:22:54 -03:00
|
|
|
goto exit;
|
2016-06-09 10:16:06 -03:00
|
|
|
}
|
2015-05-13 03:22:54 -03:00
|
|
|
return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2017-12-13 07:29:09 -04:00
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_GetACP__doc__,
|
|
|
|
"GetACP($module, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Get the current Windows ANSI code page identifier.");
|
|
|
|
|
|
|
|
#define _WINAPI_GETACP_METHODDEF \
|
|
|
|
{"GetACP", (PyCFunction)_winapi_GetACP, METH_NOARGS, _winapi_GetACP__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetACP_impl(PyObject *module);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetACP(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|
|
|
{
|
|
|
|
return _winapi_GetACP_impl(module);
|
|
|
|
}
|
2017-12-18 05:28:19 -04:00
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_GetFileType__doc__,
|
|
|
|
"GetFileType($module, /, handle)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
#define _WINAPI_GETFILETYPE_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"GetFileType", _PyCFunction_CAST(_winapi_GetFileType), METH_FASTCALL|METH_KEYWORDS, _winapi_GetFileType__doc__},
|
2017-12-18 05:28:19 -04:00
|
|
|
|
|
|
|
static DWORD
|
|
|
|
_winapi_GetFileType_impl(PyObject *module, HANDLE handle);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_GetFileType(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 1
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(handle), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2017-12-18 05:28:19 -04:00
|
|
|
static const char * const _keywords[] = {"handle", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "" F_HANDLE ":GetFileType",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2017-12-18 05:28:19 -04:00
|
|
|
HANDLE handle;
|
|
|
|
DWORD _return_value;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
&handle)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
_return_value = _winapi_GetFileType_impl(module, handle);
|
|
|
|
if ((_return_value == PY_DWORD_MAX) && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-10-20 12:08:41 -03:00
|
|
|
return_value = PyLong_FromUnsignedLong(_return_value);
|
2017-12-18 05:28:19 -04:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2021-07-08 12:48:42 -03:00
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi__mimetypes_read_windows_registry__doc__,
|
|
|
|
"_mimetypes_read_windows_registry($module, /, on_type_read)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Optimized function for reading all known MIME types from the registry.\n"
|
|
|
|
"\n"
|
|
|
|
"*on_type_read* is a callable taking *type* and *ext* arguments, as for\n"
|
|
|
|
"MimeTypes.add_type.");
|
|
|
|
|
|
|
|
#define _WINAPI__MIMETYPES_READ_WINDOWS_REGISTRY_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"_mimetypes_read_windows_registry", _PyCFunction_CAST(_winapi__mimetypes_read_windows_registry), METH_FASTCALL|METH_KEYWORDS, _winapi__mimetypes_read_windows_registry__doc__},
|
2021-07-08 12:48:42 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi__mimetypes_read_windows_registry_impl(PyObject *module,
|
|
|
|
PyObject *on_type_read);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi__mimetypes_read_windows_registry(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2022-08-13 07:09:40 -03:00
|
|
|
#define NUM_KEYWORDS 1
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(on_type_read), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2021-07-08 12:48:42 -03:00
|
|
|
static const char * const _keywords[] = {"on_type_read", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "_mimetypes_read_windows_registry",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2021-07-08 12:48:42 -03:00
|
|
|
PyObject *argsbuf[1];
|
|
|
|
PyObject *on_type_read;
|
|
|
|
|
2024-11-08 08:23:50 -04:00
|
|
|
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
|
|
|
|
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
|
2021-07-08 12:48:42 -03:00
|
|
|
if (!args) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
on_type_read = args[0];
|
|
|
|
return_value = _winapi__mimetypes_read_windows_registry_impl(module, on_type_read);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2023-04-04 19:24:13 -03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-05-30 07:00:29 -03:00
|
|
|
|
|
|
|
PyDoc_STRVAR(_winapi_CopyFile2__doc__,
|
|
|
|
"CopyFile2($module, /, existing_file_name, new_file_name, flags,\n"
|
|
|
|
" progress_routine=None)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Copies a file from one name to a new name.\n"
|
|
|
|
"\n"
|
|
|
|
"This is implemented using the CopyFile2 API, which preserves all stat\n"
|
|
|
|
"and metadata information apart from security attributes.\n"
|
|
|
|
"\n"
|
|
|
|
"progress_routine is reserved for future use, but is currently not\n"
|
|
|
|
"implemented. Its value is ignored.");
|
|
|
|
|
|
|
|
#define _WINAPI_COPYFILE2_METHODDEF \
|
|
|
|
{"CopyFile2", _PyCFunction_CAST(_winapi_CopyFile2), METH_FASTCALL|METH_KEYWORDS, _winapi_CopyFile2__doc__},
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_CopyFile2_impl(PyObject *module, LPCWSTR existing_file_name,
|
|
|
|
LPCWSTR new_file_name, DWORD flags,
|
|
|
|
PyObject *progress_routine);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_winapi_CopyFile2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
|
|
|
|
|
|
|
#define NUM_KEYWORDS 4
|
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
|
|
|
.ob_item = { &_Py_ID(existing_file_name), &_Py_ID(new_file_name), &_Py_ID(flags), &_Py_ID(progress_routine), },
|
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
|
|
|
|
|
|
|
static const char * const _keywords[] = {"existing_file_name", "new_file_name", "flags", "progress_routine", NULL};
|
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.format = "O&O&k|O:CopyFile2",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
|
|
|
LPCWSTR existing_file_name = NULL;
|
|
|
|
LPCWSTR new_file_name = NULL;
|
|
|
|
DWORD flags;
|
|
|
|
PyObject *progress_routine = Py_None;
|
|
|
|
|
|
|
|
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
|
|
|
_PyUnicode_WideCharString_Converter, &existing_file_name, _PyUnicode_WideCharString_Converter, &new_file_name, &flags, &progress_routine)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
return_value = _winapi_CopyFile2_impl(module, existing_file_name, new_file_name, flags, progress_routine);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
/* Cleanup for existing_file_name */
|
|
|
|
PyMem_Free((void *)existing_file_name);
|
|
|
|
/* Cleanup for new_file_name */
|
|
|
|
PyMem_Free((void *)new_file_name);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|
2024-11-08 08:23:50 -04:00
|
|
|
/*[clinic end generated code: output=b2a178bde6868e88 input=a9049054013a1b77]*/
|