1
0
mirror of https://github.com/python/cpython synced 2024-07-03 08:34:29 +00:00

Fixes loop variables to be the same types as their limit (GH-120958)

This commit is contained in:
Steve Dower 2024-06-24 17:11:47 +01:00 committed by GitHub
parent 2e157851e3
commit e731554337
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 26 additions and 26 deletions

View File

@ -202,7 +202,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
const char *newline, int closefd, PyObject *opener) const char *newline, int closefd, PyObject *opener)
/*[clinic end generated code: output=aefafc4ce2b46dc0 input=cd034e7cdfbf4e78]*/ /*[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 creating = 0, reading = 0, writing = 0, appending = 0, updating = 0;
int text = 0, binary = 0; int text = 0, binary = 0;

View File

@ -99,7 +99,7 @@ blob_close_impl(pysqlite_Blob *self)
void void
pysqlite_close_all_blobs(pysqlite_Connection *self) 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 *weakref = PyList_GET_ITEM(self->blobs, i);
PyObject *blob; PyObject *blob;
if (!PyWeakref_GetRef(weakref, &blob)) { if (!PyWeakref_GetRef(weakref, &blob)) {

View File

@ -185,7 +185,7 @@ test_critical_sections_threads(PyObject *self, PyObject *Py_UNUSED(args))
assert(test_data.obj2 != NULL); assert(test_data.obj2 != NULL);
assert(test_data.obj3 != 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); PyThread_start_new_thread(&thread_critical_sections, &test_data);
} }
PyEvent_Wait(&test_data.done_event); 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); 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); PyThread_start_new_thread(&thread_gc, &test_data);
} }
PyEvent_Wait(&test_data.done_event); PyEvent_Wait(&test_data.done_event);

View File

@ -573,7 +573,7 @@ get_line_delta(const uint8_t *ptr)
static PyObject * static PyObject *
remove_column_info(PyObject *locations) remove_column_info(PyObject *locations)
{ {
int offset = 0; Py_ssize_t offset = 0;
const uint8_t *data = (const uint8_t *)PyBytes_AS_STRING(locations); const uint8_t *data = (const uint8_t *)PyBytes_AS_STRING(locations);
PyObject *res = PyBytes_FromStringAndSize(NULL, 32); PyObject *res = PyBytes_FromStringAndSize(NULL, 32);
if (res == NULL) { if (res == NULL) {

View File

@ -8373,7 +8373,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
int count2 = 0, count3 = 0; int count2 = 0, count3 = 0;
int kind; int kind;
const void *data; const void *data;
Py_ssize_t length; int length;
Py_UCS4 ch; Py_UCS4 ch;
if (!PyUnicode_Check(string) || !PyUnicode_GET_LENGTH(string)) { if (!PyUnicode_Check(string) || !PyUnicode_GET_LENGTH(string)) {
@ -8382,8 +8382,7 @@ PyUnicode_BuildEncodingMap(PyObject* string)
} }
kind = PyUnicode_KIND(string); kind = PyUnicode_KIND(string);
data = PyUnicode_DATA(string); data = PyUnicode_DATA(string);
length = PyUnicode_GET_LENGTH(string); length = (int)Py_MIN(PyUnicode_GET_LENGTH(string), 256);
length = Py_MIN(length, 256);
memset(level1, 0xFF, sizeof level1); memset(level1, 0xFF, sizeof level1);
memset(level2, 0xFF, sizeof level2); memset(level2, 0xFF, sizeof level2);

View File

@ -81,7 +81,7 @@ is_same(PyObject *left, PyObject *right)
static int static int
contains(PyObject **items, Py_ssize_t size, PyObject *obj) 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); int is_duplicate = is_same(items[i], obj);
if (is_duplicate) { // -1 or 1 if (is_duplicate) { // -1 or 1
return is_duplicate; return is_duplicate;
@ -97,7 +97,7 @@ merge(PyObject **items1, Py_ssize_t size1,
PyObject *tuple = NULL; PyObject *tuple = NULL;
Py_ssize_t pos = 0; 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]; PyObject *arg = items2[i];
int is_duplicate = contains(items1, size1, arg); int is_duplicate = contains(items1, size1, arg);
if (is_duplicate < 0) { if (is_duplicate < 0) {

View File

@ -864,7 +864,7 @@ _PyPegen_make_module(Parser *p, asdl_stmt_seq *a) {
if (type_ignores == NULL) { if (type_ignores == NULL) {
return 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); PyObject *tag = _PyPegen_new_type_comment(p, p->type_ignore_comments.items[i].comment);
if (tag == NULL) { if (tag == NULL) {
return NULL; return NULL;

View File

@ -521,7 +521,7 @@ fold_binop(expr_ty node, PyArena *arena, _PyASTOptimizeState *state)
static PyObject* static PyObject*
make_const_tuple(asdl_expr_seq *elts) 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); expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
if (e->kind != Constant_kind) { if (e->kind != Constant_kind) {
return NULL; return NULL;
@ -533,7 +533,7 @@ make_const_tuple(asdl_expr_seq *elts)
return NULL; 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); expr_ty e = (expr_ty)asdl_seq_GET(elts, i);
PyObject *v = e->v.Constant.value; PyObject *v = e->v.Constant.value;
PyTuple_SET_ITEM(newval, i, Py_NewRef(v)); 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; return 0;
#define CALL_SEQ(FUNC, TYPE, ARG) { \ #define CALL_SEQ(FUNC, TYPE, ARG) { \
int i; \ Py_ssize_t i; \
asdl_ ## TYPE ## _seq *seq = (ARG); /* avoid variable capture */ \ asdl_ ## TYPE ## _seq *seq = (ARG); /* avoid variable capture */ \
for (i = 0; i < asdl_seq_LEN(seq); i++) { \ for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \ TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \

View File

@ -5109,7 +5109,7 @@ compiler_call_simple_kw_helper(struct compiler *c, location loc,
if (names == NULL) { if (names == NULL) {
return ERROR; 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); keyword_ty kw = asdl_seq_GET(keywords, i);
PyTuple_SET_ITEM(names, i, Py_NewRef(kw->arg)); PyTuple_SET_ITEM(names, i, Py_NewRef(kw->arg));
} }

View File

@ -2095,7 +2095,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
/* now index_map[i] == i if consts[i] is used, -1 otherwise */ /* now index_map[i] == i if consts[i] is used, -1 otherwise */
/* condense consts */ /* condense consts */
Py_ssize_t n_used_consts = 0; 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) { if (index_map[i] != -1) {
assert(index_map[i] == i); assert(index_map[i] == i);
index_map[n_used_consts++] = index_map[i]; index_map[n_used_consts++] = index_map[i];

View File

@ -8,7 +8,7 @@
static int static int
future_check_features(_PyFutureFeatures *ff, stmt_ty s, PyObject *filename) future_check_features(_PyFutureFeatures *ff, stmt_ty s, PyObject *filename)
{ {
int i; Py_ssize_t i;
assert(s->kind == ImportFrom_kind); assert(s->kind == ImportFrom_kind);

View File

@ -2070,7 +2070,8 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
const char *format; const char *format;
const char *msg; const char *msg;
PyObject *keyword; PyObject *keyword;
int i, pos, len; Py_ssize_t i;
int pos, len;
Py_ssize_t nkwargs; Py_ssize_t nkwargs;
freelistentry_t static_entries[STATIC_FREELIST_ENTRIES]; freelistentry_t static_entries[STATIC_FREELIST_ENTRIES];
freelist_t freelist; freelist_t freelist;

View File

@ -146,7 +146,7 @@ _Py_CalculateSuggestions(PyObject *dir,
if (buffer == NULL) { if (buffer == NULL) {
return PyErr_NoMemory(); 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); PyObject *item = PyList_GET_ITEM(dir, i);
if (_PyUnicode_Equal(name, item)) { if (_PyUnicode_Equal(name, item)) {
continue; continue;

View File

@ -398,7 +398,7 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, _PyFutureFeatures *future)
{ {
struct symtable *st = symtable_new(); struct symtable *st = symtable_new();
asdl_stmt_seq *seq; asdl_stmt_seq *seq;
int i; Py_ssize_t i;
PyThreadState *tstate; PyThreadState *tstate;
int starting_recursion_depth; int starting_recursion_depth;
@ -1594,7 +1594,7 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
#define VISIT_SEQ(ST, TYPE, SEQ) \ #define VISIT_SEQ(ST, TYPE, SEQ) \
do { \ do { \
int i; \ Py_ssize_t i; \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \ asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (i = 0; i < asdl_seq_LEN(seq); i++) { \ for (i = 0; i < asdl_seq_LEN(seq); i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(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) \ #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) \
do { \ do { \
int i; \ Py_ssize_t i; \
asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \ asdl_ ## TYPE ## _seq *seq = (SEQ); /* avoid variable capture */ \
for (i = (START); i < asdl_seq_LEN(seq); i++) { \ for (i = (START); i < asdl_seq_LEN(seq); i++) { \
TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(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); VISIT_SEQ(st, alias, s->v.ImportFrom.names);
break; break;
case Global_kind: { case Global_kind: {
int i; Py_ssize_t i;
asdl_identifier_seq *seq = s->v.Global.names; asdl_identifier_seq *seq = s->v.Global.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) { for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i); identifier name = (identifier)asdl_seq_GET(seq, i);
@ -1952,7 +1952,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
break; break;
} }
case Nonlocal_kind: { case Nonlocal_kind: {
int i; Py_ssize_t i;
asdl_identifier_seq *seq = s->v.Nonlocal.names; asdl_identifier_seq *seq = s->v.Nonlocal.names;
for (i = 0; i < asdl_seq_LEN(seq); i++) { for (i = 0; i < asdl_seq_LEN(seq); i++) {
identifier name = (identifier)asdl_seq_GET(seq, i); identifier name = (identifier)asdl_seq_GET(seq, i);
@ -2494,7 +2494,7 @@ symtable_implicit_arg(struct symtable *st, int pos)
static int static int
symtable_visit_params(struct symtable *st, asdl_arg_seq *args) symtable_visit_params(struct symtable *st, asdl_arg_seq *args)
{ {
int i; Py_ssize_t i;
if (!args) if (!args)
return -1; return -1;
@ -2555,7 +2555,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
static int static int
symtable_visit_argannotations(struct symtable *st, asdl_arg_seq *args) symtable_visit_argannotations(struct symtable *st, asdl_arg_seq *args)
{ {
int i; Py_ssize_t i;
if (!args) if (!args)
return -1; return -1;