Skip to content

Commit

Permalink
Fixes loop variables to be the same types as their limit (GH-120958)
Browse files Browse the repository at this point in the history
  • Loading branch information
zooba authored Jun 24, 2024
1 parent 2e15785 commit e731554
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testinternalcapi/test_critical_sections.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions Objects/unionobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Parser/action_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Python/ast_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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); \
Expand Down
2 changes: 1 addition & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Python/future.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Python/suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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); \
Expand All @@ -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); \
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e731554

Please sign in to comment.