bpo-9566: Fix size_t=>int downcast warnings (#5230)

* Use wider types (int => Py_ssize_t) to avoid integer overflows.
* Fix gc.get_freeze_count(): use Py_ssize_t type rather than int, since gc_list_size() returns a Py_ssize_t.
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index f98a28a..65cf3c1 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -397,7 +397,7 @@
 {
     asdl_int_seq *ops;
     asdl_seq *args;
-    int i;
+    Py_ssize_t i;
 
     ops = node->v.Compare.ops;
     args = node->v.Compare.comparators;
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 844548f..7fc2261 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -52,9 +52,9 @@
 #include "clinic/bltinmodule.c.h"
 
 static PyObject*
-update_bases(PyObject *bases, PyObject *const *args, int nargs)
+update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
 {
-    int i, j;
+    Py_ssize_t i, j;
     PyObject *base, *meth, *new_base, *result, *new_bases = NULL;
     PyObject *stack[1] = {bases};
     assert(PyTuple_Check(bases));
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index 7ebd69b..6de5481 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -367,13 +367,12 @@
     fseek(env_file, 0, SEEK_SET);
     while (!feof(env_file)) {
         char * p = fgets(buffer, MAXPATHLEN*2, env_file);
-        wchar_t *tmpbuffer;
-        int n;
 
         if (p == NULL) {
             break;
         }
-        n = strlen(p);
+
+        size_t n = strlen(p);
         if (p[n - 1] != '\n') {
             /* line has overflowed - bail */
             break;
@@ -382,7 +381,8 @@
             /* Comment - skip */
             continue;
         }
-        tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n);
+
+        wchar_t *tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n);
         if (tmpbuffer) {
             wchar_t * state;
             wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n", &state);