diff -r 78a2d1169be1 -r 9ec35c653970 Modules/_winapi.c --- a/Modules/_winapi.c Tue Apr 14 11:21:26 2015 -0700 +++ b/Modules/_winapi.c Tue Apr 14 15:05:26 2015 -0500 @@ -58,8 +58,6 @@ #define F_HANDLE F_POINTER #define F_DWORD "k" -#define F_BOOL "i" -#define F_UINT "I" #define T_HANDLE T_POINTER @@ -147,17 +145,68 @@ PyObject_Del(self); } +/*[clinic input] +module _winapi +class _winapi.Overlapped "OverlappedObject *" "&OverlappedType" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c13d3f5fd1dabb84]*/ + +/*[python input] +def create_converter(type_, format_unit): + name = type_ + '_converter' + # registered upon creation by CConverter's metaclass + type(name, (CConverter,), {'type': type_, 'format_unit': format_unit}) + +# format unit differs between platforms for these +create_converter('HANDLE', '" F_HANDLE "') +create_converter('HMODULE', '" F_HANDLE "') +create_converter('LPSECURITY_ATTRIBUTES', '" F_POINTER "') + +create_converter('BOOL', 'i') # F_BOOL used previously (always 'i') +create_converter('DWORD', 'k') # F_DWORD is always "k" (which is much shorter) +create_converter('LPCTSTR', 's') +create_converter('LPWSTR', 'u') +create_converter('UINT', 'I') # F_UINT used previously (always 'I') + +class HANDLE_return_converter(CReturnConverter): + type = 'HANDLE' + + def render(self, function, data): + self.declare(data) + self.err_occurred_if("_return_value == INVALID_HANDLE_VALUE", data) + data.return_conversion.append( + 'if (_return_value == NULL)\n Py_RETURN_NONE;\n') + data.return_conversion.append( + 'return_value = HANDLE_TO_PYNUM(_return_value);\n') + +class DWORD_return_converter(CReturnConverter): + type = 'DWORD' + + def render(self, function, data): + self.declare(data) + self.err_occurred_if("_return_value == DWORD_MAX", data) + data.return_conversion.append( + 'return_value = Py_BuildValue("k", _return_value);\n') +[python start generated code]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=374076979596ebba]*/ + +#include "clinic/_winapi.c.h" + +/*[clinic input] +_winapi.Overlapped.GetOverlappedResult + + wait: bool + / +[clinic start generated code]*/ + static PyObject * -overlapped_GetOverlappedResult(OverlappedObject *self, PyObject *waitobj) +_winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait) +/*[clinic end generated code: output=bdd0c1ed6518cd03 input=194505ee8e0e3565]*/ { - int wait; BOOL res; DWORD transferred = 0; DWORD err; - wait = PyObject_IsTrue(waitobj); - if (wait < 0) - return NULL; Py_BEGIN_ALLOW_THREADS res = GetOverlappedResult(self->handle, &self->overlapped, &transferred, wait != 0); @@ -186,8 +235,13 @@ return Py_BuildValue("II", (unsigned) transferred, (unsigned) err); } +/*[clinic input] +_winapi.Overlapped.getbuffer +[clinic start generated code]*/ + static PyObject * -overlapped_getbuffer(OverlappedObject *self) +_winapi_Overlapped_getbuffer_impl(OverlappedObject *self) +/*[clinic end generated code: output=95a3eceefae0f748 input=347fcfd56b4ceabd]*/ { PyObject *res; if (!self->completed) { @@ -201,8 +255,13 @@ return res; } +/*[clinic input] +_winapi.Overlapped.cancel +[clinic start generated code]*/ + static PyObject * -overlapped_cancel(OverlappedObject *self) +_winapi_Overlapped_cancel_impl(OverlappedObject *self) +/*[clinic end generated code: output=fcb9ab5df4ebdae5 input=cbf3da142290039f]*/ { BOOL res = TRUE; @@ -223,10 +282,9 @@ } static PyMethodDef overlapped_methods[] = { - {"GetOverlappedResult", (PyCFunction) overlapped_GetOverlappedResult, - METH_O, NULL}, - {"getbuffer", (PyCFunction) overlapped_getbuffer, METH_NOARGS, NULL}, - {"cancel", (PyCFunction) overlapped_cancel, METH_NOARGS, NULL}, + _WINAPI_OVERLAPPED_GETOVERLAPPEDRESULT_METHODDEF + _WINAPI_OVERLAPPED_GETBUFFER_METHODDEF + _WINAPI_OVERLAPPED_CANCEL_METHODDEF {NULL} }; @@ -300,22 +358,23 @@ /* -------------------------------------------------------------------- */ /* windows API functions */ -PyDoc_STRVAR(CloseHandle_doc, -"CloseHandle(handle) -> None\n\ -\n\ -Close handle."); +/*[clinic input] +_winapi.CloseHandle + + handle: HANDLE + / + +Close handle. +[clinic start generated code]*/ static PyObject * -winapi_CloseHandle(PyObject *self, PyObject *args) +_winapi_CloseHandle_impl(PyModuleDef *module, HANDLE handle) +/*[clinic end generated code: output=0548595c71cb4bf7 input=7f0e4ac36e0352b8]*/ { - HANDLE hObject; BOOL success; - if (!PyArg_ParseTuple(args, F_HANDLE ":CloseHandle", &hObject)) - return NULL; - Py_BEGIN_ALLOW_THREADS - success = CloseHandle(hObject); + success = CloseHandle(handle); Py_END_ALLOW_THREADS if (!success) @@ -324,28 +383,28 @@ Py_RETURN_NONE; } +/*[clinic input] +_winapi.ConnectNamedPipe + + handle: HANDLE + overlapped as use_overlapped: int(c_default='0') = False +[clinic start generated code]*/ + static PyObject * -winapi_ConnectNamedPipe(PyObject *self, PyObject *args, PyObject *kwds) +_winapi_ConnectNamedPipe_impl(PyModuleDef *module, HANDLE handle, int use_overlapped) +/*[clinic end generated code: output=d9a64e59c27e10f6 input=edc83da007ebf3be]*/ { - HANDLE hNamedPipe; - int use_overlapped = 0; BOOL success; OverlappedObject *overlapped = NULL; - static char *kwlist[] = {"handle", "overlapped", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, - F_HANDLE "|" F_BOOL, kwlist, - &hNamedPipe, &use_overlapped)) - return NULL; if (use_overlapped) { - overlapped = new_overlapped(hNamedPipe); + overlapped = new_overlapped(handle); if (!overlapped) return NULL; } Py_BEGIN_ALLOW_THREADS - success = ConnectNamedPipe(hNamedPipe, + success = ConnectNamedPipe(handle, overlapped ? &overlapped->overlapped : NULL); Py_END_ALLOW_THREADS @@ -369,45 +428,50 @@ Py_RETURN_NONE; } -static PyObject * -winapi_CreateFile(PyObject *self, PyObject *args) +/*[clinic input] +_winapi.CreateFile -> HANDLE + + file_name: LPCTSTR + desired_access: DWORD + share_mode: DWORD + security_attributes: LPSECURITY_ATTRIBUTES + creation_disposition: DWORD + flags_and_attributes: DWORD + template_file: HANDLE + / +[clinic start generated code]*/ + +static HANDLE +_winapi_CreateFile_impl(PyModuleDef *module, LPCTSTR file_name, DWORD desired_access, DWORD share_mode, LPSECURITY_ATTRIBUTES security_attributes, DWORD creation_disposition, DWORD flags_and_attributes, HANDLE template_file) +/*[clinic end generated code: output=f8649129a4959288 input=6423c3e40372dbd5]*/ { - LPCTSTR lpFileName; - DWORD dwDesiredAccess; - DWORD dwShareMode; - LPSECURITY_ATTRIBUTES lpSecurityAttributes; - DWORD dwCreationDisposition; - DWORD dwFlagsAndAttributes; - HANDLE hTemplateFile; HANDLE handle; - if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_POINTER - F_DWORD F_DWORD F_HANDLE, - &lpFileName, &dwDesiredAccess, &dwShareMode, - &lpSecurityAttributes, &dwCreationDisposition, - &dwFlagsAndAttributes, &hTemplateFile)) - return NULL; - Py_BEGIN_ALLOW_THREADS - handle = CreateFile(lpFileName, dwDesiredAccess, - dwShareMode, lpSecurityAttributes, - dwCreationDisposition, - dwFlagsAndAttributes, hTemplateFile); + handle = CreateFile(file_name, desired_access, + share_mode, security_attributes, + creation_disposition, + flags_and_attributes, template_file); Py_END_ALLOW_THREADS if (handle == INVALID_HANDLE_VALUE) - return PyErr_SetFromWindowsErr(0); + PyErr_SetFromWindowsErr(0); - return Py_BuildValue(F_HANDLE, handle); + return handle; } +/*[clinic input] +_winapi.CreateJunction + + src_path: LPWSTR + dst_path: LPWSTR + / +[clinic start generated code]*/ + static PyObject * -winapi_CreateJunction(PyObject *self, PyObject *args) +_winapi_CreateJunction_impl(PyModuleDef *module, LPWSTR src_path, LPWSTR dst_path) +/*[clinic end generated code: output=df22af7be7045584 input=8cd1f9964b6e3d36]*/ { - /* Input arguments */ - LPWSTR src_path = NULL; - LPWSTR dst_path = NULL; - /* Privilege adjustment */ HANDLE token = NULL; TOKEN_PRIVILEGES tp; @@ -422,9 +486,6 @@ HANDLE junction = NULL; DWORD ret = 0; - if (!PyArg_ParseTuple(args, "uu", &src_path, &dst_path)) - return NULL; - if (src_path == NULL || dst_path == NULL) return PyErr_SetFromWindowsErr(ERROR_INVALID_PARAMETER); @@ -535,62 +596,60 @@ Py_RETURN_NONE; } -static PyObject * -winapi_CreateNamedPipe(PyObject *self, PyObject *args) +/*[clinic input] +_winapi.CreateNamedPipe -> HANDLE + + name: LPCTSTR + open_mode: DWORD + pipe_mode: DWORD + max_instances: DWORD + out_buffer_size: DWORD + in_buffer_size: DWORD + default_timeout: DWORD + security_attributes: LPSECURITY_ATTRIBUTES + / +[clinic start generated code]*/ + +static HANDLE +_winapi_CreateNamedPipe_impl(PyModuleDef *module, LPCTSTR name, DWORD open_mode, DWORD pipe_mode, DWORD max_instances, DWORD out_buffer_size, DWORD in_buffer_size, DWORD default_timeout, LPSECURITY_ATTRIBUTES security_attributes) +/*[clinic end generated code: output=711e231639c25c24 input=5a73530b84d8bc37]*/ { - LPCTSTR lpName; - DWORD dwOpenMode; - DWORD dwPipeMode; - DWORD nMaxInstances; - DWORD nOutBufferSize; - DWORD nInBufferSize; - DWORD nDefaultTimeOut; - LPSECURITY_ATTRIBUTES lpSecurityAttributes; HANDLE handle; - if (!PyArg_ParseTuple(args, "s" F_DWORD F_DWORD F_DWORD - F_DWORD F_DWORD F_DWORD F_POINTER, - &lpName, &dwOpenMode, &dwPipeMode, - &nMaxInstances, &nOutBufferSize, - &nInBufferSize, &nDefaultTimeOut, - &lpSecurityAttributes)) - return NULL; - Py_BEGIN_ALLOW_THREADS - handle = CreateNamedPipe(lpName, dwOpenMode, dwPipeMode, - nMaxInstances, nOutBufferSize, - nInBufferSize, nDefaultTimeOut, - lpSecurityAttributes); + handle = CreateNamedPipe(name, open_mode, pipe_mode, + max_instances, out_buffer_size, + in_buffer_size, default_timeout, + security_attributes); Py_END_ALLOW_THREADS if (handle == INVALID_HANDLE_VALUE) - return PyErr_SetFromWindowsErr(0); + PyErr_SetFromWindowsErr(0); - return Py_BuildValue(F_HANDLE, handle); + return handle; } -PyDoc_STRVAR(CreatePipe_doc, -"CreatePipe(pipe_attrs, size) -> (read_handle, write_handle)\n\ -\n\ -Create an anonymous pipe, and return handles to the read and\n\ -write ends of the pipe.\n\ -\n\ -pipe_attrs is ignored internally and can be None."); +/*[clinic input] +_winapi.CreatePipe + + pipe_attrs: object + Ignored internally, can be None. + size: DWORD + / + +Create an anonymous pipe. + +Returns a 2-tuple of handles, to the read and write ends of the pipe. +[clinic start generated code]*/ static PyObject * -winapi_CreatePipe(PyObject* self, PyObject* args) +_winapi_CreatePipe_impl(PyModuleDef *module, PyObject *pipe_attrs, DWORD size) +/*[clinic end generated code: output=ed09baf1d43086df input=c4f2cfa56ef68d90]*/ { HANDLE read_pipe; HANDLE write_pipe; BOOL result; - PyObject* pipe_attributes; /* ignored */ - DWORD size; - - if (! PyArg_ParseTuple(args, "O" F_DWORD ":CreatePipe", - &pipe_attributes, &size)) - return NULL; - Py_BEGIN_ALLOW_THREADS result = CreatePipe(&read_pipe, &write_pipe, NULL, size); Py_END_ALLOW_THREADS @@ -721,20 +780,31 @@ return NULL; } -PyDoc_STRVAR(CreateProcess_doc, -"CreateProcess(app_name, cmd_line, proc_attrs, thread_attrs,\n\ - inherit, flags, env_mapping, curdir,\n\ - startup_info) -> (proc_handle, thread_handle,\n\ - pid, tid)\n\ -\n\ -Create a new process and its primary thread. The return\n\ -value is a tuple of the process handle, thread handle,\n\ -process ID, and thread ID.\n\ -\n\ -proc_attrs and thread_attrs are ignored internally and can be None."); +/*[clinic input] +_winapi.CreateProcess + + application_name: Py_UNICODE(nullable=True) + command_line: Py_UNICODE(nullable=True) + proc_attrs: object + Ignored internally, can be None. + thread_attrs: object + Ignored internally, can be None. + inherit_handles: BOOL + creation_flags: DWORD + env_mapping: object + current_directory: Py_UNICODE(nullable=True) + startup_info: object + / + +Create a new process and its primary thread. + +The return value is a tuple of the process handle, thread handle, +process ID, and thread ID. +[clinic start generated code]*/ static PyObject * -winapi_CreateProcess(PyObject* self, PyObject* args) +_winapi_CreateProcess_impl(PyModuleDef *module, Py_UNICODE *application_name, Py_UNICODE *command_line, PyObject *proc_attrs, PyObject *thread_attrs, BOOL inherit_handles, DWORD creation_flags, PyObject *env_mapping, Py_UNICODE *current_directory, PyObject *startup_info) +/*[clinic end generated code: output=c279c1271b4c45cf input=6667ea0bc7036472]*/ { BOOL result; PROCESS_INFORMATION pi; @@ -742,28 +812,6 @@ PyObject* environment; wchar_t *wenvironment; - wchar_t* application_name; - wchar_t* command_line; - PyObject* process_attributes; /* ignored */ - PyObject* thread_attributes; /* ignored */ - BOOL inherit_handles; - DWORD creation_flags; - PyObject* env_mapping; - wchar_t* current_directory; - PyObject* startup_info; - - if (! PyArg_ParseTuple(args, "ZZOO" F_BOOL F_DWORD "OZO:CreateProcess", - &application_name, - &command_line, - &process_attributes, - &thread_attributes, - &inherit_handles, - &creation_flags, - &env_mapping, - ¤t_directory, - &startup_info)) - return NULL; - ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); @@ -817,41 +865,31 @@ pi.dwThreadId); } -PyDoc_STRVAR(DuplicateHandle_doc, -"DuplicateHandle(source_proc_handle, source_handle,\n\ - target_proc_handle, target_handle, access,\n\ - inherit[, options]) -> handle\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."); +/*[clinic input] +_winapi.DuplicateHandle -> HANDLE -static PyObject * -winapi_DuplicateHandle(PyObject* self, PyObject* args) + source_process_handle: HANDLE + source_handle: HANDLE + target_process_handle: HANDLE + desired_access: DWORD + inherit_handle: BOOL + options: DWORD = 0 + / + +Return a duplicate handle object. + +The duplicate handle refers to the same object as the original +handle. Therefore, any changes to the object are reflected +through both handles. +[clinic start generated code]*/ + +static HANDLE +_winapi_DuplicateHandle_impl(PyModuleDef *module, HANDLE source_process_handle, HANDLE source_handle, HANDLE target_process_handle, DWORD desired_access, BOOL inherit_handle, DWORD options) +/*[clinic end generated code: output=24a7836ca4d94aba input=b933e3f2356a8c12]*/ { HANDLE target_handle; BOOL result; - HANDLE source_process_handle; - HANDLE source_handle; - HANDLE target_process_handle; - DWORD desired_access; - BOOL inherit_handle; - DWORD options = 0; - - if (! PyArg_ParseTuple(args, - F_HANDLE F_HANDLE F_HANDLE F_DWORD F_BOOL F_DWORD - ":DuplicateHandle", - &source_process_handle, - &source_handle, - &target_process_handle, - &desired_access, - &inherit_handle, - &options)) - return NULL; - Py_BEGIN_ALLOW_THREADS result = DuplicateHandle( source_process_handle, @@ -864,98 +902,111 @@ ); Py_END_ALLOW_THREADS - if (! result) - return PyErr_SetFromWindowsErr(GetLastError()); + if (! result) { + PyErr_SetFromWindowsErr(GetLastError()); + return INVALID_HANDLE_VALUE; + } - return HANDLE_TO_PYNUM(target_handle); + return target_handle; } +/*[clinic input] +_winapi.ExitProcess + + ExitCode: UINT + / + +[clinic start generated code]*/ + static PyObject * -winapi_ExitProcess(PyObject *self, PyObject *args) +_winapi_ExitProcess_impl(PyModuleDef *module, UINT ExitCode) +/*[clinic end generated code: output=25f3b499c24cedc8 input=4f05466a9406c558]*/ { - UINT uExitCode; - - if (!PyArg_ParseTuple(args, F_UINT, &uExitCode)) - return NULL; - #if defined(Py_DEBUG) SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT| SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); #endif - ExitProcess(uExitCode); + ExitProcess(ExitCode); return NULL; } -PyDoc_STRVAR(GetCurrentProcess_doc, -"GetCurrentProcess() -> handle\n\ -\n\ -Return a handle object for the current process."); +/*[clinic input] +_winapi.GetCurrentProcess -> HANDLE -static PyObject * -winapi_GetCurrentProcess(PyObject* self, PyObject* args) +Return a handle object for the current process. +[clinic start generated code]*/ + +static HANDLE +_winapi_GetCurrentProcess_impl(PyModuleDef *module) +/*[clinic end generated code: output=be29ac3ad5f8291e input=b213403fd4b96b41]*/ { - if (! PyArg_ParseTuple(args, ":GetCurrentProcess")) - return NULL; - - return HANDLE_TO_PYNUM(GetCurrentProcess()); + return GetCurrentProcess(); } -PyDoc_STRVAR(GetExitCodeProcess_doc, -"GetExitCodeProcess(handle) -> Exit code\n\ -\n\ -Return the termination status of the specified process."); +/*[clinic input] +_winapi.GetExitCodeProcess -> DWORD -static PyObject * -winapi_GetExitCodeProcess(PyObject* self, PyObject* args) + process: HANDLE + / + +Return the termination status of the specified process. +[clinic start generated code]*/ + +static DWORD +_winapi_GetExitCodeProcess_impl(PyModuleDef *module, HANDLE process) +/*[clinic end generated code: output=0b10f0848a410f65 input=61b6bfc7dc2ee374]*/ { DWORD exit_code; BOOL result; - HANDLE process; - if (! PyArg_ParseTuple(args, F_HANDLE ":GetExitCodeProcess", &process)) - return NULL; - result = GetExitCodeProcess(process, &exit_code); - if (! result) - return PyErr_SetFromWindowsErr(GetLastError()); + if (! result) { + PyErr_SetFromWindowsErr(GetLastError()); + exit_code = DWORD_MAX; + } - return PyLong_FromUnsignedLong(exit_code); + return exit_code; } -static PyObject * -winapi_GetLastError(PyObject *self, PyObject *args) +/*[clinic input] +_winapi.GetLastError -> DWORD +[clinic start generated code]*/ + +static DWORD +_winapi_GetLastError_impl(PyModuleDef *module) +/*[clinic end generated code: output=0ea00d8e67bdd056 input=62d47fb9bce038ba]*/ { - return Py_BuildValue(F_DWORD, GetLastError()); + return GetLastError(); } -PyDoc_STRVAR(GetModuleFileName_doc, -"GetModuleFileName(module) -> path\n\ -\n\ -Return the fully-qualified path for the file that contains\n\ -the specified module. The module must have been loaded by the\n\ -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."); +/*[clinic input] +_winapi.GetModuleFileName + + module_handle: HMODULE + / + +Return the fully-qualified path for the file that contains module. + +The module must have been loaded by the current process. + +The module parameter should be a handle to the loaded module +whose path is being requested. If this parameter is 0, +GetModuleFileName retrieves the path of the executable file +of the current process. +[clinic start generated code]*/ static PyObject * -winapi_GetModuleFileName(PyObject* self, PyObject* args) +_winapi_GetModuleFileName_impl(PyModuleDef *module, HMODULE module_handle) +/*[clinic end generated code: output=90063dc63bdbfa18 input=6d66ff7deca5d11f]*/ { BOOL result; - HMODULE module; WCHAR filename[MAX_PATH]; - if (! PyArg_ParseTuple(args, F_HANDLE ":GetModuleFileName", - &module)) - return NULL; - - result = GetModuleFileNameW(module, filename, MAX_PATH); + result = GetModuleFileNameW(module_handle, filename, MAX_PATH); filename[MAX_PATH-1] = '\0'; if (! result) @@ -964,91 +1015,95 @@ return PyUnicode_FromWideChar(filename, wcslen(filename)); } -PyDoc_STRVAR(GetStdHandle_doc, -"GetStdHandle(handle) -> integer\n\ -\n\ -Return a handle to the specified standard device\n\ -(STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE).\n\ -The integer associated with the handle object is returned."); +/*[clinic input] +_winapi.GetStdHandle -> HANDLE -static PyObject * -winapi_GetStdHandle(PyObject* self, PyObject* args) + std_handle: DWORD + One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE. + / + +Return a handle to the specified standard device. + +The integer associated with the handle object is returned. +[clinic start generated code]*/ + +static HANDLE +_winapi_GetStdHandle_impl(PyModuleDef *module, DWORD std_handle) +/*[clinic end generated code: output=5f5ca28b28c6fad2 input=07016b06a2fc8826]*/ { HANDLE handle; - DWORD std_handle; - - if (! PyArg_ParseTuple(args, F_DWORD ":GetStdHandle", &std_handle)) - return NULL; Py_BEGIN_ALLOW_THREADS handle = GetStdHandle(std_handle); Py_END_ALLOW_THREADS if (handle == INVALID_HANDLE_VALUE) - return PyErr_SetFromWindowsErr(GetLastError()); + PyErr_SetFromWindowsErr(GetLastError()); - if (! handle) { - Py_INCREF(Py_None); - return Py_None; - } - - /* note: returns integer, not handle object */ - return HANDLE_TO_PYNUM(handle); + return handle; } -PyDoc_STRVAR(GetVersion_doc, -"GetVersion() -> version\n\ -\n\ -Return the version number of the current operating system."); +/*[clinic input] +_winapi.GetVersion -> long +Return the version number of the current operating system. +[clinic start generated code]*/ + +static long +_winapi_GetVersion_impl(PyModuleDef *module) +/*[clinic end generated code: output=95a2f8ad3b948ca8 input=e21dff8d0baeded2]*/ /* Disable deprecation warnings about GetVersionEx as the result is being passed straight through to the caller, who is responsible for using it correctly. */ #pragma warning(push) #pragma warning(disable:4996) -static PyObject * -winapi_GetVersion(PyObject* self, PyObject* args) { - if (! PyArg_ParseTuple(args, ":GetVersion")) - return NULL; - - return PyLong_FromUnsignedLong(GetVersion()); + return GetVersion(); } #pragma warning(pop) -static PyObject * -winapi_OpenProcess(PyObject *self, PyObject *args) +/*[clinic input] +_winapi.OpenProcess -> HANDLE + + desired_access: DWORD + inherit_handle: BOOL + process_id: DWORD + / +[clinic start generated code]*/ + +static HANDLE +_winapi_OpenProcess_impl(PyModuleDef *module, DWORD desired_access, BOOL inherit_handle, DWORD process_id) +/*[clinic end generated code: output=2a7be5336f16f63c input=ec98c4cf4ea2ec36]*/ { - DWORD dwDesiredAccess; - BOOL bInheritHandle; - DWORD dwProcessId; HANDLE handle; - if (!PyArg_ParseTuple(args, F_DWORD F_BOOL F_DWORD, - &dwDesiredAccess, &bInheritHandle, &dwProcessId)) - return NULL; + handle = OpenProcess(desired_access, inherit_handle, process_id); + if (handle == NULL) { + PyErr_SetFromWindowsErr(0); + handle = INVALID_HANDLE_VALUE; + } - handle = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); - if (handle == NULL) - return PyErr_SetFromWindowsErr(0); - - return Py_BuildValue(F_HANDLE, handle); + return handle; } +/*[clinic input] +_winapi.PeekNamedPipe + + handle: HANDLE + size: int = 0 + / +[clinic start generated code]*/ + static PyObject * -winapi_PeekNamedPipe(PyObject *self, PyObject *args) +_winapi_PeekNamedPipe_impl(PyModuleDef *module, HANDLE handle, int size) +/*[clinic end generated code: output=e6c908e2fb63c798 input=c7aa53bfbce69d70]*/ { - HANDLE handle; - int size = 0; PyObject *buf = NULL; DWORD nread, navail, nleft; BOOL ret; - if (!PyArg_ParseTuple(args, F_HANDLE "|i:PeekNamedPipe" , &handle, &size)) - return NULL; - if (size < 0) { PyErr_SetString(PyExc_ValueError, "negative size"); return NULL; @@ -1081,23 +1136,23 @@ } } +/*[clinic input] +_winapi.ReadFile + + handle: HANDLE + size: int + overlapped as use_overlapped: int(c_default='0') = False +[clinic start generated code]*/ + static PyObject * -winapi_ReadFile(PyObject *self, PyObject *args, PyObject *kwds) +_winapi_ReadFile_impl(PyModuleDef *module, HANDLE handle, int size, int use_overlapped) +/*[clinic end generated code: output=5a087be0ff44479a input=8dd810194e86ac7d]*/ { - HANDLE handle; - int size; DWORD nread; PyObject *buf; BOOL ret; - int use_overlapped = 0; DWORD err; OverlappedObject *overlapped = NULL; - static char *kwlist[] = {"handle", "size", "overlapped", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, - F_HANDLE "i|i:ReadFile", kwlist, - &handle, &size, &use_overlapped)) - return NULL; buf = PyBytes_FromStringAndSize(NULL, size); if (!buf) @@ -1140,18 +1195,24 @@ return Py_BuildValue("NI", buf, err); } +/*[clinic input] +_winapi.SetNamedPipeHandleState + + named_pipe: HANDLE + mode: object + max_collection_count: object + collect_data_timeout: object + / +[clinic start generated code]*/ + static PyObject * -winapi_SetNamedPipeHandleState(PyObject *self, PyObject *args) +_winapi_SetNamedPipeHandleState_impl(PyModuleDef *module, HANDLE named_pipe, PyObject *mode, PyObject *max_collection_count, PyObject *collect_data_timeout) +/*[clinic end generated code: output=327efd18ff0c30ec input=9142d72163d0faa6]*/ { - HANDLE hNamedPipe; - PyObject *oArgs[3]; + PyObject *oArgs[3] = {mode, max_collection_count, collect_data_timeout}; DWORD dwArgs[3], *pArgs[3] = {NULL, NULL, NULL}; int i; - if (!PyArg_ParseTuple(args, F_HANDLE "OOO", - &hNamedPipe, &oArgs[0], &oArgs[1], &oArgs[2])) - return NULL; - PyErr_Clear(); for (i = 0 ; i < 3 ; i++) { @@ -1163,49 +1224,53 @@ } } - if (!SetNamedPipeHandleState(hNamedPipe, pArgs[0], pArgs[1], pArgs[2])) + if (!SetNamedPipeHandleState(named_pipe, pArgs[0], pArgs[1], pArgs[2])) return PyErr_SetFromWindowsErr(0); Py_RETURN_NONE; } -PyDoc_STRVAR(TerminateProcess_doc, -"TerminateProcess(handle, exit_code) -> None\n\ -\n\ -Terminate the specified process and all of its threads."); + +/*[clinic input] +_winapi.TerminateProcess + + handle: HANDLE + exit_code: UINT + / + +Terminate the specified process and all of its threads. +[clinic start generated code]*/ static PyObject * -winapi_TerminateProcess(PyObject* self, PyObject* args) +_winapi_TerminateProcess_impl(PyModuleDef *module, HANDLE handle, UINT exit_code) +/*[clinic end generated code: output=1559f0f6500c2283 input=d6bc0aa1ee3bb4df]*/ { BOOL result; - HANDLE process; - UINT exit_code; - if (! PyArg_ParseTuple(args, F_HANDLE F_UINT ":TerminateProcess", - &process, &exit_code)) - return NULL; - - result = TerminateProcess(process, exit_code); + result = TerminateProcess(handle, exit_code); if (! result) return PyErr_SetFromWindowsErr(GetLastError()); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +_winapi.WaitNamedPipe + + name: LPCTSTR + timeout: DWORD + / +[clinic start generated code]*/ + static PyObject * -winapi_WaitNamedPipe(PyObject *self, PyObject *args) +_winapi_WaitNamedPipe_impl(PyModuleDef *module, LPCTSTR name, DWORD timeout) +/*[clinic end generated code: output=5bca5e02f448c9d7 input=36fc781291b1862c]*/ { - LPCTSTR lpNamedPipeName; - DWORD nTimeOut; BOOL success; - if (!PyArg_ParseTuple(args, "s" F_DWORD, &lpNamedPipeName, &nTimeOut)) - return NULL; - Py_BEGIN_ALLOW_THREADS - success = WaitNamedPipe(lpNamedPipeName, nTimeOut); + success = WaitNamedPipe(name, timeout); Py_END_ALLOW_THREADS if (!success) @@ -1214,21 +1279,23 @@ Py_RETURN_NONE; } +/*[clinic input] +_winapi.WaitForMultipleObjects + + handle_seq: object + wait_flag: BOOL + milliseconds: DWORD(c_default='INFINITE') = _winapi.INFINITE + / +[clinic start generated code]*/ + static PyObject * -winapi_WaitForMultipleObjects(PyObject* self, PyObject* args) +_winapi_WaitForMultipleObjects_impl(PyModuleDef *module, PyObject *handle_seq, BOOL wait_flag, DWORD milliseconds) +/*[clinic end generated code: output=e3efee6b505dd48e input=36f76ca057cd28a0]*/ { DWORD result; - PyObject *handle_seq; HANDLE handles[MAXIMUM_WAIT_OBJECTS]; HANDLE sigint_event = NULL; Py_ssize_t nhandles, i; - BOOL wait_flag; - DWORD milliseconds = INFINITE; - - if (!PyArg_ParseTuple(args, "O" F_BOOL "|" F_DWORD - ":WaitForMultipleObjects", - &handle_seq, &wait_flag, &milliseconds)) - return NULL; if (!PySequence_Check(handle_seq)) { PyErr_Format(PyExc_TypeError, @@ -1282,53 +1349,55 @@ return PyLong_FromLong((int) result); } -PyDoc_STRVAR(WaitForSingleObject_doc, -"WaitForSingleObject(handle, timeout) -> result\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."); +/*[clinic input] +_winapi.WaitForSingleObject -> long -static PyObject * -winapi_WaitForSingleObject(PyObject* self, PyObject* args) + handle: HANDLE + milliseconds: DWORD + / + +Wait for a single object. + +Wait until the specified object is in the signaled state or +the time-out interval elapses. The timeout value is specified +in milliseconds. +[clinic start generated code]*/ + +static long +_winapi_WaitForSingleObject_impl(PyModuleDef *module, HANDLE handle, DWORD milliseconds) +/*[clinic end generated code: output=0c75bcc6eec6b973 input=443d1ab076edc7b1]*/ { DWORD result; - HANDLE handle; - DWORD milliseconds; - if (! PyArg_ParseTuple(args, F_HANDLE F_DWORD ":WaitForSingleObject", - &handle, - &milliseconds)) - return NULL; - Py_BEGIN_ALLOW_THREADS result = WaitForSingleObject(handle, milliseconds); Py_END_ALLOW_THREADS - if (result == WAIT_FAILED) - return PyErr_SetFromWindowsErr(GetLastError()); + if (result == WAIT_FAILED) { + PyErr_SetFromWindowsErr(GetLastError()); + return -1; + } - return PyLong_FromUnsignedLong(result); + return result; } +/*[clinic input] +_winapi.WriteFile + + handle: HANDLE + buffer: object + overlapped as use_overlapped: int(c_default='0') = False +[clinic start generated code]*/ + static PyObject * -winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds) +_winapi_WriteFile_impl(PyModuleDef *module, HANDLE handle, PyObject *buffer, int use_overlapped) +/*[clinic end generated code: output=37bd88e293079b2c input=51846a5af52053fd]*/ { - HANDLE handle; Py_buffer _buf, *buf; - PyObject *bufobj; DWORD len, written; BOOL ret; - int use_overlapped = 0; DWORD err; OverlappedObject *overlapped = NULL; - static char *kwlist[] = {"handle", "buffer", "overlapped", NULL}; - - /* First get handle and use_overlapped to know which Py_buffer to use */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, - F_HANDLE "O|i:WriteFile", kwlist, - &handle, &bufobj, &use_overlapped)) - return NULL; if (use_overlapped) { overlapped = new_overlapped(handle); @@ -1339,7 +1408,7 @@ else buf = &_buf; - if (!PyArg_Parse(bufobj, "y*", buf)) { + if (!PyArg_Parse(buffer, "y*", buf)) { Py_XDECREF(overlapped); return NULL; } @@ -1372,54 +1441,30 @@ static PyMethodDef winapi_functions[] = { - {"CloseHandle", winapi_CloseHandle, METH_VARARGS, - CloseHandle_doc}, - {"ConnectNamedPipe", (PyCFunction)winapi_ConnectNamedPipe, - METH_VARARGS | METH_KEYWORDS, ""}, - {"CreateFile", winapi_CreateFile, METH_VARARGS, - ""}, - {"CreateJunction", winapi_CreateJunction, METH_VARARGS, - ""}, - {"CreateNamedPipe", winapi_CreateNamedPipe, METH_VARARGS, - ""}, - {"CreatePipe", winapi_CreatePipe, METH_VARARGS, - CreatePipe_doc}, - {"CreateProcess", winapi_CreateProcess, METH_VARARGS, - CreateProcess_doc}, - {"DuplicateHandle", winapi_DuplicateHandle, METH_VARARGS, - DuplicateHandle_doc}, - {"ExitProcess", winapi_ExitProcess, METH_VARARGS, - ""}, - {"GetCurrentProcess", winapi_GetCurrentProcess, METH_VARARGS, - GetCurrentProcess_doc}, - {"GetExitCodeProcess", winapi_GetExitCodeProcess, METH_VARARGS, - GetExitCodeProcess_doc}, - {"GetLastError", winapi_GetLastError, METH_NOARGS, - GetCurrentProcess_doc}, - {"GetModuleFileName", winapi_GetModuleFileName, METH_VARARGS, - GetModuleFileName_doc}, - {"GetStdHandle", winapi_GetStdHandle, METH_VARARGS, - GetStdHandle_doc}, - {"GetVersion", winapi_GetVersion, METH_VARARGS, - GetVersion_doc}, - {"OpenProcess", winapi_OpenProcess, METH_VARARGS, - ""}, - {"PeekNamedPipe", winapi_PeekNamedPipe, METH_VARARGS, - ""}, - {"ReadFile", (PyCFunction)winapi_ReadFile, METH_VARARGS | METH_KEYWORDS, - ""}, - {"SetNamedPipeHandleState", winapi_SetNamedPipeHandleState, METH_VARARGS, - ""}, - {"TerminateProcess", winapi_TerminateProcess, METH_VARARGS, - TerminateProcess_doc}, - {"WaitNamedPipe", winapi_WaitNamedPipe, METH_VARARGS, - ""}, - {"WaitForMultipleObjects", winapi_WaitForMultipleObjects, METH_VARARGS, - ""}, - {"WaitForSingleObject", winapi_WaitForSingleObject, METH_VARARGS, - WaitForSingleObject_doc}, - {"WriteFile", (PyCFunction)winapi_WriteFile, METH_VARARGS | METH_KEYWORDS, - ""}, + _WINAPI_CLOSEHANDLE_METHODDEF + _WINAPI_CONNECTNAMEDPIPE_METHODDEF + _WINAPI_CREATEFILE_METHODDEF + _WINAPI_CREATENAMEDPIPE_METHODDEF + _WINAPI_CREATEPIPE_METHODDEF + _WINAPI_CREATEPROCESS_METHODDEF + _WINAPI_CREATEJUNCTION_METHODDEF + _WINAPI_DUPLICATEHANDLE_METHODDEF + _WINAPI_EXITPROCESS_METHODDEF + _WINAPI_GETCURRENTPROCESS_METHODDEF + _WINAPI_GETEXITCODEPROCESS_METHODDEF + _WINAPI_GETLASTERROR_METHODDEF + _WINAPI_GETMODULEFILENAME_METHODDEF + _WINAPI_GETSTDHANDLE_METHODDEF + _WINAPI_GETVERSION_METHODDEF + _WINAPI_OPENPROCESS_METHODDEF + _WINAPI_PEEKNAMEDPIPE_METHODDEF + _WINAPI_READFILE_METHODDEF + _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF + _WINAPI_TERMINATEPROCESS_METHODDEF + _WINAPI_WAITNAMEDPIPE_METHODDEF + _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF + _WINAPI_WAITFORSINGLEOBJECT_METHODDEF + _WINAPI_WRITEFILE_METHODDEF {NULL, NULL} }; diff -r 78a2d1169be1 -r 9ec35c653970 Modules/clinic/_winapi.c.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/clinic/_winapi.c.h Tue Apr 14 15:05:26 2015 -0500 @@ -0,0 +1,851 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +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; + + if (!PyArg_Parse(arg, + "p:GetOverlappedResult", + &wait)) + goto exit; + 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 * +_winapi_CloseHandle_impl(PyModuleDef *module, HANDLE handle); + +static PyObject * +_winapi_CloseHandle(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HANDLE handle; + + if (!PyArg_Parse(arg, + "" F_HANDLE ":CloseHandle", + &handle)) + goto exit; + 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 \ + {"ConnectNamedPipe", (PyCFunction)_winapi_ConnectNamedPipe, METH_VARARGS|METH_KEYWORDS, _winapi_ConnectNamedPipe__doc__}, + +static PyObject * +_winapi_ConnectNamedPipe_impl(PyModuleDef *module, HANDLE handle, int use_overlapped); + +static PyObject * +_winapi_ConnectNamedPipe(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"handle", "overlapped", NULL}; + HANDLE handle; + int use_overlapped = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "" F_HANDLE "|i:ConnectNamedPipe", _keywords, + &handle, &use_overlapped)) + goto exit; + return_value = _winapi_ConnectNamedPipe_impl(module, handle, use_overlapped); + +exit: + return return_value; +} + +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 \ + {"CreateFile", (PyCFunction)_winapi_CreateFile, METH_VARARGS, _winapi_CreateFile__doc__}, + +static HANDLE +_winapi_CreateFile_impl(PyModuleDef *module, LPCTSTR file_name, DWORD desired_access, DWORD share_mode, LPSECURITY_ATTRIBUTES security_attributes, DWORD creation_disposition, DWORD flags_and_attributes, HANDLE template_file); + +static PyObject * +_winapi_CreateFile(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + LPCTSTR file_name; + DWORD desired_access; + DWORD share_mode; + LPSECURITY_ATTRIBUTES security_attributes; + DWORD creation_disposition; + DWORD flags_and_attributes; + HANDLE template_file; + HANDLE _return_value; + + if (!PyArg_ParseTuple(args, + "skk" F_POINTER "kk" F_HANDLE ":CreateFile", + &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) + goto exit; + _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file); + 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: + return return_value; +} + +PyDoc_STRVAR(_winapi_CreateJunction__doc__, +"CreateJunction($module, src_path, dst_path, /)\n" +"--\n" +"\n"); + +#define _WINAPI_CREATEJUNCTION_METHODDEF \ + {"CreateJunction", (PyCFunction)_winapi_CreateJunction, METH_VARARGS, _winapi_CreateJunction__doc__}, + +static PyObject * +_winapi_CreateJunction_impl(PyModuleDef *module, LPWSTR src_path, LPWSTR dst_path); + +static PyObject * +_winapi_CreateJunction(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + LPWSTR src_path; + LPWSTR dst_path; + + if (!PyArg_ParseTuple(args, + "uu:CreateJunction", + &src_path, &dst_path)) + goto exit; + return_value = _winapi_CreateJunction_impl(module, src_path, dst_path); + +exit: + return return_value; +} + +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 \ + {"CreateNamedPipe", (PyCFunction)_winapi_CreateNamedPipe, METH_VARARGS, _winapi_CreateNamedPipe__doc__}, + +static HANDLE +_winapi_CreateNamedPipe_impl(PyModuleDef *module, LPCTSTR name, DWORD open_mode, DWORD pipe_mode, DWORD max_instances, DWORD out_buffer_size, DWORD in_buffer_size, DWORD default_timeout, LPSECURITY_ATTRIBUTES security_attributes); + +static PyObject * +_winapi_CreateNamedPipe(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + LPCTSTR name; + 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; + + if (!PyArg_ParseTuple(args, + "skkkkkk" F_POINTER ":CreateNamedPipe", + &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) + goto exit; + _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes); + 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: + 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 \ + {"CreatePipe", (PyCFunction)_winapi_CreatePipe, METH_VARARGS, _winapi_CreatePipe__doc__}, + +static PyObject * +_winapi_CreatePipe_impl(PyModuleDef *module, PyObject *pipe_attrs, DWORD size); + +static PyObject * +_winapi_CreatePipe(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *pipe_attrs; + DWORD size; + + if (!PyArg_ParseTuple(args, + "Ok:CreatePipe", + &pipe_attrs, &size)) + goto exit; + 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" +" 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 \ + {"CreateProcess", (PyCFunction)_winapi_CreateProcess, METH_VARARGS, _winapi_CreateProcess__doc__}, + +static PyObject * +_winapi_CreateProcess_impl(PyModuleDef *module, Py_UNICODE *application_name, Py_UNICODE *command_line, PyObject *proc_attrs, PyObject *thread_attrs, BOOL inherit_handles, DWORD creation_flags, PyObject *env_mapping, Py_UNICODE *current_directory, PyObject *startup_info); + +static PyObject * +_winapi_CreateProcess(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_UNICODE *application_name; + Py_UNICODE *command_line; + PyObject *proc_attrs; + PyObject *thread_attrs; + BOOL inherit_handles; + DWORD creation_flags; + PyObject *env_mapping; + Py_UNICODE *current_directory; + PyObject *startup_info; + + if (!PyArg_ParseTuple(args, + "ZZOOikOZO:CreateProcess", + &application_name, &command_line, &proc_attrs, &thread_attrs, &inherit_handles, &creation_flags, &env_mapping, ¤t_directory, &startup_info)) + goto exit; + 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: + 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 \ + {"DuplicateHandle", (PyCFunction)_winapi_DuplicateHandle, METH_VARARGS, _winapi_DuplicateHandle__doc__}, + +static HANDLE +_winapi_DuplicateHandle_impl(PyModuleDef *module, HANDLE source_process_handle, HANDLE source_handle, HANDLE target_process_handle, DWORD desired_access, BOOL inherit_handle, DWORD options); + +static PyObject * +_winapi_DuplicateHandle(PyModuleDef *module, PyObject *args) +{ + 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; + + if (!PyArg_ParseTuple(args, + "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle", + &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) + goto exit; + _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options); + 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: + 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 * +_winapi_ExitProcess_impl(PyModuleDef *module, UINT ExitCode); + +static PyObject * +_winapi_ExitProcess(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + UINT ExitCode; + + if (!PyArg_Parse(arg, + "I:ExitProcess", + &ExitCode)) + goto exit; + 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 +_winapi_GetCurrentProcess_impl(PyModuleDef *module); + +static PyObject * +_winapi_GetCurrentProcess(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + HANDLE _return_value; + + _return_value = _winapi_GetCurrentProcess_impl(module); + 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: + 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 +_winapi_GetExitCodeProcess_impl(PyModuleDef *module, HANDLE process); + +static PyObject * +_winapi_GetExitCodeProcess(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HANDLE process; + DWORD _return_value; + + if (!PyArg_Parse(arg, + "" F_HANDLE ":GetExitCodeProcess", + &process)) + goto exit; + _return_value = _winapi_GetExitCodeProcess_impl(module, process); + if ((_return_value == DWORD_MAX) && PyErr_Occurred()) + goto exit; + return_value = Py_BuildValue("k", _return_value); + +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 +_winapi_GetLastError_impl(PyModuleDef *module); + +static PyObject * +_winapi_GetLastError(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + DWORD _return_value; + + _return_value = _winapi_GetLastError_impl(module); + if ((_return_value == DWORD_MAX) && PyErr_Occurred()) + goto exit; + return_value = Py_BuildValue("k", _return_value); + +exit: + return return_value; +} + +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 * +_winapi_GetModuleFileName_impl(PyModuleDef *module, HMODULE module_handle); + +static PyObject * +_winapi_GetModuleFileName(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HMODULE module_handle; + + if (!PyArg_Parse(arg, + "" F_HANDLE ":GetModuleFileName", + &module_handle)) + goto exit; + return_value = _winapi_GetModuleFileName_impl(module, module_handle); + +exit: + return return_value; +} + +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 +_winapi_GetStdHandle_impl(PyModuleDef *module, DWORD std_handle); + +static PyObject * +_winapi_GetStdHandle(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + DWORD std_handle; + HANDLE _return_value; + + if (!PyArg_Parse(arg, + "k:GetStdHandle", + &std_handle)) + goto exit; + _return_value = _winapi_GetStdHandle_impl(module, std_handle); + 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: + 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 +_winapi_GetVersion_impl(PyModuleDef *module); + +static PyObject * +_winapi_GetVersion(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + long _return_value; + + _return_value = _winapi_GetVersion_impl(module); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(_winapi_OpenProcess__doc__, +"OpenProcess($module, desired_access, inherit_handle, process_id, /)\n" +"--\n" +"\n"); + +#define _WINAPI_OPENPROCESS_METHODDEF \ + {"OpenProcess", (PyCFunction)_winapi_OpenProcess, METH_VARARGS, _winapi_OpenProcess__doc__}, + +static HANDLE +_winapi_OpenProcess_impl(PyModuleDef *module, DWORD desired_access, BOOL inherit_handle, DWORD process_id); + +static PyObject * +_winapi_OpenProcess(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + DWORD desired_access; + BOOL inherit_handle; + DWORD process_id; + HANDLE _return_value; + + if (!PyArg_ParseTuple(args, + "kik:OpenProcess", + &desired_access, &inherit_handle, &process_id)) + goto exit; + _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id); + 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: + return return_value; +} + +PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__, +"PeekNamedPipe($module, handle, size=0, /)\n" +"--\n" +"\n"); + +#define _WINAPI_PEEKNAMEDPIPE_METHODDEF \ + {"PeekNamedPipe", (PyCFunction)_winapi_PeekNamedPipe, METH_VARARGS, _winapi_PeekNamedPipe__doc__}, + +static PyObject * +_winapi_PeekNamedPipe_impl(PyModuleDef *module, HANDLE handle, int size); + +static PyObject * +_winapi_PeekNamedPipe(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HANDLE handle; + int size = 0; + + if (!PyArg_ParseTuple(args, + "" F_HANDLE "|i:PeekNamedPipe", + &handle, &size)) + goto exit; + return_value = _winapi_PeekNamedPipe_impl(module, handle, size); + +exit: + return return_value; +} + +PyDoc_STRVAR(_winapi_ReadFile__doc__, +"ReadFile($module, /, handle, size, overlapped=False)\n" +"--\n" +"\n"); + +#define _WINAPI_READFILE_METHODDEF \ + {"ReadFile", (PyCFunction)_winapi_ReadFile, METH_VARARGS|METH_KEYWORDS, _winapi_ReadFile__doc__}, + +static PyObject * +_winapi_ReadFile_impl(PyModuleDef *module, HANDLE handle, int size, int use_overlapped); + +static PyObject * +_winapi_ReadFile(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"handle", "size", "overlapped", NULL}; + HANDLE handle; + int size; + int use_overlapped = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "" F_HANDLE "i|i:ReadFile", _keywords, + &handle, &size, &use_overlapped)) + goto exit; + return_value = _winapi_ReadFile_impl(module, handle, size, use_overlapped); + +exit: + return return_value; +} + +PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__, +"SetNamedPipeHandleState($module, named_pipe, mode,\n" +" max_collection_count, collect_data_timeout, /)\n" +"--\n" +"\n"); + +#define _WINAPI_SETNAMEDPIPEHANDLESTATE_METHODDEF \ + {"SetNamedPipeHandleState", (PyCFunction)_winapi_SetNamedPipeHandleState, METH_VARARGS, _winapi_SetNamedPipeHandleState__doc__}, + +static PyObject * +_winapi_SetNamedPipeHandleState_impl(PyModuleDef *module, HANDLE named_pipe, PyObject *mode, PyObject *max_collection_count, PyObject *collect_data_timeout); + +static PyObject * +_winapi_SetNamedPipeHandleState(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HANDLE named_pipe; + PyObject *mode; + PyObject *max_collection_count; + PyObject *collect_data_timeout; + + if (!PyArg_ParseTuple(args, + "" F_HANDLE "OOO:SetNamedPipeHandleState", + &named_pipe, &mode, &max_collection_count, &collect_data_timeout)) + goto exit; + 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 \ + {"TerminateProcess", (PyCFunction)_winapi_TerminateProcess, METH_VARARGS, _winapi_TerminateProcess__doc__}, + +static PyObject * +_winapi_TerminateProcess_impl(PyModuleDef *module, HANDLE handle, UINT exit_code); + +static PyObject * +_winapi_TerminateProcess(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HANDLE handle; + UINT exit_code; + + if (!PyArg_ParseTuple(args, + "" F_HANDLE "I:TerminateProcess", + &handle, &exit_code)) + goto exit; + return_value = _winapi_TerminateProcess_impl(module, handle, exit_code); + +exit: + return return_value; +} + +PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__, +"WaitNamedPipe($module, name, timeout, /)\n" +"--\n" +"\n"); + +#define _WINAPI_WAITNAMEDPIPE_METHODDEF \ + {"WaitNamedPipe", (PyCFunction)_winapi_WaitNamedPipe, METH_VARARGS, _winapi_WaitNamedPipe__doc__}, + +static PyObject * +_winapi_WaitNamedPipe_impl(PyModuleDef *module, LPCTSTR name, DWORD timeout); + +static PyObject * +_winapi_WaitNamedPipe(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + LPCTSTR name; + DWORD timeout; + + if (!PyArg_ParseTuple(args, + "sk:WaitNamedPipe", + &name, &timeout)) + goto exit; + return_value = _winapi_WaitNamedPipe_impl(module, name, timeout); + +exit: + return return_value; +} + +PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__, +"WaitForMultipleObjects($module, handle_seq, wait_flag,\n" +" milliseconds=_winapi.INFINITE, /)\n" +"--\n" +"\n"); + +#define _WINAPI_WAITFORMULTIPLEOBJECTS_METHODDEF \ + {"WaitForMultipleObjects", (PyCFunction)_winapi_WaitForMultipleObjects, METH_VARARGS, _winapi_WaitForMultipleObjects__doc__}, + +static PyObject * +_winapi_WaitForMultipleObjects_impl(PyModuleDef *module, PyObject *handle_seq, BOOL wait_flag, DWORD milliseconds); + +static PyObject * +_winapi_WaitForMultipleObjects(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *handle_seq; + BOOL wait_flag; + DWORD milliseconds = INFINITE; + + if (!PyArg_ParseTuple(args, + "Oi|k:WaitForMultipleObjects", + &handle_seq, &wait_flag, &milliseconds)) + goto exit; + 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 \ + {"WaitForSingleObject", (PyCFunction)_winapi_WaitForSingleObject, METH_VARARGS, _winapi_WaitForSingleObject__doc__}, + +static long +_winapi_WaitForSingleObject_impl(PyModuleDef *module, HANDLE handle, DWORD milliseconds); + +static PyObject * +_winapi_WaitForSingleObject(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HANDLE handle; + DWORD milliseconds; + long _return_value; + + if (!PyArg_ParseTuple(args, + "" F_HANDLE "k:WaitForSingleObject", + &handle, &milliseconds)) + goto exit; + _return_value = _winapi_WaitForSingleObject_impl(module, handle, milliseconds); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + 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 \ + {"WriteFile", (PyCFunction)_winapi_WriteFile, METH_VARARGS|METH_KEYWORDS, _winapi_WriteFile__doc__}, + +static PyObject * +_winapi_WriteFile_impl(PyModuleDef *module, HANDLE handle, PyObject *buffer, int use_overlapped); + +static PyObject * +_winapi_WriteFile(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"handle", "buffer", "overlapped", NULL}; + HANDLE handle; + PyObject *buffer; + int use_overlapped = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "" F_HANDLE "O|i:WriteFile", _keywords, + &handle, &buffer, &use_overlapped)) + goto exit; + return_value = _winapi_WriteFile_impl(module, handle, buffer, use_overlapped); + +exit: + return return_value; +} +/*[clinic end generated code: output=107b73892f62ff3c input=a9049054013a1b77]*/ diff -r 78a2d1169be1 -r 9ec35c653970 PC/clinic/msvcrtmodule.c.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/clinic/msvcrtmodule.c.h Tue Apr 14 15:05:26 2015 -0500 @@ -0,0 +1,604 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(msvcrt_heapmin__doc__, +"heapmin($module, /)\n" +"--\n" +"\n" +"Minimize the malloc() heap.\n" +"\n" +"Force the malloc() heap to clean itself up and return unused blocks\n" +"to the operating system. On failure, this raises OSError."); + +#define MSVCRT_HEAPMIN_METHODDEF \ + {"heapmin", (PyCFunction)msvcrt_heapmin, METH_NOARGS, msvcrt_heapmin__doc__}, + +static PyObject * +msvcrt_heapmin_impl(PyModuleDef *module); + +static PyObject * +msvcrt_heapmin(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return msvcrt_heapmin_impl(module); +} + +PyDoc_STRVAR(msvcrt_locking__doc__, +"locking($module, fd, mode, nbytes, /)\n" +"--\n" +"\n" +"Lock part of a file based on file descriptor fd from the C runtime.\n" +"\n" +"Raises IOError on failure. The locked region of the file extends from\n" +"the current file position for nbytes bytes, and may continue beyond\n" +"the end of the file. mode must be one of the LK_* constants listed\n" +"below. Multiple regions in a file may be locked at the same time, but\n" +"may not overlap. Adjacent regions are not merged; they must be unlocked\n" +"individually."); + +#define MSVCRT_LOCKING_METHODDEF \ + {"locking", (PyCFunction)msvcrt_locking, METH_VARARGS, msvcrt_locking__doc__}, + +static PyObject * +msvcrt_locking_impl(PyModuleDef *module, int fd, int mode, long nbytes); + +static PyObject * +msvcrt_locking(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int fd; + int mode; + long nbytes; + + if (!PyArg_ParseTuple(args, + "iil:locking", + &fd, &mode, &nbytes)) + goto exit; + return_value = msvcrt_locking_impl(module, fd, mode, nbytes); + +exit: + return return_value; +} + +PyDoc_STRVAR(msvcrt_setmode__doc__, +"setmode($module, fd, mode, /)\n" +"--\n" +"\n" +"Set the line-end translation mode for the file descriptor fd.\n" +"\n" +"To set it to text mode, flags should be os.O_TEXT; for binary, it\n" +"should be os.O_BINARY.\n" +"\n" +"Return value is the previous mode."); + +#define MSVCRT_SETMODE_METHODDEF \ + {"setmode", (PyCFunction)msvcrt_setmode, METH_VARARGS, msvcrt_setmode__doc__}, + +static long +msvcrt_setmode_impl(PyModuleDef *module, int fd, int flags); + +static PyObject * +msvcrt_setmode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int fd; + int flags; + long _return_value; + + if (!PyArg_ParseTuple(args, + "ii:setmode", + &fd, &flags)) + goto exit; + _return_value = msvcrt_setmode_impl(module, fd, flags); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(msvcrt_open_osfhandle__doc__, +"open_osfhandle($module, handle, flags, /)\n" +"--\n" +"\n" +"Create a C runtime file descriptor from the file handle handle.\n" +"\n" +"The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n" +"and os.O_TEXT. The returned file descriptor may be used as a parameter\n" +"to os.fdopen() to create a file object."); + +#define MSVCRT_OPEN_OSFHANDLE_METHODDEF \ + {"open_osfhandle", (PyCFunction)msvcrt_open_osfhandle, METH_VARARGS, msvcrt_open_osfhandle__doc__}, + +static long +msvcrt_open_osfhandle_impl(PyModuleDef *module, Py_intptr_t handle, int flags); + +static PyObject * +msvcrt_open_osfhandle(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_intptr_t handle; + int flags; + long _return_value; + + if (!PyArg_ParseTuple(args, + ""_Py_PARSE_INTPTR"i:open_osfhandle", + &handle, &flags)) + goto exit; + _return_value = msvcrt_open_osfhandle_impl(module, handle, flags); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(msvcrt_get_osfhandle__doc__, +"get_osfhandle($module, fd, /)\n" +"--\n" +"\n" +"Return the file handle for the file descriptor fd.\n" +"\n" +"Raises IOError if fd is not recognized."); + +#define MSVCRT_GET_OSFHANDLE_METHODDEF \ + {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__}, + +static Py_intptr_t +msvcrt_get_osfhandle_impl(PyModuleDef *module, int fd); + +static PyObject * +msvcrt_get_osfhandle(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int fd; + Py_intptr_t _return_value; + + if (!PyArg_Parse(arg, + "i:get_osfhandle", + &fd)) + goto exit; + _return_value = msvcrt_get_osfhandle_impl(module, fd); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromVoidPtr((void *)_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(msvcrt_kbhit__doc__, +"kbhit($module, /)\n" +"--\n" +"\n" +"Return true if a keypress is waiting to be read."); + +#define MSVCRT_KBHIT_METHODDEF \ + {"kbhit", (PyCFunction)msvcrt_kbhit, METH_NOARGS, msvcrt_kbhit__doc__}, + +static long +msvcrt_kbhit_impl(PyModuleDef *module); + +static PyObject * +msvcrt_kbhit(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + long _return_value; + + _return_value = msvcrt_kbhit_impl(module); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(msvcrt_getch__doc__, +"getch($module, /)\n" +"--\n" +"\n" +"Read a keypress and return the resulting character as a byte string.\n" +"\n" +"Nothing is echoed to the console. This call will block if a keypress is\n" +"not already available, but will not wait for Enter to be pressed. If the\n" +"pressed key was a special function key, this will return \'\\000\' or\n" +"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n" +"cannot be read with this function."); + +#define MSVCRT_GETCH_METHODDEF \ + {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__}, + +static int +msvcrt_getch_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getch(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + char s[1]; + + s[0] = msvcrt_getch_impl(module); + return_value = PyBytes_FromStringAndSize(s, 1); + + return return_value; +} + +#if defined(_WCONIO_DEFINED) + +PyDoc_STRVAR(msvcrt_getwch__doc__, +"getwch($module, /)\n" +"--\n" +"\n" +"Wide char variant of getch(), returning a Unicode value."); + +#define MSVCRT_GETWCH_METHODDEF \ + {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__}, + +static wchar_t +msvcrt_getwch_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getwch(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + wchar_t _return_value; + + _return_value = msvcrt_getwch_impl(module); + return_value = PyUnicode_FromOrdinal(_return_value); + + return return_value; +} + +#endif /* defined(_WCONIO_DEFINED) */ + +PyDoc_STRVAR(msvcrt_getche__doc__, +"getche($module, /)\n" +"--\n" +"\n" +"Similar to getch(), but the keypress will be echoed if possible."); + +#define MSVCRT_GETCHE_METHODDEF \ + {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__}, + +static int +msvcrt_getche_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getche(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + char s[1]; + + s[0] = msvcrt_getche_impl(module); + return_value = PyBytes_FromStringAndSize(s, 1); + + return return_value; +} + +#if defined(_WCONIO_DEFINED) + +PyDoc_STRVAR(msvcrt_getwche__doc__, +"getwche($module, /)\n" +"--\n" +"\n" +"Wide char variant of getche(), returning a Unicode value."); + +#define MSVCRT_GETWCHE_METHODDEF \ + {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__}, + +static wchar_t +msvcrt_getwche_impl(PyModuleDef *module); + +static PyObject * +msvcrt_getwche(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + wchar_t _return_value; + + _return_value = msvcrt_getwche_impl(module); + return_value = PyUnicode_FromOrdinal(_return_value); + + return return_value; +} + +#endif /* defined(_WCONIO_DEFINED) */ + +PyDoc_STRVAR(msvcrt_putch__doc__, +"putch($module, char, /)\n" +"--\n" +"\n" +"Print the byte string char to the console without buffering."); + +#define MSVCRT_PUTCH_METHODDEF \ + {"putch", (PyCFunction)msvcrt_putch, METH_O, msvcrt_putch__doc__}, + +static PyObject * +msvcrt_putch_impl(PyModuleDef *module, char char_value); + +static PyObject * +msvcrt_putch(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + char char_value; + + if (!PyArg_Parse(arg, + "c:putch", + &char_value)) + goto exit; + return_value = msvcrt_putch_impl(module, char_value); + +exit: + return return_value; +} + +#if defined(_WCONIO_DEFINED) + +PyDoc_STRVAR(msvcrt_putwch__doc__, +"putwch($module, unicode_char, /)\n" +"--\n" +"\n" +"Wide char variant of putch(), accepting a Unicode value."); + +#define MSVCRT_PUTWCH_METHODDEF \ + {"putwch", (PyCFunction)msvcrt_putwch, METH_O, msvcrt_putwch__doc__}, + +static PyObject * +msvcrt_putwch_impl(PyModuleDef *module, int unicode_char); + +static PyObject * +msvcrt_putwch(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int unicode_char; + + if (!PyArg_Parse(arg, + "C:putwch", + &unicode_char)) + goto exit; + return_value = msvcrt_putwch_impl(module, unicode_char); + +exit: + return return_value; +} + +#endif /* defined(_WCONIO_DEFINED) */ + +PyDoc_STRVAR(msvcrt_ungetch__doc__, +"ungetch($module, char, /)\n" +"--\n" +"\n" +"Opposite of getch.\n" +"\n" +"Cause the byte string char to be \"pushed back\" into the\n" +"console buffer; it will be the next character read by\n" +"getch() or getche()."); + +#define MSVCRT_UNGETCH_METHODDEF \ + {"ungetch", (PyCFunction)msvcrt_ungetch, METH_O, msvcrt_ungetch__doc__}, + +static PyObject * +msvcrt_ungetch_impl(PyModuleDef *module, char char_value); + +static PyObject * +msvcrt_ungetch(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + char char_value; + + if (!PyArg_Parse(arg, + "c:ungetch", + &char_value)) + goto exit; + return_value = msvcrt_ungetch_impl(module, char_value); + +exit: + return return_value; +} + +#if defined(_WCONIO_DEFINED) + +PyDoc_STRVAR(msvcrt_ungetwch__doc__, +"ungetwch($module, unicode_char, /)\n" +"--\n" +"\n" +"Wide char variant of ungetch(), accepting a Unicode value."); + +#define MSVCRT_UNGETWCH_METHODDEF \ + {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_O, msvcrt_ungetwch__doc__}, + +static PyObject * +msvcrt_ungetwch_impl(PyModuleDef *module, int unicode_char); + +static PyObject * +msvcrt_ungetwch(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int unicode_char; + + if (!PyArg_Parse(arg, + "C:ungetwch", + &unicode_char)) + goto exit; + return_value = msvcrt_ungetwch_impl(module, unicode_char); + +exit: + return return_value; +} + +#endif /* defined(_WCONIO_DEFINED) */ + +#if defined(_DEBUG) + +PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__, +"CrtSetReportFile($module, type, file, /)\n" +"--\n" +"\n" +"Wrapper around _CrtSetReportFile.\n" +"\n" +"Only available on Debug builds."); + +#define MSVCRT_CRTSETREPORTFILE_METHODDEF \ + {"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_VARARGS, msvcrt_CrtSetReportFile__doc__}, + +static long +msvcrt_CrtSetReportFile_impl(PyModuleDef *module, int type, int file); + +static PyObject * +msvcrt_CrtSetReportFile(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int type; + int file; + long _return_value; + + if (!PyArg_ParseTuple(args, + "ii:CrtSetReportFile", + &type, &file)) + goto exit; + _return_value = msvcrt_CrtSetReportFile_impl(module, type, file); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +#endif /* defined(_DEBUG) */ + +#if defined(_DEBUG) + +PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__, +"CrtSetReportMode($module, type, mode, /)\n" +"--\n" +"\n" +"Wrapper around _CrtSetReportMode.\n" +"\n" +"Only available on Debug builds."); + +#define MSVCRT_CRTSETREPORTMODE_METHODDEF \ + {"CrtSetReportMode", (PyCFunction)msvcrt_CrtSetReportMode, METH_VARARGS, msvcrt_CrtSetReportMode__doc__}, + +static long +msvcrt_CrtSetReportMode_impl(PyModuleDef *module, int type, int mode); + +static PyObject * +msvcrt_CrtSetReportMode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int type; + int mode; + long _return_value; + + if (!PyArg_ParseTuple(args, + "ii:CrtSetReportMode", + &type, &mode)) + goto exit; + _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +#endif /* defined(_DEBUG) */ + +#if defined(_DEBUG) + +PyDoc_STRVAR(msvcrt_set_error_mode__doc__, +"set_error_mode($module, mode, /)\n" +"--\n" +"\n" +"Wrapper around _set_error_mode.\n" +"\n" +"Only available on Debug builds."); + +#define MSVCRT_SET_ERROR_MODE_METHODDEF \ + {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_O, msvcrt_set_error_mode__doc__}, + +static long +msvcrt_set_error_mode_impl(PyModuleDef *module, int mode); + +static PyObject * +msvcrt_set_error_mode(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int mode; + long _return_value; + + if (!PyArg_Parse(arg, + "i:set_error_mode", + &mode)) + goto exit; + _return_value = msvcrt_set_error_mode_impl(module, mode); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong(_return_value); + +exit: + return return_value; +} + +#endif /* defined(_DEBUG) */ + +PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, +"SetErrorMode($module, mode, /)\n" +"--\n" +"\n" +"Wrapper around SetErrorMode."); + +#define MSVCRT_SETERRORMODE_METHODDEF \ + {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_O, msvcrt_SetErrorMode__doc__}, + +static PyObject * +msvcrt_SetErrorMode_impl(PyModuleDef *module, unsigned int mode); + +static PyObject * +msvcrt_SetErrorMode(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + unsigned int mode; + + if (!PyArg_Parse(arg, + "I:SetErrorMode", + &mode)) + goto exit; + return_value = msvcrt_SetErrorMode_impl(module, mode); + +exit: + return return_value; +} + +#ifndef MSVCRT_GETWCH_METHODDEF + #define MSVCRT_GETWCH_METHODDEF +#endif /* !defined(MSVCRT_GETWCH_METHODDEF) */ + +#ifndef MSVCRT_GETWCHE_METHODDEF + #define MSVCRT_GETWCHE_METHODDEF +#endif /* !defined(MSVCRT_GETWCHE_METHODDEF) */ + +#ifndef MSVCRT_PUTWCH_METHODDEF + #define MSVCRT_PUTWCH_METHODDEF +#endif /* !defined(MSVCRT_PUTWCH_METHODDEF) */ + +#ifndef MSVCRT_UNGETWCH_METHODDEF + #define MSVCRT_UNGETWCH_METHODDEF +#endif /* !defined(MSVCRT_UNGETWCH_METHODDEF) */ + +#ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF + #define MSVCRT_CRTSETREPORTFILE_METHODDEF +#endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */ + +#ifndef MSVCRT_CRTSETREPORTMODE_METHODDEF + #define MSVCRT_CRTSETREPORTMODE_METHODDEF +#endif /* !defined(MSVCRT_CRTSETREPORTMODE_METHODDEF) */ + +#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF + #define MSVCRT_SET_ERROR_MODE_METHODDEF +#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */ +/*[clinic end generated code: output=41dfb6ca722afa4f input=a9049054013a1b77]*/ diff -r 78a2d1169be1 -r 9ec35c653970 PC/clinic/winreg.c.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/clinic/winreg.c.h Tue Apr 14 15:05:26 2015 -0500 @@ -0,0 +1,1078 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(winreg_HKEYType_Close__doc__, +"Close($self, /)\n" +"--\n" +"\n" +"Closes the underlying Windows handle.\n" +"\n" +"If the handle is already closed, no error is raised."); + +#define WINREG_HKEYTYPE_CLOSE_METHODDEF \ + {"Close", (PyCFunction)winreg_HKEYType_Close, METH_NOARGS, winreg_HKEYType_Close__doc__}, + +static PyObject * +winreg_HKEYType_Close_impl(PyHKEYObject *self); + +static PyObject * +winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) +{ + return winreg_HKEYType_Close_impl(self); +} + +PyDoc_STRVAR(winreg_HKEYType_Detach__doc__, +"Detach($self, /)\n" +"--\n" +"\n" +"Detaches the Windows handle from the handle object.\n" +"\n" +"The result is the value of the handle before it is detached. If the\n" +"handle is already detached, this will return zero.\n" +"\n" +"After calling this function, the handle is effectively invalidated,\n" +"but the handle is not closed. You would call this function when you\n" +"need the underlying win32 handle to exist beyond the lifetime of the\n" +"handle object."); + +#define WINREG_HKEYTYPE_DETACH_METHODDEF \ + {"Detach", (PyCFunction)winreg_HKEYType_Detach, METH_NOARGS, winreg_HKEYType_Detach__doc__}, + +static PyObject * +winreg_HKEYType_Detach_impl(PyHKEYObject *self); + +static PyObject * +winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) +{ + return winreg_HKEYType_Detach_impl(self); +} + +PyDoc_STRVAR(winreg_HKEYType___enter____doc__, +"__enter__($self, /)\n" +"--\n" +"\n"); + +#define WINREG_HKEYTYPE___ENTER___METHODDEF \ + {"__enter__", (PyCFunction)winreg_HKEYType___enter__, METH_NOARGS, winreg_HKEYType___enter____doc__}, + +static PyHKEYObject * +winreg_HKEYType___enter___impl(PyHKEYObject *self); + +static PyObject * +winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) +{ + PyObject *return_value = NULL; + PyHKEYObject *_return_value; + + _return_value = winreg_HKEYType___enter___impl(self); + return_value = (PyObject *)_return_value; + + return return_value; +} + +PyDoc_STRVAR(winreg_HKEYType___exit____doc__, +"__exit__($self, /, exc_type, exc_value, traceback)\n" +"--\n" +"\n"); + +#define WINREG_HKEYTYPE___EXIT___METHODDEF \ + {"__exit__", (PyCFunction)winreg_HKEYType___exit__, METH_VARARGS|METH_KEYWORDS, winreg_HKEYType___exit____doc__}, + +static PyObject * +winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type, PyObject *exc_value, PyObject *traceback); + +static PyObject * +winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"exc_type", "exc_value", "traceback", NULL}; + PyObject *exc_type; + PyObject *exc_value; + PyObject *traceback; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "OOO:__exit__", _keywords, + &exc_type, &exc_value, &traceback)) + goto exit; + return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_CloseKey__doc__, +"CloseKey($module, hkey, /)\n" +"--\n" +"\n" +"Closes a previously opened registry key.\n" +"\n" +" hkey\n" +" A previously opened key.\n" +"\n" +"Note that if the key is not closed using this method, it will be\n" +"closed when the hkey object is destroyed by Python."); + +#define WINREG_CLOSEKEY_METHODDEF \ + {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__}, + +PyDoc_STRVAR(winreg_ConnectRegistry__doc__, +"ConnectRegistry($module, computer_name, key, /)\n" +"--\n" +"\n" +"Establishes a connection to the registry on on another computer.\n" +"\n" +" computer_name\n" +" The name of the remote computer, of the form r\"\\\\computername\". If\n" +" None, the local computer is used.\n" +" key\n" +" The predefined key to connect to.\n" +"\n" +"The return value is the handle of the opened key.\n" +"If the function fails, an OSError exception is raised."); + +#define WINREG_CONNECTREGISTRY_METHODDEF \ + {"ConnectRegistry", (PyCFunction)winreg_ConnectRegistry, METH_VARARGS, winreg_ConnectRegistry__doc__}, + +static HKEY +winreg_ConnectRegistry_impl(PyModuleDef *module, Py_UNICODE *computer_name, HKEY key); + +static PyObject * +winreg_ConnectRegistry(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_UNICODE *computer_name; + HKEY key; + HKEY _return_value; + + if (!PyArg_ParseTuple(args, + "ZO&:ConnectRegistry", + &computer_name, clinic_HKEY_converter, &key)) + goto exit; + _return_value = winreg_ConnectRegistry_impl(module, computer_name, key); + if (_return_value == NULL) + goto exit; + return_value = PyHKEY_FromHKEY(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_CreateKey__doc__, +"CreateKey($module, key, sub_key, /)\n" +"--\n" +"\n" +"Creates or opens the specified key.\n" +"\n" +" key\n" +" An already open key, or one of the predefined HKEY_* constants.\n" +" sub_key\n" +" The name of the key this method opens or creates.\n" +"\n" +"If key is one of the predefined keys, sub_key may be None. In that case,\n" +"the handle returned is the same key handle passed in to the function.\n" +"\n" +"If the key already exists, this function opens the existing key.\n" +"\n" +"The return value is the handle of the opened key.\n" +"If the function fails, an OSError exception is raised."); + +#define WINREG_CREATEKEY_METHODDEF \ + {"CreateKey", (PyCFunction)winreg_CreateKey, METH_VARARGS, winreg_CreateKey__doc__}, + +static HKEY +winreg_CreateKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key); + +static PyObject * +winreg_CreateKey(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *sub_key; + HKEY _return_value; + + if (!PyArg_ParseTuple(args, + "O&Z:CreateKey", + clinic_HKEY_converter, &key, &sub_key)) + goto exit; + _return_value = winreg_CreateKey_impl(module, key, sub_key); + if (_return_value == NULL) + goto exit; + return_value = PyHKEY_FromHKEY(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_CreateKeyEx__doc__, +"CreateKeyEx($module, /, key, sub_key, reserved=0,\n" +" access=winreg.KEY_WRITE)\n" +"--\n" +"\n" +"Creates or opens the specified key.\n" +"\n" +" key\n" +" An already open key, or one of the predefined HKEY_* constants.\n" +" sub_key\n" +" The name of the key this method opens or creates.\n" +" reserved\n" +" A reserved integer, and must be zero. Default is zero.\n" +" access\n" +" An integer that specifies an access mask that describes the\n" +" desired security access for the key. Default is KEY_WRITE.\n" +"\n" +"If key is one of the predefined keys, sub_key may be None. In that case,\n" +"the handle returned is the same key handle passed in to the function.\n" +"\n" +"If the key already exists, this function opens the existing key\n" +"\n" +"The return value is the handle of the opened key.\n" +"If the function fails, an OSError exception is raised."); + +#define WINREG_CREATEKEYEX_METHODDEF \ + {"CreateKeyEx", (PyCFunction)winreg_CreateKeyEx, METH_VARARGS|METH_KEYWORDS, winreg_CreateKeyEx__doc__}, + +static HKEY +winreg_CreateKeyEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, int reserved, REGSAM access); + +static PyObject * +winreg_CreateKeyEx(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"key", "sub_key", "reserved", "access", NULL}; + HKEY key; + Py_UNICODE *sub_key; + int reserved = 0; + REGSAM access = KEY_WRITE; + HKEY _return_value; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O&Z|ii:CreateKeyEx", _keywords, + clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) + goto exit; + _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access); + if (_return_value == NULL) + goto exit; + return_value = PyHKEY_FromHKEY(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_DeleteKey__doc__, +"DeleteKey($module, key, sub_key, /)\n" +"--\n" +"\n" +"Deletes the specified key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that must be the name of a subkey of the key identified by\n" +" the key parameter. This value must not be None, and the key may not\n" +" have subkeys.\n" +"\n" +"This method can not delete keys with subkeys.\n" +"\n" +"If the function succeeds, the entire key, including all of its values,\n" +"is removed. If the function fails, an OSError exception is raised."); + +#define WINREG_DELETEKEY_METHODDEF \ + {"DeleteKey", (PyCFunction)winreg_DeleteKey, METH_VARARGS, winreg_DeleteKey__doc__}, + +static PyObject * +winreg_DeleteKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key); + +static PyObject * +winreg_DeleteKey(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *sub_key; + + if (!PyArg_ParseTuple(args, + "O&u:DeleteKey", + clinic_HKEY_converter, &key, &sub_key)) + goto exit; + return_value = winreg_DeleteKey_impl(module, key, sub_key); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_DeleteKeyEx__doc__, +"DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n" +" reserved=0)\n" +"--\n" +"\n" +"Deletes the specified key (64-bit OS only).\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that must be the name of a subkey of the key identified by\n" +" the key parameter. This value must not be None, and the key may not\n" +" have subkeys.\n" +" access\n" +" An integer that specifies an access mask that describes the\n" +" desired security access for the key. Default is KEY_WOW64_64KEY.\n" +" reserved\n" +" A reserved integer, and must be zero. Default is zero.\n" +"\n" +"This method can not delete keys with subkeys.\n" +"\n" +"If the function succeeds, the entire key, including all of its values,\n" +"is removed. If the function fails, an OSError exception is raised.\n" +"On unsupported Windows versions, NotImplementedError is raised."); + +#define WINREG_DELETEKEYEX_METHODDEF \ + {"DeleteKeyEx", (PyCFunction)winreg_DeleteKeyEx, METH_VARARGS|METH_KEYWORDS, winreg_DeleteKeyEx__doc__}, + +static PyObject * +winreg_DeleteKeyEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, REGSAM access, int reserved); + +static PyObject * +winreg_DeleteKeyEx(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"key", "sub_key", "access", "reserved", NULL}; + HKEY key; + Py_UNICODE *sub_key; + REGSAM access = KEY_WOW64_64KEY; + int reserved = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O&u|ii:DeleteKeyEx", _keywords, + clinic_HKEY_converter, &key, &sub_key, &access, &reserved)) + goto exit; + return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_DeleteValue__doc__, +"DeleteValue($module, key, value, /)\n" +"--\n" +"\n" +"Removes a named value from a registry key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" value\n" +" A string that identifies the value to remove."); + +#define WINREG_DELETEVALUE_METHODDEF \ + {"DeleteValue", (PyCFunction)winreg_DeleteValue, METH_VARARGS, winreg_DeleteValue__doc__}, + +static PyObject * +winreg_DeleteValue_impl(PyModuleDef *module, HKEY key, Py_UNICODE *value); + +static PyObject * +winreg_DeleteValue(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *value; + + if (!PyArg_ParseTuple(args, + "O&Z:DeleteValue", + clinic_HKEY_converter, &key, &value)) + goto exit; + return_value = winreg_DeleteValue_impl(module, key, value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_EnumKey__doc__, +"EnumKey($module, key, index, /)\n" +"--\n" +"\n" +"Enumerates subkeys of an open registry key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" index\n" +" An integer that identifies the index of the key to retrieve.\n" +"\n" +"The function retrieves the name of one subkey each time it is called.\n" +"It is typically called repeatedly until an OSError exception is\n" +"raised, indicating no more values are available."); + +#define WINREG_ENUMKEY_METHODDEF \ + {"EnumKey", (PyCFunction)winreg_EnumKey, METH_VARARGS, winreg_EnumKey__doc__}, + +static PyObject * +winreg_EnumKey_impl(PyModuleDef *module, HKEY key, int index); + +static PyObject * +winreg_EnumKey(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + int index; + + if (!PyArg_ParseTuple(args, + "O&i:EnumKey", + clinic_HKEY_converter, &key, &index)) + goto exit; + return_value = winreg_EnumKey_impl(module, key, index); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_EnumValue__doc__, +"EnumValue($module, key, index, /)\n" +"--\n" +"\n" +"Enumerates values of an open registry key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" index\n" +" An integer that identifies the index of the value to retrieve.\n" +"\n" +"The function retrieves the name of one subkey each time it is called.\n" +"It is typically called repeatedly, until an OSError exception\n" +"is raised, indicating no more values.\n" +"\n" +"The result is a tuple of 3 items:\n" +" value_name\n" +" A string that identifies the value.\n" +" value_data\n" +" An object that holds the value data, and whose type depends\n" +" on the underlying registry type.\n" +" data_type\n" +" An integer that identifies the type of the value data."); + +#define WINREG_ENUMVALUE_METHODDEF \ + {"EnumValue", (PyCFunction)winreg_EnumValue, METH_VARARGS, winreg_EnumValue__doc__}, + +static PyObject * +winreg_EnumValue_impl(PyModuleDef *module, HKEY key, int index); + +static PyObject * +winreg_EnumValue(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + int index; + + if (!PyArg_ParseTuple(args, + "O&i:EnumValue", + clinic_HKEY_converter, &key, &index)) + goto exit; + return_value = winreg_EnumValue_impl(module, key, index); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__, +"ExpandEnvironmentStrings($module, string, /)\n" +"--\n" +"\n" +"Expand environment vars."); + +#define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \ + {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__}, + +static PyObject * +winreg_ExpandEnvironmentStrings_impl(PyModuleDef *module, Py_UNICODE *string); + +static PyObject * +winreg_ExpandEnvironmentStrings(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + Py_UNICODE *string; + + if (!PyArg_Parse(arg, + "u:ExpandEnvironmentStrings", + &string)) + goto exit; + return_value = winreg_ExpandEnvironmentStrings_impl(module, string); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_FlushKey__doc__, +"FlushKey($module, key, /)\n" +"--\n" +"\n" +"Writes all the attributes of a key to the registry.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +"\n" +"It is not necessary to call FlushKey to change a key. Registry changes\n" +"are flushed to disk by the registry using its lazy flusher. Registry\n" +"changes are also flushed to disk at system shutdown. Unlike\n" +"CloseKey(), the FlushKey() method returns only when all the data has\n" +"been written to the registry.\n" +"\n" +"An application should only call FlushKey() if it requires absolute\n" +"certainty that registry changes are on disk. If you don\'t know whether\n" +"a FlushKey() call is required, it probably isn\'t."); + +#define WINREG_FLUSHKEY_METHODDEF \ + {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__}, + +static PyObject * +winreg_FlushKey_impl(PyModuleDef *module, HKEY key); + +static PyObject * +winreg_FlushKey(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HKEY key; + + if (!PyArg_Parse(arg, + "O&:FlushKey", + clinic_HKEY_converter, &key)) + goto exit; + return_value = winreg_FlushKey_impl(module, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_LoadKey__doc__, +"LoadKey($module, key, sub_key, file_name, /)\n" +"--\n" +"\n" +"Insert data into the registry from a file.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that identifies the sub-key to load.\n" +" file_name\n" +" The name of the file to load registry data from. This file must\n" +" have been created with the SaveKey() function. Under the file\n" +" allocation table (FAT) file system, the filename may not have an\n" +" extension.\n" +"\n" +"Creates a subkey under the specified key and stores registration\n" +"information from a specified file into that subkey.\n" +"\n" +"A call to LoadKey() fails if the calling process does not have the\n" +"SE_RESTORE_PRIVILEGE privilege.\n" +"\n" +"If key is a handle returned by ConnectRegistry(), then the path\n" +"specified in fileName is relative to the remote computer.\n" +"\n" +"The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n" +"tree."); + +#define WINREG_LOADKEY_METHODDEF \ + {"LoadKey", (PyCFunction)winreg_LoadKey, METH_VARARGS, winreg_LoadKey__doc__}, + +static PyObject * +winreg_LoadKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, Py_UNICODE *file_name); + +static PyObject * +winreg_LoadKey(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *sub_key; + Py_UNICODE *file_name; + + if (!PyArg_ParseTuple(args, + "O&uu:LoadKey", + clinic_HKEY_converter, &key, &sub_key, &file_name)) + goto exit; + return_value = winreg_LoadKey_impl(module, key, sub_key, file_name); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_OpenKey__doc__, +"OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" +"--\n" +"\n" +"Opens the specified key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that identifies the sub_key to open.\n" +" reserved\n" +" A reserved integer that must be zero. Default is zero.\n" +" access\n" +" An integer that specifies an access mask that describes the desired\n" +" security access for the key. Default is KEY_READ.\n" +"\n" +"The result is a new handle to the specified key.\n" +"If the function fails, an OSError exception is raised."); + +#define WINREG_OPENKEY_METHODDEF \ + {"OpenKey", (PyCFunction)winreg_OpenKey, METH_VARARGS|METH_KEYWORDS, winreg_OpenKey__doc__}, + +static HKEY +winreg_OpenKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, int reserved, REGSAM access); + +static PyObject * +winreg_OpenKey(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"key", "sub_key", "reserved", "access", NULL}; + HKEY key; + Py_UNICODE *sub_key; + int reserved = 0; + REGSAM access = KEY_READ; + HKEY _return_value; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O&Z|ii:OpenKey", _keywords, + clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) + goto exit; + _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access); + if (_return_value == NULL) + goto exit; + return_value = PyHKEY_FromHKEY(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_OpenKeyEx__doc__, +"OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" +"--\n" +"\n" +"Opens the specified key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that identifies the sub_key to open.\n" +" reserved\n" +" A reserved integer that must be zero. Default is zero.\n" +" access\n" +" An integer that specifies an access mask that describes the desired\n" +" security access for the key. Default is KEY_READ.\n" +"\n" +"The result is a new handle to the specified key.\n" +"If the function fails, an OSError exception is raised."); + +#define WINREG_OPENKEYEX_METHODDEF \ + {"OpenKeyEx", (PyCFunction)winreg_OpenKeyEx, METH_VARARGS|METH_KEYWORDS, winreg_OpenKeyEx__doc__}, + +static HKEY +winreg_OpenKeyEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, int reserved, REGSAM access); + +static PyObject * +winreg_OpenKeyEx(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"key", "sub_key", "reserved", "access", NULL}; + HKEY key; + Py_UNICODE *sub_key; + int reserved = 0; + REGSAM access = KEY_READ; + HKEY _return_value; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O&Z|ii:OpenKeyEx", _keywords, + clinic_HKEY_converter, &key, &sub_key, &reserved, &access)) + goto exit; + _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access); + if (_return_value == NULL) + goto exit; + return_value = PyHKEY_FromHKEY(_return_value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_QueryInfoKey__doc__, +"QueryInfoKey($module, key, /)\n" +"--\n" +"\n" +"Returns information about a key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +"\n" +"The result is a tuple of 3 items:\n" +"An integer that identifies the number of sub keys this key has.\n" +"An integer that identifies the number of values this key has.\n" +"An integer that identifies when the key was last modified (if available)\n" +"as 100\'s of nanoseconds since Jan 1, 1600."); + +#define WINREG_QUERYINFOKEY_METHODDEF \ + {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__}, + +static PyObject * +winreg_QueryInfoKey_impl(PyModuleDef *module, HKEY key); + +static PyObject * +winreg_QueryInfoKey(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HKEY key; + + if (!PyArg_Parse(arg, + "O&:QueryInfoKey", + clinic_HKEY_converter, &key)) + goto exit; + return_value = winreg_QueryInfoKey_impl(module, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_QueryValue__doc__, +"QueryValue($module, key, sub_key, /)\n" +"--\n" +"\n" +"Retrieves the unnamed value for a key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that holds the name of the subkey with which the value\n" +" is associated. If this parameter is None or empty, the function\n" +" retrieves the value set by the SetValue() method for the key\n" +" identified by key.\n" +"\n" +"Values in the registry have name, type, and data components. This method\n" +"retrieves the data for a key\'s first value that has a NULL name.\n" +"But since the underlying API call doesn\'t return the type, you\'ll\n" +"probably be happier using QueryValueEx; this function is just here for\n" +"completeness."); + +#define WINREG_QUERYVALUE_METHODDEF \ + {"QueryValue", (PyCFunction)winreg_QueryValue, METH_VARARGS, winreg_QueryValue__doc__}, + +static PyObject * +winreg_QueryValue_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key); + +static PyObject * +winreg_QueryValue(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *sub_key; + + if (!PyArg_ParseTuple(args, + "O&Z:QueryValue", + clinic_HKEY_converter, &key, &sub_key)) + goto exit; + return_value = winreg_QueryValue_impl(module, key, sub_key); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_QueryValueEx__doc__, +"QueryValueEx($module, key, name, /)\n" +"--\n" +"\n" +"Retrieves the type and value of a specified sub-key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" name\n" +" A string indicating the value to query.\n" +"\n" +"Behaves mostly like QueryValue(), but also returns the type of the\n" +"specified value name associated with the given open registry key.\n" +"\n" +"The return value is a tuple of the value and the type_id."); + +#define WINREG_QUERYVALUEEX_METHODDEF \ + {"QueryValueEx", (PyCFunction)winreg_QueryValueEx, METH_VARARGS, winreg_QueryValueEx__doc__}, + +static PyObject * +winreg_QueryValueEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *name); + +static PyObject * +winreg_QueryValueEx(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *name; + + if (!PyArg_ParseTuple(args, + "O&Z:QueryValueEx", + clinic_HKEY_converter, &key, &name)) + goto exit; + return_value = winreg_QueryValueEx_impl(module, key, name); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_SaveKey__doc__, +"SaveKey($module, key, file_name, /)\n" +"--\n" +"\n" +"Saves the specified key, and all its subkeys to the specified file.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" file_name\n" +" The name of the file to save registry data to. This file cannot\n" +" already exist. If this filename includes an extension, it cannot be\n" +" used on file allocation table (FAT) file systems by the LoadKey(),\n" +" ReplaceKey() or RestoreKey() methods.\n" +"\n" +"If key represents a key on a remote computer, the path described by\n" +"file_name is relative to the remote computer.\n" +"\n" +"The caller of this method must possess the SeBackupPrivilege\n" +"security privilege. This function passes NULL for security_attributes\n" +"to the API."); + +#define WINREG_SAVEKEY_METHODDEF \ + {"SaveKey", (PyCFunction)winreg_SaveKey, METH_VARARGS, winreg_SaveKey__doc__}, + +static PyObject * +winreg_SaveKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *file_name); + +static PyObject * +winreg_SaveKey(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *file_name; + + if (!PyArg_ParseTuple(args, + "O&u:SaveKey", + clinic_HKEY_converter, &key, &file_name)) + goto exit; + return_value = winreg_SaveKey_impl(module, key, file_name); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_SetValue__doc__, +"SetValue($module, key, sub_key, type, value, /)\n" +"--\n" +"\n" +"Associates a value with a specified key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" sub_key\n" +" A string that names the subkey with which the value is associated.\n" +" type\n" +" An integer that specifies the type of the data. Currently this must\n" +" be REG_SZ, meaning only strings are supported.\n" +" value\n" +" A string that specifies the new value.\n" +"\n" +"If the key specified by the sub_key parameter does not exist, the\n" +"SetValue function creates it.\n" +"\n" +"Value lengths are limited by available memory. Long values (more than\n" +"2048 bytes) should be stored as files with the filenames stored in\n" +"the configuration registry to help the registry perform efficiently.\n" +"\n" +"The key identified by the key parameter must have been opened with\n" +"KEY_SET_VALUE access."); + +#define WINREG_SETVALUE_METHODDEF \ + {"SetValue", (PyCFunction)winreg_SetValue, METH_VARARGS, winreg_SetValue__doc__}, + +static PyObject * +winreg_SetValue_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, DWORD type, Py_UNICODE *value, Py_ssize_clean_t value_length); + +static PyObject * +winreg_SetValue(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *sub_key; + DWORD type; + Py_UNICODE *value; + Py_ssize_clean_t value_length; + + if (!PyArg_ParseTuple(args, + "O&Zku#:SetValue", + clinic_HKEY_converter, &key, &sub_key, &type, &value, &value_length)) + goto exit; + return_value = winreg_SetValue_impl(module, key, sub_key, type, value, value_length); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_SetValueEx__doc__, +"SetValueEx($module, key, value_name, reserved, type, value, /)\n" +"--\n" +"\n" +"Stores data in the value field of an open registry key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +" value_name\n" +" A string containing the name of the value to set, or None.\n" +" reserved\n" +" Can be anything - zero is always passed to the API.\n" +" type\n" +" An integer that specifies the type of the data, one of:\n" +" REG_BINARY -- Binary data in any form.\n" +" REG_DWORD -- A 32-bit number.\n" +" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.\n" +" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n" +" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n" +" references to environment variables (for example,\n" +" %PATH%).\n" +" REG_LINK -- A Unicode symbolic link.\n" +" REG_MULTI_SZ -- An sequence of null-terminated strings, terminated\n" +" by two null characters. Note that Python handles\n" +" this termination automatically.\n" +" REG_NONE -- No defined value type.\n" +" REG_RESOURCE_LIST -- A device-driver resource list.\n" +" REG_SZ -- A null-terminated string.\n" +" value\n" +" A string that specifies the new value.\n" +"\n" +"This method can also set additional value and type information for the\n" +"specified key. The key identified by the key parameter must have been\n" +"opened with KEY_SET_VALUE access.\n" +"\n" +"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n" +"\n" +"Value lengths are limited by available memory. Long values (more than\n" +"2048 bytes) should be stored as files with the filenames stored in\n" +"the configuration registry to help the registry perform efficiently."); + +#define WINREG_SETVALUEEX_METHODDEF \ + {"SetValueEx", (PyCFunction)winreg_SetValueEx, METH_VARARGS, winreg_SetValueEx__doc__}, + +static PyObject * +winreg_SetValueEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *value_name, PyObject *reserved, DWORD type, PyObject *value); + +static PyObject * +winreg_SetValueEx(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + HKEY key; + Py_UNICODE *value_name; + PyObject *reserved; + DWORD type; + PyObject *value; + + if (!PyArg_ParseTuple(args, + "O&ZOkO:SetValueEx", + clinic_HKEY_converter, &key, &value_name, &reserved, &type, &value)) + goto exit; + return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_DisableReflectionKey__doc__, +"DisableReflectionKey($module, key, /)\n" +"--\n" +"\n" +"Disables registry reflection for 32bit processes running on a 64bit OS.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +"\n" +"Will generally raise NotImplemented if executed on a 32bit OS.\n" +"\n" +"If the key is not on the reflection list, the function succeeds but has\n" +"no effect. Disabling reflection for a key does not affect reflection\n" +"of any subkeys."); + +#define WINREG_DISABLEREFLECTIONKEY_METHODDEF \ + {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__}, + +static PyObject * +winreg_DisableReflectionKey_impl(PyModuleDef *module, HKEY key); + +static PyObject * +winreg_DisableReflectionKey(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HKEY key; + + if (!PyArg_Parse(arg, + "O&:DisableReflectionKey", + clinic_HKEY_converter, &key)) + goto exit; + return_value = winreg_DisableReflectionKey_impl(module, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_EnableReflectionKey__doc__, +"EnableReflectionKey($module, key, /)\n" +"--\n" +"\n" +"Restores registry reflection for the specified disabled key.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +"\n" +"Will generally raise NotImplemented if executed on a 32bit OS.\n" +"Restoring reflection for a key does not affect reflection of any\n" +"subkeys."); + +#define WINREG_ENABLEREFLECTIONKEY_METHODDEF \ + {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__}, + +static PyObject * +winreg_EnableReflectionKey_impl(PyModuleDef *module, HKEY key); + +static PyObject * +winreg_EnableReflectionKey(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HKEY key; + + if (!PyArg_Parse(arg, + "O&:EnableReflectionKey", + clinic_HKEY_converter, &key)) + goto exit; + return_value = winreg_EnableReflectionKey_impl(module, key); + +exit: + return return_value; +} + +PyDoc_STRVAR(winreg_QueryReflectionKey__doc__, +"QueryReflectionKey($module, key, /)\n" +"--\n" +"\n" +"Returns the reflection state for the specified key as a bool.\n" +"\n" +" key\n" +" An already open key, or any one of the predefined HKEY_* constants.\n" +"\n" +"Will generally raise NotImplemented if executed on a 32bit OS."); + +#define WINREG_QUERYREFLECTIONKEY_METHODDEF \ + {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__}, + +static PyObject * +winreg_QueryReflectionKey_impl(PyModuleDef *module, HKEY key); + +static PyObject * +winreg_QueryReflectionKey(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + HKEY key; + + if (!PyArg_Parse(arg, + "O&:QueryReflectionKey", + clinic_HKEY_converter, &key)) + goto exit; + return_value = winreg_QueryReflectionKey_impl(module, key); + +exit: + return return_value; +} +/*[clinic end generated code: output=be6e50b901570878 input=a9049054013a1b77]*/ diff -r 78a2d1169be1 -r 9ec35c653970 PC/clinic/winsound.c.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PC/clinic/winsound.c.h Tue Apr 14 15:05:26 2015 -0500 @@ -0,0 +1,103 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(winsound_PlaySound__doc__, +"PlaySound($module, sound, flags, /)\n" +"--\n" +"\n" +"A wrapper around the Windows PlaySound API.\n" +"\n" +" sound\n" +" The sound to play; a filename, data, or None.\n" +" flags\n" +" Flag values, ored together. See module documentation."); + +#define WINSOUND_PLAYSOUND_METHODDEF \ + {"PlaySound", (PyCFunction)winsound_PlaySound, METH_VARARGS, winsound_PlaySound__doc__}, + +static PyObject * +winsound_PlaySound_impl(PyModuleDef *module, Py_UNICODE *sound, int flags); + +static PyObject * +winsound_PlaySound(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_UNICODE *sound; + int flags; + + if (!PyArg_ParseTuple(args, + "Zi:PlaySound", + &sound, &flags)) + goto exit; + return_value = winsound_PlaySound_impl(module, sound, flags); + +exit: + return return_value; +} + +PyDoc_STRVAR(winsound_Beep__doc__, +"Beep($module, frequency, duration, /)\n" +"--\n" +"\n" +"A wrapper around the Windows Beep API.\n" +"\n" +" frequency\n" +" Frequency of the sound in hertz.\n" +" Must be in the range 37 through 32,767.\n" +" duration\n" +" How long the sound should play, in milliseconds."); + +#define WINSOUND_BEEP_METHODDEF \ + {"Beep", (PyCFunction)winsound_Beep, METH_VARARGS, winsound_Beep__doc__}, + +static PyObject * +winsound_Beep_impl(PyModuleDef *module, int frequency, int duration); + +static PyObject * +winsound_Beep(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int frequency; + int duration; + + if (!PyArg_ParseTuple(args, + "ii:Beep", + &frequency, &duration)) + goto exit; + return_value = winsound_Beep_impl(module, frequency, duration); + +exit: + return return_value; +} + +PyDoc_STRVAR(winsound_MessageBeep__doc__, +"MessageBeep($module, x=MB_OK, /)\n" +"--\n" +"\n" +"Call Windows MessageBeep(x).\n" +"\n" +"x defaults to MB_OK."); + +#define WINSOUND_MESSAGEBEEP_METHODDEF \ + {"MessageBeep", (PyCFunction)winsound_MessageBeep, METH_VARARGS, winsound_MessageBeep__doc__}, + +static PyObject * +winsound_MessageBeep_impl(PyModuleDef *module, int x); + +static PyObject * +winsound_MessageBeep(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int x = MB_OK; + + if (!PyArg_ParseTuple(args, + "|i:MessageBeep", + &x)) + goto exit; + return_value = winsound_MessageBeep_impl(module, x); + +exit: + return return_value; +} +/*[clinic end generated code: output=89c85ed36c3af2fd input=a9049054013a1b77]*/ diff -r 78a2d1169be1 -r 9ec35c653970 PC/msvcrtmodule.c --- a/PC/msvcrtmodule.c Tue Apr 14 11:21:26 2015 -0700 +++ b/PC/msvcrtmodule.c Tue Apr 14 15:05:26 2015 -0500 @@ -32,329 +32,473 @@ #endif #endif -// Force the malloc heap to clean itself up, and free unused blocks -// back to the OS. (According to the docs, only works on NT.) +/*[python input] +class Py_intptr_t_converter(CConverter): + type = 'Py_intptr_t' + format_unit = '"_Py_PARSE_INTPTR"' + +class handle_return_converter(long_return_converter): + type = 'Py_intptr_t' + cast = '(void *)' + conversion_fn = 'PyLong_FromVoidPtr' + +class byte_char_return_converter(CReturnConverter): + type = 'int' + + def render(self, function, data): + data.declarations.append('char s[1];') + data.return_value = 's[0]' + data.return_conversion.append( + 'return_value = PyBytes_FromStringAndSize(s, 1);\n') + +class wchar_t_return_converter(CReturnConverter): + type = 'wchar_t' + + def render(self, function, data): + self.declare(data) + data.return_conversion.append( + 'return_value = PyUnicode_FromOrdinal(_return_value);\n') +[python start generated code]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=6a54fc4e73d0b367]*/ + +/*[clinic input] +module msvcrt +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f31a87a783d036cd]*/ + +#include "clinic/msvcrtmodule.c.h" + +/*[clinic input] +msvcrt.heapmin + +Minimize the malloc() heap. + +Force the malloc() heap to clean itself up and return unused blocks +to the operating system. On failure, this raises OSError. +[clinic start generated code]*/ + static PyObject * -msvcrt_heapmin(PyObject *self, PyObject *args) +msvcrt_heapmin_impl(PyModuleDef *module) +/*[clinic end generated code: output=464f866feb57c436 input=82e1771d21bde2d8]*/ { - if (!PyArg_ParseTuple(args, ":heapmin")) - return NULL; - if (_heapmin() != 0) return PyErr_SetFromErrno(PyExc_IOError); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +msvcrt.locking -PyDoc_STRVAR(heapmin_doc, -"heapmin() -> None\n\ -\n\ -Force the malloc() heap to clean itself up and return unused blocks\n\ -to the operating system. On failure, this raises IOError."); + fd: int + mode: int + nbytes: long + / -// Perform locking operations on a C runtime file descriptor. +Lock part of a file based on file descriptor fd from the C runtime. + +Raises IOError on failure. The locked region of the file extends from +the current file position for nbytes bytes, and may continue beyond +the end of the file. mode must be one of the LK_* constants listed +below. Multiple regions in a file may be locked at the same time, but +may not overlap. Adjacent regions are not merged; they must be unlocked +individually. +[clinic start generated code]*/ + static PyObject * -msvcrt_locking(PyObject *self, PyObject *args) +msvcrt_locking_impl(PyModuleDef *module, int fd, int mode, long nbytes) +/*[clinic end generated code: output=dff41e5e76d544de input=d9f13f0f6a713ba7]*/ { - int fd; - int mode; - long nbytes; int err; - if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) - return NULL; - Py_BEGIN_ALLOW_THREADS err = _locking(fd, mode, nbytes); Py_END_ALLOW_THREADS if (err != 0) return PyErr_SetFromErrno(PyExc_IOError); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -PyDoc_STRVAR(locking_doc, -"locking(fd, mode, nbytes) -> None\n\ -\n\ -Lock part of a file based on file descriptor fd from the C runtime.\n\ -Raises IOError on failure. The locked region of the file extends from\n\ -the current file position for nbytes bytes, and may continue beyond\n\ -the end of the file. mode must be one of the LK_* constants listed\n\ -below. Multiple regions in a file may be locked at the same time, but\n\ -may not overlap. Adjacent regions are not merged; they must be unlocked\n\ -individually."); +/*[clinic input] +msvcrt.setmode -> long -// Set the file translation mode for a C runtime file descriptor. -static PyObject * -msvcrt_setmode(PyObject *self, PyObject *args) + fd: int + mode as flags: int + / + +Set the line-end translation mode for the file descriptor fd. + +To set it to text mode, flags should be os.O_TEXT; for binary, it +should be os.O_BINARY. + +Return value is the previous mode. +[clinic start generated code]*/ + +static long +msvcrt_setmode_impl(PyModuleDef *module, int fd, int flags) +/*[clinic end generated code: output=8c84e5b37c586d0d input=76e7c01f6b137f75]*/ +{ + flags = _setmode(fd, flags); + if (flags == -1) + PyErr_SetFromErrno(PyExc_IOError); + + return flags; +} + +/*[clinic input] +msvcrt.open_osfhandle -> long + + handle: Py_intptr_t + flags: int + / + +Create a C runtime file descriptor from the file handle handle. + +The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY, +and os.O_TEXT. The returned file descriptor may be used as a parameter +to os.fdopen() to create a file object. +[clinic start generated code]*/ + +static long +msvcrt_open_osfhandle_impl(PyModuleDef *module, Py_intptr_t handle, int flags) +/*[clinic end generated code: output=8cda35b8e4ea4178 input=4d8516ed32db8f65]*/ { int fd; - int flags; - if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) - return NULL; - - flags = _setmode(fd, flags); - if (flags == -1) - return PyErr_SetFromErrno(PyExc_IOError); - - return PyLong_FromLong(flags); -} - -PyDoc_STRVAR(setmode_doc, -"setmode(fd, mode) -> Previous mode\n\ -\n\ -Set the line-end translation mode for the file descriptor fd. To set\n\ -it to text mode, flags should be os.O_TEXT; for binary, it should be\n\ -os.O_BINARY."); - -// Convert an OS file handle to a C runtime file descriptor. -static PyObject * -msvcrt_open_osfhandle(PyObject *self, PyObject *args) -{ - Py_intptr_t handle; - int flags; - int fd; - - if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:open_osfhandle", - &handle, &flags)) - return NULL; fd = _open_osfhandle(handle, flags); if (fd == -1) - return PyErr_SetFromErrno(PyExc_IOError); + PyErr_SetFromErrno(PyExc_IOError); - return PyLong_FromLong(fd); + return fd; } -PyDoc_STRVAR(open_osfhandle_doc, -"open_osfhandle(handle, flags) -> file descriptor\n\ -\n\ -Create a C runtime file descriptor from the file handle handle. The\n\ -flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\ -and os.O_TEXT. The returned file descriptor may be used as a parameter\n\ -to os.fdopen() to create a file object."); +/*[clinic input] +msvcrt.get_osfhandle -> handle -// Convert a C runtime file descriptor to an OS file handle. -static PyObject * -msvcrt_get_osfhandle(PyObject *self, PyObject *args) + fd: int + / + +Return the file handle for the file descriptor fd. + +Raises IOError if fd is not recognized. +[clinic start generated code]*/ + +static Py_intptr_t +msvcrt_get_osfhandle_impl(PyModuleDef *module, int fd) +/*[clinic end generated code: output=376bff52586b55a6 input=c7d18d02c8017ec1]*/ { - int fd; - Py_intptr_t handle; + Py_intptr_t handle = -1; - if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) - return NULL; + if (!_PyVerify_fd(fd)) { + PyErr_SetFromErrno(PyExc_IOError); + } + else { + _Py_BEGIN_SUPPRESS_IPH + handle = _get_osfhandle(fd); + _Py_END_SUPPRESS_IPH + if (handle == -1) + PyErr_SetFromErrno(PyExc_IOError); + } - if (!_PyVerify_fd(fd)) - return PyErr_SetFromErrno(PyExc_IOError); - - _Py_BEGIN_SUPPRESS_IPH - handle = _get_osfhandle(fd); - _Py_END_SUPPRESS_IPH - if (handle == -1) - return PyErr_SetFromErrno(PyExc_IOError); - - /* technically 'handle' is not a pointer, but a integer as - large as a pointer, Python's *VoidPtr interface is the - most appropriate here */ - return PyLong_FromVoidPtr((void*)handle); + return handle; } -PyDoc_STRVAR(get_osfhandle_doc, -"get_osfhandle(fd) -> file handle\n\ -\n\ -Return the file handle for the file descriptor fd. Raises IOError\n\ -if fd is not recognized."); +/* Console I/O */ +/*[clinic input] +msvcrt.kbhit -> long -/* Console I/O */ +Return true if a keypress is waiting to be read. +[clinic start generated code]*/ -static PyObject * -msvcrt_kbhit(PyObject *self, PyObject *args) +static long +msvcrt_kbhit_impl(PyModuleDef *module) +/*[clinic end generated code: output=2b7293fcbe5cb24e input=e70d678a5c2f6acc]*/ { - int ok; - - if (!PyArg_ParseTuple(args, ":kbhit")) - return NULL; - - ok = _kbhit(); - return PyLong_FromLong(ok); + return _kbhit(); } -PyDoc_STRVAR(kbhit_doc, -"kbhit() -> bool\n\ -\n\ -Return true if a keypress is waiting to be read."); +/*[clinic input] +msvcrt.getch -> byte_char -static PyObject * -msvcrt_getch(PyObject *self, PyObject *args) +Read a keypress and return the resulting character as a byte string. + +Nothing is echoed to the console. This call will block if a keypress is +not already available, but will not wait for Enter to be pressed. If the +pressed key was a special function key, this will return '\000' or +'\xe0'; the next call will return the keycode. The Control-C keypress +cannot be read with this function. +[clinic start generated code]*/ + +static int +msvcrt_getch_impl(PyModuleDef *module) +/*[clinic end generated code: output=199e3d89f49c166a input=37a40cf0ed0d1153]*/ { int ch; - char s[1]; - - if (!PyArg_ParseTuple(args, ":getch")) - return NULL; Py_BEGIN_ALLOW_THREADS ch = _getch(); Py_END_ALLOW_THREADS - s[0] = ch; - return PyBytes_FromStringAndSize(s, 1); + return ch; } -PyDoc_STRVAR(getch_doc, -"getch() -> key character\n\ -\n\ -Read a keypress and return the resulting character as a byte string.\n\ -Nothing is echoed to the console. This call will block if a keypress is\n\ -not already available, but will not wait for Enter to be pressed. If the\n\ -pressed key was a special function key, this will return '\\000' or\n\ -'\\xe0'; the next call will return the keycode. The Control-C keypress\n\ -cannot be read with this function."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.getwch -> wchar_t -#ifdef _WCONIO_DEFINED -static PyObject * -msvcrt_getwch(PyObject *self, PyObject *args) +Wide char variant of getch(), returning a Unicode value. +[clinic start generated code]*/ + +static wchar_t +msvcrt_getwch_impl(PyModuleDef *module) +/*[clinic end generated code: output=9d3762861328b1fe input=27b3dec8ad823d7c]*/ { wchar_t ch; - if (!PyArg_ParseTuple(args, ":getwch")) - return NULL; - Py_BEGIN_ALLOW_THREADS ch = _getwch(); Py_END_ALLOW_THREADS - return PyUnicode_FromOrdinal(ch); + return ch; } +#endif /* _WCONIO_DEFINED */ -PyDoc_STRVAR(getwch_doc, -"getwch() -> Unicode key character\n\ -\n\ -Wide char variant of getch(), returning a Unicode value."); -#endif +/*[clinic input] +msvcrt.getche -> byte_char -static PyObject * -msvcrt_getche(PyObject *self, PyObject *args) +Similar to getch(), but the keypress will be echoed if possible. +[clinic start generated code]*/ + +static int +msvcrt_getche_impl(PyModuleDef *module) +/*[clinic end generated code: output=8aa369be6550068e input=43311ade9ed4a9c0]*/ { int ch; - char s[1]; - - if (!PyArg_ParseTuple(args, ":getche")) - return NULL; Py_BEGIN_ALLOW_THREADS ch = _getche(); Py_END_ALLOW_THREADS - s[0] = ch; - return PyBytes_FromStringAndSize(s, 1); + return ch; } -PyDoc_STRVAR(getche_doc, -"getche() -> key character\n\ -\n\ -Similar to getch(), but the keypress will be echoed if it represents\n\ -a printable character."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.getwche -> wchar_t -#ifdef _WCONIO_DEFINED -static PyObject * -msvcrt_getwche(PyObject *self, PyObject *args) +Wide char variant of getche(), returning a Unicode value. +[clinic start generated code]*/ + +static wchar_t +msvcrt_getwche_impl(PyModuleDef *module) +/*[clinic end generated code: output=3693cf78e3ea0cf6 input=49337d59d1a591f8]*/ { wchar_t ch; - if (!PyArg_ParseTuple(args, ":getwche")) - return NULL; - Py_BEGIN_ALLOW_THREADS ch = _getwche(); Py_END_ALLOW_THREADS - return PyUnicode_FromOrdinal(ch); + return ch; +} +#endif /* _WCONIO_DEFINED */ + +/*[clinic input] +msvcrt.putch + + char: char + / + +Print the byte string char to the console without buffering. +[clinic start generated code]*/ + +static PyObject * +msvcrt_putch_impl(PyModuleDef *module, char char_value) +/*[clinic end generated code: output=c05548b11554f36f input=ec078dd10cb054d6]*/ +{ + _putch(char_value); + Py_RETURN_NONE; } -PyDoc_STRVAR(getwche_doc, -"getwche() -> Unicode key character\n\ -\n\ -Wide char variant of getche(), returning a Unicode value."); -#endif +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.putwch + + unicode_char: int(types='str') + / + +Wide char variant of putch(), accepting a Unicode value. +[clinic start generated code]*/ static PyObject * -msvcrt_putch(PyObject *self, PyObject *args) +msvcrt_putwch_impl(PyModuleDef *module, int unicode_char) +/*[clinic end generated code: output=c216a73694ca73dd input=74377c932af728a4]*/ { - char ch; - - if (!PyArg_ParseTuple(args, "c:putch", &ch)) - return NULL; - - _putch(ch); - Py_INCREF(Py_None); - return Py_None; -} - -PyDoc_STRVAR(putch_doc, -"putch(char) -> None\n\ -\n\ -Print the byte string char to the console without buffering."); - -#ifdef _WCONIO_DEFINED -static PyObject * -msvcrt_putwch(PyObject *self, PyObject *args) -{ - int ch; - - if (!PyArg_ParseTuple(args, "C:putwch", &ch)) - return NULL; - - _putwch(ch); + _putwch(unicode_char); Py_RETURN_NONE; } +#endif /* _WCONIO_DEFINED */ -PyDoc_STRVAR(putwch_doc, -"putwch(unicode_char) -> None\n\ -\n\ -Wide char variant of putch(), accepting a Unicode value."); -#endif +/*[clinic input] +msvcrt.ungetch + + char: char + / + +Opposite of getch. + +Cause the byte string char to be "pushed back" into the +console buffer; it will be the next character read by +getch() or getche(). +[clinic start generated code]*/ static PyObject * -msvcrt_ungetch(PyObject *self, PyObject *args) +msvcrt_ungetch_impl(PyModuleDef *module, char char_value) +/*[clinic end generated code: output=19a4cd3249709ec9 input=22f07ee9001bbf0f]*/ { - char ch; - - if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) - return NULL; - - if (_ungetch(ch) == EOF) + if (_ungetch(char_value) == EOF) return PyErr_SetFromErrno(PyExc_IOError); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -PyDoc_STRVAR(ungetch_doc, -"ungetch(char) -> None\n\ -\n\ -Cause the byte string char to be \"pushed back\" into the\n\ -console buffer; it will be the next character read by\n\ -getch() or getche()."); +#ifdef _WCONIO_DEFINED +/*[clinic input] +msvcrt.ungetwch -#ifdef _WCONIO_DEFINED + unicode_char: int(types='str') + / + +Wide char variant of ungetch(), accepting a Unicode value. +[clinic start generated code]*/ + static PyObject * -msvcrt_ungetwch(PyObject *self, PyObject *args) +msvcrt_ungetwch_impl(PyModuleDef *module, int unicode_char) +/*[clinic end generated code: output=1ee7674710322bd1 input=6bcd16276e035902]*/ { - int ch; + if (_ungetwch(unicode_char) == WEOF) + return PyErr_SetFromErrno(PyExc_IOError); + Py_RETURN_NONE; +} +#endif /* _WCONIO_DEFINED */ - if (!PyArg_ParseTuple(args, "C:ungetwch", &ch)) - return NULL; +#ifdef _DEBUG +/*[clinic input] +msvcrt.CrtSetReportFile -> long - if (_ungetwch(ch) == WEOF) - return PyErr_SetFromErrno(PyExc_IOError); - Py_INCREF(Py_None); - return Py_None; + type: int + file: int + / + +Wrapper around _CrtSetReportFile. + +Only available on Debug builds. +[clinic start generated code]*/ + +static long +msvcrt_CrtSetReportFile_impl(PyModuleDef *module, int type, int file) +/*[clinic end generated code: output=8c3644fb2edfa808 input=bb8f721a604fcc45]*/ +{ + return (long)_CrtSetReportFile(type, (_HFILE)file); } -PyDoc_STRVAR(ungetwch_doc, -"ungetwch(unicode_char) -> None\n\ -\n\ -Wide char variant of ungetch(), accepting a Unicode value."); -#endif +/*[clinic input] +msvcrt.CrtSetReportMode -> long + + type: int + mode: int + / + +Wrapper around _CrtSetReportMode. + +Only available on Debug builds. +[clinic start generated code]*/ + +static long +msvcrt_CrtSetReportMode_impl(PyModuleDef *module, int type, int mode) +/*[clinic end generated code: output=b407fbf8716a52b9 input=9319d29b4319426b]*/ +{ + int res; + + res = _CrtSetReportMode(type, mode); + if (res == -1) + PyErr_SetFromErrno(PyExc_IOError); + return res; +} + +/*[clinic input] +msvcrt.set_error_mode -> long + + mode: int + / + +Wrapper around _set_error_mode. + +Only available on Debug builds. +[clinic start generated code]*/ + +static long +msvcrt_set_error_mode_impl(PyModuleDef *module, int mode) +/*[clinic end generated code: output=62148adffa90867d input=046fca59c0f20872]*/ +{ + return _set_error_mode(mode); +} +#endif /* _DEBUG */ + +/*[clinic input] +msvcrt.SetErrorMode + + mode: unsigned_int(bitwise=True) + / + +Wrapper around SetErrorMode. +[clinic start generated code]*/ + +static PyObject * +msvcrt_SetErrorMode_impl(PyModuleDef *module, unsigned int mode) +/*[clinic end generated code: output=544c60b085be79c6 input=d8b167258d32d907]*/ +{ + unsigned int res; + + res = SetErrorMode(mode); + return PyLong_FromUnsignedLong(res); +} + +/*[clinic input] +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/ + +/* List of functions exported by this module */ +static struct PyMethodDef msvcrt_functions[] = { + MSVCRT_HEAPMIN_METHODDEF + MSVCRT_LOCKING_METHODDEF + MSVCRT_SETMODE_METHODDEF + MSVCRT_OPEN_OSFHANDLE_METHODDEF + MSVCRT_GET_OSFHANDLE_METHODDEF + MSVCRT_KBHIT_METHODDEF + MSVCRT_GETCH_METHODDEF + MSVCRT_GETCHE_METHODDEF + MSVCRT_PUTCH_METHODDEF + MSVCRT_UNGETCH_METHODDEF + MSVCRT_SETERRORMODE_METHODDEF + MSVCRT_CRTSETREPORTFILE_METHODDEF + MSVCRT_CRTSETREPORTMODE_METHODDEF + MSVCRT_SET_ERROR_MODE_METHODDEF + MSVCRT_GETWCH_METHODDEF + MSVCRT_GETWCHE_METHODDEF + MSVCRT_PUTWCH_METHODDEF + MSVCRT_UNGETWCH_METHODDEF + {NULL, NULL} +}; + + +static struct PyModuleDef msvcrtmodule = { + PyModuleDef_HEAD_INIT, + "msvcrt", + NULL, + -1, + msvcrt_functions, + NULL, + NULL, + NULL, + NULL +}; static void insertint(PyObject *d, char *name, int value) @@ -370,101 +514,6 @@ } } -#ifdef _DEBUG - -static PyObject* -msvcrt_setreportfile(PyObject *self, PyObject *args) -{ - int type, file; - _HFILE res; - - if (!PyArg_ParseTuple(args, "ii", &type, &file)) - return NULL; - res = _CrtSetReportFile(type, (_HFILE)file); - return PyLong_FromLong((long)res); - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject* -msvcrt_setreportmode(PyObject *self, PyObject *args) -{ - int type, mode; - int res; - - if (!PyArg_ParseTuple(args, "ii", &type, &mode)) - return NULL; - res = _CrtSetReportMode(type, mode); - if (res == -1) - return PyErr_SetFromErrno(PyExc_IOError); - return PyLong_FromLong(res); -} - -static PyObject* -msvcrt_seterrormode(PyObject *self, PyObject *args) -{ - int mode, res; - - if (!PyArg_ParseTuple(args, "i", &mode)) - return NULL; - res = _set_error_mode(mode); - return PyLong_FromLong(res); -} - -#endif - -static PyObject* -seterrormode(PyObject *self, PyObject *args) -{ - unsigned int mode, res; - - if (!PyArg_ParseTuple(args, "I", &mode)) - return NULL; - res = SetErrorMode(mode); - return PyLong_FromUnsignedLong(res); -} - - -/* List of functions exported by this module */ -static struct PyMethodDef msvcrt_functions[] = { - {"heapmin", msvcrt_heapmin, METH_VARARGS, heapmin_doc}, - {"locking", msvcrt_locking, METH_VARARGS, locking_doc}, - {"setmode", msvcrt_setmode, METH_VARARGS, setmode_doc}, - {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc}, - {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc}, - {"kbhit", msvcrt_kbhit, METH_VARARGS, kbhit_doc}, - {"getch", msvcrt_getch, METH_VARARGS, getch_doc}, - {"getche", msvcrt_getche, METH_VARARGS, getche_doc}, - {"putch", msvcrt_putch, METH_VARARGS, putch_doc}, - {"ungetch", msvcrt_ungetch, METH_VARARGS, ungetch_doc}, - {"SetErrorMode", seterrormode, METH_VARARGS}, -#ifdef _DEBUG - {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS}, - {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS}, - {"set_error_mode", msvcrt_seterrormode, METH_VARARGS}, -#endif -#ifdef _WCONIO_DEFINED - {"getwch", msvcrt_getwch, METH_VARARGS, getwch_doc}, - {"getwche", msvcrt_getwche, METH_VARARGS, getwche_doc}, - {"putwch", msvcrt_putwch, METH_VARARGS, putwch_doc}, - {"ungetwch", msvcrt_ungetwch, METH_VARARGS, ungetwch_doc}, -#endif - {NULL, NULL} -}; - - -static struct PyModuleDef msvcrtmodule = { - PyModuleDef_HEAD_INIT, - "msvcrt", - NULL, - -1, - msvcrt_functions, - NULL, - NULL, - NULL, - NULL -}; - PyMODINIT_FUNC PyInit_msvcrt(void) { diff -r 78a2d1169be1 -r 9ec35c653970 PC/winreg.c --- a/PC/winreg.c Tue Apr 14 11:21:26 2015 -0700 +++ b/PC/winreg.c Tue Apr 14 15:05:26 2015 -0500 @@ -17,6 +17,7 @@ #include "windows.h" static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); +static BOOL clinic_HKEY_converter(PyObject *ob, void *p); static PyObject *PyHKEY_FromHKEY(HKEY h); static BOOL PyHKEY_Close(PyObject *obHandle); @@ -46,10 +47,12 @@ "DeleteValue() - Removes a named value from the specified registry key.\n" "EnumKey() - Enumerates subkeys of the specified open registry key.\n" "EnumValue() - Enumerates values of the specified open registry key.\n" -"ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ string.\n" +"ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ\n" +" string.\n" "FlushKey() - Writes all the attributes of the specified key to the registry.\n" -"LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores\n" -" registration information from a specified file into that subkey.\n" +"LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and\n" +" stores registration information from a specified file into that\n" +" subkey.\n" "OpenKey() - Opens the specified key.\n" "OpenKeyEx() - Alias of OpenKey().\n" "QueryValue() - Retrieves the value associated with the unnamed value for a\n" @@ -71,299 +74,6 @@ "to see what constants are used, and where."); -PyDoc_STRVAR(CloseKey_doc, -"CloseKey(hkey)\n" -"Closes a previously opened registry key.\n" -"\n" -"The hkey argument specifies a previously opened key.\n" -"\n" -"Note that if the key is not closed using this method, it will be\n" -"closed when the hkey object is destroyed by Python."); - -PyDoc_STRVAR(ConnectRegistry_doc, -"ConnectRegistry(computer_name, key) -> key\n" -"Establishes a connection to a predefined registry handle on another computer.\n" -"\n" -"computer_name is the name of the remote computer, of the form \\\\computername.\n" -" If None, the local computer is used.\n" -"key is the predefined handle to connect to.\n" -"\n" -"The return value is the handle of the opened key.\n" -"If the function fails, an OSError exception is raised."); - -PyDoc_STRVAR(CreateKey_doc, -"CreateKey(key, sub_key) -> key\n" -"Creates or opens the specified key.\n" -"\n" -"key is an already open key, or one of the predefined HKEY_* constants.\n" -"sub_key is a string that names the key this method opens or creates.\n" -"\n" -"If key is one of the predefined keys, sub_key may be None. In that case,\n" -"the handle returned is the same key handle passed in to the function.\n" -"\n" -"If the key already exists, this function opens the existing key.\n" -"\n" -"The return value is the handle of the opened key.\n" -"If the function fails, an OSError exception is raised."); - -PyDoc_STRVAR(CreateKeyEx_doc, -"CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE) -> key\n" -"Creates or opens the specified key.\n" -"\n" -"key is an already open key, or one of the predefined HKEY_* constants\n" -"sub_key is a string that names the key this method opens or creates.\n" -"reserved is a reserved integer, and must be zero. Default is zero.\n" -"access is an integer that specifies an access mask that describes the \n" -" desired security access for the key. Default is KEY_WRITE.\n" -"\n" -"If key is one of the predefined keys, sub_key may be None. In that case,\n" -"the handle returned is the same key handle passed in to the function.\n" -"\n" -"If the key already exists, this function opens the existing key\n" -"\n" -"The return value is the handle of the opened key.\n" -"If the function fails, an OSError exception is raised."); - -PyDoc_STRVAR(DeleteKey_doc, -"DeleteKey(key, sub_key)\n" -"Deletes the specified key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"sub_key is a string that must be a subkey of the key identified by the key\n" -" parameter. This value must not be None, and the key may not have\n" -" subkeys.\n" -"\n" -"This method can not delete keys with subkeys.\n" -"\n" -"If the function succeeds, the entire key, including all of its values,\n" -"is removed. If the function fails, an OSError exception is raised."); - -PyDoc_STRVAR(DeleteKeyEx_doc, -"DeleteKeyEx(key, sub_key, access=KEY_WOW64_64KEY, reserved=0)\n" -"Deletes the specified key (64-bit OS only).\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"sub_key is a string that must be a subkey of the key identified by the key\n" -" parameter. This value must not be None, and the key may not have\n" -" subkeys.\n" -"reserved is a reserved integer, and must be zero. Default is zero.\n" -"access is an integer that specifies an access mask that describes the \n" -" desired security access for the key. Default is KEY_WOW64_64KEY.\n" -"\n" -"This method can not delete keys with subkeys.\n" -"\n" -"If the function succeeds, the entire key, including all of its values,\n" -"is removed. If the function fails, an OSError exception is raised.\n" -"On unsupported Windows versions, NotImplementedError is raised."); - -PyDoc_STRVAR(DeleteValue_doc, -"DeleteValue(key, value)\n" -"Removes a named value from a registry key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"value is a string that identifies the value to remove."); - -PyDoc_STRVAR(EnumKey_doc, -"EnumKey(key, index) -> string\n" -"Enumerates subkeys of an open registry key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"index is an integer that identifies the index of the key to retrieve.\n" -"\n" -"The function retrieves the name of one subkey each time it is called.\n" -"It is typically called repeatedly until an OSError exception is\n" -"raised, indicating no more values are available."); - -PyDoc_STRVAR(EnumValue_doc, -"EnumValue(key, index) -> tuple\n" -"Enumerates values of an open registry key.\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"index is an integer that identifies the index of the value to retrieve.\n" -"\n" -"The function retrieves the name of one subkey each time it is called.\n" -"It is typically called repeatedly, until an OSError exception\n" -"is raised, indicating no more values.\n" -"\n" -"The result is a tuple of 3 items:\n" -"value_name is a string that identifies the value.\n" -"value_data is an object that holds the value data, and whose type depends\n" -" on the underlying registry type.\n" -"data_type is an integer that identifies the type of the value data."); - -PyDoc_STRVAR(ExpandEnvironmentStrings_doc, -"ExpandEnvironmentStrings(string) -> string\n" -"Expand environment vars.\n"); - -PyDoc_STRVAR(FlushKey_doc, -"FlushKey(key)\n" -"Writes all the attributes of a key to the registry.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"\n" -"It is not necessary to call FlushKey to change a key. Registry changes are\n" -"flushed to disk by the registry using its lazy flusher. Registry changes are\n" -"also flushed to disk at system shutdown. Unlike CloseKey(), the FlushKey()\n" -"method returns only when all the data has been written to the registry.\n" -"\n" -"An application should only call FlushKey() if it requires absolute certainty\n" -"that registry changes are on disk. If you don't know whether a FlushKey()\n" -"call is required, it probably isn't."); - -PyDoc_STRVAR(LoadKey_doc, -"LoadKey(key, sub_key, file_name)\n" -"Creates a subkey under the specified key and stores registration information\n" -"from a specified file into that subkey.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"sub_key is a string that identifies the sub_key to load.\n" -"file_name is the name of the file to load registry data from. This file must\n" -" have been created with the SaveKey() function. Under the file\n" -" allocation table (FAT) file system, the filename may not have an\n" -" extension.\n" -"\n" -"A call to LoadKey() fails if the calling process does not have the\n" -"SE_RESTORE_PRIVILEGE privilege.\n" -"\n" -"If key is a handle returned by ConnectRegistry(), then the path specified\n" -"in fileName is relative to the remote computer.\n" -"\n" -"The docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE tree"); - -PyDoc_STRVAR(OpenKey_doc, -"OpenKey(key, sub_key, reserved=0, access=KEY_READ) -> key\n" -"Opens the specified key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"sub_key is a string that identifies the sub_key to open.\n" -"reserved is a reserved integer, and must be zero. Default is zero.\n" -"access is an integer that specifies an access mask that describes the desired\n" -" security access for the key. Default is KEY_READ\n" -"\n" -"The result is a new handle to the specified key\n" -"If the function fails, an OSError exception is raised."); - -PyDoc_STRVAR(OpenKeyEx_doc, "See OpenKey()"); - -PyDoc_STRVAR(QueryInfoKey_doc, -"QueryInfoKey(key) -> tuple\n" -"Returns information about a key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"\n" -"The result is a tuple of 3 items:" -"An integer that identifies the number of sub keys this key has.\n" -"An integer that identifies the number of values this key has.\n" -"An integer that identifies when the key was last modified (if available)\n" -" as 100's of nanoseconds since Jan 1, 1600."); - -PyDoc_STRVAR(QueryValue_doc, -"QueryValue(key, sub_key) -> string\n" -"Retrieves the unnamed value for a key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"sub_key is a string that holds the name of the subkey with which the value\n" -" is associated. If this parameter is None or empty, the function\n" -" retrieves the value set by the SetValue() method for the key\n" -" identified by key." -"\n" -"Values in the registry have name, type, and data components. This method\n" -"retrieves the data for a key's first value that has a NULL name.\n" -"But the underlying API call doesn't return the type, Lame Lame Lame, DONT USE THIS!!!"); - -PyDoc_STRVAR(QueryValueEx_doc, -"QueryValueEx(key, value_name) -> (value, type_id)\n" -"Retrieves the type and data for a specified value name associated with an\n" -"open registry key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"value_name is a string indicating the value to query"); - -PyDoc_STRVAR(SaveKey_doc, -"SaveKey(key, file_name)\n" -"Saves the specified key, and all its subkeys to the specified file.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"file_name is the name of the file to save registry data to. This file cannot\n" -" already exist. If this filename includes an extension, it cannot be\n" -" used on file allocation table (FAT) file systems by the LoadKey(),\n" -" ReplaceKey() or RestoreKey() methods.\n" -"\n" -"If key represents a key on a remote computer, the path described by file_name\n" -"is relative to the remote computer.\n" -"\n" -"The caller of this method must possess the SeBackupPrivilege security\n" -"privilege. This function passes NULL for security_attributes to the API."); - -PyDoc_STRVAR(SetValue_doc, -"SetValue(key, sub_key, type, value)\n" -"Associates a value with a specified key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"sub_key is a string that names the subkey with which the value is associated.\n" -"type is an integer that specifies the type of the data. Currently this must\n" -" be REG_SZ, meaning only strings are supported.\n" -"value is a string that specifies the new value.\n" -"\n" -"If the key specified by the sub_key parameter does not exist, the SetValue\n" -"function creates it.\n" -"\n" -"Value lengths are limited by available memory. Long values (more than\n" -"2048 bytes) should be stored as files with the filenames stored in \n" -"the configuration registry. This helps the registry perform efficiently.\n" -"\n" -"The key identified by the key parameter must have been opened with\n" -"KEY_SET_VALUE access."); - -PyDoc_STRVAR(SetValueEx_doc, -"SetValueEx(key, value_name, reserved, type, value)\n" -"Stores data in the value field of an open registry key.\n" -"\n" -"key is an already open key, or any one of the predefined HKEY_* constants.\n" -"value_name is a string containing the name of the value to set, or None.\n" -"reserved can be anything - zero is always passed to the API.\n" -"type is an integer that specifies the type of the data. This should be one of:\n" -" REG_BINARY -- Binary data in any form.\n" -" REG_DWORD -- A 32-bit number.\n" -" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.\n" -" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n" -" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded references\n" -" to environment variables (for example, %PATH%).\n" -" REG_LINK -- A Unicode symbolic link.\n" -" REG_MULTI_SZ -- An sequence of null-terminated strings, terminated by\n" -" two null characters. Note that Python handles this\n" -" termination automatically.\n" -" REG_NONE -- No defined value type.\n" -" REG_RESOURCE_LIST -- A device-driver resource list.\n" -" REG_SZ -- A null-terminated string.\n" -"value is a string that specifies the new value.\n" -"\n" -"This method can also set additional value and type information for the\n" -"specified key. The key identified by the key parameter must have been\n" -"opened with KEY_SET_VALUE access.\n" -"\n" -"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n" -"\n" -"Value lengths are limited by available memory. Long values (more than\n" -"2048 bytes) should be stored as files with the filenames stored in \n" -"the configuration registry. This helps the registry perform efficiently."); - -PyDoc_STRVAR(DisableReflectionKey_doc, -"Disables registry reflection for 32-bit processes running on a 64-bit\n" -"Operating System. Will generally raise NotImplemented if executed on\n" -"a 32-bit Operating System.\n" -"\n" -"If the key is not on the reflection list, the function succeeds but has no effect.\n" -"Disabling reflection for a key does not affect reflection of any subkeys."); - -PyDoc_STRVAR(EnableReflectionKey_doc, -"Restores registry reflection for the specified disabled key.\n" -"Will generally raise NotImplemented if executed on a 32-bit Operating System.\n" -"Restoring reflection for a key does not affect reflection of any subkeys."); - -PyDoc_STRVAR(QueryReflectionKey_doc, -"QueryReflectionKey(hkey) -> bool\n" -"Determines the reflection state for the specified key.\n" -"Will generally raise NotImplemented if executed on a 32-bit Operating System.\n"); /* PyHKEY docstrings */ PyDoc_STRVAR(PyHKEY_doc, @@ -389,24 +99,6 @@ "rich comparison - Handle objects are compared using the handle value."); -PyDoc_STRVAR(PyHKEY_Close_doc, -"key.Close()\n" -"Closes the underlying Windows handle.\n" -"\n" -"If the handle is already closed, no error is raised."); - -PyDoc_STRVAR(PyHKEY_Detach_doc, -"key.Detach() -> int\n" -"Detaches the Windows handle from the handle object.\n" -"\n" -"The result is the value of the handle before it is detached. If the\n" -"handle is already detached, this will return zero.\n" -"\n" -"After calling this function, the handle is effectively invalidated,\n" -"but the handle is not closed. You would call this function when you\n" -"need the underlying win32 handle to exist beyond the lifetime of the\n" -"handle object."); - /************************************************************************ @@ -516,16 +208,134 @@ PyHKEY_unaryFailureFunc, /* nb_float */ }; -static PyObject *PyHKEY_CloseMethod(PyObject *self, PyObject *args); -static PyObject *PyHKEY_DetachMethod(PyObject *self, PyObject *args); -static PyObject *PyHKEY_Enter(PyObject *self); -static PyObject *PyHKEY_Exit(PyObject *self, PyObject *args); +/*[clinic input] +module winreg +class winreg.HKEYType "PyHKEYObject *" "&PyHKEY_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4c964eba3bf914d6]*/ + +/*[python input] +class REGSAM_converter(CConverter): + type = 'REGSAM' + format_unit = 'i' + +class DWORD_converter(CConverter): + type = 'DWORD' + format_unit = 'k' + +class HKEY_converter(CConverter): + type = 'HKEY' + converter = 'clinic_HKEY_converter' + +class HKEY_return_converter(CReturnConverter): + type = 'HKEY' + + def render(self, function, data): + self.declare(data) + self.err_occurred_if_null_pointer("_return_value", data) + data.return_conversion.append( + 'return_value = PyHKEY_FromHKEY(_return_value);\n') + +# HACK: this only works for PyHKEYObjects, nothing else. +# Should this be generalized and enshrined in clinic.py, +# destroy this converter with prejudice. +class self_return_converter(CReturnConverter): + type = 'PyHKEYObject *' + + def render(self, function, data): + self.declare(data) + data.return_conversion.append( + 'return_value = (PyObject *)_return_value;\n') +[python start generated code]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=22f7aedc6d68e80e]*/ + +#include "clinic/winreg.c.h" + +/************************************************************************ + + The PyHKEY object methods + +************************************************************************/ +/*[clinic input] +winreg.HKEYType.Close + +Closes the underlying Windows handle. + +If the handle is already closed, no error is raised. +[clinic start generated code]*/ + +static PyObject * +winreg_HKEYType_Close_impl(PyHKEYObject *self) +/*[clinic end generated code: output=fced3a624fb0c344 input=6786ac75f6b89de6]*/ +{ + if (!PyHKEY_Close((PyObject *)self)) + return NULL; + Py_RETURN_NONE; +} + +/*[clinic input] +winreg.HKEYType.Detach + +Detaches the Windows handle from the handle object. + +The result is the value of the handle before it is detached. If the +handle is already detached, this will return zero. + +After calling this function, the handle is effectively invalidated, +but the handle is not closed. You would call this function when you +need the underlying win32 handle to exist beyond the lifetime of the +handle object. +[clinic start generated code]*/ + +static PyObject * +winreg_HKEYType_Detach_impl(PyHKEYObject *self) +/*[clinic end generated code: output=dda5a9e1a01ae78f input=dd2cc09e6c6ba833]*/ +{ + void* ret; + ret = (void*)self->hkey; + self->hkey = 0; + return PyLong_FromVoidPtr(ret); +} + +/*[clinic input] +winreg.HKEYType.__enter__ -> self +[clinic start generated code]*/ + +static PyHKEYObject * +winreg_HKEYType___enter___impl(PyHKEYObject *self) +/*[clinic end generated code: output=52c34986dab28990 input=c40fab1f0690a8e2]*/ +{ + Py_XINCREF(self); + return self; +} + + +/*[clinic input] +winreg.HKEYType.__exit__ + + exc_type: object + exc_value: object + traceback: object +[clinic start generated code]*/ + +static PyObject * +winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type, PyObject *exc_value, PyObject *traceback) +/*[clinic end generated code: output=51adcc1522e9c847 input=fb32489ee92403c7]*/ +{ + if (!PyHKEY_Close((PyObject *)self)) + return NULL; + Py_RETURN_NONE; +} + +/*[clinic input] +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/ static struct PyMethodDef PyHKEY_methods[] = { - {"Close", PyHKEY_CloseMethod, METH_VARARGS, PyHKEY_Close_doc}, - {"Detach", PyHKEY_DetachMethod, METH_VARARGS, PyHKEY_Detach_doc}, - {"__enter__", (PyCFunction)PyHKEY_Enter, METH_NOARGS, NULL}, - {"__exit__", PyHKEY_Exit, METH_VARARGS, NULL}, + WINREG_HKEYTYPE_CLOSE_METHODDEF + WINREG_HKEYTYPE_DETACH_METHODDEF + WINREG_HKEYTYPE___ENTER___METHODDEF + WINREG_HKEYTYPE___EXIT___METHODDEF {NULL} }; @@ -570,50 +380,6 @@ }; /************************************************************************ - - The PyHKEY object methods - -************************************************************************/ -static PyObject * -PyHKEY_CloseMethod(PyObject *self, PyObject *args) -{ - if (!PyArg_ParseTuple(args, ":Close")) - return NULL; - if (!PyHKEY_Close(self)) - return NULL; - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -PyHKEY_DetachMethod(PyObject *self, PyObject *args) -{ - void* ret; - PyHKEYObject *pThis = (PyHKEYObject *)self; - if (!PyArg_ParseTuple(args, ":Detach")) - return NULL; - ret = (void*)pThis->hkey; - pThis->hkey = 0; - return PyLong_FromVoidPtr(ret); -} - -static PyObject * -PyHKEY_Enter(PyObject *self) -{ - Py_XINCREF(self); - return self; -} - -static PyObject * -PyHKEY_Exit(PyObject *self, PyObject *args) -{ - if (!PyHKEY_Close(self)) - return NULL; - Py_RETURN_NONE; -} - - -/************************************************************************ The public PyHKEY API (well, not public yet :-) ************************************************************************/ PyObject * @@ -675,6 +441,14 @@ return TRUE; } +BOOL +clinic_HKEY_converter(PyObject *ob, void *p) +{ + if (!PyHKEY_AsHKEY(ob, (HKEY *)p, FALSE)) + return FALSE; + return TRUE; +} + PyObject * PyHKEY_FromHKEY(HKEY h) { @@ -985,120 +759,196 @@ /* The Python methods */ +/*[clinic input] +winreg.CloseKey + + hkey: object + A previously opened key. + / + +Closes a previously opened registry key. + +Note that if the key is not closed using this method, it will be +closed when the hkey object is destroyed by Python. +[clinic start generated code]*/ + static PyObject * -PyCloseKey(PyObject *self, PyObject *args) +winreg_CloseKey(PyModuleDef *module, PyObject *hkey) +/*[clinic end generated code: output=d96f73439403a064 input=5b1aac65ba5127ad]*/ { - PyObject *obKey; - if (!PyArg_ParseTuple(args, "O:CloseKey", &obKey)) + if (!PyHKEY_Close(hkey)) return NULL; - if (!PyHKEY_Close(obKey)) - return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -static PyObject * -PyConnectRegistry(PyObject *self, PyObject *args) +/*[clinic input] +winreg.ConnectRegistry -> HKEY + + computer_name: Py_UNICODE(nullable=True) + The name of the remote computer, of the form r"\\computername". If + None, the local computer is used. + key: HKEY + The predefined key to connect to. + / + +Establishes a connection to the registry on on another computer. + +The return value is the handle of the opened key. +If the function fails, an OSError exception is raised. +[clinic start generated code]*/ + +static HKEY +winreg_ConnectRegistry_impl(PyModuleDef *module, Py_UNICODE *computer_name, HKEY key) +/*[clinic end generated code: output=bce735a41d767290 input=dcea2c433af51576]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *szCompName = NULL; HKEY retKey; long rc; - if (!PyArg_ParseTuple(args, "ZO:ConnectRegistry", &szCompName, &obKey)) + Py_BEGIN_ALLOW_THREADS + rc = RegConnectRegistryW(computer_name, key, &retKey); + Py_END_ALLOW_THREADS + if (rc != ERROR_SUCCESS) { + PyErr_SetFromWindowsErrWithFunction(rc, "ConnectRegistry"); return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - Py_BEGIN_ALLOW_THREADS - rc = RegConnectRegistryW(szCompName, hKey, &retKey); - Py_END_ALLOW_THREADS - if (rc != ERROR_SUCCESS) - return PyErr_SetFromWindowsErrWithFunction(rc, - "ConnectRegistry"); - return PyHKEY_FromHKEY(retKey); + } + return retKey; } -static PyObject * -PyCreateKey(PyObject *self, PyObject *args) +/*[clinic input] +winreg.CreateKey -> HKEY + + key: HKEY + An already open key, or one of the predefined HKEY_* constants. + sub_key: Py_UNICODE(nullable=True) + The name of the key this method opens or creates. + / + +Creates or opens the specified key. + +If key is one of the predefined keys, sub_key may be None. In that case, +the handle returned is the same key handle passed in to the function. + +If the key already exists, this function opens the existing key. + +The return value is the handle of the opened key. +If the function fails, an OSError exception is raised. +[clinic start generated code]*/ + +static HKEY +winreg_CreateKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key) +/*[clinic end generated code: output=cd6843f30a73fc0e input=8014b171a5682fe7]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *subKey; HKEY retKey; long rc; - if (!PyArg_ParseTuple(args, "OZ:CreateKey", &obKey, &subKey)) + + rc = RegCreateKeyW(key, sub_key, &retKey); + if (rc != ERROR_SUCCESS) { + PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey"); return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - rc = RegCreateKeyW(hKey, subKey, &retKey); - if (rc != ERROR_SUCCESS) - return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey"); - return PyHKEY_FromHKEY(retKey); + } + return retKey; } -static PyObject * -PyCreateKeyEx(PyObject *self, PyObject *args, PyObject *kwargs) +/*[clinic input] +winreg.CreateKeyEx -> HKEY + + key: HKEY + An already open key, or one of the predefined HKEY_* constants. + sub_key: Py_UNICODE(nullable=True) + The name of the key this method opens or creates. + reserved: int = 0 + A reserved integer, and must be zero. Default is zero. + access: REGSAM(c_default='KEY_WRITE') = winreg.KEY_WRITE + An integer that specifies an access mask that describes the + desired security access for the key. Default is KEY_WRITE. + +Creates or opens the specified key. + +If key is one of the predefined keys, sub_key may be None. In that case, +the handle returned is the same key handle passed in to the function. + +If the key already exists, this function opens the existing key + +The return value is the handle of the opened key. +If the function fails, an OSError exception is raised. +[clinic start generated code]*/ + +static HKEY +winreg_CreateKeyEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, int reserved, REGSAM access) +/*[clinic end generated code: output=543d176b19183749 input=4322acd5c7f2e787]*/ { - HKEY hKey; - PyObject *key; - wchar_t *sub_key; HKEY retKey; - int reserved = 0; - REGSAM access = KEY_WRITE; long rc; - char *kwlist[] = {"key", "sub_key", "reserved", "access", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OZ|ii:CreateKeyEx", kwlist, - &key, &sub_key, &reserved, &access)) + rc = RegCreateKeyExW(key, sub_key, reserved, NULL, (DWORD)NULL, + access, NULL, &retKey, NULL); + if (rc != ERROR_SUCCESS) { + PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx"); return NULL; - if (!PyHKEY_AsHKEY(key, &hKey, FALSE)) - return NULL; - - rc = RegCreateKeyExW(hKey, sub_key, reserved, NULL, (DWORD)NULL, - access, NULL, &retKey, NULL); - if (rc != ERROR_SUCCESS) - return PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx"); - return PyHKEY_FromHKEY(retKey); + } + return retKey; } +/*[clinic input] +winreg.DeleteKey + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + sub_key: Py_UNICODE + A string that must be the name of a subkey of the key identified by + the key parameter. This value must not be None, and the key may not + have subkeys. + / + +Deletes the specified key. + +This method can not delete keys with subkeys. + +If the function succeeds, the entire key, including all of its values, +is removed. If the function fails, an OSError exception is raised. +[clinic start generated code]*/ + static PyObject * -PyDeleteKey(PyObject *self, PyObject *args) +winreg_DeleteKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key) +/*[clinic end generated code: output=875c8917dacbc99d input=b31d225b935e4211]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *subKey; long rc; - if (!PyArg_ParseTuple(args, "Ou:DeleteKey", &obKey, &subKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - rc = RegDeleteKeyW(hKey, subKey ); + rc = RegDeleteKeyW(key, sub_key ); if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.DeleteKeyEx + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + sub_key: Py_UNICODE + A string that must be the name of a subkey of the key identified by + the key parameter. This value must not be None, and the key may not + have subkeys. + access: REGSAM(c_default='KEY_WOW64_64KEY') = winreg.KEY_WOW64_64KEY + An integer that specifies an access mask that describes the + desired security access for the key. Default is KEY_WOW64_64KEY. + reserved: int = 0 + A reserved integer, and must be zero. Default is zero. + +Deletes the specified key (64-bit OS only). + +This method can not delete keys with subkeys. + +If the function succeeds, the entire key, including all of its values, +is removed. If the function fails, an OSError exception is raised. +On unsupported Windows versions, NotImplementedError is raised. +[clinic start generated code]*/ + static PyObject * -PyDeleteKeyEx(PyObject *self, PyObject *args, PyObject *kwargs) +winreg_DeleteKeyEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, REGSAM access, int reserved) +/*[clinic end generated code: output=8b8a20684a59a902 input=711d9d89e7ecbed7]*/ { - HKEY hKey; - PyObject *key; HMODULE hMod; typedef LONG (WINAPI *RDKEFunc)(HKEY, const wchar_t*, REGSAM, int); RDKEFunc pfn = NULL; - wchar_t *sub_key; long rc; - int reserved = 0; - REGSAM access = KEY_WOW64_64KEY; - - char *kwlist[] = {"key", "sub_key", "access", "reserved", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ou|ii:DeleteKeyEx", kwlist, - &key, &sub_key, &access, &reserved)) - return NULL; - if (!PyHKEY_AsHKEY(key, &hKey, FALSE)) - return NULL; /* Only available on 64bit platforms, so we must load it dynamically. */ @@ -1112,42 +962,60 @@ return NULL; } Py_BEGIN_ALLOW_THREADS - rc = (*pfn)(hKey, sub_key, access, reserved); + rc = (*pfn)(key, sub_key, access, reserved); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.DeleteValue + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + value: Py_UNICODE(nullable=True) + A string that identifies the value to remove. + / + +Removes a named value from a registry key. +[clinic start generated code]*/ + static PyObject * -PyDeleteValue(PyObject *self, PyObject *args) +winreg_DeleteValue_impl(PyModuleDef *module, HKEY key, Py_UNICODE *value) +/*[clinic end generated code: output=308550b8cdcfd8e1 input=417a5c1005cbbddc]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *subKey; long rc; - if (!PyArg_ParseTuple(args, "OZ:DeleteValue", &obKey, &subKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; Py_BEGIN_ALLOW_THREADS - rc = RegDeleteValueW(hKey, subKey); + rc = RegDeleteValueW(key, value); Py_END_ALLOW_THREADS if (rc !=ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteValue"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.EnumKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + index: int + An integer that identifies the index of the key to retrieve. + / + +Enumerates subkeys of an open registry key. + +The function retrieves the name of one subkey each time it is called. +It is typically called repeatedly until an OSError exception is +raised, indicating no more values are available. +[clinic start generated code]*/ + static PyObject * -PyEnumKey(PyObject *self, PyObject *args) +winreg_EnumKey_impl(PyModuleDef *module, HKEY key, int index) +/*[clinic end generated code: output=58074ffabbc67896 input=fad9a7c00ab0e04b]*/ { - HKEY hKey; - PyObject *obKey; - int index; long rc; PyObject *retStr; @@ -1160,13 +1028,8 @@ wchar_t tmpbuf[257]; DWORD len = sizeof(tmpbuf)/sizeof(wchar_t); /* includes NULL terminator */ - if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - Py_BEGIN_ALLOW_THREADS - rc = RegEnumKeyExW(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL); + rc = RegEnumKeyExW(key, index, tmpbuf, &len, NULL, NULL, NULL, NULL); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx"); @@ -1175,12 +1038,35 @@ return retStr; /* can be NULL */ } +/*[clinic input] +winreg.EnumValue + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + index: int + An integer that identifies the index of the value to retrieve. + / + +Enumerates values of an open registry key. + +The function retrieves the name of one subkey each time it is called. +It is typically called repeatedly, until an OSError exception +is raised, indicating no more values. + +The result is a tuple of 3 items: + value_name + A string that identifies the value. + value_data + An object that holds the value data, and whose type depends + on the underlying registry type. + data_type + An integer that identifies the type of the value data. +[clinic start generated code]*/ + static PyObject * -PyEnumValue(PyObject *self, PyObject *args) +winreg_EnumValue_impl(PyModuleDef *module, HKEY key, int index) +/*[clinic end generated code: output=4570367ebaf0e979 input=4414f47a6fb238b5]*/ { - HKEY hKey; - PyObject *obKey; - int index; long rc; wchar_t *retValueBuf; BYTE *tmpBuf; @@ -1191,12 +1077,7 @@ PyObject *obData; PyObject *retVal; - if (!PyArg_ParseTuple(args, "Oi:EnumValue", &obKey, &index)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - - if ((rc = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, + if ((rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &retValueSize, &retDataSize, NULL, NULL)) != ERROR_SUCCESS) @@ -1217,7 +1098,7 @@ while (1) { Py_BEGIN_ALLOW_THREADS - rc = RegEnumValueW(hKey, + rc = RegEnumValueW(key, index, retValueBuf, &retValueSize, @@ -1260,19 +1141,25 @@ return retVal; } +/*[clinic input] +winreg.ExpandEnvironmentStrings + + string: Py_UNICODE + / + +Expand environment vars. +[clinic start generated code]*/ + static PyObject * -PyExpandEnvironmentStrings(PyObject *self, PyObject *args) +winreg_ExpandEnvironmentStrings_impl(PyModuleDef *module, Py_UNICODE *string) +/*[clinic end generated code: output=4cb6914065a8663c input=b2a9714d2b751aa6]*/ { wchar_t *retValue = NULL; - wchar_t *src; DWORD retValueSize; DWORD rc; PyObject *o; - if (!PyArg_ParseTuple(args, "u:ExpandEnvironmentStrings", &src)) - return NULL; - - retValueSize = ExpandEnvironmentStringsW(src, retValue, 0); + retValueSize = ExpandEnvironmentStringsW(string, retValue, 0); if (retValueSize == 0) { return PyErr_SetFromWindowsErrWithFunction(retValueSize, "ExpandEnvironmentStrings"); @@ -1282,7 +1169,7 @@ return PyErr_NoMemory(); } - rc = ExpandEnvironmentStringsW(src, retValue, retValueSize); + rc = ExpandEnvironmentStringsW(string, retValue, retValueSize); if (rc == 0) { PyMem_Free(retValue); return PyErr_SetFromWindowsErrWithFunction(retValueSize, @@ -1293,90 +1180,163 @@ return o; } +/*[clinic input] +winreg.FlushKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + / + +Writes all the attributes of a key to the registry. + +It is not necessary to call FlushKey to change a key. Registry changes +are flushed to disk by the registry using its lazy flusher. Registry +changes are also flushed to disk at system shutdown. Unlike +CloseKey(), the FlushKey() method returns only when all the data has +been written to the registry. + +An application should only call FlushKey() if it requires absolute +certainty that registry changes are on disk. If you don't know whether +a FlushKey() call is required, it probably isn't. +[clinic start generated code]*/ + static PyObject * -PyFlushKey(PyObject *self, PyObject *args) +winreg_FlushKey_impl(PyModuleDef *module, HKEY key) +/*[clinic end generated code: output=b9a7a6e405466420 input=f57457c12297d82f]*/ { - HKEY hKey; - PyObject *obKey; long rc; - if (!PyArg_ParseTuple(args, "O:FlushKey", &obKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; Py_BEGIN_ALLOW_THREADS - rc = RegFlushKey(hKey); + rc = RegFlushKey(key); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } + + +/*[clinic input] +winreg.LoadKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + sub_key: Py_UNICODE + A string that identifies the sub-key to load. + file_name: Py_UNICODE + The name of the file to load registry data from. This file must + have been created with the SaveKey() function. Under the file + allocation table (FAT) file system, the filename may not have an + extension. + / + +Insert data into the registry from a file. + +Creates a subkey under the specified key and stores registration +information from a specified file into that subkey. + +A call to LoadKey() fails if the calling process does not have the +SE_RESTORE_PRIVILEGE privilege. + +If key is a handle returned by ConnectRegistry(), then the path +specified in fileName is relative to the remote computer. + +The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE +tree. +[clinic start generated code]*/ + static PyObject * -PyLoadKey(PyObject *self, PyObject *args) +winreg_LoadKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, Py_UNICODE *file_name) +/*[clinic end generated code: output=53b22607f8e73d34 input=e3b5b45ade311582]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *subKey; - wchar_t *fileName; + long rc; - long rc; - if (!PyArg_ParseTuple(args, "Ouu:LoadKey", &obKey, &subKey, &fileName)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; Py_BEGIN_ALLOW_THREADS - rc = RegLoadKeyW(hKey, subKey, fileName ); + rc = RegLoadKeyW(key, sub_key, file_name ); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } -static PyObject * -PyOpenKey(PyObject *self, PyObject *args, PyObject *kwargs) +/*[clinic input] +winreg.OpenKey -> HKEY + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + sub_key: Py_UNICODE(nullable=True) + A string that identifies the sub_key to open. + reserved: int = 0 + A reserved integer that must be zero. Default is zero. + access: REGSAM(c_default='KEY_READ') = winreg.KEY_READ + An integer that specifies an access mask that describes the desired + security access for the key. Default is KEY_READ. + +Opens the specified key. + +The result is a new handle to the specified key. +If the function fails, an OSError exception is raised. +[clinic start generated code]*/ + +static HKEY +winreg_OpenKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, int reserved, REGSAM access) +/*[clinic end generated code: output=8bf50881521469c6 input=dc84a4af4af4d387]*/ { - HKEY hKey; - PyObject *key; - wchar_t *sub_key; - int reserved = 0; HKEY retKey; long rc; - REGSAM access = KEY_READ; - - char *kwlist[] = {"key", "sub_key", "reserved", "access", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OZ|ii:OpenKey", kwlist, - &key, &sub_key, &reserved, &access)) - return NULL; - if (!PyHKEY_AsHKEY(key, &hKey, FALSE)) - return NULL; Py_BEGIN_ALLOW_THREADS - rc = RegOpenKeyExW(hKey, sub_key, reserved, access, &retKey); + rc = RegOpenKeyExW(key, sub_key, reserved, access, &retKey); Py_END_ALLOW_THREADS - if (rc != ERROR_SUCCESS) - return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); - return PyHKEY_FromHKEY(retKey); + if (rc != ERROR_SUCCESS) { + PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); + return NULL; + } + return retKey; } +/*[clinic input] +winreg.OpenKeyEx = winreg.OpenKey + +Opens the specified key. + +The result is a new handle to the specified key. +If the function fails, an OSError exception is raised. +[clinic start generated code]*/ + +static HKEY +winreg_OpenKeyEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, int reserved, REGSAM access) +/*[clinic end generated code: output=f6f7cd4befb9585b input=c6c4972af8622959]*/ +{ + return winreg_OpenKey_impl(module, key, sub_key, reserved, access); +} + +/*[clinic input] +winreg.QueryInfoKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + / + +Returns information about a key. + +The result is a tuple of 3 items: +An integer that identifies the number of sub keys this key has. +An integer that identifies the number of values this key has. +An integer that identifies when the key was last modified (if available) +as 100's of nanoseconds since Jan 1, 1600. +[clinic start generated code]*/ static PyObject * -PyQueryInfoKey(PyObject *self, PyObject *args) +winreg_QueryInfoKey_impl(PyModuleDef *module, HKEY key) +/*[clinic end generated code: output=ae885222fe966a34 input=c3593802390cde1f]*/ { - HKEY hKey; - PyObject *obKey; long rc; DWORD nSubKeys, nValues; FILETIME ft; LARGE_INTEGER li; PyObject *l; PyObject *ret; - if (!PyArg_ParseTuple(args, "O:QueryInfoKey", &obKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - if ((rc = RegQueryInfoKey(hKey, NULL, NULL, 0, &nSubKeys, NULL, NULL, + + if ((rc = RegQueryInfoKey(key, NULL, NULL, 0, &nSubKeys, NULL, NULL, &nValues, NULL, NULL, NULL, &ft)) != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey"); @@ -1390,12 +1350,31 @@ return ret; } +/*[clinic input] +winreg.QueryValue + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + sub_key: Py_UNICODE(nullable=True) + A string that holds the name of the subkey with which the value + is associated. If this parameter is None or empty, the function + retrieves the value set by the SetValue() method for the key + identified by key. + / + +Retrieves the unnamed value for a key. + +Values in the registry have name, type, and data components. This method +retrieves the data for a key's first value that has a NULL name. +But since the underlying API call doesn't return the type, you'll +probably be happier using QueryValueEx; this function is just here for +completeness. +[clinic start generated code]*/ + static PyObject * -PyQueryValue(PyObject *self, PyObject *args) +winreg_QueryValue_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key) +/*[clinic end generated code: output=f91cb6f623c3b65a input=e6ec57bb8d39aaa6]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *subKey; long rc; PyObject *retStr; wchar_t *retBuf; @@ -1403,13 +1382,7 @@ DWORD retSize = 0; wchar_t *tmp; - if (!PyArg_ParseTuple(args, "OZ:QueryValue", &obKey, &subKey)) - return NULL; - - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - - rc = RegQueryValueW(hKey, subKey, NULL, &retSize); + rc = RegQueryValueW(key, sub_key, NULL, &retSize); if (rc == ERROR_MORE_DATA) retSize = 256; else if (rc != ERROR_SUCCESS) @@ -1423,7 +1396,7 @@ while (1) { retSize = bufSize; - rc = RegQueryValueW(hKey, subKey, retBuf, &retSize); + rc = RegQueryValueW(key, sub_key, retBuf, &retSize); if (rc != ERROR_MORE_DATA) break; @@ -1447,13 +1420,28 @@ return retStr; } + +/*[clinic input] +winreg.QueryValueEx + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + name: Py_UNICODE(nullable=True) + A string indicating the value to query. + / + +Retrieves the type and value of a specified sub-key. + +Behaves mostly like QueryValue(), but also returns the type of the +specified value name associated with the given open registry key. + +The return value is a tuple of the value and the type_id. +[clinic start generated code]*/ + static PyObject * -PyQueryValueEx(PyObject *self, PyObject *args) +winreg_QueryValueEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *name) +/*[clinic end generated code: output=a4b07f7807194f23 input=4403ae868b44e563]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *valueName; - long rc; BYTE *retBuf, *tmp; DWORD bufSize = 0, retSize; @@ -1461,13 +1449,7 @@ PyObject *obData; PyObject *result; - if (!PyArg_ParseTuple(args, "OZ:QueryValueEx", &obKey, &valueName)) - return NULL; - - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - - rc = RegQueryValueExW(hKey, valueName, NULL, NULL, NULL, &bufSize); + rc = RegQueryValueExW(key, name, NULL, NULL, NULL, &bufSize); if (rc == ERROR_MORE_DATA) bufSize = 256; else if (rc != ERROR_SUCCESS) @@ -1479,7 +1461,7 @@ while (1) { retSize = bufSize; - rc = RegQueryValueExW(hKey, valueName, NULL, &typ, + rc = RegQueryValueExW(key, name, NULL, &typ, (BYTE *)retBuf, &retSize); if (rc != ERROR_MORE_DATA) break; @@ -1507,91 +1489,146 @@ return result; } +/*[clinic input] +winreg.SaveKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + file_name: Py_UNICODE + The name of the file to save registry data to. This file cannot + already exist. If this filename includes an extension, it cannot be + used on file allocation table (FAT) file systems by the LoadKey(), + ReplaceKey() or RestoreKey() methods. + / + +Saves the specified key, and all its subkeys to the specified file. + +If key represents a key on a remote computer, the path described by +file_name is relative to the remote computer. + +The caller of this method must possess the SeBackupPrivilege +security privilege. This function passes NULL for security_attributes +to the API. +[clinic start generated code]*/ static PyObject * -PySaveKey(PyObject *self, PyObject *args) +winreg_SaveKey_impl(PyModuleDef *module, HKEY key, Py_UNICODE *file_name) +/*[clinic end generated code: output=33109b96bfabef8f input=da735241f91ac7a2]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *fileName; LPSECURITY_ATTRIBUTES pSA = NULL; long rc; - if (!PyArg_ParseTuple(args, "Ou:SaveKey", &obKey, &fileName)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; /* One day we may get security into the core? if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE)) return NULL; */ Py_BEGIN_ALLOW_THREADS - rc = RegSaveKeyW(hKey, fileName, pSA ); + rc = RegSaveKeyW(key, file_name, pSA ); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.SetValue + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + sub_key: Py_UNICODE(nullable=True) + A string that names the subkey with which the value is associated. + type: DWORD + An integer that specifies the type of the data. Currently this must + be REG_SZ, meaning only strings are supported. + value: Py_UNICODE(length=True) + A string that specifies the new value. + / + +Associates a value with a specified key. + +If the key specified by the sub_key parameter does not exist, the +SetValue function creates it. + +Value lengths are limited by available memory. Long values (more than +2048 bytes) should be stored as files with the filenames stored in +the configuration registry to help the registry perform efficiently. + +The key identified by the key parameter must have been opened with +KEY_SET_VALUE access. +[clinic start generated code]*/ + static PyObject * -PySetValue(PyObject *self, PyObject *args) +winreg_SetValue_impl(PyModuleDef *module, HKEY key, Py_UNICODE *sub_key, DWORD type, Py_UNICODE *value, Py_ssize_clean_t value_length) +/*[clinic end generated code: output=807274a1c01961b5 input=83ad2fae2ffbb941]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *subKey; - wchar_t *str; - DWORD typ; - DWORD len; long rc; - if (!PyArg_ParseTuple(args, "OZiu#:SetValue", - &obKey, - &subKey, - &typ, - &str, - &len)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - if (typ != REG_SZ) { + + if (type != REG_SZ) { PyErr_SetString(PyExc_TypeError, "Type must be winreg.REG_SZ"); return NULL; } Py_BEGIN_ALLOW_THREADS - rc = RegSetValueW(hKey, subKey, REG_SZ, str, len+1); + rc = RegSetValueW(key, sub_key, REG_SZ, value, value_length+1); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.SetValueEx + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + value_name: Py_UNICODE(nullable=True) + A string containing the name of the value to set, or None. + reserved: object + Can be anything - zero is always passed to the API. + type: DWORD + An integer that specifies the type of the data, one of: + REG_BINARY -- Binary data in any form. + REG_DWORD -- A 32-bit number. + REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. + REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format. + REG_EXPAND_SZ -- A null-terminated string that contains unexpanded + references to environment variables (for example, + %PATH%). + REG_LINK -- A Unicode symbolic link. + REG_MULTI_SZ -- An sequence of null-terminated strings, terminated + by two null characters. Note that Python handles + this termination automatically. + REG_NONE -- No defined value type. + REG_RESOURCE_LIST -- A device-driver resource list. + REG_SZ -- A null-terminated string. + value: object + A string that specifies the new value. + / + +Stores data in the value field of an open registry key. + +This method can also set additional value and type information for the +specified key. The key identified by the key parameter must have been +opened with KEY_SET_VALUE access. + +To open the key, use the CreateKeyEx() or OpenKeyEx() methods. + +Value lengths are limited by available memory. Long values (more than +2048 bytes) should be stored as files with the filenames stored in +the configuration registry to help the registry perform efficiently. +[clinic start generated code]*/ + static PyObject * -PySetValueEx(PyObject *self, PyObject *args) +winreg_SetValueEx_impl(PyModuleDef *module, HKEY key, Py_UNICODE *value_name, PyObject *reserved, DWORD type, PyObject *value) +/*[clinic end generated code: output=a53ac3aecef9b977 input=8fe45d7ac381cf96]*/ { - HKEY hKey; - PyObject *obKey; - wchar_t *valueName; - PyObject *obRes; - PyObject *value; BYTE *data; DWORD len; - DWORD typ; LONG rc; - if (!PyArg_ParseTuple(args, "OZOiO:SetValueEx", - &obKey, - &valueName, - &obRes, - &typ, - &value)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - if (!Py2Reg(value, typ, &data, &len)) + if (!Py2Reg(value, type, &data, &len)) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_ValueError, @@ -1599,31 +1636,40 @@ return NULL; } Py_BEGIN_ALLOW_THREADS - rc = RegSetValueExW(hKey, valueName, 0, typ, data, len); + rc = RegSetValueExW(key, value_name, 0, type, data, len); Py_END_ALLOW_THREADS PyMem_DEL(data); if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValueEx"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.DisableReflectionKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + / + +Disables registry reflection for 32bit processes running on a 64bit OS. + +Will generally raise NotImplemented if executed on a 32bit OS. + +If the key is not on the reflection list, the function succeeds but has +no effect. Disabling reflection for a key does not affect reflection +of any subkeys. +[clinic start generated code]*/ + static PyObject * -PyDisableReflectionKey(PyObject *self, PyObject *args) +winreg_DisableReflectionKey_impl(PyModuleDef *module, HKEY key) +/*[clinic end generated code: output=50fe6e2604324cdd input=a6c9e5ca5410193c]*/ { - HKEY hKey; - PyObject *obKey; HMODULE hMod; typedef LONG (WINAPI *RDRKFunc)(HKEY); RDRKFunc pfn = NULL; LONG rc; - if (!PyArg_ParseTuple(args, "O:DisableReflectionKey", &obKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - /* Only available on 64bit platforms, so we must load it dynamically.*/ hMod = GetModuleHandleW(L"advapi32.dll"); @@ -1636,30 +1682,37 @@ return NULL; } Py_BEGIN_ALLOW_THREADS - rc = (*pfn)(hKey); + rc = (*pfn)(key); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDisableReflectionKey"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.EnableReflectionKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + / + +Restores registry reflection for the specified disabled key. + +Will generally raise NotImplemented if executed on a 32bit OS. +Restoring reflection for a key does not affect reflection of any +subkeys. +[clinic start generated code]*/ + static PyObject * -PyEnableReflectionKey(PyObject *self, PyObject *args) +winreg_EnableReflectionKey_impl(PyModuleDef *module, HKEY key) +/*[clinic end generated code: output=e3f23edb414f24a4 input=7748abbacd1e166a]*/ { - HKEY hKey; - PyObject *obKey; HMODULE hMod; typedef LONG (WINAPI *RERKFunc)(HKEY); RERKFunc pfn = NULL; LONG rc; - if (!PyArg_ParseTuple(args, "O:EnableReflectionKey", &obKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - /* Only available on 64bit platforms, so we must load it dynamically.*/ hMod = GetModuleHandleW(L"advapi32.dll"); @@ -1672,31 +1725,36 @@ return NULL; } Py_BEGIN_ALLOW_THREADS - rc = (*pfn)(hKey); + rc = (*pfn)(key); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnableReflectionKey"); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winreg.QueryReflectionKey + + key: HKEY + An already open key, or any one of the predefined HKEY_* constants. + / + +Returns the reflection state for the specified key as a bool. + +Will generally raise NotImplemented if executed on a 32bit OS. +[clinic start generated code]*/ + static PyObject * -PyQueryReflectionKey(PyObject *self, PyObject *args) +winreg_QueryReflectionKey_impl(PyModuleDef *module, HKEY key) +/*[clinic end generated code: output=2a49c564ca162e50 input=9f325eacb5a65d88]*/ { - HKEY hKey; - PyObject *obKey; HMODULE hMod; typedef LONG (WINAPI *RQRKFunc)(HKEY, BOOL *); RQRKFunc pfn = NULL; BOOL result; LONG rc; - if (!PyArg_ParseTuple(args, "O:QueryReflectionKey", &obKey)) - return NULL; - if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) - return NULL; - /* Only available on 64bit platforms, so we must load it dynamically.*/ hMod = GetModuleHandleW(L"advapi32.dll"); @@ -1709,7 +1767,7 @@ return NULL; } Py_BEGIN_ALLOW_THREADS - rc = (*pfn)(hKey, &result); + rc = (*pfn)(key, &result); Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, @@ -1718,34 +1776,29 @@ } static struct PyMethodDef winreg_methods[] = { - {"CloseKey", PyCloseKey, METH_VARARGS, CloseKey_doc}, - {"ConnectRegistry", PyConnectRegistry, METH_VARARGS, ConnectRegistry_doc}, - {"CreateKey", PyCreateKey, METH_VARARGS, CreateKey_doc}, - {"CreateKeyEx", (PyCFunction)PyCreateKeyEx, - METH_VARARGS | METH_KEYWORDS, CreateKeyEx_doc}, - {"DeleteKey", PyDeleteKey, METH_VARARGS, DeleteKey_doc}, - {"DeleteKeyEx", (PyCFunction)PyDeleteKeyEx, - METH_VARARGS | METH_KEYWORDS, DeleteKeyEx_doc}, - {"DeleteValue", PyDeleteValue, METH_VARARGS, DeleteValue_doc}, - {"DisableReflectionKey", PyDisableReflectionKey, METH_VARARGS, DisableReflectionKey_doc}, - {"EnableReflectionKey", PyEnableReflectionKey, METH_VARARGS, EnableReflectionKey_doc}, - {"EnumKey", PyEnumKey, METH_VARARGS, EnumKey_doc}, - {"EnumValue", PyEnumValue, METH_VARARGS, EnumValue_doc}, - {"ExpandEnvironmentStrings", PyExpandEnvironmentStrings, METH_VARARGS, - ExpandEnvironmentStrings_doc }, - {"FlushKey", PyFlushKey, METH_VARARGS, FlushKey_doc}, - {"LoadKey", PyLoadKey, METH_VARARGS, LoadKey_doc}, - {"OpenKey", (PyCFunction)PyOpenKey, METH_VARARGS | METH_KEYWORDS, - OpenKey_doc}, - {"OpenKeyEx", (PyCFunction)PyOpenKey, METH_VARARGS | METH_KEYWORDS, - OpenKeyEx_doc}, - {"QueryValue", PyQueryValue, METH_VARARGS, QueryValue_doc}, - {"QueryValueEx", PyQueryValueEx, METH_VARARGS, QueryValueEx_doc}, - {"QueryInfoKey", PyQueryInfoKey, METH_VARARGS, QueryInfoKey_doc}, - {"QueryReflectionKey",PyQueryReflectionKey,METH_VARARGS, QueryReflectionKey_doc}, - {"SaveKey", PySaveKey, METH_VARARGS, SaveKey_doc}, - {"SetValue", PySetValue, METH_VARARGS, SetValue_doc}, - {"SetValueEx", PySetValueEx, METH_VARARGS, SetValueEx_doc}, + WINREG_CLOSEKEY_METHODDEF + WINREG_CONNECTREGISTRY_METHODDEF + WINREG_CREATEKEY_METHODDEF + WINREG_CREATEKEYEX_METHODDEF + WINREG_DELETEKEY_METHODDEF + WINREG_DELETEKEYEX_METHODDEF + WINREG_DELETEVALUE_METHODDEF + WINREG_DISABLEREFLECTIONKEY_METHODDEF + WINREG_ENABLEREFLECTIONKEY_METHODDEF + WINREG_ENUMKEY_METHODDEF + WINREG_ENUMVALUE_METHODDEF + WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF + WINREG_FLUSHKEY_METHODDEF + WINREG_LOADKEY_METHODDEF + WINREG_OPENKEY_METHODDEF + WINREG_OPENKEYEX_METHODDEF + WINREG_QUERYVALUE_METHODDEF + WINREG_QUERYVALUEEX_METHODDEF + WINREG_QUERYINFOKEY_METHODDEF + WINREG_QUERYREFLECTIONKEY_METHODDEF + WINREG_SAVEKEY_METHODDEF + WINREG_SETVALUE_METHODDEF + WINREG_SETVALUEEX_METHODDEF NULL, }; diff -r 78a2d1169be1 -r 9ec35c653970 PC/winsound.c --- a/PC/winsound.c Tue Apr 14 11:21:26 2015 -0700 +++ b/PC/winsound.c Tue Apr 14 15:05:26 2015 -0500 @@ -39,22 +39,6 @@ #include #include -PyDoc_STRVAR(sound_playsound_doc, -"PlaySound(sound, flags) - a wrapper around the Windows PlaySound API\n" -"\n" -"The sound argument can be a filename, data, or None.\n" -"For flag values, ored together, see module documentation."); - -PyDoc_STRVAR(sound_beep_doc, -"Beep(frequency, duration) - a wrapper around the Windows Beep API\n" -"\n" -"The frequency argument specifies frequency, in hertz, of the sound.\n" -"This parameter must be in the range 37 through 32,767.\n" -"The duration argument specifies the number of milliseconds.\n"); - -PyDoc_STRVAR(sound_msgbeep_doc, -"MessageBeep(x) - call Windows MessageBeep(x). x defaults to MB_OK."); - PyDoc_STRVAR(sound_module_doc, "PlaySound(sound, flags) - play a sound\n" "SND_FILENAME - sound is a wav file name\n" @@ -67,79 +51,112 @@ "SND_NOSTOP - Do not interrupt any sounds currently playing\n" // Raising RuntimeError if needed "SND_NOWAIT - Return immediately if the sound driver is busy\n" // Without any errors "\n" -"Beep(frequency, duration) - Make a beep through the PC speaker."); +"Beep(frequency, duration) - Make a beep through the PC speaker.\n" +"MessageBeep(x) - Call Windows MessageBeep."); + +/*[clinic input] +module winsound +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a18401142d97b8d5]*/ + +#include "clinic/winsound.c.h" + +/*[clinic input] +winsound.PlaySound + + sound: Py_UNICODE(nullable=True) + The sound to play; a filename, data, or None. + flags: int + Flag values, ored together. See module documentation. + / + +A wrapper around the Windows PlaySound API. +[clinic start generated code]*/ static PyObject * -sound_playsound(PyObject *s, PyObject *args) +winsound_PlaySound_impl(PyModuleDef *module, Py_UNICODE *sound, int flags) +/*[clinic end generated code: output=614273784bf59e5c input=c86fab5d8e86f31d]*/ { - wchar_t *wsound; - int flags; int ok; - if (PyArg_ParseTuple(args, "Zi:PlaySound", &wsound, &flags)) { - if (flags & SND_ASYNC && flags & SND_MEMORY) { - /* Sidestep reference counting headache; unfortunately this also - prevent SND_LOOP from memory. */ - PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously from memory"); - return NULL; - } - Py_BEGIN_ALLOW_THREADS - ok = PlaySoundW(wsound, NULL, flags); - Py_END_ALLOW_THREADS - if (!ok) { - PyErr_SetString(PyExc_RuntimeError, "Failed to play sound"); - return NULL; - } - Py_INCREF(Py_None); - return Py_None; + if (flags & SND_ASYNC && flags & SND_MEMORY) { + /* Sidestep reference counting headache; unfortunately this also + prevent SND_LOOP from memory. */ + PyErr_SetString(PyExc_RuntimeError, + "Cannot play asynchronously from memory"); + return NULL; } - return NULL; + + Py_BEGIN_ALLOW_THREADS + ok = PlaySoundW(sound, NULL, flags); + Py_END_ALLOW_THREADS + if (!ok) { + PyErr_SetString(PyExc_RuntimeError, "Failed to play sound"); + return NULL; + } + Py_RETURN_NONE; } +/*[clinic input] +winsound.Beep + + frequency: int + Frequency of the sound in hertz. + Must be in the range 37 through 32,767. + duration: int + How long the sound should play, in milliseconds. + / + +A wrapper around the Windows Beep API. +[clinic start generated code]*/ + static PyObject * -sound_beep(PyObject *self, PyObject *args) +winsound_Beep_impl(PyModuleDef *module, int frequency, int duration) +/*[clinic end generated code: output=c75f282035a872bd input=628a99d2ddf73798]*/ { - int freq; - int dur; BOOL ok; - if (!PyArg_ParseTuple(args, "ii:Beep", &freq, &dur)) - return NULL; - - if (freq < 37 || freq > 32767) { + if (frequency < 37 || frequency > 32767) { PyErr_SetString(PyExc_ValueError, "frequency must be in 37 thru 32767"); return NULL; } Py_BEGIN_ALLOW_THREADS - ok = Beep(freq, dur); + ok = Beep(frequency, duration); Py_END_ALLOW_THREADS if (!ok) { PyErr_SetString(PyExc_RuntimeError,"Failed to beep"); return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } +/*[clinic input] +winsound.MessageBeep + + x: int(c_default="MB_OK") = MB_OK + / + +Call Windows MessageBeep(x). + +x defaults to MB_OK. +[clinic start generated code]*/ + static PyObject * -sound_msgbeep(PyObject *self, PyObject *args) +winsound_MessageBeep_impl(PyModuleDef *module, int x) +/*[clinic end generated code: output=92aa6a822bdc66ad input=a776c8a85c9853f6]*/ { - int x = MB_OK; - if (!PyArg_ParseTuple(args, "|i:MessageBeep", &x)) - return NULL; MessageBeep(x); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static struct PyMethodDef sound_methods[] = { - {"PlaySound", sound_playsound, METH_VARARGS, sound_playsound_doc}, - {"Beep", sound_beep, METH_VARARGS, sound_beep_doc}, - {"MessageBeep", sound_msgbeep, METH_VARARGS, sound_msgbeep_doc}, + WINSOUND_PLAYSOUND_METHODDEF + WINSOUND_BEEP_METHODDEF + WINSOUND_MESSAGEBEEP_METHODDEF {NULL, NULL} };