Index: Python/getargs.c =================================================================== --- Python/getargs.c (revision 60053) +++ Python/getargs.c (working copy) @@ -339,7 +339,7 @@ const char *message) { char buf[512]; - int i; + unsigned int i; char *p = buf; if (PyErr_Occurred()) @@ -894,7 +894,7 @@ char **buffer; const char *encoding; PyObject *s; - Py_ssize_t size; + size_t size; int recode_strings; /* Get 'e' parameter: the encoding name */ Index: Python/ast.c =================================================================== --- Python/ast.c (revision 60053) +++ Python/ast.c (working copy) @@ -983,7 +983,7 @@ */ expr_ty elt; asdl_seq *listcomps; - int i, n_fors; + unsigned int i, n_fors; node *ch; REQ(n, listmaker); @@ -1031,7 +1031,7 @@ return NULL; if (NCH(ch) == 5) { - int j, n_ifs; + unsigned int j, n_ifs; asdl_seq *ifs; expr_ty list_for_expr; @@ -1138,7 +1138,7 @@ argument: [test '='] test [gen_for] # Really [keyword '='] test */ expr_ty elt; asdl_seq *genexps; - int i, n_fors; + unsigned int i, n_fors; node *ch; assert(TYPE(n) == (testlist_gexp) || TYPE(n) == (argument)); @@ -1187,7 +1187,7 @@ return NULL; if (NCH(ch) == 5) { - int j, n_ifs; + unsigned int j, n_ifs; asdl_seq *ifs; ch = CHILD(ch, 4); Index: Python/import.c =================================================================== --- Python/import.c (revision 60053) +++ Python/import.c (working copy) @@ -3121,7 +3121,7 @@ { static struct _inittab *our_copy = NULL; struct _inittab *p; - int i, n; + unsigned int i, n; /* Count the number of entries in both tables */ for (n = 0; newtab[n].name != NULL; n++) Index: Python/modsupport.c =================================================================== --- Python/modsupport.c (revision 60053) +++ Python/modsupport.c (working copy) @@ -513,7 +513,7 @@ va_build_value(const char *format, va_list va, int flags) { const char *f = format; - int n = countformat(f, '\0'); + unsigned int n = countformat(f, '\0'); va_list lva; #ifdef VA_LIST_IS_ARRAY Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 60053) +++ Python/bltinmodule.c (working copy) @@ -831,7 +831,8 @@ PyObject *func, *result; sequence *seqs = NULL, *sqp; - Py_ssize_t n, len; + Py_ssize_t len; + size_t n; register int i, j; n = PyTuple_Size(args); Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (revision 60053) +++ Python/sysmodule.c (working copy) @@ -642,7 +642,7 @@ sys_getframe(PyObject *self, PyObject *args) { PyFrameObject *f = PyThreadState_GET()->frame; - int depth = -1; + unsigned int depth = 0; if (!PyArg_ParseTuple(args, "|i:_getframe", &depth)) return NULL; Index: Include/intobject.h =================================================================== --- Include/intobject.h (revision 60053) +++ Include/intobject.h (working copy) @@ -32,7 +32,7 @@ PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int); #ifdef Py_USING_UNICODE -PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int); +PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, size_t, int); #endif PyAPI_FUNC(PyObject *) PyInt_FromLong(long); PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t); Index: Include/longobject.h =================================================================== --- Include/longobject.h (revision 60053) +++ Include/longobject.h (working copy) @@ -49,7 +49,7 @@ PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int); #ifdef Py_USING_UNICODE -PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); +PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, size_t, int); #endif /* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0. Index: configure.in =================================================================== --- configure.in (revision 60053) +++ configure.in (working copy) @@ -758,9 +758,12 @@ if test "$CC" != 'g++' ; then STRICT_PROTO="-Wstrict-prototypes" fi - # For gcc 4.x we need to use -fwrapv so lets check if its supported - if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then - WRAP="-fwrapv" + # For gcc 4.2+ we need to use -Wstrict-overflow so lets check if its supported + if "$CC" -v --help 2>/dev/null |grep -- -Wstrict-overflow > /dev/null; then + OVERFLOW_CHECK="-Wstrict-overflow=3 -Werror=strict-overflow" + # Otherwise check if -fwrapv is supported and use it + elif "$CC" -v --help 2>/dev/null |grep -- -Wstrict-overflow > /dev/null; then + WRAPV="-fwrapv" fi case $ac_cv_prog_cc_g in yes) @@ -769,7 +772,7 @@ # debug builds. OPT="-g -Wall $STRICT_PROTO" else - OPT="-g $WRAP -O3 -Wall $STRICT_PROTO" + OPT="-g -O3 -Wall $WRAPV $OVERFLOW_CHECK $STRICT_PROTO" fi ;; *) Index: Objects/abstract.c =================================================================== --- Objects/abstract.c (revision 60053) +++ Objects/abstract.c (working copy) @@ -2018,7 +2018,8 @@ static PyObject * objargs_mktuple(va_list va) { - int i, n = 0; + int i; + unsigned int n = 0; va_list countva; PyObject *result, *tmp; Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 60053) +++ Objects/typeobject.c (working copy) @@ -1145,7 +1145,7 @@ static int pmerge(PyObject *acc, PyObject* to_merge) { - Py_ssize_t i, j, to_merge_size, empty_cnt; + size_t i, j, to_merge_size, empty_cnt; int *remain; int ok; Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 60053) +++ Objects/unicodeobject.c (working copy) @@ -4560,7 +4560,7 @@ const Py_UNICODE *sep = ␣ Py_ssize_t seplen = 1; PyUnicodeObject *res = NULL; /* the result */ - Py_ssize_t res_alloc = 100; /* # allocated bytes for string in res */ + size_t res_alloc = 100; /* # allocated bytes for string in res */ Py_ssize_t res_used; /* # used bytes */ Py_UNICODE *res_p; /* pointer to free byte in res's string area */ PyObject *fseq; /* PySequence_Fast(seq) */ @@ -5365,7 +5365,7 @@ static int unicode_compare(PyUnicodeObject *str1, PyUnicodeObject *str2) { - register Py_ssize_t len1, len2; + register size_t len1, len2; Py_UNICODE *s1 = str1->str; Py_UNICODE *s2 = str2->str; @@ -5689,7 +5689,7 @@ Py_UNICODE *e; Py_UNICODE *p; Py_UNICODE *q; - Py_ssize_t i, j, old_j; + size_t i, j, old_j; PyUnicodeObject *u; int tabsize = 8; Index: Objects/intobject.c =================================================================== --- Objects/intobject.c (revision 60053) +++ Objects/intobject.c (working copy) @@ -388,7 +388,7 @@ #ifdef Py_USING_UNICODE PyObject * -PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base) +PyInt_FromUnicode(Py_UNICODE *s, size_t length, int base) { PyObject *result; char *buffer = (char *)PyMem_MALLOC(length+1); Index: Objects/listobject.c =================================================================== --- Objects/listobject.c (revision 60053) +++ Objects/listobject.c (working copy) @@ -1308,7 +1308,7 @@ * to MIN_GALLOP. merge_lo and merge_hi tend to nudge it higher for * random data, and lower for highly structured data. */ - Py_ssize_t min_gallop; + size_t min_gallop; /* 'a' is temp storage to help with merges. It contains room for * alloced entries. @@ -1397,7 +1397,7 @@ PyObject *compare; PyObject **dest; int result = -1; /* guilty until proved innocent */ - Py_ssize_t min_gallop = ms->min_gallop; + size_t min_gallop = ms->min_gallop; assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb); if (MERGE_GETMEM(ms, na) < 0) @@ -1530,7 +1530,7 @@ int result = -1; /* guilty until proved innocent */ PyObject **basea; PyObject **baseb; - Py_ssize_t min_gallop = ms->min_gallop; + size_t min_gallop = ms->min_gallop; assert(ms && pa && pb && na > 0 && nb > 0 && pa + na == pb); if (MERGE_GETMEM(ms, nb) < 0) Index: Objects/stringlib/count.h =================================================================== --- Objects/stringlib/count.h (revision 60053) +++ Objects/stringlib/count.h (working copy) @@ -11,7 +11,7 @@ stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len, const STRINGLIB_CHAR* sub, Py_ssize_t sub_len) { - Py_ssize_t count; + size_t count; if (sub_len == 0) { if (str_len < 0) Index: Objects/longobject.c =================================================================== --- Objects/longobject.c (revision 60053) +++ Objects/longobject.c (working copy) @@ -679,7 +679,7 @@ const double multiplier = (double)(1L << SHIFT); Py_ssize_t i; int sign; - int nbitsneeded; + unsigned int nbitsneeded; if (vv == NULL || !PyLong_Check(vv)) { PyErr_BadInternalCall(); @@ -701,7 +701,7 @@ nbitsneeded = NBITS_WANTED - 1; /* Invariant: i Python digits remain unaccounted for. */ while (i > 0 && nbitsneeded > 0) { - --i; + --i; x = x * multiplier + (double)v->ob_digit[i]; nbitsneeded -= SHIFT; } @@ -1695,7 +1695,7 @@ #ifdef Py_USING_UNICODE PyObject * -PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) +PyLong_FromUnicode(Py_UNICODE *u, size_t length, int base) { PyObject *result; char *buffer = (char *)PyMem_MALLOC(length+1); @@ -1783,7 +1783,8 @@ PyLongObject *v = mul1(v1, d); PyLongObject *w = mul1(w1, d); PyLongObject *a; - Py_ssize_t j, k; + Py_ssize_t j; + size_t k; if (v == NULL || w == NULL) { Py_XDECREF(v); @@ -1799,7 +1800,7 @@ k = size_v - size_w; a = _PyLong_New(k + 1); - for (j = size_v; a != NULL && k >= 0; --j, --k) { + for (j = size_v; a != NULL && (signed)k >= 0; --j, --k) { digit vj = (j >= size_v) ? 0 : v->ob_digit[j]; twodigits q; stwodigits carry = 0; @@ -1957,7 +1958,7 @@ { Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); PyLongObject *z; - int i; + unsigned int i; digit carry = 0; /* Ensure a is the larger of the two: */ Index: Objects/stringobject.c =================================================================== --- Objects/stringobject.c (revision 60053) +++ Objects/stringobject.c (working copy) @@ -2498,14 +2498,14 @@ int direction) { if (start < 0) { - start += target_len; + start += (unsigned)target_len; if (start < 0) start = 0; } if (end > target_len) { end = target_len; } else if (end < 0) { - end += target_len; + end += (unsigned)target_len; if (end < 0) end = 0; } @@ -2648,7 +2648,7 @@ char *self_s, *result_s; char *start, *next, *end; Py_ssize_t self_len, result_len; - Py_ssize_t count; + size_t count; PyStringObject *result; self_len = PyString_GET_SIZE(self); @@ -3301,7 +3301,8 @@ { const char *e, *p; char *q; - Py_ssize_t i, j, old_j; + size_t i; + Py_ssize_t j, old_j; PyObject *u; int tabsize = 8; Index: Parser/acceler.c =================================================================== --- Parser/acceler.c (revision 60053) +++ Parser/acceler.c (working copy) @@ -79,7 +79,7 @@ for (k = s->s_narcs; --k >= 0; a++) { int lbl = a->a_lbl; label *l = &g->g_ll.ll_label[lbl]; - int type = l->lb_type; + unsigned int type = l->lb_type; if (a->a_arrow >= (1 << 7)) { printf("XXX too many states!\n"); continue; Index: Parser/tokenizer.c =================================================================== --- Parser/tokenizer.c (revision 60053) +++ Parser/tokenizer.c (working copy) @@ -170,9 +170,9 @@ } static char * -new_string(const char *s, Py_ssize_t len) +new_string(const char *s, size_t len) { - char* result = (char *)PyMem_MALLOC(len + 1); + char* result = (char *)PyMem_MALLOC(len + 1); if (result != NULL) { memcpy(result, s, len); result[len] = '\0'; @@ -585,7 +585,7 @@ { PyObject* utf8 = NULL; const char *s; - int lineno = 0; + unsigned int lineno = 0; tok->enc = NULL; tok->str = str; if (!check_bom(buf_getc, buf_ungetc, buf_setreadl, tok)) @@ -603,7 +603,7 @@ for (s = str;; s++) { if (*s == '\0') break; else if (*s == '\n') { - lineno++; + lineno++; if (lineno == 2) break; } } @@ -1409,7 +1409,7 @@ Py_ssize_t quote2 = tok->cur - tok->start + 1; int quote = c; int triple = 0; - int tripcount = 0; + unsigned int tripcount = 0; for (;;) { c = tok_nextc(tok); if (c == '\n') { Index: Parser/tokenizer.h =================================================================== --- Parser/tokenizer.h (revision 60053) +++ Parser/tokenizer.h (working copy) @@ -25,7 +25,7 @@ /* NB If done != E_OK, cur must be == inp!!! */ FILE *fp; /* Rest of input; NULL if tokenizing a string */ int tabsize; /* Tab spacing */ - int indent; /* Current indentation index */ + unsigned int indent; /* Current indentation index */ int indstack[MAXINDENT]; /* Stack of indents */ int atbol; /* Nonzero if at begin of new line */ int pendin; /* Pending indents (if > 0) or dedents (if < 0) */ Index: Parser/node.c =================================================================== --- Parser/node.c (revision 60053) +++ Parser/node.c (working copy) @@ -78,7 +78,7 @@ int PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset) { - const int nch = n1->n_nchildren; + const unsigned int nch = n1->n_nchildren; int current_capacity; int required_capacity; node *n; Index: Parser/firstsets.c =================================================================== --- Parser/firstsets.c (revision 60053) +++ Parser/firstsets.c (working copy) @@ -28,7 +28,7 @@ static void calcfirstset(grammar *g, dfa *d) { - int i, j; + unsigned int i, j; state *s; arc *a; int nsyms; Index: Parser/pgen.c =================================================================== --- Parser/pgen.c (revision 60053) +++ Parser/pgen.c (working copy) @@ -242,7 +242,7 @@ static void compile_item(labellist *ll, nfa *nf, node *n, int *pa, int *pb) { - int i; + unsigned int i; int a, b; REQ(n, ITEM); @@ -389,7 +389,7 @@ int xx_nstates; ss_state *xx_state, *yy; ss_arc *zz; - int istate, jstate, iarc, jarc, ibit; + unsigned int istate, jstate, iarc, jarc, ibit; nfastate *st; nfaarc *ar; @@ -549,7 +549,7 @@ static void renamestates(int xx_nstates, ss_state *xx_state, int from, int to) { - int i, j; + unsigned int i, j; if (Py_DebugFlag) printf("Rename state %d to %d.\n", from, to); @@ -597,7 +597,7 @@ static void convert(dfa *d, int xx_nstates, ss_state *xx_state) { - int i, j; + unsigned int i, j; ss_state *yy; ss_arc *zz; Index: Modules/_sre.c =================================================================== --- Modules/_sre.c (revision 60053) +++ Modules/_sre.c (working copy) @@ -807,7 +807,8 @@ { SRE_CHAR* end = (SRE_CHAR *)state->end; Py_ssize_t alloc_pos, ctx_pos = -1; - Py_ssize_t i, ret = 0; + Py_ssize_t i; + size_t ret = 0; Py_ssize_t jump; SRE_MATCH_CONTEXT* ctx; Index: Modules/gcmodule.c =================================================================== --- Modules/gcmodule.c (revision 60053) +++ Modules/gcmodule.c (working copy) @@ -725,7 +725,7 @@ /* This is the main function. Read this to understand how the * collection process works. */ static Py_ssize_t -collect(int generation) +collect(unsigned int generation) { int i; Py_ssize_t m = 0; /* # objects collected */