]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixes loop variables to be the same types as their limit (GH-120958)
authorSteve Dower <steve.dower@python.org>
Mon, 24 Jun 2024 16:11:47 +0000 (17:11 +0100)
committerGitHub <noreply@github.com>
Mon, 24 Jun 2024 16:11:47 +0000 (17:11 +0100)
14 files changed:
Modules/_io/_iomodule.c
Modules/_sqlite/blob.c
Modules/_testinternalcapi/test_critical_sections.c
Objects/codeobject.c
Objects/unicodeobject.c
Objects/unionobject.c
Parser/action_helpers.c
Python/ast_opt.c
Python/compile.c
Python/flowgraph.c
Python/future.c
Python/getargs.c
Python/suggestions.c
Python/symtable.c

index d236098e6977e8116bd5c12f045d7c714241bd2a..1238e6074246d0f2502835f134138c6ba98ade8b 100644 (file)
@@ -202,7 +202,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
               const char *newline, int closefd, PyObject *opener)
 /*[clinic end generated code: output=aefafc4ce2b46dc0 input=cd034e7cdfbf4e78]*/
 {
-    unsigned i;
+    size_t i;
 
     int creating = 0, reading = 0, writing = 0, appending = 0, updating = 0;
     int text = 0, binary = 0;
index 7deb58bf1b9b82fda935d50e6cf9d823aafd2e03..d1a549a971c24a233a8df1d90565fd9009fe7648 100644 (file)
@@ -99,7 +99,7 @@ blob_close_impl(pysqlite_Blob *self)
 void
 pysqlite_close_all_blobs(pysqlite_Connection *self)
 {
-    for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
+    for (Py_ssize_t i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
         PyObject *weakref = PyList_GET_ITEM(self->blobs, i);
         PyObject *blob;
         if (!PyWeakref_GetRef(weakref, &blob)) {
index 0129bd49ca93c3ba118a31103256b2cf051304f5..1df960f9881f7093128b6ca285f72c53c9c1080d 100644 (file)
@@ -185,7 +185,7 @@ test_critical_sections_threads(PyObject *self, PyObject *Py_UNUSED(args))
     assert(test_data.obj2 != NULL);
     assert(test_data.obj3 != NULL);
 
-    for (int i = 0; i < NUM_THREADS; i++) {
+    for (Py_ssize_t i = 0; i < NUM_THREADS; i++) {
         PyThread_start_new_thread(&thread_critical_sections, &test_data);
     }
     PyEvent_Wait(&test_data.done_event);
@@ -271,7 +271,7 @@ test_critical_sections_gc(PyObject *self, PyObject *Py_UNUSED(args))
     };
     assert(test_data.obj != NULL);
 
-    for (int i = 0; i < NUM_THREADS; i++) {
+    for (Py_ssize_t i = 0; i < NUM_THREADS; i++) {
         PyThread_start_new_thread(&thread_gc, &test_data);
     }
     PyEvent_Wait(&test_data.done_event);
index 95da63506c670ae7bb636be21ec32d1c755fc760..4be17708d3aab71b11aa2305e152c1a4423a1f5a 100644 (file)
@@ -573,7 +573,7 @@ get_line_delta(const uint8_t *ptr)
 static PyObject *
 remove_column_info(PyObject *locations)
 {
-    int offset = 0;
+    Py_ssize_t offset = 0;
     const uint8_t *data = (const uint8_t *)PyBytes_AS_STRING(locations);
     PyObject *res = PyBytes_FromStringAndSize(NULL, 32);
     if (res == NULL) {
index 698e57f5ad0407e112591cea8aa8e2521f8723ce..0710c6286c80dad53000bff897c11bf009a46605 100644 (file)
@@ -8373,7 +8373,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
     int count2 = 0, count3 = 0;
     int kind;
     const void *data;
-    Py_ssize_t length;
+    int length;
     Py_UCS4 ch;
 
     if (!PyUnicode_Check(string) || !PyUnicode_GET_LENGTH(string)) {
@@ -8382,8 +8382,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
     }
     kind = PyUnicode_KIND(string);
     data = PyUnicode_DATA(string);
-    length = PyUnicode_GET_LENGTH(string);
-    length = Py_MIN(length, 256);
+    length = (int)Py_MIN(PyUnicode_GET_LENGTH(string), 256);
     memset(level1, 0xFF, sizeof level1);
     memset(level2, 0xFF, sizeof level2);
 
index 49b01e0aeb5d83bc9fa8f37b36c1b9cd72cf5f16..7931f4345f7fdde309f4604cb972ed2e5da4ad83 100644 (file)
@@ -81,7 +81,7 @@ is_same(PyObject *left, PyObject *right)
 static int
 contains(PyObject **items, Py_ssize_t size, PyObject *obj)
 {
-    for (int i = 0; i < size; i++) {
+    for (Py_ssize_t i = 0; i < size; i++) {
         int is_duplicate = is_same(items[i], obj);
         if (is_duplicate) {  // -1 or 1
             return is_duplicate;
@@ -97,7 +97,7 @@ merge(PyObject **items1, Py_ssize_t size1,
     PyObject *tuple = NULL;
     Py_ssize_t pos = 0;
 
-    for (int i = 0; i < size2; i++) {
+    for (Py_ssize_t i = 0; i < size2; i++) {
         PyObject *arg = items2[i];
         int is_duplicate = contains(items1, size1, arg);
         if (is_duplicate < 0) {
index 6ebc457f6328c5d0a98f8496a8de4a7f2ec6a370..44bf87da8288a6a346a92e2d867c593cc8034672 100644 (file)
@@ -864,7 +864,7 @@ _PyPegen_make_module(Parser *p, asdl_stmt_seq *a) {
         if (type_ignores == NULL) {
             return NULL;
         }
-        for (int i = 0; i < num; i++) {
+        for (Py_ssize_t i = 0; i < num; i++) {
             PyObject *tag = _PyPegen_new_type_comment(p, p->type_ignore_comments.items[i].comment);
             if (tag == NULL) {
                 return NULL;
index 6d1bfafef3ca92027a32d152b4d0b7348f6d2eea..2e2c78b9d4d7d25618a740d42b742002e1550115 100644 (file)
@@ -521,7 +521,7 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
 static PyObject*
 make_const_tuple(asdl_expr_seq *elts)
 {
-    for (int i = 0; i < asdl_seq_LEN(elts); i++) {
+    for (Py_ssize_t i = 0; i < asdl_seq_LEN(elts); i++) {
         expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
         if (e->kind != Constant_kind) {
             return NULL;
@@ -533,7 +533,7 @@ make_const_tuple(asdl_expr_seq *elts)
         return NULL;
     }
 
-    for (int i = 0; i < asdl_seq_LEN(elts); i++) {
+    for (Py_ssize_t i = 0; i < asdl_seq_LEN(elts); i++) {
         expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
         PyObject *v = e->v.Constant.value;
         PyTuple_SET_ITEM(newval, i, Py_NewRef(v));
@@ -650,7 +650,7 @@ static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimize
         return 0;
 
 #define CALL_SEQ(FUNC, TYPE, ARG) { \
-    int i; \
+    Py_ssize_t i; \
     asdl_ ## TYPE ## _seq *seq = (ARG); /* avoid variable capture */ \
     for (i = 0; i < asdl_seq_LEN(seq); i++) { \
         TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
index b572481cc23dda8f4483526f9419c0186789bc05..cdac438393dc0c8f95697f7b614075f9ce6d89e7 100644 (file)
@@ -5109,7 +5109,7 @@ compiler_call_simple_kw_helper(struct compiler *c, location loc,
     if (names == NULL) {
         return ERROR;
     }
-    for (int i = 0; i < nkwelts; i++) {
+    for (Py_ssize_t i = 0; i < nkwelts; i++) {
         keyword_ty kw = asdl_seq_GET(keywords, i);
         PyTuple_SET_ITEM(names, i, Py_NewRef(kw->arg));
     }
index 8c1c20a0583c8c6a992011583cb8241aa4a539e9..ec91b0e616c0a6602e98cd31cfb7280a9ae30dec 100644 (file)
@@ -2095,7 +2095,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
     /* now index_map[i] == i if consts[i] is used, -1 otherwise */
     /* condense consts */
     Py_ssize_t n_used_consts = 0;
-    for (int i = 0; i < nconsts; i++) {
+    for (Py_ssize_t i = 0; i < nconsts; i++) {
         if (index_map[i] != -1) {
             assert(index_map[i] == i);
             index_map[n_used_consts++] = index_map[i];
index 8d94d515605dcd62a940bca2d28c32501dd8ef7f..8aeb541cb0510715d15b3af3fddf9bdf9643b986 100644 (file)
@@ -8,7 +8,7 @@
 static int
 future_check_features(_PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
 {
-    int i;
+    Py_ssize_t i;
 
     assert(s->kind == ImportFrom_kind);
 
index 75c1797a80e56e44dcdccf2a2960fdb3dbf5bb10..3e3828010bfaa2367c0551c13f619aab613c0379 100644 (file)
@@ -2070,7 +2070,8 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
     const char *format;
     const char *msg;
     PyObject *keyword;
-    int i, pos, len;
+    Py_ssize_t i;
+    int pos, len;
     Py_ssize_t nkwargs;
     freelistentry_t static_entries[STATIC_FREELIST_ENTRIES];
     freelist_t freelist;
index a09b3ce6d9dab260100cfd83901d64bf85579888..2ce0bcfd54e23f572ddf403e45b01af32b971936 100644 (file)
@@ -146,7 +146,7 @@ _Py_CalculateSuggestions(PyObject *dir,
     if (buffer == NULL) {
         return PyErr_NoMemory();
     }
-    for (int i = 0; i < dir_size; ++i) {
+    for (Py_ssize_t i = 0; i < dir_size; ++i) {
         PyObject *item = PyList_GET_ITEM(dir, i);
         if (_PyUnicode_Equal(name, item)) {
             continue;
index a8e4ba331f4fd8604820cd49eb8937ef6ce0c038..2e56ea6e830846f6291cf61a447a9977be7e8b80 100644 (file)
@@ -398,7 +398,7 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, _PyFutureFeatures *future)
 {
     struct symtable *st = symtable_new();
     asdl_stmt_seq *seq;
-    int i;
+    Py_ssize_t i;
     PyThreadState *tstate;
     int starting_recursion_depth;
 
@@ -1594,7 +1594,7 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
 
 #define VISIT_SEQ(ST, TYPE, SEQ) \
     do { \
-        int i; \
+        Py_ssize_t i; \
         asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
         for (i = 0; i < asdl_seq_LEN(seq); i++) { \
             TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
@@ -1605,7 +1605,7 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
 
 #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) \
     do { \
-        int i; \
+        Py_ssize_t i; \
         asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
         for (i = (START); i < asdl_seq_LEN(seq); i++) { \
             TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
@@ -1916,7 +1916,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
         VISIT_SEQ(st, alias, s->v.ImportFrom.names);
         break;
     case Global_kind: {
-        int i;
+        Py_ssize_t i;
         asdl_identifier_seq *seq = s->v.Global.names;
         for (i = 0; i < asdl_seq_LEN(seq); i++) {
             identifier name = (identifier)asdl_seq_GET(seq, i);
@@ -1952,7 +1952,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
         break;
     }
     case Nonlocal_kind: {
-        int i;
+        Py_ssize_t i;
         asdl_identifier_seq *seq = s->v.Nonlocal.names;
         for (i = 0; i < asdl_seq_LEN(seq); i++) {
             identifier name = (identifier)asdl_seq_GET(seq, i);
@@ -2494,7 +2494,7 @@ symtable_implicit_arg(struct symtable *st, int pos)
 static int
 symtable_visit_params(struct symtable *st, asdl_arg_seq *args)
 {
-    int i;
+    Py_ssize_t i;
 
     if (!args)
         return -1;
@@ -2555,7 +2555,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
 static int
 symtable_visit_argannotations(struct symtable *st, asdl_arg_seq *args)
 {
-    int i;
+    Py_ssize_t i;
 
     if (!args)
         return -1;