diff Modules/socketmodule.c @ 80962:39803c20c9bf 2.7

#8853: Allow port to be of type long for socket.getaddrinfo()
author Petri Lehtinen <petri@digip.org>
date Thu, 20 Dec 2012 21:06:14 +0200
parents b7d4a13c736e
children d544873d62e9
line wrap: on
line diff
--- a/Modules/socketmodule.c	Thu Dec 20 12:55:52 2012 -0600
+++ b/Modules/socketmodule.c	Thu Dec 20 21:06:14 2012 +0200
@@ -4090,15 +4090,19 @@
                         "getaddrinfo() argument 1 must be string or None");
         return NULL;
     }
-    if (PyInt_Check(pobj)) {
-        PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
+    if (PyInt_Check(pobj) || PyLong_Check(pobj)) {
+        long value = PyLong_AsLong(pobj);
+        if (value == -1 && PyErr_Occurred())
+            return NULL;
+        PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
         pptr = pbuf;
     } else if (PyString_Check(pobj)) {
         pptr = PyString_AsString(pobj);
     } else if (pobj == Py_None) {
         pptr = (char *)NULL;
     } else {
-        PyErr_SetString(socket_error, "Int or String expected");
+        PyErr_SetString(socket_error,
+                        "getaddrinfo() argument 2 must be integer or string");
         goto err;
     }
     memset(&hints, 0, sizeof(hints));