[Python-checkins] r87733 - in python/branches/py3k: Modules/_ctypes/_ctypes.c Modules/_testcapimodule.c Modules/audioop.c Modules/md5module.c Modules/pyexpat.c Modules/selectmodule.c Modules/sha1module.c Modules/sha256module.c Modules/sha512module.c Modules/unicodedata.c Objects/codeobject.c Objects/listobject.c Objects/typeobject.c Python/pythonrun.c

victor.stinner python-checkins at python.org
Tue Jan 4 13:59:16 CET 2011


Author: victor.stinner
Date: Tue Jan  4 13:59:15 2011
New Revision: 87733

Log:
Issue #9566: use Py_ssize_t instead of int

Modified:
   python/branches/py3k/Modules/_ctypes/_ctypes.c
   python/branches/py3k/Modules/_testcapimodule.c
   python/branches/py3k/Modules/audioop.c
   python/branches/py3k/Modules/md5module.c
   python/branches/py3k/Modules/pyexpat.c
   python/branches/py3k/Modules/selectmodule.c
   python/branches/py3k/Modules/sha1module.c
   python/branches/py3k/Modules/sha256module.c
   python/branches/py3k/Modules/sha512module.c
   python/branches/py3k/Modules/unicodedata.c
   python/branches/py3k/Objects/codeobject.c
   python/branches/py3k/Objects/listobject.c
   python/branches/py3k/Objects/typeobject.c
   python/branches/py3k/Python/pythonrun.c

Modified: python/branches/py3k/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/py3k/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/py3k/Modules/_ctypes/_ctypes.c	Tue Jan  4 13:59:15 2011
@@ -3925,14 +3925,14 @@
 
   Returns -1 on error, or the index of next argument on success.
  */
-static int
+static Py_ssize_t
 _init_pos_args(PyObject *self, PyTypeObject *type,
                PyObject *args, PyObject *kwds,
-               int index)
+               Py_ssize_t index)
 {
     StgDictObject *dict;
     PyObject *fields;
-    int i;
+    Py_ssize_t i;
 
     if (PyType_stgdict((PyObject *)type->tp_base)) {
         index = _init_pos_args(self, type->tp_base,

Modified: python/branches/py3k/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k/Modules/_testcapimodule.c	(original)
+++ python/branches/py3k/Modules/_testcapimodule.c	Tue Jan  4 13:59:15 2011
@@ -2188,7 +2188,7 @@
             /* argument converter not called? */
             return NULL;
         /* Should be 1 */
-        res = PyLong_FromLong(Py_REFCNT(str2));
+        res = PyLong_FromSsize_t(Py_REFCNT(str2));
         Py_DECREF(str2);
         PyErr_Clear();
         return res;

Modified: python/branches/py3k/Modules/audioop.c
==============================================================================
--- python/branches/py3k/Modules/audioop.c	(original)
+++ python/branches/py3k/Modules/audioop.c	Tue Jan  4 13:59:15 2011
@@ -309,7 +309,7 @@
 }
 
 static int
-audioop_check_parameters(int len, int size)
+audioop_check_parameters(Py_ssize_t len, int size)
 {
     if (!audioop_check_size(size))
         return 0;

Modified: python/branches/py3k/Modules/md5module.c
==============================================================================
--- python/branches/py3k/Modules/md5module.c	(original)
+++ python/branches/py3k/Modules/md5module.c	Tue Jan  4 13:59:15 2011
@@ -228,9 +228,9 @@
    @param inlen  The length of the data (octets)
 */
 void md5_process(struct md5_state *md5,
-                const unsigned char *in, unsigned long inlen)
+                const unsigned char *in, Py_ssize_t inlen)
 {
-    unsigned long n;
+    Py_ssize_t n;
 
     assert(md5 != NULL);
     assert(in != NULL);

Modified: python/branches/py3k/Modules/pyexpat.c
==============================================================================
--- python/branches/py3k/Modules/pyexpat.c	(original)
+++ python/branches/py3k/Modules/pyexpat.c	Tue Jan  4 13:59:15 2011
@@ -800,7 +800,7 @@
     PyObject *arg = NULL;
     PyObject *bytes = NULL;
     PyObject *str = NULL;
-    int len = -1;
+    Py_ssize_t len = -1;
     char *ptr;
 
     if ((bytes = PyLong_FromLong(buf_size)) == NULL)
@@ -831,7 +831,7 @@
     if (len > buf_size) {
         PyErr_Format(PyExc_ValueError,
                      "read() returned too much data: "
-                     "%i bytes requested, %i returned",
+                     "%i bytes requested, %zi returned",
                      buf_size, len);
         goto finally;
     }
@@ -839,7 +839,7 @@
 finally:
     Py_XDECREF(arg);
     Py_XDECREF(str);
-    return len;
+    return (int)len;
 }
 
 PyDoc_STRVAR(xmlparse_ParseFile__doc__,
@@ -1807,7 +1807,7 @@
         Py_XDECREF(rev_codes_dict);
         return NULL;
     }
-    
+
 #define MYCONST(name) \
     if (PyModule_AddStringConstant(errors_module, #name,               \
                                    (char *)XML_ErrorString(name)) < 0) \
@@ -1873,7 +1873,7 @@
         return NULL;
     if (PyModule_AddObject(errors_module, "messages", rev_codes_dict) < 0)
         return NULL;
-    
+
 #undef MYCONST
 
 #define MYCONST(c) PyModule_AddIntConstant(m, #c, c)

Modified: python/branches/py3k/Modules/selectmodule.c
==============================================================================
--- python/branches/py3k/Modules/selectmodule.c	(original)
+++ python/branches/py3k/Modules/selectmodule.c	Tue Jan  4 13:59:15 2011
@@ -81,10 +81,9 @@
 static int
 seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
 {
-    int i;
     int max = -1;
     int index = 0;
-    int len = -1;
+    Py_ssize_t i, len = -1;
     PyObject* fast_seq = NULL;
     PyObject* o = NULL;
 

Modified: python/branches/py3k/Modules/sha1module.c
==============================================================================
--- python/branches/py3k/Modules/sha1module.c	(original)
+++ python/branches/py3k/Modules/sha1module.c	Tue Jan  4 13:59:15 2011
@@ -203,9 +203,9 @@
    @param inlen  The length of the data (octets)
 */
 void sha1_process(struct sha1_state *sha1,
-                  const unsigned char *in, unsigned long inlen)
+                  const unsigned char *in, Py_ssize_t inlen)
 {
-    unsigned long n;
+    Py_ssize_t n;
 
     assert(sha1 != NULL);
     assert(in != NULL);

Modified: python/branches/py3k/Modules/sha256module.c
==============================================================================
--- python/branches/py3k/Modules/sha256module.c	(original)
+++ python/branches/py3k/Modules/sha256module.c	Tue Jan  4 13:59:15 2011
@@ -265,9 +265,9 @@
 /* update the SHA digest */
 
 static void
-sha_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
+sha_update(SHAobject *sha_info, SHA_BYTE *buffer, Py_ssize_t count)
 {
-    int i;
+    Py_ssize_t i;
     SHA_INT32 clo;
 
     clo = sha_info->count_lo + ((SHA_INT32) count << 3);

Modified: python/branches/py3k/Modules/sha512module.c
==============================================================================
--- python/branches/py3k/Modules/sha512module.c	(original)
+++ python/branches/py3k/Modules/sha512module.c	Tue Jan  4 13:59:15 2011
@@ -291,9 +291,9 @@
 /* update the SHA digest */
 
 static void
-sha512_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
+sha512_update(SHAobject *sha_info, SHA_BYTE *buffer, Py_ssize_t count)
 {
-    int i;
+    Py_ssize_t i;
     SHA_INT32 clo;
 
     clo = sha_info->count_lo + ((SHA_INT32) count << 3);

Modified: python/branches/py3k/Modules/unicodedata.c
==============================================================================
--- python/branches/py3k/Modules/unicodedata.c	(original)
+++ python/branches/py3k/Modules/unicodedata.c	Tue Jan  4 13:59:15 2011
@@ -403,7 +403,8 @@
 {
     PyUnicodeObject *v;
     char decomp[256];
-    int code, index, count, i;
+    int code, index, count;
+    size_t i;
     unsigned int prefix_index;
     Py_UCS4 c;
 
@@ -450,15 +451,12 @@
     while (count-- > 0) {
         if (i)
             decomp[i++] = ' ';
-        assert((size_t)i < sizeof(decomp));
+        assert(i < sizeof(decomp));
         PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X",
                       decomp_data[++index]);
         i += strlen(decomp + i);
     }
-
-    decomp[i] = '\0';
-
-    return PyUnicode_FromString(decomp);
+    return PyUnicode_FromStringAndSize(decomp, i);
 }
 
 static void

Modified: python/branches/py3k/Objects/codeobject.c
==============================================================================
--- python/branches/py3k/Objects/codeobject.c	(original)
+++ python/branches/py3k/Objects/codeobject.c	Tue Jan  4 13:59:15 2011
@@ -492,7 +492,7 @@
 int
 PyCode_Addr2Line(PyCodeObject *co, int addrq)
 {
-    int size = PyBytes_Size(co->co_lnotab) / 2;
+    Py_ssize_t size = PyBytes_Size(co->co_lnotab) / 2;
     unsigned char *p = (unsigned char*)PyBytes_AsString(co->co_lnotab);
     int line = co->co_firstlineno;
     int addr = 0;
@@ -510,7 +510,8 @@
 int
 _PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds)
 {
-    int size, addr, line;
+    Py_ssize_t size;
+    int addr, line;
     unsigned char* p;
 
     p = (unsigned char*)PyBytes_AS_STRING(co->co_lnotab);

Modified: python/branches/py3k/Objects/listobject.c
==============================================================================
--- python/branches/py3k/Objects/listobject.c	(original)
+++ python/branches/py3k/Objects/listobject.c	Tue Jan  4 13:59:15 2011
@@ -1381,7 +1381,7 @@
 
 /* Conceptually a MergeState's constructor. */
 static void
-merge_init(MergeState *ms, int list_size, int has_keyfunc)
+merge_init(MergeState *ms, Py_ssize_t list_size, int has_keyfunc)
 {
     assert(ms != NULL);
     if (has_keyfunc) {

Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c	(original)
+++ python/branches/py3k/Objects/typeobject.c	Tue Jan  4 13:59:15 2011
@@ -2325,7 +2325,7 @@
     res->ht_type.tp_basicsize = spec->basicsize;
     res->ht_type.tp_itemsize = spec->itemsize;
     res->ht_type.tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;
-    
+
     for (slot = spec->slots; slot->slot; slot++) {
 	if (slot->slot >= sizeof(slotoffsets)/sizeof(slotoffsets[0])) {
 	    PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
@@ -2335,7 +2335,7 @@
     }
 
     return (PyObject*)res;
-    
+
  fail:
     Py_DECREF(res);
     return NULL;
@@ -6202,7 +6202,7 @@
            and first local variable on the stack. */
         PyFrameObject *f = PyThreadState_GET()->frame;
         PyCodeObject *co = f->f_code;
-        int i, n;
+        Py_ssize_t i, n;
         if (co == NULL) {
             PyErr_SetString(PyExc_SystemError,
                             "super(): no code object");

Modified: python/branches/py3k/Python/pythonrun.c
==============================================================================
--- python/branches/py3k/Python/pythonrun.c	(original)
+++ python/branches/py3k/Python/pythonrun.c	Tue Jan  4 13:59:15 2011
@@ -1202,7 +1202,8 @@
 {
     PyObject *m, *d, *v;
     const char *ext;
-    int set_file_name = 0, ret, len;
+    int set_file_name = 0, ret;
+    size_t len;
 
     m = PyImport_AddModule("__main__");
     if (m == NULL)


More information about the Python-checkins mailing list