From 2e7ddb3f77d90d1f995a2ac6e8665d97f3cd0463 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sun, 3 Jul 2022 00:32:56 +0300 Subject: [PATCH 1/3] Fix forced arg format in AC-processed multiprocessing --- .../clinic/multiprocessing.c.h | 30 +++++++++++++++---- Modules/_multiprocessing/multiprocessing.c | 10 ++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Modules/_multiprocessing/clinic/multiprocessing.c.h b/Modules/_multiprocessing/clinic/multiprocessing.c.h index e9953215aca7df..3a30833904792d 100644 --- a/Modules/_multiprocessing/clinic/multiprocessing.c.h +++ b/Modules/_multiprocessing/clinic/multiprocessing.c.h @@ -21,7 +21,8 @@ _multiprocessing_closesocket(PyObject *module, PyObject *arg) PyObject *return_value = NULL; HANDLE handle; - if (!PyArg_Parse(arg, ""F_HANDLE":closesocket", &handle)) { + handle = PyLong_AsVoidPtr(arg); + if (!handle && PyErr_Occurred()) { goto exit; } return_value = _multiprocessing_closesocket_impl(module, handle); @@ -52,8 +53,15 @@ _multiprocessing_recv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HANDLE handle; int size; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"i:recv", - &handle, &size)) { + if (!_PyArg_CheckPositional("recv", nargs, 2, 2)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + size = _PyLong_AsInt(args[1]); + if (size == -1 && PyErr_Occurred()) { goto exit; } return_value = _multiprocessing_recv_impl(module, handle, size); @@ -84,8 +92,18 @@ _multiprocessing_send(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HANDLE handle; Py_buffer buf = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*:send", - &handle, &buf)) { + if (!_PyArg_CheckPositional("send", nargs, 2, 2)) { + goto exit; + } + handle = PyLong_AsVoidPtr(args[0]); + if (!handle && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &buf, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&buf, 'C')) { + _PyArg_BadArgument("send", "argument 2", "contiguous buffer", args[1]); goto exit; } return_value = _multiprocessing_send_impl(module, handle, &buf); @@ -148,4 +166,4 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg) #ifndef _MULTIPROCESSING_SEND_METHODDEF #define _MULTIPROCESSING_SEND_METHODDEF #endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */ -/*[clinic end generated code: output=d3bbf69de578db7b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ab64ce752f933c55 input=a9049054013a1b77]*/ diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c index 0809c2455dbebc..ed89a1e29a433f 100644 --- a/Modules/_multiprocessing/multiprocessing.c +++ b/Modules/_multiprocessing/multiprocessing.c @@ -14,8 +14,16 @@ class HANDLE_converter(CConverter): type = "HANDLE" format_unit = '"F_HANDLE"' + def parse_arg(self, argname, displayname): + return """ + {paramname} = PyLong_AsVoidPtr({argname}); + if (!{paramname} && PyErr_Occurred()) {{{{ + goto exit; + }}}} + """.format(argname=argname, paramname=self.parser_name) + [python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=9fad6080b79ace91]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=3e537d244034affb]*/ /*[clinic input] module _multiprocessing From f4591329487d94cbf694fb89ccbeb51e0d754cd4 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sun, 3 Jul 2022 23:11:40 +0300 Subject: [PATCH 2/3] Add a NEWS entry --- .../next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst diff --git a/Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst b/Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst new file mode 100644 index 00000000000000..ec56953d1a118f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst @@ -0,0 +1 @@ +Convert :mod:`multiprocessing` to use Argument Clinic. From 4a8a05341cb8375a0c8985e9fbd2072ab4f34856 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Mon, 4 Jul 2022 15:16:16 +0300 Subject: [PATCH 3/3] Revert "Add a NEWS entry" This reverts commit f4591329487d94cbf694fb89ccbeb51e0d754cd4. --- .../next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst diff --git a/Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst b/Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst deleted file mode 100644 index ec56953d1a118f..00000000000000 --- a/Misc/NEWS.d/next/Library/2022-07-03-23-11-27.gh-issue-94512.x9nqmv.rst +++ /dev/null @@ -1 +0,0 @@ -Convert :mod:`multiprocessing` to use Argument Clinic.