]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94512: Fix forced arg format in AC-processed multiprocessing (GH-94517)
authorOleg Iarygin <oleg@arhadthedev.net>
Mon, 4 Jul 2022 13:11:11 +0000 (16:11 +0300)
committerGitHub <noreply@github.com>
Mon, 4 Jul 2022 13:11:11 +0000 (14:11 +0100)
Modules/_multiprocessing/clinic/multiprocessing.c.h
Modules/_multiprocessing/multiprocessing.c

index e9953215aca7dfaa6501d810b90375522fcc3408..3a30833904792d4df959f4cfc23364ba57070b8b 100644 (file)
@@ -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 @@ exit:
 #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]*/
index 0809c2455dbebc1098e90f0f1137e74d189c8809..ed89a1e29a433fd8644ca6e221455eaf798dd399 100644 (file)
@@ -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