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

Skip to content

Commit f72006f

Browse files
committed
Merged revisions 84146-84147,84150 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r84146 | antoine.pitrou | 2010-08-17 19:55:07 +0200 (mar., 17 août 2010) | 4 lines Issue #9612: The set object is now 64-bit clean under Windows. ........ r84147 | antoine.pitrou | 2010-08-17 20:30:06 +0200 (mar., 17 août 2010) | 3 lines Fix <deque iterator>.__length_hint__() under 64-bit Windows. ........ r84150 | antoine.pitrou | 2010-08-17 21:33:30 +0200 (mar., 17 août 2010) | 3 lines Clean some 64-bit issues. Also, always spell "ssize_t" "Py_ssize_t". ........
1 parent 960c211 commit f72006f

4 files changed

Lines changed: 49 additions & 42 deletions

File tree

Include/setobject.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ no meaning otherwise.
2222
#define PySet_MINSIZE 8
2323

2424
typedef struct {
25-
long hash; /* cached hash code for the entry key */
25+
/* Cached hash code of the key. Note that hash codes are C longs.
26+
* We have to use Py_ssize_t instead because set_pop() abuses
27+
* the hash field to hold a search finger.
28+
*/
29+
Py_ssize_t hash;
2630
PyObject *key;
2731
} setentry;
2832

Modules/_collectionsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ dequeiter_next(dequeiterobject *it)
10351035
static PyObject *
10361036
dequeiter_len(dequeiterobject *it)
10371037
{
1038-
return PyLong_FromLong(it->counter);
1038+
return PyLong_FromSsize_t(it->counter);
10391039
}
10401040

10411041
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");

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 */
@@ -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)
22212224
static PyObject *
22222225
sock_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

24962497
PyDoc_STRVAR(recvfrom_into_doc,
@@ -2505,7 +2506,8 @@ static PyObject *
25052506
sock_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

25422544
PyDoc_STRVAR(send_doc,
@@ -2553,7 +2555,8 @@ static PyObject *
25532555
sock_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

26562659
PyDoc_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);

Objects/setobject.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
349349
} else {
350350
/* ACTIVE */
351351
--i;
352-
set_insert_clean(so, entry->key, entry->hash);
352+
set_insert_clean(so, entry->key, (long) entry->hash);
353353
}
354354
}
355355

@@ -368,7 +368,7 @@ set_add_entry(register PySetObject *so, setentry *entry)
368368
assert(so->fill <= so->mask); /* at least one empty slot */
369369
n_used = so->used;
370370
Py_INCREF(entry->key);
371-
if (set_insert_key(so, entry->key, entry->hash) == -1) {
371+
if (set_insert_key(so, entry->key, (long) entry->hash) == -1) {
372372
Py_DECREF(entry->key);
373373
return -1;
374374
}
@@ -409,7 +409,7 @@ set_discard_entry(PySetObject *so, setentry *oldentry)
409409
{ register setentry *entry;
410410
PyObject *old_key;
411411

412-
entry = (so->lookup)(so, oldentry->key, oldentry->hash);
412+
entry = (so->lookup)(so, oldentry->key, (long) oldentry->hash);
413413
if (entry == NULL)
414414
return -1;
415415
if (entry->key == NULL || entry->key == dummy)
@@ -660,7 +660,7 @@ set_merge(PySetObject *so, PyObject *otherset)
660660
if (entry->key != NULL &&
661661
entry->key != dummy) {
662662
Py_INCREF(entry->key);
663-
if (set_insert_key(so, entry->key, entry->hash) == -1) {
663+
if (set_insert_key(so, entry->key, (long) entry->hash) == -1) {
664664
Py_DECREF(entry->key);
665665
return -1;
666666
}
@@ -694,7 +694,7 @@ set_contains_entry(PySetObject *so, setentry *entry)
694694
PyObject *key;
695695
setentry *lu_entry;
696696

697-
lu_entry = (so->lookup)(so, entry->key, entry->hash);
697+
lu_entry = (so->lookup)(so, entry->key, (long) entry->hash);
698698
if (lu_entry == NULL)
699699
return -1;
700700
key = lu_entry->key;
@@ -769,14 +769,14 @@ frozenset_hash(PyObject *self)
769769
if (so->hash != -1)
770770
return so->hash;
771771

772-
hash *= PySet_GET_SIZE(self) + 1;
772+
hash *= (long) PySet_GET_SIZE(self) + 1;
773773
while (set_next(so, &pos, &entry)) {
774774
/* Work to increase the bit dispersion for closely spaced hash
775775
values. The is important because some use cases have many
776776
combinations of a small number of elements with nearby
777777
hashes so that many distinct combinations collapse to only
778778
a handful of distinct hash values. */
779-
h = entry->hash;
779+
h = (long) entry->hash;
780780
hash ^= (h ^ (h << 16) ^ 89869747L) * 3644798167u;
781781
}
782782
hash = hash * 69069L + 907133923L;
@@ -816,7 +816,7 @@ setiter_len(setiterobject *si)
816816
Py_ssize_t len = 0;
817817
if (si->si_set != NULL && si->si_used == si->si_set->used)
818818
len = si->len;
819-
return PyLong_FromLong(len);
819+
return PyLong_FromSsize_t(len);
820820
}
821821

822822
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -1547,7 +1547,7 @@ set_difference(PySetObject *so, PyObject *other)
15471547
setentry entrycopy;
15481548
entrycopy.hash = entry->hash;
15491549
entrycopy.key = entry->key;
1550-
if (!_PyDict_Contains(other, entry->key, entry->hash)) {
1550+
if (!_PyDict_Contains(other, entry->key, (long) entry->hash)) {
15511551
if (set_add_entry((PySetObject *)result, &entrycopy) == -1) {
15521552
Py_DECREF(result);
15531553
return NULL;
@@ -2309,7 +2309,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
23092309
if (set_next((PySetObject *)set, pos, &entry) == 0)
23102310
return 0;
23112311
*key = entry->key;
2312-
*hash = entry->hash;
2312+
*hash = (long) entry->hash;
23132313
return 1;
23142314
}
23152315

0 commit comments

Comments
 (0)