Skip to content

Commit 2c2c849

Browse files
zoobaestyxx
authored andcommitted
Fixes loop variables to be the same types as their limit (pythonGH-120958)
1 parent cdc2954 commit 2c2c849

File tree

14 files changed

+26
-26
lines changed

14 files changed

+26
-26
lines changed

Modules/_io/_iomodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
202202
const char *newline, int closefd, PyObject *opener)
203203
/*[clinic end generated code: output=aefafc4ce2b46dc0 input=cd034e7cdfbf4e78]*/
204204
{
205-
unsigned i;
205+
size_t i;
206206

207207
int creating = 0, reading = 0, writing = 0, appending = 0, updating = 0;
208208
int text = 0, binary = 0;

Modules/_sqlite/blob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ blob_close_impl(pysqlite_Blob *self)
9999
void
100100
pysqlite_close_all_blobs(pysqlite_Connection *self)
101101
{
102-
for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
102+
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
103103
PyObject *weakref = PyList_GET_ITEM(self->blobs, i);
104104
PyObject *blob;
105105
if (!PyWeakref_GetRef(weakref, &blob)) {

Modules/_testinternalcapi/test_critical_sections.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ test_critical_sections_threads(PyObject *self, PyObject *Py_UNUSED(args))
185185
assert(test_data.obj2 != NULL);
186186
assert(test_data.obj3 != NULL);
187187

188-
for (int i = 0; i < NUM_THREADS; i++) {
188+
for (Py_ssize_t i = 0; i < NUM_THREADS; i++) {
189189
PyThread_start_new_thread(&thread_critical_sections, &test_data);
190190
}
191191
PyEvent_Wait(&test_data.done_event);
@@ -271,7 +271,7 @@ test_critical_sections_gc(PyObject *self, PyObject *Py_UNUSED(args))
271271
};
272272
assert(test_data.obj != NULL);
273273

274-
for (int i = 0; i < NUM_THREADS; i++) {
274+
for (Py_ssize_t i = 0; i < NUM_THREADS; i++) {
275275
PyThread_start_new_thread(&thread_gc, &test_data);
276276
}
277277
PyEvent_Wait(&test_data.done_event);

Objects/codeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ get_line_delta(const uint8_t *ptr)
573573
static PyObject *
574574
remove_column_info(PyObject *locations)
575575
{
576-
int offset = 0;
576+
Py_ssize_t offset = 0;
577577
const uint8_t *data = (const uint8_t *)PyBytes_AS_STRING(locations);
578578
PyObject *res = PyBytes_FromStringAndSize(NULL, 32);
579579
if (res == NULL) {

Objects/unicodeobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8373,7 +8373,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
83738373
int count2 = 0, count3 = 0;
83748374
int kind;
83758375
const void *data;
8376-
Py_ssize_t length;
8376+
int length;
83778377
Py_UCS4 ch;
83788378

83798379
if (!PyUnicode_Check(string) || !PyUnicode_GET_LENGTH(string)) {
@@ -8382,8 +8382,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
83828382
}
83838383
kind = PyUnicode_KIND(string);
83848384
data = PyUnicode_DATA(string);
8385-
length = PyUnicode_GET_LENGTH(string);
8386-
length = Py_MIN(length, 256);
8385+
length = (int)Py_MIN(PyUnicode_GET_LENGTH(string), 256);
83878386
memset(level1, 0xFF, sizeof level1);
83888387
memset(level2, 0xFF, sizeof level2);
83898388

Objects/unionobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ is_same(PyObject *left, PyObject *right)
8181
static int
8282
contains(PyObject **items, Py_ssize_t size, PyObject *obj)
8383
{
84-
for (int i = 0; i < size; i++) {
84+
for (Py_ssize_t i = 0; i < size; i++) {
8585
int is_duplicate = is_same(items[i], obj);
8686
if (is_duplicate) { // -1 or 1
8787
return is_duplicate;
@@ -97,7 +97,7 @@ merge(PyObject **items1, Py_ssize_t size1,
9797
PyObject *tuple = NULL;
9898
Py_ssize_t pos = 0;
9999

100-
for (int i = 0; i < size2; i++) {
100+
for (Py_ssize_t i = 0; i < size2; i++) {
101101
PyObject *arg = items2[i];
102102
int is_duplicate = contains(items1, size1, arg);
103103
if (is_duplicate < 0) {

Parser/action_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ _PyPegen_make_module(Parser *p, asdl_stmt_seq *a) {
864864
if (type_ignores == NULL) {
865865
return NULL;
866866
}
867-
for (int i = 0; i < num; i++) {
867+
for (Py_ssize_t i = 0; i < num; i++) {
868868
PyObject *tag = _PyPegen_new_type_comment(p, p->type_ignore_comments.items[i].comment);
869869
if (tag == NULL) {
870870
return NULL;

Python/ast_opt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
521521
static PyObject*
522522
make_const_tuple(asdl_expr_seq *elts)
523523
{
524-
for (int i = 0; i < asdl_seq_LEN(elts); i++) {
524+
for (Py_ssize_t i = 0; i < asdl_seq_LEN(elts); i++) {
525525
expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
526526
if (e->kind != Constant_kind) {
527527
return NULL;
@@ -533,7 +533,7 @@ make_const_tuple(asdl_expr_seq *elts)
533533
return NULL;
534534
}
535535

536-
for (int i = 0; i < asdl_seq_LEN(elts); i++) {
536+
for (Py_ssize_t i = 0; i < asdl_seq_LEN(elts); i++) {
537537
expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
538538
PyObject *v = e->v.Constant.value;
539539
PyTuple_SET_ITEM(newval, i, Py_NewRef(v));
@@ -650,7 +650,7 @@ static int astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTOptimize
650650
return 0;
651651

652652
#define CALL_SEQ(FUNC, TYPE, ARG) { \
653-
int i; \
653+
Py_ssize_t i; \
654654
asdl_ ## TYPE ## _seq *seq = (ARG); /* avoid variable capture */ \
655655
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
656656
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5109,7 +5109,7 @@ compiler_call_simple_kw_helper(struct compiler *c, location loc,
51095109
if (names == NULL) {
51105110
return ERROR;
51115111
}
5112-
for (int i = 0; i < nkwelts; i++) {
5112+
for (Py_ssize_t i = 0; i < nkwelts; i++) {
51135113
keyword_ty kw = asdl_seq_GET(keywords, i);
51145114
PyTuple_SET_ITEM(names, i, Py_NewRef(kw->arg));
51155115
}

Python/flowgraph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
20952095
/* now index_map[i] == i if consts[i] is used, -1 otherwise */
20962096
/* condense consts */
20972097
Py_ssize_t n_used_consts = 0;
2098-
for (int i = 0; i < nconsts; i++) {
2098+
for (Py_ssize_t i = 0; i < nconsts; i++) {
20992099
if (index_map[i] != -1) {
21002100
assert(index_map[i] == i);
21012101
index_map[n_used_consts++] = index_map[i];

Python/future.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
static int
99
future_check_features(_PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
1010
{
11-
int i;
11+
Py_ssize_t i;
1212

1313
assert(s->kind == ImportFrom_kind);
1414

Python/getargs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,8 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
20702070
const char *format;
20712071
const char *msg;
20722072
PyObject *keyword;
2073-
int i, pos, len;
2073+
Py_ssize_t i;
2074+
int pos, len;
20742075
Py_ssize_t nkwargs;
20752076
freelistentry_t static_entries[STATIC_FREELIST_ENTRIES];
20762077
freelist_t freelist;

Python/suggestions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ _Py_CalculateSuggestions(PyObject *dir,
146146
if (buffer == NULL) {
147147
return PyErr_NoMemory();
148148
}
149-
for (int i = 0; i < dir_size; ++i) {
149+
for (Py_ssize_t i = 0; i < dir_size; ++i) {
150150
PyObject *item = PyList_GET_ITEM(dir, i);
151151
if (_PyUnicode_Equal(name, item)) {
152152
continue;

Python/symtable.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, _PyFutureFeatures *future)
398398
{
399399
struct symtable *st = symtable_new();
400400
asdl_stmt_seq *seq;
401-
int i;
401+
Py_ssize_t i;
402402
PyThreadState *tstate;
403403
int starting_recursion_depth;
404404

@@ -1594,7 +1594,7 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
15941594

15951595
#define VISIT_SEQ(ST, TYPE, SEQ) \
15961596
do { \
1597-
int i; \
1597+
Py_ssize_t i; \
15981598
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
15991599
for (i = 0; i < asdl_seq_LEN(seq); i++) { \
16001600
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
@@ -1605,7 +1605,7 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
16051605

16061606
#define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) \
16071607
do { \
1608-
int i; \
1608+
Py_ssize_t i; \
16091609
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
16101610
for (i = (START); i < asdl_seq_LEN(seq); i++) { \
16111611
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
@@ -1916,7 +1916,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
19161916
VISIT_SEQ(st, alias, s->v.ImportFrom.names);
19171917
break;
19181918
case Global_kind: {
1919-
int i;
1919+
Py_ssize_t i;
19201920
asdl_identifier_seq *seq = s->v.Global.names;
19211921
for (i = 0; i < asdl_seq_LEN(seq); i++) {
19221922
identifier name = (identifier)asdl_seq_GET(seq, i);
@@ -1952,7 +1952,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
19521952
break;
19531953
}
19541954
case Nonlocal_kind: {
1955-
int i;
1955+
Py_ssize_t i;
19561956
asdl_identifier_seq *seq = s->v.Nonlocal.names;
19571957
for (i = 0; i < asdl_seq_LEN(seq); i++) {
19581958
identifier name = (identifier)asdl_seq_GET(seq, i);
@@ -2494,7 +2494,7 @@ symtable_implicit_arg(struct symtable *st, int pos)
24942494
static int
24952495
symtable_visit_params(struct symtable *st, asdl_arg_seq *args)
24962496
{
2497-
int i;
2497+
Py_ssize_t i;
24982498

24992499
if (!args)
25002500
return -1;
@@ -2555,7 +2555,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
25552555
static int
25562556
symtable_visit_argannotations(struct symtable *st, asdl_arg_seq *args)
25572557
{
2558-
int i;
2558+
Py_ssize_t i;
25592559

25602560
if (!args)
25612561
return -1;

0 commit comments

Comments
 (0)