diff options
author | Oleg Iarygin <oleg@arhadthedev.net> | 2022-07-28 22:09:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 22:09:46 (GMT) |
commit | 26d4af0ba538ea58d7a7fdbcc4471d9b32689b28 (patch) | |
tree | 158d7868cdb4987215d3524a3f8a2fdf4fc4ed62 | |
parent | 38bb2068fe1f51a74b36c46e820abc5f6422cded (diff) | |
download | cpython-26d4af0ba538ea58d7a7fdbcc4471d9b32689b28.zip cpython-26d4af0ba538ea58d7a7fdbcc4471d9b32689b28.tar.gz cpython-26d4af0ba538ea58d7a7fdbcc4471d9b32689b28.tar.bz2 |
gh-94512: Fix forced arg format in AC-processed overlapped (GH-94516)
-rw-r--r-- | Modules/clinic/overlapped.c.h | 371 | ||||
-rw-r--r-- | Modules/overlapped.c | 28 |
2 files changed, 335 insertions, 64 deletions
diff --git a/Modules/clinic/overlapped.c.h b/Modules/clinic/overlapped.c.h index cac44d0..721b38c 100644 --- a/Modules/clinic/overlapped.c.h +++ b/Modules/clinic/overlapped.c.h @@ -26,8 +26,22 @@ _overlapped_CreateIoCompletionPort(PyObject *module, PyObject *const *args, Py_s ULONG_PTR CompletionKey; DWORD NumberOfConcurrentThreads; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE""F_HANDLE""F_ULONG_PTR"k:CreateIoCompletionPort", - &FileHandle, &ExistingCompletionPort, &CompletionKey, &NumberOfConcurrentThreads)) { + if (!_PyArg_CheckPositional("CreateIoCompletionPort", nargs, 4, 4)) { + goto exit; + } + FileHandle = PyLong_AsVoidPtr(args[0]); + if (!FileHandle && PyErr_Occurred()) { + goto exit; + } + ExistingCompletionPort = PyLong_AsVoidPtr(args[1]); + if (!ExistingCompletionPort && PyErr_Occurred()) { + goto exit; + } + CompletionKey = PyLong_AsVoidPtr(args[2]); + if (!CompletionKey && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[3], &NumberOfConcurrentThreads)) { goto exit; } return_value = _overlapped_CreateIoCompletionPort_impl(module, FileHandle, ExistingCompletionPort, CompletionKey, NumberOfConcurrentThreads); @@ -59,8 +73,14 @@ _overlapped_GetQueuedCompletionStatus(PyObject *module, PyObject *const *args, P HANDLE CompletionPort; DWORD Milliseconds; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"k:GetQueuedCompletionStatus", - &CompletionPort, &Milliseconds)) { + if (!_PyArg_CheckPositional("GetQueuedCompletionStatus", nargs, 2, 2)) { + goto exit; + } + CompletionPort = PyLong_AsVoidPtr(args[0]); + if (!CompletionPort && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &Milliseconds)) { goto exit; } return_value = _overlapped_GetQueuedCompletionStatus_impl(module, CompletionPort, Milliseconds); @@ -94,8 +114,22 @@ _overlapped_PostQueuedCompletionStatus(PyObject *module, PyObject *const *args, ULONG_PTR CompletionKey; OVERLAPPED *Overlapped; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"k"F_ULONG_PTR""F_POINTER":PostQueuedCompletionStatus", - &CompletionPort, &NumberOfBytes, &CompletionKey, &Overlapped)) { + if (!_PyArg_CheckPositional("PostQueuedCompletionStatus", nargs, 4, 4)) { + goto exit; + } + CompletionPort = PyLong_AsVoidPtr(args[0]); + if (!CompletionPort && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &NumberOfBytes)) { + goto exit; + } + CompletionKey = PyLong_AsVoidPtr(args[2]); + if (!CompletionKey && PyErr_Occurred()) { + goto exit; + } + Overlapped = PyLong_AsVoidPtr(args[3]); + if (!Overlapped && PyErr_Occurred()) { goto exit; } return_value = _overlapped_PostQueuedCompletionStatus_impl(module, CompletionPort, NumberOfBytes, CompletionKey, Overlapped); @@ -129,8 +163,22 @@ _overlapped_RegisterWaitWithQueue(PyObject *module, PyObject *const *args, Py_ss OVERLAPPED *Overlapped; DWORD Milliseconds; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE""F_HANDLE""F_POINTER"k:RegisterWaitWithQueue", - &Object, &CompletionPort, &Overlapped, &Milliseconds)) { + if (!_PyArg_CheckPositional("RegisterWaitWithQueue", nargs, 4, 4)) { + goto exit; + } + Object = PyLong_AsVoidPtr(args[0]); + if (!Object && PyErr_Occurred()) { + goto exit; + } + CompletionPort = PyLong_AsVoidPtr(args[1]); + if (!CompletionPort && PyErr_Occurred()) { + goto exit; + } + Overlapped = PyLong_AsVoidPtr(args[2]); + if (!Overlapped && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[3], &Milliseconds)) { goto exit; } return_value = _overlapped_RegisterWaitWithQueue_impl(module, Object, CompletionPort, Overlapped, Milliseconds); @@ -157,7 +205,8 @@ _overlapped_UnregisterWait(PyObject *module, PyObject *arg) PyObject *return_value = NULL; HANDLE WaitHandle; - if (!PyArg_Parse(arg, ""F_HANDLE":UnregisterWait", &WaitHandle)) { + WaitHandle = PyLong_AsVoidPtr(arg); + if (!WaitHandle && PyErr_Occurred()) { goto exit; } return_value = _overlapped_UnregisterWait_impl(module, WaitHandle); @@ -186,8 +235,15 @@ _overlapped_UnregisterWaitEx(PyObject *module, PyObject *const *args, Py_ssize_t HANDLE WaitHandle; HANDLE Event; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE""F_HANDLE":UnregisterWaitEx", - &WaitHandle, &Event)) { + if (!_PyArg_CheckPositional("UnregisterWaitEx", nargs, 2, 2)) { + goto exit; + } + WaitHandle = PyLong_AsVoidPtr(args[0]); + if (!WaitHandle && PyErr_Occurred()) { + goto exit; + } + Event = PyLong_AsVoidPtr(args[1]); + if (!Event && PyErr_Occurred()) { goto exit; } return_value = _overlapped_UnregisterWaitEx_impl(module, WaitHandle, Event); @@ -222,8 +278,29 @@ _overlapped_CreateEvent(PyObject *module, PyObject *const *args, Py_ssize_t narg BOOL InitialState; const Py_UNICODE *Name; - if (!_PyArg_ParseStack(args, nargs, "OiiO&:CreateEvent", - &EventAttributes, &ManualReset, &InitialState, _PyUnicode_WideCharString_Opt_Converter, &Name)) { + if (!_PyArg_CheckPositional("CreateEvent", nargs, 4, 4)) { + goto exit; + } + EventAttributes = args[0]; + ManualReset = _PyLong_AsInt(args[1]); + if (ManualReset == -1 && PyErr_Occurred()) { + goto exit; + } + InitialState = _PyLong_AsInt(args[2]); + if (InitialState == -1 && PyErr_Occurred()) { + goto exit; + } + if (args[3] == Py_None) { + Name = NULL; + } + else if (PyUnicode_Check(args[3])) { + Name = PyUnicode_AsWideCharString(args[3], NULL); + if (Name == NULL) { + goto exit; + } + } + else { + _PyArg_BadArgument("CreateEvent", "argument 4", "str or None", args[3]); goto exit; } return_value = _overlapped_CreateEvent_impl(module, EventAttributes, ManualReset, InitialState, Name); @@ -253,7 +330,8 @@ _overlapped_SetEvent(PyObject *module, PyObject *arg) PyObject *return_value = NULL; HANDLE Handle; - if (!PyArg_Parse(arg, ""F_HANDLE":SetEvent", &Handle)) { + Handle = PyLong_AsVoidPtr(arg); + if (!Handle && PyErr_Occurred()) { goto exit; } return_value = _overlapped_SetEvent_impl(module, Handle); @@ -280,7 +358,8 @@ _overlapped_ResetEvent(PyObject *module, PyObject *arg) PyObject *return_value = NULL; HANDLE Handle; - if (!PyArg_Parse(arg, ""F_HANDLE":ResetEvent", &Handle)) { + Handle = PyLong_AsVoidPtr(arg); + if (!Handle && PyErr_Occurred()) { goto exit; } return_value = _overlapped_ResetEvent_impl(module, Handle); @@ -310,8 +389,15 @@ _overlapped_BindLocal(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HANDLE Socket; int Family; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"i:BindLocal", - &Socket, &Family)) { + if (!_PyArg_CheckPositional("BindLocal", nargs, 2, 2)) { + goto exit; + } + Socket = PyLong_AsVoidPtr(args[0]); + if (!Socket && PyErr_Occurred()) { + goto exit; + } + Family = _PyLong_AsInt(args[1]); + if (Family == -1 && PyErr_Occurred()) { goto exit; } return_value = _overlapped_BindLocal_impl(module, Socket, Family); @@ -338,7 +424,7 @@ _overlapped_FormatMessage(PyObject *module, PyObject *arg) PyObject *return_value = NULL; DWORD code; - if (!PyArg_Parse(arg, "k:FormatMessage", &code)) { + if (!_PyLong_UnsignedLong_Converter(arg, &code)) { goto exit; } return_value = _overlapped_FormatMessage_impl(module, code); @@ -361,13 +447,25 @@ _overlapped_Overlapped(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static const char * const _keywords[] = {"event", NULL}; - static _PyArg_Parser _parser = {"|"F_HANDLE":Overlapped", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "Overlapped", 0}; + PyObject *argsbuf[1]; + PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); + Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; HANDLE event = INVALID_HANDLE_VALUE; - if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, - &event)) { + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf); + if (!fastargs) { + goto exit; + } + if (!noptargs) { + goto skip_optional_pos; + } + event = PyLong_AsVoidPtr(fastargs[0]); + if (!event && PyErr_Occurred()) { goto exit; } +skip_optional_pos: return_value = _overlapped_Overlapped_impl(type, event); exit: @@ -413,10 +511,17 @@ _overlapped_Overlapped_getresult(OverlappedObject *self, PyObject *const *args, PyObject *return_value = NULL; BOOL wait = FALSE; - if (!_PyArg_ParseStack(args, nargs, "|i:getresult", - &wait)) { + if (!_PyArg_CheckPositional("getresult", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + wait = _PyLong_AsInt(args[0]); + if (wait == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _overlapped_Overlapped_getresult_impl(self, wait); exit: @@ -443,8 +548,14 @@ _overlapped_Overlapped_ReadFile(OverlappedObject *self, PyObject *const *args, P HANDLE handle; DWORD size; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"k:ReadFile", - &handle, &size)) { + if (!_PyArg_CheckPositional("ReadFile", nargs, 2, 2)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &size)) { goto exit; } return_value = _overlapped_Overlapped_ReadFile_impl(self, handle, size); @@ -473,8 +584,18 @@ _overlapped_Overlapped_ReadFileInto(OverlappedObject *self, PyObject *const *arg HANDLE handle; Py_buffer bufobj = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*:ReadFileInto", - &handle, &bufobj)) { + if (!_PyArg_CheckPositional("ReadFileInto", nargs, 2, 2)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&bufobj, 'C')) { + _PyArg_BadArgument("ReadFileInto", "argument 2", "contiguous buffer", args[1]); goto exit; } return_value = _overlapped_Overlapped_ReadFileInto_impl(self, handle, &bufobj); @@ -509,10 +630,23 @@ _overlapped_Overlapped_WSARecv(OverlappedObject *self, PyObject *const *args, Py DWORD size; DWORD flags = 0; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"k|k:WSARecv", - &handle, &size, &flags)) { + if (!_PyArg_CheckPositional("WSARecv", nargs, 2, 3)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &size)) { goto exit; } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) { + goto exit; + } +skip_optional: return_value = _overlapped_Overlapped_WSARecv_impl(self, handle, size, flags); exit: @@ -541,8 +675,21 @@ _overlapped_Overlapped_WSARecvInto(OverlappedObject *self, PyObject *const *args Py_buffer bufobj = {NULL, NULL}; DWORD flags; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*k:WSARecvInto", - &handle, &bufobj, &flags)) { + if (!_PyArg_CheckPositional("WSARecvInto", nargs, 3, 3)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&bufobj, 'C')) { + _PyArg_BadArgument("WSARecvInto", "argument 2", "contiguous buffer", args[1]); + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) { goto exit; } return_value = _overlapped_Overlapped_WSARecvInto_impl(self, handle, &bufobj, flags); @@ -576,8 +723,18 @@ _overlapped_Overlapped_WriteFile(OverlappedObject *self, PyObject *const *args, HANDLE handle; Py_buffer bufobj = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*:WriteFile", - &handle, &bufobj)) { + if (!_PyArg_CheckPositional("WriteFile", nargs, 2, 2)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&bufobj, 'C')) { + _PyArg_BadArgument("WriteFile", "argument 2", "contiguous buffer", args[1]); goto exit; } return_value = _overlapped_Overlapped_WriteFile_impl(self, handle, &bufobj); @@ -612,8 +769,21 @@ _overlapped_Overlapped_WSASend(OverlappedObject *self, PyObject *const *args, Py Py_buffer bufobj = {NULL, NULL}; DWORD flags; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*k:WSASend", - &handle, &bufobj, &flags)) { + if (!_PyArg_CheckPositional("WSASend", nargs, 3, 3)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&bufobj, 'C')) { + _PyArg_BadArgument("WSASend", "argument 2", "contiguous buffer", args[1]); + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) { goto exit; } return_value = _overlapped_Overlapped_WSASend_impl(self, handle, &bufobj, flags); @@ -648,8 +818,15 @@ _overlapped_Overlapped_AcceptEx(OverlappedObject *self, PyObject *const *args, P HANDLE ListenSocket; HANDLE AcceptSocket; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE""F_HANDLE":AcceptEx", - &ListenSocket, &AcceptSocket)) { + if (!_PyArg_CheckPositional("AcceptEx", nargs, 2, 2)) { + goto exit; + } + ListenSocket = PyLong_AsVoidPtr(args[0]); + if (!ListenSocket && PyErr_Occurred()) { + goto exit; + } + AcceptSocket = PyLong_AsVoidPtr(args[1]); + if (!AcceptSocket && PyErr_Occurred()) { goto exit; } return_value = _overlapped_Overlapped_AcceptEx_impl(self, ListenSocket, AcceptSocket); @@ -681,10 +858,18 @@ _overlapped_Overlapped_ConnectEx(OverlappedObject *self, PyObject *const *args, HANDLE ConnectSocket; PyObject *AddressObj; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"O!:ConnectEx", - &ConnectSocket, &PyTuple_Type, &AddressObj)) { + if (!_PyArg_CheckPositional("ConnectEx", nargs, 2, 2)) { + goto exit; + } + ConnectSocket = PyLong_AsVoidPtr(args[0]); + if (!ConnectSocket && PyErr_Occurred()) { goto exit; } + if (!PyTuple_Check(args[1])) { + _PyArg_BadArgument("ConnectEx", "argument 2", "tuple", args[1]); + goto exit; + } + AddressObj = args[1]; return_value = _overlapped_Overlapped_ConnectEx_impl(self, ConnectSocket, AddressObj); exit: @@ -710,8 +895,14 @@ _overlapped_Overlapped_DisconnectEx(OverlappedObject *self, PyObject *const *arg HANDLE Socket; DWORD flags; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"k:DisconnectEx", - &Socket, &flags)) { + if (!_PyArg_CheckPositional("DisconnectEx", nargs, 2, 2)) { + goto exit; + } + Socket = PyLong_AsVoidPtr(args[0]); + if (!Socket && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &flags)) { goto exit; } return_value = _overlapped_Overlapped_DisconnectEx_impl(self, Socket, flags); @@ -749,8 +940,30 @@ _overlapped_Overlapped_TransmitFile(OverlappedObject *self, PyObject *const *arg DWORD count_per_send; DWORD flags; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE""F_HANDLE"kkkkk:TransmitFile", - &Socket, &File, &offset, &offset_high, &count_to_write, &count_per_send, &flags)) { + if (!_PyArg_CheckPositional("TransmitFile", nargs, 7, 7)) { + goto exit; + } + Socket = PyLong_AsVoidPtr(args[0]); + if (!Socket && PyErr_Occurred()) { + goto exit; + } + File = PyLong_AsVoidPtr(args[1]); + if (!File && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &offset)) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[3], &offset_high)) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[4], &count_to_write)) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[5], &count_per_send)) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[6], &flags)) { goto exit; } return_value = _overlapped_Overlapped_TransmitFile_impl(self, Socket, File, offset, offset_high, count_to_write, count_per_send, flags); @@ -778,7 +991,8 @@ _overlapped_Overlapped_ConnectNamedPipe(OverlappedObject *self, PyObject *arg) PyObject *return_value = NULL; HANDLE Pipe; - if (!PyArg_Parse(arg, ""F_HANDLE":ConnectNamedPipe", &Pipe)) { + Pipe = PyLong_AsVoidPtr(arg); + if (!Pipe && PyErr_Occurred()) { goto exit; } return_value = _overlapped_Overlapped_ConnectNamedPipe_impl(self, Pipe); @@ -843,10 +1057,14 @@ _overlapped_WSAConnect(PyObject *module, PyObject *const *args, Py_ssize_t nargs HANDLE ConnectSocket; PyObject *AddressObj; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"O:WSAConnect", - &ConnectSocket, &AddressObj)) { + if (!_PyArg_CheckPositional("WSAConnect", nargs, 2, 2)) { + goto exit; + } + ConnectSocket = PyLong_AsVoidPtr(args[0]); + if (!ConnectSocket && PyErr_Occurred()) { goto exit; } + AddressObj = args[1]; return_value = _overlapped_WSAConnect_impl(module, ConnectSocket, AddressObj); exit: @@ -876,10 +1094,24 @@ _overlapped_Overlapped_WSASendTo(OverlappedObject *self, PyObject *const *args, DWORD flags; PyObject *AddressObj; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*kO:WSASendTo", - &handle, &bufobj, &flags, &AddressObj)) { + if (!_PyArg_CheckPositional("WSASendTo", nargs, 4, 4)) { goto exit; } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&bufobj, 'C')) { + _PyArg_BadArgument("WSASendTo", "argument 2", "contiguous buffer", args[1]); + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) { + goto exit; + } + AddressObj = args[3]; return_value = _overlapped_Overlapped_WSASendTo_impl(self, handle, &bufobj, flags, AddressObj); exit: @@ -913,10 +1145,23 @@ _overlapped_Overlapped_WSARecvFrom(OverlappedObject *self, PyObject *const *args DWORD size; DWORD flags = 0; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"k|k:WSARecvFrom", - &handle, &size, &flags)) { + if (!_PyArg_CheckPositional("WSARecvFrom", nargs, 2, 3)) { goto exit; } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &size)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &flags)) { + goto exit; + } +skip_optional: return_value = _overlapped_Overlapped_WSARecvFrom_impl(self, handle, size, flags); exit: @@ -946,10 +1191,30 @@ _overlapped_Overlapped_WSARecvFromInto(OverlappedObject *self, PyObject *const * DWORD size; DWORD flags = 0; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*k|k:WSARecvFromInto", - &handle, &bufobj, &size, &flags)) { + if (!_PyArg_CheckPositional("WSARecvFromInto", nargs, 3, 4)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &bufobj, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&bufobj, 'C')) { + _PyArg_BadArgument("WSARecvFromInto", "argument 2", "contiguous buffer", args[1]); + goto exit; + } + if (!_PyLong_UnsignedLong_Converter(args[2], &size)) { + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (!_PyLong_UnsignedLong_Converter(args[3], &flags)) { goto exit; } +skip_optional: return_value = _overlapped_Overlapped_WSARecvFromInto_impl(self, handle, &bufobj, size, flags); exit: @@ -960,4 +1225,4 @@ exit: return return_value; } -/*[clinic end generated code: output=9078d9f9984864a2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d90cda84e49a7c23 input=a9049054013a1b77]*/ diff --git a/Modules/overlapped.c b/Modules/overlapped.c index 19d25a5..0cec9ee 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -32,27 +32,33 @@ #define T_HANDLE T_POINTER /*[python input] -class OVERLAPPED_converter(CConverter): - type = 'OVERLAPPED *' +class pointer_converter(CConverter): format_unit = '"F_POINTER"' -class HANDLE_converter(CConverter): + def parse_arg(self, argname, displayname): + return """ + {paramname} = PyLong_AsVoidPtr({argname}); + if (!{paramname} && PyErr_Occurred()) {{{{ + goto exit; + }}}} + """.format(argname=argname, paramname=self.parser_name) + +class OVERLAPPED_converter(pointer_converter): + type = 'OVERLAPPED *' + +class HANDLE_converter(pointer_converter): type = 'HANDLE' - format_unit = '"F_HANDLE"' -class ULONG_PTR_converter(CConverter): +class ULONG_PTR_converter(pointer_converter): type = 'ULONG_PTR' - format_unit = '"F_ULONG_PTR"' -class DWORD_converter(CConverter): +class DWORD_converter(unsigned_long_converter): type = 'DWORD' - format_unit = 'k' -class BOOL_converter(CConverter): +class BOOL_converter(int_converter): type = 'BOOL' - format_unit = 'i' [python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=83bb8c2c2514f2a8]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=a19133a9e14fae9c]*/ /*[clinic input] module _overlapped |