[Python-checkins] cpython (merge 3.2 -> default): Issue #5421: merge fix

antoine.pitrou python-checkins at python.org
Thu Mar 17 22:46:56 CET 2011


http://hg.python.org/cpython/rev/90cdc371a3b8
changeset:   68661:90cdc371a3b8
parent:      68658:8945e087a5a6
parent:      68660:2af7a6d765fd
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Thu Mar 17 22:46:17 2011 +0100
summary:
  Issue #5421: merge fix

files:
  Misc/ACKS
  Misc/NEWS
  Modules/socketmodule.c

diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -72,6 +72,9 @@
 Library
 -------
 
+- Issue #5421: Fix misleading error message when one of socket.sendto()'s
+  arguments has the wrong type.  Patch by Nikita Vetoshkin.
+
 - Issue #10812: Add some extra posix functions to the os module.
 
 - Issue #10979: unittest stdout buffering now works with class and module
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2747,17 +2747,28 @@
     Py_buffer pbuf;
     PyObject *addro;
     char *buf;
-    Py_ssize_t len;
+    Py_ssize_t len, arglen;
     sock_addr_t addrbuf;
     int addrlen, n = -1, flags, timeout;
 
     flags = 0;
-    if (!PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro)) {
-        PyErr_Clear();
-        if (!PyArg_ParseTuple(args, "y*iO:sendto",
-                              &pbuf, &flags, &addro))
-            return NULL;
+    arglen = PyTuple_Size(args);
+    switch (arglen) {
+        case 2:
+            PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro);
+            break;
+        case 3:
+            PyArg_ParseTuple(args, "y*iO:sendto",
+                             &pbuf, &flags, &addro);
+            break;
+        default:
+            PyErr_Format(PyExc_TypeError,
+                         "sendto() takes 2 or 3 arguments (%d given)",
+                         arglen);
     }
+    if (PyErr_Occurred())
+        return NULL;
+
     buf = pbuf.buf;
     len = pbuf.len;
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list