@@ -678,9 +678,11 @@ internal_select(PySocketSockObject *s, int writing)
678678
679679 /* See if the socket is ready */
680680 if (writing )
681- n = select (s -> sock_fd + 1 , NULL , & fds , NULL , & tv );
681+ n = select (Py_SAFE_DOWNCAST (s -> sock_fd + 1 , SOCKET_T , int ),
682+ NULL , & fds , NULL , & tv );
682683 else
683- n = select (s -> sock_fd + 1 , & fds , NULL , NULL , & tv );
684+ n = select (Py_SAFE_DOWNCAST (s -> sock_fd + 1 , SOCKET_T , int ),
685+ & fds , NULL , NULL , & tv );
684686 }
685687#endif
686688
@@ -937,7 +939,7 @@ makebdaddr(bdaddr_t *bdaddr)
937939
938940/*ARGSUSED*/
939941static PyObject *
940- makesockaddr (int sockfd , struct sockaddr * addr , int addrlen , int proto )
942+ makesockaddr (SOCKET_T sockfd , struct sockaddr * addr , size_t addrlen , int proto )
941943{
942944 if (addrlen == 0 ) {
943945 /* No address -- may be recvfrom() from known socket */
@@ -1893,7 +1895,8 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
18931895 FD_SET (s -> sock_fd , & fds );
18941896 FD_ZERO (& fds_exc );
18951897 FD_SET (s -> sock_fd , & fds_exc );
1896- res = select (s -> sock_fd + 1 , NULL , & fds , & fds_exc , & tv );
1898+ res = select (Py_SAFE_DOWNCAST (s -> sock_fd + 1 , SOCKET_T , int ),
1899+ NULL , & fds , & fds_exc , & tv );
18971900 if (res == 0 ) {
18981901 res = WSAEWOULDBLOCK ;
18991902 timeout = 1 ;
@@ -2136,10 +2139,10 @@ will allow before refusing new connections.");
21362139 * also possible that we return a number of bytes smaller than the request
21372140 * bytes.
21382141 */
2139- static ssize_t
2140- sock_recv_guts (PySocketSockObject * s , char * cbuf , int len , int flags )
2142+ static Py_ssize_t
2143+ sock_recv_guts (PySocketSockObject * s , char * cbuf , Py_ssize_t len , int flags )
21412144{
2142- ssize_t outlen = -1 ;
2145+ Py_ssize_t outlen = -1 ;
21432146 int timeout ;
21442147#ifdef __VMS
21452148 int remaining ;
@@ -2221,11 +2224,11 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
22212224static PyObject *
22222225sock_recv (PySocketSockObject * s , PyObject * args )
22232226{
2224- int recvlen , flags = 0 ;
2225- ssize_t outlen ;
2227+ Py_ssize_t recvlen , outlen ;
2228+ int flags = 0 ;
22262229 PyObject * buf ;
22272230
2228- if (!PyArg_ParseTuple (args , "i |i:recv" , & recvlen , & flags ))
2231+ if (!PyArg_ParseTuple (args , "n |i:recv" , & recvlen , & flags ))
22292232 return NULL ;
22302233
22312234 if (recvlen < 0 ) {
@@ -2272,14 +2275,13 @@ sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds)
22722275{
22732276 static char * kwlist [] = {"buffer" , "nbytes" , "flags" , 0 };
22742277
2275- int recvlen = 0 , flags = 0 ;
2276- ssize_t readlen ;
2278+ int flags = 0 ;
22772279 Py_buffer pbuf ;
22782280 char * buf ;
2279- int buflen ;
2281+ Py_ssize_t buflen , readlen , recvlen = 0 ;
22802282
22812283 /* Get the buffer's memory */
2282- if (!PyArg_ParseTupleAndKeywords (args , kwds , "w*|ii :recv_into" , kwlist ,
2284+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "w*|ni :recv_into" , kwlist ,
22832285 & pbuf , & recvlen , & flags ))
22842286 return NULL ;
22852287 buf = pbuf .buf ;
@@ -2339,13 +2341,13 @@ See recv() for documentation about the flags.");
23392341 * 'addr' is a return value for the address object. Note that you must decref
23402342 * it yourself.
23412343 */
2342- static ssize_t
2343- sock_recvfrom_guts (PySocketSockObject * s , char * cbuf , int len , int flags ,
2344+ static Py_ssize_t
2345+ sock_recvfrom_guts (PySocketSockObject * s , char * cbuf , Py_ssize_t len , int flags ,
23442346 PyObject * * addr )
23452347{
23462348 sock_addr_t addrbuf ;
23472349 int timeout ;
2348- ssize_t n = -1 ;
2350+ Py_ssize_t n = -1 ;
23492351 socklen_t addrlen ;
23502352
23512353 * addr = NULL ;
@@ -2401,10 +2403,10 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
24012403 PyObject * buf = NULL ;
24022404 PyObject * addr = NULL ;
24032405 PyObject * ret = NULL ;
2404- int recvlen , flags = 0 ;
2405- ssize_t outlen ;
2406+ int flags = 0 ;
2407+ Py_ssize_t recvlen , outlen ;
24062408
2407- if (!PyArg_ParseTuple (args , "i |i:recvfrom" , & recvlen , & flags ))
2409+ if (!PyArg_ParseTuple (args , "n |i:recvfrom" , & recvlen , & flags ))
24082410 return NULL ;
24092411
24102412 if (recvlen < 0 ) {
@@ -2452,15 +2454,14 @@ sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
24522454{
24532455 static char * kwlist [] = {"buffer" , "nbytes" , "flags" , 0 };
24542456
2455- int recvlen = 0 , flags = 0 ;
2456- ssize_t readlen ;
2457+ int flags = 0 ;
24572458 Py_buffer pbuf ;
24582459 char * buf ;
2459- int buflen ;
2460+ Py_ssize_t readlen , buflen , recvlen = 0 ;
24602461
24612462 PyObject * addr = NULL ;
24622463
2463- if (!PyArg_ParseTupleAndKeywords (args , kwds , "w*|ii :recvfrom_into" ,
2464+ if (!PyArg_ParseTupleAndKeywords (args , kwds , "w*|ni :recvfrom_into" ,
24642465 kwlist , & pbuf ,
24652466 & recvlen , & flags ))
24662467 return NULL ;
@@ -2490,7 +2491,7 @@ sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
24902491 PyBuffer_Release (& pbuf );
24912492 /* Return the number of bytes read and the address. Note that we do
24922493 not do anything special here in the case that readlen < recvlen. */
2493- return Py_BuildValue ("lN " , readlen , addr );
2494+ return Py_BuildValue ("nN " , readlen , addr );
24942495}
24952496
24962497PyDoc_STRVAR (recvfrom_into_doc ,
@@ -2505,7 +2506,8 @@ static PyObject *
25052506sock_send (PySocketSockObject * s , PyObject * args )
25062507{
25072508 char * buf ;
2508- int len , n = -1 , flags = 0 , timeout ;
2509+ Py_ssize_t len , n = -1 ;
2510+ int flags = 0 , timeout ;
25092511 Py_buffer pbuf ;
25102512
25112513 if (!PyArg_ParseTuple (args , "y*|i:send" , & pbuf , & flags ))
@@ -2536,7 +2538,7 @@ sock_send(PySocketSockObject *s, PyObject *args)
25362538 }
25372539 if (n < 0 )
25382540 return s -> errorhandler ();
2539- return PyLong_FromLong (( long ) n );
2541+ return PyLong_FromSsize_t ( n );
25402542}
25412543
25422544PyDoc_STRVAR (send_doc ,
@@ -2553,7 +2555,8 @@ static PyObject *
25532555sock_sendall (PySocketSockObject * s , PyObject * args )
25542556{
25552557 char * buf ;
2556- int len , n = -1 , flags = 0 , timeout ;
2558+ Py_ssize_t len , n = -1 ;
2559+ int flags = 0 , timeout ;
25572560 Py_buffer pbuf ;
25582561
25592562 if (!PyArg_ParseTuple (args , "y*|i:sendall" , & pbuf , & flags ))
@@ -2650,7 +2653,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
26502653 }
26512654 if (n < 0 )
26522655 return s -> errorhandler ();
2653- return PyLong_FromLong (( long ) n );
2656+ return PyLong_FromSsize_t ( n );
26542657}
26552658
26562659PyDoc_STRVAR (sendto_doc ,
@@ -3942,7 +3945,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
39423945 }
39433946#endif
39443947 }
3945- error = getnameinfo (res -> ai_addr , res -> ai_addrlen ,
3948+ error = getnameinfo (res -> ai_addr , ( socklen_t ) res -> ai_addrlen ,
39463949 hbuf , sizeof (hbuf ), pbuf , sizeof (pbuf ), flags );
39473950 if (error ) {
39483951 set_gaierror (error );
0 commit comments