[Python-checkins] cpython: Silenced some warnings about comparison between signed and unsigned integer

serhiy.storchaka python-checkins at python.org
Fri Sep 5 09:11:38 CEST 2014


http://hg.python.org/cpython/rev/858747aac9e9
changeset:   92345:858747aac9e9
parent:      92342:034ebeb8be2d
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Fri Sep 05 10:10:23 2014 +0300
summary:
  Silenced some warnings about comparison between signed and unsigned integer
expressions.

files:
  Modules/_pickle.c     |  6 +++---
  Parser/node.c         |  4 ++--
  Parser/pgenmain.c     |  7 ++++---
  Parser/printgrammar.c |  5 +++--
  4 files changed, 12 insertions(+), 10 deletions(-)


diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1456,7 +1456,7 @@
             pdata[1] = (unsigned char)(*value & 0xff);
             len = 2;
         }
-        else if (*value <= 0xffffffffL) {
+        else if ((size_t)*value <= 0xffffffffUL) {
             pdata[0] = LONG_BINGET;
             pdata[1] = (unsigned char)(*value & 0xff);
             pdata[2] = (unsigned char)((*value >> 8) & 0xff);
@@ -1513,7 +1513,7 @@
             pdata[1] = (unsigned char)idx;
             len = 2;
         }
-        else if (idx <= 0xffffffffL) {
+        else if ((size_t)idx <= 0xffffffffUL) {
             pdata[0] = LONG_BINPUT;
             pdata[1] = (unsigned char)(idx & 0xff);
             pdata[2] = (unsigned char)((idx >> 8) & 0xff);
@@ -2013,7 +2013,7 @@
             header[1] = (unsigned char)size;
             len = 2;
         }
-        else if (size <= 0xffffffffL) {
+        else if ((size_t)size <= 0xffffffffUL) {
             header[0] = BINBYTES;
             header[1] = (unsigned char)(size & 0xff);
             header[2] = (unsigned char)((size >> 8) & 0xff);
diff --git a/Parser/node.c b/Parser/node.c
--- a/Parser/node.c
+++ b/Parser/node.c
@@ -70,8 +70,8 @@
  * Note that this would be straightforward if a node stored its current
  * capacity.  The code is tricky to avoid that.
  */
-#define XXXROUNDUP(n) ((n) <= 1 ? (n) :                 \
-               (n) <= 128 ? _Py_SIZE_ROUND_UP((n), 4) : \
+#define XXXROUNDUP(n) ((n) <= 1 ? (n) :                         \
+               (n) <= 128 ? (int)_Py_SIZE_ROUND_UP((n), 4) :    \
                fancy_roundup(n))
 
 
diff --git a/Parser/pgenmain.c b/Parser/pgenmain.c
--- a/Parser/pgenmain.c
+++ b/Parser/pgenmain.c
@@ -96,10 +96,11 @@
         fprintf(stderr, "Parsing error %d, line %d.\n",
             err.error, err.lineno);
         if (err.text != NULL) {
-            size_t i;
+            size_t len;
+            int i;
             fprintf(stderr, "%s", err.text);
-            i = strlen(err.text);
-            if (i == 0 || err.text[i-1] != '\n')
+            len = strlen(err.text);
+            if (len == 0 || err.text[len-1] != '\n')
                 fprintf(stderr, "\n");
             for (i = 0; i < err.offset; i++) {
                 if (err.text[i] == '\t')
diff --git a/Parser/printgrammar.c b/Parser/printgrammar.c
--- a/Parser/printgrammar.c
+++ b/Parser/printgrammar.c
@@ -84,7 +84,7 @@
 printdfas(grammar *g, FILE *fp)
 {
     dfa *d;
-    int i, j;
+    int i, j, n;
 
     printstates(g, fp);
     fprintf(fp, "static dfa dfas[%d] = {\n", g->g_ndfas);
@@ -93,7 +93,8 @@
         fprintf(fp, "    {%d, \"%s\", %d, %d, states_%d,\n",
             d->d_type, d->d_name, d->d_initial, d->d_nstates, i);
         fprintf(fp, "     \"");
-        for (j = 0; j < NBYTES(g->g_ll.ll_nlabels); j++)
+        n = NBYTES(g->g_ll.ll_nlabels);
+        for (j = 0; j < n; j++)
             fprintf(fp, "\\%03o", d->d_first[j] & 0xff);
         fprintf(fp, "\"},\n");
     }

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


More information about the Python-checkins mailing list