Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19467d2

Browse files
committed
Clean some 64-bit issues. Also, always spell "ssize_t" "Py_ssize_t".
1 parent 3fccfcb commit 19467d2

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

Modules/socketmodule.c

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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*/
939941
static 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 */
@@ -1908,7 +1910,8 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen,
19081910
FD_SET(s->sock_fd, &fds);
19091911
FD_ZERO(&fds_exc);
19101912
FD_SET(s->sock_fd, &fds_exc);
1911-
res = select(s->sock_fd+1, NULL, &fds, &fds_exc, &tv);
1913+
res = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int),
1914+
NULL, &fds, &fds_exc, &tv);
19121915
if (res == 0) {
19131916
res = WSAEWOULDBLOCK;
19141917
timeout = 1;
@@ -2151,10 +2154,10 @@ will allow before refusing new connections.");
21512154
* also possible that we return a number of bytes smaller than the request
21522155
* bytes.
21532156
*/
2154-
static ssize_t
2155-
sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
2157+
static Py_ssize_t
2158+
sock_recv_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags)
21562159
{
2157-
ssize_t outlen = -1;
2160+
Py_ssize_t outlen = -1;
21582161
int timeout;
21592162
#ifdef __VMS
21602163
int remaining;
@@ -2236,11 +2239,11 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
22362239
static PyObject *
22372240
sock_recv(PySocketSockObject *s, PyObject *args)
22382241
{
2239-
int recvlen, flags = 0;
2240-
ssize_t outlen;
2242+
Py_ssize_t recvlen, outlen;
2243+
int flags = 0;
22412244
PyObject *buf;
22422245

2243-
if (!PyArg_ParseTuple(args, "i|i:recv", &recvlen, &flags))
2246+
if (!PyArg_ParseTuple(args, "n|i:recv", &recvlen, &flags))
22442247
return NULL;
22452248

22462249
if (recvlen < 0) {
@@ -2287,14 +2290,13 @@ sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds)
22872290
{
22882291
static char *kwlist[] = {"buffer", "nbytes", "flags", 0};
22892292

2290-
int recvlen = 0, flags = 0;
2291-
ssize_t readlen;
2293+
int flags = 0;
22922294
Py_buffer pbuf;
22932295
char *buf;
2294-
int buflen;
2296+
Py_ssize_t buflen, readlen, recvlen = 0;
22952297

22962298
/* Get the buffer's memory */
2297-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recv_into", kwlist,
2299+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ni:recv_into", kwlist,
22982300
&pbuf, &recvlen, &flags))
22992301
return NULL;
23002302
buf = pbuf.buf;
@@ -2354,13 +2356,13 @@ See recv() for documentation about the flags.");
23542356
* 'addr' is a return value for the address object. Note that you must decref
23552357
* it yourself.
23562358
*/
2357-
static ssize_t
2358-
sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags,
2359+
static Py_ssize_t
2360+
sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags,
23592361
PyObject** addr)
23602362
{
23612363
sock_addr_t addrbuf;
23622364
int timeout;
2363-
ssize_t n = -1;
2365+
Py_ssize_t n = -1;
23642366
socklen_t addrlen;
23652367

23662368
*addr = NULL;
@@ -2416,10 +2418,10 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
24162418
PyObject *buf = NULL;
24172419
PyObject *addr = NULL;
24182420
PyObject *ret = NULL;
2419-
int recvlen, flags = 0;
2420-
ssize_t outlen;
2421+
int flags = 0;
2422+
Py_ssize_t recvlen, outlen;
24212423

2422-
if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
2424+
if (!PyArg_ParseTuple(args, "n|i:recvfrom", &recvlen, &flags))
24232425
return NULL;
24242426

24252427
if (recvlen < 0) {
@@ -2467,15 +2469,14 @@ sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
24672469
{
24682470
static char *kwlist[] = {"buffer", "nbytes", "flags", 0};
24692471

2470-
int recvlen = 0, flags = 0;
2471-
ssize_t readlen;
2472+
int flags = 0;
24722473
Py_buffer pbuf;
24732474
char *buf;
2474-
int buflen;
2475+
Py_ssize_t readlen, buflen, recvlen = 0;
24752476

24762477
PyObject *addr = NULL;
24772478

2478-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recvfrom_into",
2479+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ni:recvfrom_into",
24792480
kwlist, &pbuf,
24802481
&recvlen, &flags))
24812482
return NULL;
@@ -2505,7 +2506,7 @@ sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
25052506
PyBuffer_Release(&pbuf);
25062507
/* Return the number of bytes read and the address. Note that we do
25072508
not do anything special here in the case that readlen < recvlen. */
2508-
return Py_BuildValue("lN", readlen, addr);
2509+
return Py_BuildValue("nN", readlen, addr);
25092510
}
25102511

25112512
PyDoc_STRVAR(recvfrom_into_doc,
@@ -2520,7 +2521,8 @@ static PyObject *
25202521
sock_send(PySocketSockObject *s, PyObject *args)
25212522
{
25222523
char *buf;
2523-
int len, n = -1, flags = 0, timeout;
2524+
Py_ssize_t len, n = -1;
2525+
int flags = 0, timeout;
25242526
Py_buffer pbuf;
25252527

25262528
if (!PyArg_ParseTuple(args, "y*|i:send", &pbuf, &flags))
@@ -2551,7 +2553,7 @@ sock_send(PySocketSockObject *s, PyObject *args)
25512553
}
25522554
if (n < 0)
25532555
return s->errorhandler();
2554-
return PyLong_FromLong((long)n);
2556+
return PyLong_FromSsize_t(n);
25552557
}
25562558

25572559
PyDoc_STRVAR(send_doc,
@@ -2568,7 +2570,8 @@ static PyObject *
25682570
sock_sendall(PySocketSockObject *s, PyObject *args)
25692571
{
25702572
char *buf;
2571-
int len, n = -1, flags = 0, timeout;
2573+
Py_ssize_t len, n = -1;
2574+
int flags = 0, timeout;
25722575
Py_buffer pbuf;
25732576

25742577
if (!PyArg_ParseTuple(args, "y*|i:sendall", &pbuf, &flags))
@@ -2678,7 +2681,7 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
26782681
}
26792682
if (n < 0)
26802683
return s->errorhandler();
2681-
return PyLong_FromLong((long)n);
2684+
return PyLong_FromSsize_t(n);
26822685
}
26832686

26842687
PyDoc_STRVAR(sendto_doc,
@@ -3993,7 +3996,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
39933996
}
39943997
#endif
39953998
}
3996-
error = getnameinfo(res->ai_addr, res->ai_addrlen,
3999+
error = getnameinfo(res->ai_addr, (socklen_t) res->ai_addrlen,
39974000
hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), flags);
39984001
if (error) {
39994002
set_gaierror(error);

0 commit comments

Comments
 (0)