[Python-checkins] cpython: Use Py_ssize_t type for sizes in getargs.c

victor.stinner python-checkins at python.org
Mon Nov 18 01:21:23 CET 2013


http://hg.python.org/cpython/rev/103998db4407
changeset:   87231:103998db4407
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Nov 18 01:21:12 2013 +0100
summary:
  Use Py_ssize_t type for sizes in getargs.c

Fix compiler warnings on Windows 64-bit

files:
  Python/getargs.c |  25 ++++++++++++++++++-------
  1 files changed, 18 insertions(+), 7 deletions(-)


diff --git a/Python/getargs.c b/Python/getargs.c
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -421,6 +421,7 @@
     int n = 0;
     const char *format = *p_format;
     int i;
+    Py_ssize_t len;
 
     for (;;) {
         int c = *format++;
@@ -450,12 +451,20 @@
         return msgbuf;
     }
 
-    if ((i = PySequence_Size(arg)) != n) {
+    len = PySequence_Size(arg);
+    if (len != n) {
         levels[0] = 0;
-        PyOS_snprintf(msgbuf, bufsize,
-                      toplevel ? "expected %d arguments, not %d" :
-                     "must be sequence of length %d, not %d",
-                  n, i);
+        if (toplevel) {
+            PyOS_snprintf(msgbuf, bufsize,
+                          "expected %d arguments, not %" PY_FORMAT_SIZE_T "d",
+                          n, len);
+        }
+        else {
+            PyOS_snprintf(msgbuf, bufsize,
+                          "must be sequence of length %d, "
+                          "not %" PY_FORMAT_SIZE_T "d",
+                          n, len);
+        }
         return msgbuf;
     }
 
@@ -1426,7 +1435,8 @@
     const char *fname, *msg, *custom_msg, *keyword;
     int min = INT_MAX;
     int max = INT_MAX;
-    int i, len, nargs, nkeywords;
+    int i, len;
+    Py_ssize_t nargs, nkeywords;
     PyObject *current_arg;
     freelistentry_t static_entries[STATIC_FREELIST_ENTRIES];
     freelist_t freelist = {static_entries, 0, 0};
@@ -1466,7 +1476,8 @@
     nkeywords = (keywords == NULL) ? 0 : PyDict_Size(keywords);
     if (nargs + nkeywords > len) {
         PyErr_Format(PyExc_TypeError,
-                     "%s%s takes at most %d argument%s (%d given)",
+                     "%s%s takes at most %d argument%s "
+                     "(%" PY_FORMAT_SIZE_T "d given)",
                      (fname == NULL) ? "function" : fname,
                      (fname == NULL) ? "" : "()",
                      len,

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list