[Python-checkins] r84151 - in python/branches/release31-maint: Include/setobject.h Modules/_collectionsmodule.c Modules/socketmodule.c Objects/setobject.c

antoine.pitrou python-checkins at python.org
Tue Aug 17 21:39:40 CEST 2010


Author: antoine.pitrou
Date: Tue Aug 17 21:39:39 2010
New Revision: 84151

Log:
Merged revisions 84146-84147,84150 via svnmerge from 
svn+ssh://pythondev@svn.python.org/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".
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Include/setobject.h
   python/branches/release31-maint/Modules/_collectionsmodule.c
   python/branches/release31-maint/Modules/socketmodule.c
   python/branches/release31-maint/Objects/setobject.c

Modified: python/branches/release31-maint/Include/setobject.h
==============================================================================
--- python/branches/release31-maint/Include/setobject.h	(original)
+++ python/branches/release31-maint/Include/setobject.h	Tue Aug 17 21:39:39 2010
@@ -22,7 +22,11 @@
 #define PySet_MINSIZE 8
 
 typedef struct {
-    long hash;      /* cached hash code for the entry key */
+    /* Cached hash code of the key.  Note that hash codes are C longs.
+     * We have to use Py_ssize_t instead because set_pop() abuses
+     * the hash field to hold a search finger.
+     */
+    Py_ssize_t hash;
     PyObject *key;
 } setentry;
 

Modified: python/branches/release31-maint/Modules/_collectionsmodule.c
==============================================================================
--- python/branches/release31-maint/Modules/_collectionsmodule.c	(original)
+++ python/branches/release31-maint/Modules/_collectionsmodule.c	Tue Aug 17 21:39:39 2010
@@ -1035,7 +1035,7 @@
 static PyObject *
 dequeiter_len(dequeiterobject *it)
 {
-    return PyLong_FromLong(it->counter);
+    return PyLong_FromSsize_t(it->counter);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");

Modified: python/branches/release31-maint/Modules/socketmodule.c
==============================================================================
--- python/branches/release31-maint/Modules/socketmodule.c	(original)
+++ python/branches/release31-maint/Modules/socketmodule.c	Tue Aug 17 21:39:39 2010
@@ -678,9 +678,11 @@
 
         /* See if the socket is ready */
         if (writing)
-            n = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
+            n = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int),
+                       NULL, &fds, NULL, &tv);
         else
-            n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
+            n = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int),
+                       &fds, NULL, NULL, &tv);
     }
 #endif
 
@@ -937,7 +939,7 @@
 
 /*ARGSUSED*/
 static PyObject *
-makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
+makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
 {
     if (addrlen == 0) {
         /* No address -- may be recvfrom() from known socket */
@@ -1893,7 +1895,8 @@
             FD_SET(s->sock_fd, &fds);
             FD_ZERO(&fds_exc);
             FD_SET(s->sock_fd, &fds_exc);
-            res = select(s->sock_fd+1, NULL, &fds, &fds_exc, &tv);
+            res = select(Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int),
+                         NULL, &fds, &fds_exc, &tv);
             if (res == 0) {
                 res = WSAEWOULDBLOCK;
                 timeout = 1;
@@ -2136,10 +2139,10 @@
  * also possible that we return a number of bytes smaller than the request
  * bytes.
  */
-static ssize_t
-sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags)
+static Py_ssize_t
+sock_recv_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags)
 {
-    ssize_t outlen = -1;
+    Py_ssize_t outlen = -1;
     int timeout;
 #ifdef __VMS
     int remaining;
@@ -2221,11 +2224,11 @@
 static PyObject *
 sock_recv(PySocketSockObject *s, PyObject *args)
 {
-    int recvlen, flags = 0;
-    ssize_t outlen;
+    Py_ssize_t recvlen, outlen;
+    int flags = 0;
     PyObject *buf;
 
-    if (!PyArg_ParseTuple(args, "i|i:recv", &recvlen, &flags))
+    if (!PyArg_ParseTuple(args, "n|i:recv", &recvlen, &flags))
         return NULL;
 
     if (recvlen < 0) {
@@ -2272,14 +2275,13 @@
 {
     static char *kwlist[] = {"buffer", "nbytes", "flags", 0};
 
-    int recvlen = 0, flags = 0;
-    ssize_t readlen;
+    int flags = 0;
     Py_buffer pbuf;
     char *buf;
-    int buflen;
+    Py_ssize_t buflen, readlen, recvlen = 0;
 
     /* Get the buffer's memory */
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recv_into", kwlist,
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ni:recv_into", kwlist,
                                      &pbuf, &recvlen, &flags))
         return NULL;
     buf = pbuf.buf;
@@ -2339,13 +2341,13 @@
  * 'addr' is a return value for the address object.  Note that you must decref
  * it yourself.
  */
-static ssize_t
-sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags,
+static Py_ssize_t
+sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, Py_ssize_t len, int flags,
                    PyObject** addr)
 {
     sock_addr_t addrbuf;
     int timeout;
-    ssize_t n = -1;
+    Py_ssize_t n = -1;
     socklen_t addrlen;
 
     *addr = NULL;
@@ -2401,10 +2403,10 @@
     PyObject *buf = NULL;
     PyObject *addr = NULL;
     PyObject *ret = NULL;
-    int recvlen, flags = 0;
-    ssize_t outlen;
+    int flags = 0;
+    Py_ssize_t recvlen, outlen;
 
-    if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
+    if (!PyArg_ParseTuple(args, "n|i:recvfrom", &recvlen, &flags))
         return NULL;
 
     if (recvlen < 0) {
@@ -2452,15 +2454,14 @@
 {
     static char *kwlist[] = {"buffer", "nbytes", "flags", 0};
 
-    int recvlen = 0, flags = 0;
-    ssize_t readlen;
+    int flags = 0;
     Py_buffer pbuf;
     char *buf;
-    int buflen;
+    Py_ssize_t readlen, buflen, recvlen = 0;
 
     PyObject *addr = NULL;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ii:recvfrom_into",
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "w*|ni:recvfrom_into",
                                      kwlist, &pbuf,
                                      &recvlen, &flags))
         return NULL;
@@ -2490,7 +2491,7 @@
     PyBuffer_Release(&pbuf);
     /* Return the number of bytes read and the address.  Note that we do
        not do anything special here in the case that readlen < recvlen. */
-    return Py_BuildValue("lN", readlen, addr);
+    return Py_BuildValue("nN", readlen, addr);
 }
 
 PyDoc_STRVAR(recvfrom_into_doc,
@@ -2505,7 +2506,8 @@
 sock_send(PySocketSockObject *s, PyObject *args)
 {
     char *buf;
-    int len, n = -1, flags = 0, timeout;
+    Py_ssize_t len, n = -1;
+    int flags = 0, timeout;
     Py_buffer pbuf;
 
     if (!PyArg_ParseTuple(args, "y*|i:send", &pbuf, &flags))
@@ -2536,7 +2538,7 @@
     }
     if (n < 0)
         return s->errorhandler();
-    return PyLong_FromLong((long)n);
+    return PyLong_FromSsize_t(n);
 }
 
 PyDoc_STRVAR(send_doc,
@@ -2553,7 +2555,8 @@
 sock_sendall(PySocketSockObject *s, PyObject *args)
 {
     char *buf;
-    int len, n = -1, flags = 0, timeout;
+    Py_ssize_t len, n = -1;
+    int flags = 0, timeout;
     Py_buffer pbuf;
 
     if (!PyArg_ParseTuple(args, "y*|i:sendall", &pbuf, &flags))
@@ -2650,7 +2653,7 @@
     }
     if (n < 0)
         return s->errorhandler();
-    return PyLong_FromLong((long)n);
+    return PyLong_FromSsize_t(n);
 }
 
 PyDoc_STRVAR(sendto_doc,
@@ -3942,7 +3945,7 @@
         }
 #endif
     }
-    error = getnameinfo(res->ai_addr, res->ai_addrlen,
+    error = getnameinfo(res->ai_addr, (socklen_t) res->ai_addrlen,
                     hbuf, sizeof(hbuf), pbuf, sizeof(pbuf), flags);
     if (error) {
         set_gaierror(error);

Modified: python/branches/release31-maint/Objects/setobject.c
==============================================================================
--- python/branches/release31-maint/Objects/setobject.c	(original)
+++ python/branches/release31-maint/Objects/setobject.c	Tue Aug 17 21:39:39 2010
@@ -349,7 +349,7 @@
         } else {
             /* ACTIVE */
             --i;
-            set_insert_clean(so, entry->key, entry->hash);
+            set_insert_clean(so, entry->key, (long) entry->hash);
         }
     }
 
@@ -368,7 +368,7 @@
     assert(so->fill <= so->mask);  /* at least one empty slot */
     n_used = so->used;
     Py_INCREF(entry->key);
-    if (set_insert_key(so, entry->key, entry->hash) == -1) {
+    if (set_insert_key(so, entry->key, (long) entry->hash) == -1) {
         Py_DECREF(entry->key);
         return -1;
     }
@@ -409,7 +409,7 @@
 {       register setentry *entry;
     PyObject *old_key;
 
-    entry = (so->lookup)(so, oldentry->key, oldentry->hash);
+    entry = (so->lookup)(so, oldentry->key, (long) oldentry->hash);
     if (entry == NULL)
         return -1;
     if (entry->key == NULL  ||  entry->key == dummy)
@@ -660,7 +660,7 @@
         if (entry->key != NULL &&
             entry->key != dummy) {
             Py_INCREF(entry->key);
-            if (set_insert_key(so, entry->key, entry->hash) == -1) {
+            if (set_insert_key(so, entry->key, (long) entry->hash) == -1) {
                 Py_DECREF(entry->key);
                 return -1;
             }
@@ -694,7 +694,7 @@
     PyObject *key;
     setentry *lu_entry;
 
-    lu_entry = (so->lookup)(so, entry->key, entry->hash);
+    lu_entry = (so->lookup)(so, entry->key, (long) entry->hash);
     if (lu_entry == NULL)
         return -1;
     key = lu_entry->key;
@@ -769,14 +769,14 @@
     if (so->hash != -1)
         return so->hash;
 
-    hash *= PySet_GET_SIZE(self) + 1;
+    hash *= (long) PySet_GET_SIZE(self) + 1;
     while (set_next(so, &pos, &entry)) {
         /* Work to increase the bit dispersion for closely spaced hash
            values.  The is important because some use cases have many
            combinations of a small number of elements with nearby
            hashes so that many distinct combinations collapse to only
            a handful of distinct hash values. */
-        h = entry->hash;
+        h = (long) entry->hash;
         hash ^= (h ^ (h << 16) ^ 89869747L)  * 3644798167u;
     }
     hash = hash * 69069L + 907133923L;
@@ -816,7 +816,7 @@
     Py_ssize_t len = 0;
     if (si->si_set != NULL && si->si_used == si->si_set->used)
         len = si->len;
-    return PyLong_FromLong(len);
+    return PyLong_FromSsize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
@@ -1547,7 +1547,7 @@
             setentry entrycopy;
             entrycopy.hash = entry->hash;
             entrycopy.key = entry->key;
-            if (!_PyDict_Contains(other, entry->key, entry->hash)) {
+            if (!_PyDict_Contains(other, entry->key, (long) entry->hash)) {
                 if (set_add_entry((PySetObject *)result, &entrycopy) == -1) {
                     Py_DECREF(result);
                     return NULL;
@@ -2309,7 +2309,7 @@
     if (set_next((PySetObject *)set, pos, &entry) == 0)
         return 0;
     *key = entry->key;
-    *hash = entry->hash;
+    *hash = (long) entry->hash;
     return 1;
 }
 


More information about the Python-checkins mailing list