[m-rev.] diff: tighten the scope of loop control variables in the runtime
Julien Fischer
jfischer at opturion.com
Fri May 15 16:41:51 AEST 2026
Tighten the scope of loop control variables in the runtime.
C99 lets variables be declared in the head of for statements and restricts the
scope of those variables to the body of for statement. Historically, we have
not used this feature in order to preserve compatibility with C compilers that
had limited C99 support. We have required C99 support for a while now, so make
use of the above feature.
runtime/*.c:
As above.
Julien.
diff --git a/runtime/mercury_accurate_gc.c b/runtime/mercury_accurate_gc.c
index 88bb34e58..b9cc603f3 100644
--- a/runtime/mercury_accurate_gc.c
+++ b/runtime/mercury_accurate_gc.c
@@ -620,7 +620,6 @@ traverse_frame(MR_bool registers_live, const
MR_LabelLayout *label_layout,
{
int short_var_count;
int long_var_count;
- int i;
MR_MemoryList allocated_memory_cells;
MR_TypeInfoParams type_params;
MR_ShortLval locn;
@@ -659,7 +658,7 @@ traverse_frame(MR_bool registers_live, const
MR_LabelLayout *label_layout,
// Copy each live variable.
- for (i = 0; i < long_var_count; i++) {
+ for (int i = 0; i < long_var_count; i++) {
locn = MR_long_desc_var_locn(label_layout, i);
pseudo_type_info = MR_var_pti(label_layout, i);
@@ -671,7 +670,7 @@ traverse_frame(MR_bool registers_live, const
MR_LabelLayout *label_layout,
allocated_memory_cells = NULL;
}
- for (i = 0; i < short_var_count; i++) {
+ for (int i = 0; i < short_var_count; i++) {
locn = MR_short_desc_var_locn(label_layout, i);
pseudo_type_info = MR_var_pti(label_layout, i);
diff --git a/runtime/mercury_agc_debug.c b/runtime/mercury_agc_debug.c
index f7983ba0a..4f4fd5a9f 100644
--- a/runtime/mercury_agc_debug.c
+++ b/runtime/mercury_agc_debug.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1998-2007, 2009, 2011 The University of Melbourne.
-// Copyright (C) 2016, 2018 The Mercury team.
+// Copyright (C) 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// Debugging support for the accurate garbage collector.
@@ -227,7 +227,6 @@ MR_dump_live_variables(const MR_LabelLayout *label_layout,
{
int short_var_count;
int long_var_count;
- int i;
MR_TypeInfo type_info;
MR_Word value;
MR_TypeInfoParams type_params;
@@ -257,7 +256,7 @@ MR_dump_live_variables(const MR_LabelLayout *label_layout,
type_params = MR_materialize_type_params_base(label_layout,
current_regs, stack_pointer, current_frame);
- for (i = 0; i < long_var_count; i++) {
+ for (int i = 0; i < long_var_count; i++) {
fprintf(stderr, "%-12s\t", "");
if (MR_PROC_LAYOUT_HAS_PROC_ID(label_layout->MR_sll_entry)) {
MR_print_proc_id(stderr, label_layout->MR_sll_entry);
@@ -286,7 +285,7 @@ MR_dump_live_variables(const MR_LabelLayout *label_layout,
}
}
- for (i = 0; i < short_var_count; i++) {
+ for (int i = 0; i < short_var_count; i++) {
fprintf(stderr, "%-12s\t", "");
if (MR_PROC_LAYOUT_HAS_PROC_ID(label_layout->MR_sll_entry)) {
MR_print_proc_id(stderr, label_layout->MR_sll_entry);
diff --git a/runtime/mercury_atomic_ops.c b/runtime/mercury_atomic_ops.c
index 334ecf8fb..dfc73bbea 100644
--- a/runtime/mercury_atomic_ops.c
+++ b/runtime/mercury_atomic_ops.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2007, 2009-2011 The University of Melbourne.
-// Copyright (C) 2014-2016, 2018 The Mercury team.
+// Copyright (C) 2014-2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// mercury_atomic_ops.c
@@ -318,8 +318,6 @@ MR_do_cpu_feature_detection(void)
#define CPUID_BRAND_STRING_SIZE (3*4*4 + 1)
char buff[CPUID_BRAND_STRING_SIZE];
- unsigned int page;
- unsigned int byte;
unsigned int shift;
// This processor supports the brand string from which we can
@@ -329,13 +327,13 @@ MR_do_cpu_feature_detection(void)
// This does not work on AMD processors since they don't include
// the clock speed in the brand string.
- for (page = 0; page < 3; page++) {
+ for (unsigned int page = 0; page < 3; page++) {
MR_cpuid(page + 0x80000002, 0, &a, &b, &c, &d);
#if MR_DEBUG_CPU_FEATURE_DETECTION
fprintf(stderr, "CPUID page: 0x%.8x, eax: 0x%.8x, ebx:
0x%.8x, ecx: 0x%.8x, edx: 0x%.8x\n",
page + 0x80000002, a, b, c, d);
#endif
- for (byte = 0; byte < 4; byte++) {
+ for (unsigned int byte = 0; byte < 4; byte++) {
shift = byte * 8;
buff[page*4*4 + 0 + byte] = (char)(0xFF & (a >> shift));
buff[page*4*4 + 4 + byte] = (char)(0xFF & (b >> shift));
@@ -367,7 +365,6 @@ static MR_uint_least64_t
parse_freq_from_x86_brand_string(char *string)
{
unsigned int brand_string_len;
- unsigned int i;
double multiplier;
int freq_index = -1;
@@ -404,9 +401,9 @@ parse_freq_from_x86_brand_string(char *string)
}
// Search for the beginning of the digits.
- for (i = brand_string_len - 4; i >= 0; i--) {
+ for (unsigned int i = brand_string_len - 4; i >= 0; i--) {
if (string[i] == ' ') {
- freq_index = i+1;
+ freq_index = i + 1;
break;
}
}
diff --git a/runtime/mercury_bitmap.c b/runtime/mercury_bitmap.c
index bbf663d91..7900766bb 100644
--- a/runtime/mercury_bitmap.c
+++ b/runtime/mercury_bitmap.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2007 The University of Melbourne.
-// Copyright (C) 2014, 2016, 2018 The Mercury team.
+// Copyright (C) 2014, 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// mercury_bitmap.c - bitmap handling
@@ -51,7 +51,6 @@ MR_do_bitmap_to_string(MR_ConstBitmapPtr b,
MR_bool quote, MR_bool use_saved_hp, MR_AllocSiteInfoPtr alloc_id)
{
MR_String result;
- size_t i;
size_t len;
size_t num_bytes;
size_t num_bits_len;
@@ -86,7 +85,7 @@ MR_do_bitmap_to_string(MR_ConstBitmapPtr b,
strcpy(result + start, num_bits_str);
start += num_bits_len;
result[start++] = ':';
- for (i = 0; i < num_bytes; i++) {
+ for (size_t i = 0; i < num_bytes; i++) {
result[start++] = hex_digits[(b->elements[i] >> 4) & 0xf];
result[start++] = hex_digits[b->elements[i] & 0xf];
}
diff --git a/runtime/mercury_construct.c b/runtime/mercury_construct.c
index bc486ce5f..eaec99029 100644
--- a/runtime/mercury_construct.c
+++ b/runtime/mercury_construct.c
@@ -41,11 +41,10 @@ MR_get_enum_functor_ordinal(MR_TypeCtorInfo type_ctor_info,
} else {
MR_EnumTypeLayout enum_layout;
int num_functors;
- int i;
enum_layout = MR_type_ctor_layout(type_ctor_info).MR_layout_enum;
num_functors = MR_type_ctor_num_functors(type_ctor_info);
- for (i = 0; i < num_functors; i++) {
+ for (int i = 0; i < num_functors; i++) {
if (enum_layout[i]->MR_enum_functor_value == value) {
return i;
}
@@ -270,11 +269,10 @@ MR_typecheck_arguments(MR_TypeInfo type_info,
int arity, MR_Word arg_list,
MR_TypeInfo arg_type_info;
MR_TypeInfo list_arg_type_info;
int comp;
- int i;
// Type check the list of arguments.
- for (i = 0; i < arity; i++) {
+ for (int i = 0; i < arity; i++) {
if (MR_list_is_empty(arg_list)) {
return MR_FALSE;
}
diff --git a/runtime/mercury_context.c b/runtime/mercury_context.c
index e432ba839..75f57870c 100644
--- a/runtime/mercury_context.c
+++ b/runtime/mercury_context.c
@@ -348,10 +348,6 @@ static void MR_make_cpu_unavailable(int cpu);
void
MR_init_context_stuff(void)
{
-#ifdef MR_LL_PARALLEL_CONJ
- unsigned i;
-#endif
-
#ifdef MR_THREAD_SAFE
pthread_mutex_init(&MR_runqueue_lock, MR_MUTEX_ATTR);
@@ -366,7 +362,7 @@ MR_init_context_stuff(void)
#ifdef MR_HIGHLEVEL_CODE
MR_KEY_CREATE(&MR_backjump_handler_key, NULL);
- MR_KEY_CREATE(&MR_backjump_next_choice_id_key, (void *)0);
+ MR_KEY_CREATE(&MR_backjump_next_choice_id_key, (void *) 0);
#endif
#ifdef MR_LL_PARALLEL_CONJ
@@ -386,13 +382,13 @@ MR_init_context_stuff(void)
MR_spark_deques = MR_GC_NEW_ARRAY_ATTRIB(MR_SparkDeque*,
MR_max_engines, MR_ALLOC_SITE_RUNTIME);
- for (i = 0; i < MR_max_engines; i++) {
+ for (unsigned i = 0; i < MR_max_engines; i++) {
MR_spark_deques[i] = NULL;
}
engine_sleep_sync_data = MR_GC_NEW_ARRAY_ATTRIB(engine_sleep_sync,
MR_max_engines, MR_ALLOC_SITE_RUNTIME);
- for (i = 0; i < MR_max_engines; i++) {
+ for (unsigned i = 0; i < MR_max_engines; i++) {
engine_sleep_sync *esync = get_engine_sleep_sync(i);
MR_sem_init(&esync->d.es_sleep_semaphore, 0);
pthread_mutex_init(&esync->d.es_wake_lock, MR_MUTEX_ATTR);
@@ -615,7 +611,6 @@ MR_pin_thread_no_locking(void)
{
int initial_cpu;
int max;
- int i;
initial_cpu = MR_current_cpu();
#ifdef MR_DEBUG_THREAD_PINNING
@@ -631,7 +626,7 @@ MR_pin_thread_no_locking(void)
#error Should be unreachable
#endif
- for (i = 0; (i < max) && MR_thread_pinning; i++) {
+ for (int i = 0; (i < max) && MR_thread_pinning; i++) {
int target_cpu = (initial_cpu + i) % max;
if (MR_do_pin_thread(target_cpu)) {
@@ -802,7 +797,6 @@ static MR_bool MR_make_pu_unavailable(const struct
hwloc_obj *pu)
{
hwloc_obj_t core;
static int siblings_to_make_unavailable;
- int i;
#ifdef MR_DEBUG_THREAD_PINNING
char *cpusetstr;
@@ -835,7 +829,7 @@ static MR_bool MR_make_pu_unavailable(const struct
hwloc_obj *pu)
return MR_FALSE;
}
- for (i = 0;
+ for (int i = 0;
(i < core->arity && siblings_to_make_unavailable > 0);
i++) {
if (core->children[i] == pu) {
@@ -1480,7 +1474,6 @@ MR_find_ready_context(void)
static MR_bool
MR_attempt_steal_spark(MR_Spark *spark)
{
- int i;
int offset;
int victim_id;
int max_victim_id;
@@ -1497,7 +1490,7 @@ MR_attempt_steal_spark(MR_Spark *spark)
max_victim_id = MR_num_ws_engines;
- for (i = 0; i < max_victim_id; i++) {
+ for (int i = 0; i < max_victim_id; i++) {
victim_id = (i + offset) % max_victim_id;
if (victim_id == MR_ENGINE(MR_eng_id)) {
// There is no point in stealing from ourselves.
@@ -1898,7 +1891,6 @@ MR_try_wake_ws_engine(MR_EngineId
preferred_engine, int action,
union MR_engine_wake_action_data *action_data, MR_EngineId *target_eng)
{
MR_EngineId current_engine;
- int i = 0;
int state;
MR_bool result;
MR_Unsigned valid_states;
@@ -1924,7 +1916,7 @@ MR_try_wake_ws_engine(MR_EngineId
preferred_engine, int action,
// Right now this algorithm is naive, it searches from the preferred engine
// around the loop until it finds an engine.
- for (i = 0; i < MR_num_ws_engines; i++) {
+ for (int i = 0; i < MR_num_ws_engines; i++) {
current_engine = (i + preferred_engine) % MR_num_ws_engines;
if (current_engine == MR_ENGINE(MR_eng_id)) {
// Don't post superfluous events to ourself.
@@ -2089,10 +2081,9 @@ try_notify_engine(MR_EngineId engine_id, int action,
void
MR_shutdown_ws_engines(void)
{
- int i;
MR_bool result;
- for (i = 0; i < MR_num_ws_engines; i++) {
+ for (int i = 0; i < MR_num_ws_engines; i++) {
if (i == MR_ENGINE(MR_eng_id)) {
continue;
}
diff --git a/runtime/mercury_debug.c b/runtime/mercury_debug.c
index 45eea1a57..d009d043f 100644
--- a/runtime/mercury_debug.c
+++ b/runtime/mercury_debug.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1996-2007, 2010 The University of Melbourne.
-// Copyright (C) 2013-2014, 2016, 2018 The Mercury team.
+// Copyright (C) 2013-2014, 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
#include "mercury_imp.h"
@@ -473,14 +473,13 @@ MR_goto_msg(FILE *fp, const MR_Code *addr)
void
MR_reg_msg(FILE *fp)
{
- int i;
MR_Integer x;
if (!MR_lld_print_enabled) {
return;
}
- for (i=1; i<=8; i++) {
+ for (int i = 1; i <= 8; i++) {
x = (MR_Integer) MR_get_reg(i);
#ifndef MR_CONSERVATIVE_GC
if ((MR_Integer) MR_ENGINE(MR_eng_heap_zone)->MR_zone_min <= x
@@ -589,8 +588,6 @@ MR_printheap(FILE *fp, const MR_Word *h)
void
MR_dumpframe(FILE *fp, const MR_Word *fr)
{
- int i;
-
fprintf(fp, "frame at ");
MR_printnondetstack(fp, fr),
fprintf(fp, "\n");
@@ -603,7 +600,7 @@ MR_dumpframe(FILE *fp, const MR_Word *fr)
fprintf(fp, "\t prevfr ");
MR_printnondetstack(fp, MR_prevfr_slot(fr));
- for (i = 1; &MR_based_framevar(fr,i) > MR_prevfr_slot(fr); i++) {
+ for (int i = 1; &MR_based_framevar(fr,i) > MR_prevfr_slot(fr); i++) {
fprintf(fp, "\t framevar(%d) %ld 0x%lx\n",
i, (long) (MR_Integer) MR_based_framevar(fr,i),
(unsigned long) MR_based_framevar(fr,i));
@@ -660,10 +657,9 @@ MR_printregs(FILE *fp, const char *msg)
static void
MR_print_ordinary_regs(FILE *fp)
{
- int i;
MR_Integer value;
- for (i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++) {
fprintf(fp, "r%d: ", i + 1);
value = (MR_Integer) MR_get_reg(i+1);
diff --git a/runtime/mercury_deconstruct.c b/runtime/mercury_deconstruct.c
index 01c104247..61c0358ca 100644
--- a/runtime/mercury_deconstruct.c
+++ b/runtime/mercury_deconstruct.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2002-2007, 2011 The University of Melbourne.
-// Copyright (C) 2013-2018 The Mercury team.
+// Copyright (C) 2013-2018, 2021, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// mercury_deconstruct.c
@@ -134,7 +134,6 @@ MR_named_arg_num(MR_TypeInfo type_info, MR_Word *term_ptr,
int ptag;
MR_Word sectag;
MR_TypeInfo eqv_type_info;
- int i;
type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
@@ -182,7 +181,7 @@ MR_named_arg_num(MR_TypeInfo type_info, MR_Word *term_ptr,
return MR_FALSE;
}
- for (i = 0; i < functor_desc->MR_du_functor_orig_arity; i++) {
+ for (int i = 0; i < functor_desc->MR_du_functor_orig_arity; i++) {
if (functor_desc->MR_du_functor_arg_names[i] != NULL
&& MR_streq(arg_name,
functor_desc->MR_du_functor_arg_names[i]))
diff --git a/runtime/mercury_deep_profiling.c b/runtime/mercury_deep_profiling.c
index ec6aa6703..a0af5545c 100644
--- a/runtime/mercury_deep_profiling.c
+++ b/runtime/mercury_deep_profiling.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2001-2008, 2010-2011 The University of Melbourne.
-// Copyright (C) 2016, 2018-2019, 2022, 2024-2025 The Mercury team.
+// Copyright (C) 2016, 2018-2019, 2022, 2024-2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// Deep profiling module
@@ -412,10 +412,6 @@ MR_write_out_profiling_tree(void)
time_t seconds_since_epoch;
struct tm *tm;
-#ifdef MR_DEEP_PROFILING_STATISTICS
- int i;
-#endif
-
if (MR_deep_prof_std_name_flag) {
strncpy(data_filename, "Deep.data", MR_FILENAME_BUF_LEN);
strncpy(procrep_filename, "Deep.procrep", MR_FILENAME_BUF_LEN);
@@ -706,7 +702,7 @@ MR_write_out_profiling_tree(void)
MR_deep_num_dynlist_nodes * sizeof(MR_CallSiteDynList));
fprintf(stderr, "\nTypeInfo search length histogram:\n");
- for (i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
+ for (int i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
if (MR_dictionary_search_lengths[i] > 0) {
fprintf(stderr, "\t%3d: %12d\n", i,
MR_dictionary_search_lengths[i]);
@@ -714,14 +710,14 @@ MR_write_out_profiling_tree(void)
}
fprintf(stderr, "\nClosure search length histogram:\n");
- for (i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
+ for (int i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
if (MR_closure_search_lengths[i] > 0) {
fprintf(stderr, "\t%3d: %12d\n", i, MR_closure_search_lengths[i]);
}
}
fprintf(stderr, "\nMethod search length histogram:\n");
- for (i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
+ for (int i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
if (MR_method_search_lengths[i] > 0) {
fprintf(stderr, "\t%3d: %12d\n", i, MR_method_search_lengths[i]);
}
@@ -890,14 +886,13 @@ MR_write_out_module_proc_reps_start(FILE *procrep_fp,
const MR_uint_least8_t *oisu_bytecode;
const MR_uint_least8_t *type_bytecode;
int size;
- int bytenum;
putc(MR_next_module, procrep_fp);
MR_write_string(procrep_fp, module_layout->MR_ml_name);
MR_write_num(procrep_fp, module_layout->MR_ml_string_table_size);
size = module_layout->MR_ml_string_table_size;
- for (bytenum = 0; bytenum < size; bytenum++) {
+ for (int bytenum = 0; bytenum < size; bytenum++) {
putc(module_layout->MR_ml_string_table[bytenum], procrep_fp);
}
@@ -914,7 +909,7 @@ MR_write_out_module_proc_reps_start(FILE *procrep_fp,
size = (oisu_bytecode[0] << 24) + (oisu_bytecode[1] << 16) +
(oisu_bytecode[2] << 8) + oisu_bytecode[3];
- for (bytenum = 0; bytenum < size; bytenum++) {
+ for (int bytenum = 0; bytenum < size; bytenum++) {
putc(oisu_bytecode[bytenum], procrep_fp);
}
}
@@ -932,7 +927,7 @@ MR_write_out_module_proc_reps_start(FILE *procrep_fp,
size = (type_bytecode[0] << 24) + (type_bytecode[1] << 16) +
(type_bytecode[2] << 8) + type_bytecode[3];
- for (bytenum = 0; bytenum < size; bytenum++) {
+ for (int bytenum = 0; bytenum < size; bytenum++) {
putc(type_bytecode[bytenum], procrep_fp);
}
}
@@ -953,7 +948,6 @@ MR_write_out_proc_static(FILE *deep_fp, FILE *procrep_fp,
int ps_id;
int css_id;
MR_bool already_written;
- int i;
if (proc_layout == NULL) {
MR_fatal_error("MR_write_out_proc_static: null proc_layout");
@@ -991,7 +985,7 @@ MR_write_out_proc_static(FILE *deep_fp, FILE *procrep_fp,
procid->MR_proc_user.MR_user_mode);
}
- for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
+ for (int i = 0; i < ps->MR_ps_num_call_sites; i++) {
if (i == 0) {
fputs("\n\t", deep_fp);
} else {
@@ -1094,7 +1088,7 @@ MR_write_out_proc_static(FILE *deep_fp, FILE *procrep_fp,
// Write out pointers to Call Site Statics. These are read in with the
// proc static.
- for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
+ for (int i = 0; i < ps->MR_ps_num_call_sites; i++) {
(void) MR_insert_call_site_static(&ps->MR_ps_call_sites[i], &css_id,
NULL, MR_FALSE);
@@ -1118,7 +1112,7 @@ MR_write_out_proc_static(FILE *deep_fp, FILE *procrep_fp,
// Write out the actual call site statics, These are read in after the
// proc static, not as part of it.
- for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
+ for (int i = 0; i < ps->MR_ps_num_call_sites; i++) {
#ifdef MR_DEEP_PROFILING_DEBUG
if (debug_fp != NULL) {
fprintf(debug_fp, "in proc_static %p/%p/%d, call site %d\n",
@@ -1148,14 +1142,13 @@ MR_write_out_proc_static(FILE *deep_fp, FILE
*procrep_fp,
bytecode = proc_layout->MR_sle_body_bytes;
if (bytecode != NULL) {
int size;
- int bytenum;
putc(MR_next_proc, procrep_fp);
MR_write_out_str_proc_label(procrep_fp, procid);
size = (bytecode[0] << 24) + (bytecode[1] << 16) +
(bytecode[2] << 8) + bytecode[3];
- for (bytenum = 0; bytenum < size; bytenum++) {
+ for (int bytenum = 0; bytenum < size; bytenum++) {
putc(bytecode[bytenum], procrep_fp);
}
}
@@ -1401,7 +1394,6 @@ MR_write_out_proc_dynamic(FILE *fp, const
MR_ProcDynamic *pd)
int pd_id;
int ps_id;
MR_bool already_written;
- int i;
if (pd == NULL) {
// This shouldn't really happen except that we don't have
@@ -1445,7 +1437,7 @@ MR_write_out_proc_dynamic(FILE *fp, const
MR_ProcDynamic *pd)
MR_write_out_coverage_points_dynamic(fp, pd);
#endif
- for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
+ for (int i = 0; i < ps->MR_ps_num_call_sites; i++) {
MR_write_kind(fp, ps->MR_ps_call_sites[i].MR_css_kind);
switch (ps->MR_ps_call_sites[i].MR_css_kind)
{
@@ -1470,7 +1462,7 @@ MR_write_out_proc_dynamic(FILE *fp, const
MR_ProcDynamic *pd)
}
}
- for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
+ for (int i = 0; i < ps->MR_ps_num_call_sites; i++) {
switch (ps->MR_ps_call_sites[i].MR_css_kind)
{
case MR_callsite_normal_call:
@@ -1540,7 +1532,6 @@ MR_write_out_coverage_points_static(FILE *fp,
const MR_ProcStatic *ps)
#ifdef MR_DEEP_PROFILING_COVERAGE_STATIC
const MR_Unsigned *cps;
#endif
- unsigned int i;
cps_static = ps->MR_ps_coverage_points_static;
#ifdef MR_DEEP_PROFILING_COVERAGE_STATIC
@@ -1548,7 +1539,7 @@ MR_write_out_coverage_points_static(FILE *fp,
const MR_ProcStatic *ps)
#endif
MR_write_num(fp, ps->MR_ps_num_coverage_points);
- for (i = 0; i < ps->MR_ps_num_coverage_points; i++) {
+ for (unsigned int i = 0; i < ps->MR_ps_num_coverage_points; i++) {
#ifdef MR_DEEP_PROFILING_DETAIL_DEBUG
if (debug_fp != NULL) {
@@ -1575,7 +1566,6 @@ MR_write_out_coverage_points_dynamic(FILE *fp,
const MR_ProcDynamic *pd)
{
#ifdef MR_DEEP_PROFILING_COVERAGE_DYNAMIC
const MR_Unsigned *cps;
- unsigned int i;
unsigned int ncps;
cps = pd->MR_pd_coverage_points;
@@ -1583,7 +1573,7 @@ MR_write_out_coverage_points_dynamic(FILE *fp,
const MR_ProcDynamic *pd)
MR_ps_num_coverage_points;
MR_write_num(fp, ncps);
- for (i = 0; i < ncps; i++) {
+ for (unsigned int i = 0; i < ncps; i++) {
#ifdef MR_DEEP_PROFILING_DETAIL_DEBUG
if (debug_fp != NULL) {
fprintf(debug_fp, "coverage point: %d",
@@ -1670,15 +1660,13 @@ MR_write_num(FILE *fp, unsigned long num)
static void
MR_write_fixed_size_int(FILE *fp, MR_uint_least64_t num)
{
- int i;
-
#ifdef MR_DEEP_PROFILING_DETAIL_DEBUG
if (debug_fp != NULL) {
fprintf(debug_fp, "fixed_size_int: %ld\n", num);
}
#endif
- for (i = 0; i < MR_FIXED_SIZE_INT_BYTES; i++) {
+ for (int i = 0; i < MR_FIXED_SIZE_INT_BYTES; i++) {
putc(num & ((1 << 8) - 1), fp);
num = num >> 8;
}
@@ -1687,7 +1675,6 @@ MR_write_fixed_size_int(FILE *fp, MR_uint_least64_t num)
static void
MR_write_string(FILE *fp, const char *ptr)
{
- int i;
int len;
#ifdef MR_DEEP_PROFILING_DETAIL_DEBUG
@@ -1698,7 +1685,7 @@ MR_write_string(FILE *fp, const char *ptr)
len = strlen(ptr);
MR_write_num(fp, len);
- for (i = 0; i < len; i++) {
+ for (int i = 0; i < len; i++) {
putc(ptr[i], fp);
}
}
@@ -1719,14 +1706,13 @@ static MR_ProfilingHashTable *
MR_create_hash_table(int size)
{
MR_ProfilingHashTable *ptr;
- int i;
ptr = MR_NEW(MR_ProfilingHashTable);
ptr->length = size;
ptr->last_id = 0;
ptr->nodes = MR_NEW_ARRAY(MR_ProfilingHashNode *, size);
- for (i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
ptr->nodes[i] = NULL;
}
@@ -1982,12 +1968,11 @@ static int
MR_hash_table_check_all_written_INTERNAL(FILE *fp, const char *type,
MR_ProfilingHashTable *table, void write_func(FILE *, const void *))
{
- int i;
int errors;
MR_ProfilingHashNode *node;
errors = 0;
- for (i = 0; i < table->length ; i++) {
+ for (int i = 0; i < table->length ; i++) {
for (node = table->nodes[i]; node != NULL; node = node->next) {
if (! node->written) {
errors++;
diff --git a/runtime/mercury_engine.c b/runtime/mercury_engine.c
index 0cdd04ddf..b67d57011 100644
--- a/runtime/mercury_engine.c
+++ b/runtime/mercury_engine.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1993-2001, 2003-2007, 2009-2011 The University of Melbourne.
-// Copyright (C) 2014, 2016, 2018 The Mercury team.
+// Copyright (C) 2014, 2016, 2018, 2022-2023, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
/*
@@ -626,7 +626,6 @@ static int prev_fp_index = 0;
void
MR_dump_prev_locations(void)
{
- int i;
int pos;
#if !defined(MR_DEBUG_GOTOS)
@@ -634,7 +633,7 @@ MR_dump_prev_locations(void)
#endif
{
printf("previous %d locations:\n", NUM_PREV_FPS);
- for (i = 0; i < NUM_PREV_FPS; i++) {
+ for (int i = 0; i < NUM_PREV_FPS; i++) {
pos = (i + prev_fp_index) % NUM_PREV_FPS;
MR_printlabel(stdout, prev_fps[pos]);
}
diff --git a/runtime/mercury_float.c b/runtime/mercury_float.c
index aae0787ab..65b74341c 100644
--- a/runtime/mercury_float.c
+++ b/runtime/mercury_float.c
@@ -12,7 +12,7 @@
#endif
// The function `MR_hash_float()' is used by the library predicate
-// `float__hash' and also for hashing floats for `pragma fact_table' indexing.
+// `float.hash' and also for hashing floats for `pragma fact_table' indexing.
// It computes a non-negative MR_Integer hash value for a MR_Float.
// The exact hash function used depend on the relative sizes of MR_Float and
// MR_Integer.
@@ -29,7 +29,6 @@ MR_Integer
MR_hash_float(MR_Float f)
{
union MR_Float_Integer fi;
- size_t i;
MR_Integer h = 0;
fi.i = 0;
@@ -38,11 +37,11 @@ MR_hash_float(MR_Float f)
if (sizeof(MR_Float) <= sizeof(MR_Integer)) {
h = fi.i;
} else if (sizeof(MR_Float) % sizeof(MR_Integer) == 0) {
- for (i = 0; i < sizeof(MR_Float)/sizeof(MR_Integer); i++) {
+ for (size_t i = 0; i < sizeof(MR_Float) / sizeof(MR_Integer); i++) {
h ^= fi.j[i];
}
} else {
- for (i = 0; i < sizeof(MR_Float)/sizeof(char); i++) {
+ for (size_t i = 0; i < sizeof(MR_Float) / sizeof(char); i++) {
h ^= (h << 5);
h ^= fi.c[i];
}
diff --git a/runtime/mercury_hash_table.c b/runtime/mercury_hash_table.c
index b4fa178ea..3c3a74e0b 100644
--- a/runtime/mercury_hash_table.c
+++ b/runtime/mercury_hash_table.c
@@ -21,12 +21,10 @@
void
MR_ht_init_table(MR_Hash_Table *table)
{
- int i;
-
table->MR_ht_store = MR_GC_NEW_ARRAY_ATTRIB(MR_Dlist *, table->MR_ht_size,
MR_ALLOC_SITE_RUNTIME);
- for (i = 0; i < table->MR_ht_size; i++) {
+ for (int i = 0; i < table->MR_ht_size; i++) {
table->MR_ht_store[i] = NULL;
}
}
@@ -90,10 +88,9 @@ MR_Dlist *
MR_ht_get_all_entries(const MR_Hash_Table *table)
{
MR_Dlist *list;
- int i;
list = MR_dlist_makelist0();
- for (i = 0; i < table->MR_ht_size; i++) {
+ for (int i = 0; i < table->MR_ht_size; i++) {
MR_dlist_addndlist(list, table->MR_ht_store[i]);
}
@@ -104,9 +101,8 @@ void
MR_ht_process_all_entries(const MR_Hash_Table *table, void f(const void *))
{
MR_Dlist *ptr;
- int i;
- for (i = 0; i < table->MR_ht_size; i++) {
+ for (int i = 0; i < table->MR_ht_size; i++) {
MR_for_dlist (ptr, table->MR_ht_store[i]) {
f(MR_dlist_data(ptr));
}
diff --git a/runtime/mercury_heap_profile.c b/runtime/mercury_heap_profile.c
index 7626a01a5..73f216d3d 100644
--- a/runtime/mercury_heap_profile.c
+++ b/runtime/mercury_heap_profile.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1997, 1999-2001, 2006, 2011 The University of Melbourne.
-// Copyright (C) 2016, 2018 The Mercury team.
+// Copyright (C) 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// File: mercury_heap_profile.c.
@@ -263,7 +263,6 @@ MR_register_alloc_sites(const MR_AllocSiteInfo
*alloc_sites, int size)
{
size_t bytes;
unsigned id;
- int i;
if (attrib_count_table == NULL) {
// We must not use GC allocation here.
@@ -276,7 +275,7 @@ MR_register_alloc_sites(const MR_AllocSiteInfo
*alloc_sites, int size)
MR_NUM_BUILTIN_ALLOC_SITES);
}
- for (i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
// Enlarge the hash table if necessary.
if (attrib_count_table_size > 0 &&
2 * attrib_count_table_used >= attrib_count_table_size)
@@ -320,14 +319,13 @@ rehash_attrib_count_table(void)
MR_AttribCount *new_table;
size_t new_size;
size_t new_used;
- size_t i;
new_size = attrib_count_table_size * 2;
new_table = MR_malloc(new_size * sizeof(MR_AttribCount));
memset(new_table, 0, new_size * sizeof(MR_AttribCount));
new_used = 0;
- for (i = 0; i < attrib_count_table_size; i++) {
+ for (int i = 0; i < attrib_count_table_size; i++) {
if (attrib_count_table[i].MR_atc_alloc_site != NULL) {
add_attrib_count_entry(new_table, new_size, &new_used,
attrib_count_table[i].MR_atc_id,
@@ -480,9 +478,7 @@ finish_reachable_report(const char *label)
static void
write_attrib_counts(FILE *fp, MR_AttribCount *table, size_t table_size)
{
- size_t i;
-
- for (i = 0; i < table_size; i++) {
+ for (size_t i = 0; i < table_size; i++) {
if (table[i].MR_atc_alloc_site != NULL &&
table[i].MR_atc_num_cells != 0)
{
@@ -524,7 +520,6 @@ MR_finish_prof_snapshots_file(void)
{
FILE *fp;
const MR_AllocSiteInfo *site;
- size_t i;
if (!(fp = snapshot_file)) {
return;
@@ -534,7 +529,7 @@ MR_finish_prof_snapshots_file(void)
GC_mercury_write_size_map(fp);
fprintf(fp, "\n");
- for (i = 0; i < attrib_count_table_size; i++) {
+ for (size_t i = 0; i < attrib_count_table_size; i++) {
site = attrib_count_table[i].MR_atc_alloc_site;
if (site != NULL) {
fprintf(fp, "%u\t", attrib_count_table[i].MR_atc_id);
diff --git a/runtime/mercury_hgc.c b/runtime/mercury_hgc.c
index e7b2cc3d9..51cd96740 100644
--- a/runtime/mercury_hgc.c
+++ b/runtime/mercury_hgc.c
@@ -867,7 +867,6 @@ MR_hgc_init(void)
hgc_int initial_big_heap_size; // In words.
hgc_int initial_heap_size; // In words.
hgc_ptr heap_midpoint;
- int i;
char *envvar;
// Just return if we have already been initialised.
@@ -930,14 +929,14 @@ MR_hgc_init(void)
small_bot = page(heap_bot + page_size - 1);
small_top = small_bot;
small_high_water = small_bot + initial_small_heap_size;
- for (i = 0; i <= max_small_payload; i++) {
+ for (int i = 0; i <= max_small_payload; i++) {
small_cell_free_list[i] = NULL;
}
// Set up the big heap (this grows downwards). We have to create the
// initial empty cell and add it to the right free list.
- for (i = 0; i <= max_big_cell_size_index; i++) {
+ for (int i = 0; i <= max_big_cell_size_index; i++) {
big_cell_free_list[i] = NULL;
}
big_size_index = min_big_cell_size_index;
diff --git a/runtime/mercury_ho_call.c b/runtime/mercury_ho_call.c
index 5012e961b..ce5d4b08a 100644
--- a/runtime/mercury_ho_call.c
+++ b/runtime/mercury_ho_call.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1995-2007 The University of Melbourne.
-// Copyright (C) 2014, 2016, 2018, 2021 The Mercury team.
+// Copyright (C) 2014, 2016, 2018, 2021-2022, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This module provides much of the functionality for doing higher order
@@ -341,30 +341,28 @@ static unsigned int
MR_hidden_method_arg_histogram[MR_MAX_STATS_ARG];
void
MR_print_hidden_arg_stats(FILE *fp)
{
- int i;
-
- for (i = 0; i < MR_MAX_STATS_ARG; i++) {
+ for (int i = 0; i < MR_MAX_STATS_ARG; i++) {
if (MR_explicit_closure_arg_histogram[i] > 0) {
fprintf(fp, "closure invocations with %d explicit args: %d\n",
i, MR_explicit_closure_arg_histogram[i]);
}
}
- for (i = 0; i < MR_MAX_STATS_ARG; i++) {
+ for (int i = 0; i < MR_MAX_STATS_ARG; i++) {
if (MR_explicit_method_arg_histogram[i] > 0) {
fprintf(fp, "method invocations with %d explicit args: %d\n",
i, MR_explicit_method_arg_histogram[i]);
}
}
- for (i = 0; i < MR_MAX_STATS_ARG; i++) {
+ for (int i = 0; i < MR_MAX_STATS_ARG; i++) {
if (MR_hidden_closure_arg_histogram[i] > 0) {
fprintf(fp, "closure invocations with %d hidden args: %d\n",
i, MR_hidden_closure_arg_histogram[i]);
}
}
- for (i = 0; i < MR_MAX_STATS_ARG; i++) {
+ for (int i = 0; i < MR_MAX_STATS_ARG; i++) {
if (MR_hidden_method_arg_histogram[i] > 0) {
fprintf(fp, "method invocations with %d hidden args: %d\n",
i, MR_hidden_method_arg_histogram[i]);
@@ -776,7 +774,6 @@ MR_compare_closures_representation(MR_Closure *x,
MR_Closure *y)
int num_args;
int r_offset;
int f_offset;
- int i;
int result;
// Optimize the simple case.
@@ -839,7 +836,7 @@ MR_compare_closures_representation(MR_Closure *x,
MR_Closure *y)
r_offset = 0;
f_offset = MR_closure_num_hidden_r_args(x);
- for (i = 0; i < num_args; i++) {
+ for (int i = 0; i < num_args; i++) {
MR_TypeInfo x_arg_type_info;
MR_TypeInfo y_arg_type_info;
MR_TypeInfo arg_type_info;
diff --git a/runtime/mercury_layout_util.c b/runtime/mercury_layout_util.c
index d0b802e37..f28c8722b 100644
--- a/runtime/mercury_layout_util.c
+++ b/runtime/mercury_layout_util.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1998-2007, 2009, 2012 The University of Melbourne.
-// Copyright (C) 2013, 2015-2016, 2018 The Mercury team.
+// Copyright (C) 2013, 2015-2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This file implements utilities that can be useful
@@ -41,17 +41,15 @@ MR_copy_regs_to_saved_regs(int max_mr_num, MR_Word
*saved_regs,
// We never use real machine registers for floats so we just have
// to copy them from the MR_float_reg array.
- int i;
-
MR_restore_transient_registers();
MR_save_registers();
- for (i = 0; i <= max_mr_num; i++) {
+ for (int i = 0; i <= max_mr_num; i++) {
saved_regs[i] = MR_fake_reg[i];
}
#ifdef MR_BOXED_FLOAT
- for (i = 0; i <= max_f_num; i++) {
+ for (int i = 0; i <= max_f_num; i++) {
saved_f_regs[i] = MR_float_reg[i];
}
#else
@@ -69,14 +67,12 @@ MR_copy_saved_regs_to_regs(int max_mr_num, MR_Word
*saved_regs,
// MR_restore_transient_registers macro after MR_trace will do the
// right thing.
- int i;
-
- for (i = 0; i <= max_mr_num; i++) {
+ for (int i = 0; i <= max_mr_num; i++) {
MR_fake_reg[i] = saved_regs[i];
}
#ifdef MR_BOXED_FLOAT
- for (i = 0; i <= max_f_num; i++) {
+ for (int i = 0; i <= max_f_num; i++) {
MR_float_reg[i] = saved_f_regs[i];
}
#else
@@ -107,12 +103,11 @@ MR_materialize_type_params_base(const
MR_LabelLayout *label_layout,
MR_TypeInfoParams type_params;
MR_bool succeeded;
MR_Integer count;
- int i;
count = tvar_locns->MR_tp_param_count;
type_params = (MR_TypeInfoParams) MR_NEW_ARRAY(MR_Word, count + 1);
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
if (tvar_locns->MR_tp_param_locns[i] != 0) {
type_params[i + 1] = (MR_TypeInfo)
MR_lookup_long_lval_base(tvar_locns->MR_tp_param_locns[i],
@@ -141,12 +136,11 @@ MR_materialize_closure_type_params(MR_Closure *closure)
MR_TypeInfoParams type_params;
MR_bool succeeded;
MR_Integer count;
- int i;
count = tvar_locns->MR_tp_param_count;
type_params = (MR_TypeInfoParams) MR_NEW_ARRAY(MR_Word, count + 1);
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
if (tvar_locns->MR_tp_param_locns[i] != 0) {
type_params[i + 1] = (MR_TypeInfo)
MR_lookup_closure_long_lval(
@@ -175,12 +169,11 @@
MR_materialize_typeclass_info_type_params(MR_Word typeclass_info,
MR_TypeInfoParams type_params;
MR_bool succeeded;
MR_Integer count;
- int i;
count = tvar_locns->MR_tp_param_count;
type_params = (MR_TypeInfoParams) MR_NEW_ARRAY(MR_Word, count + 1);
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
if (tvar_locns->MR_tp_param_locns[i] != 0)
{
type_params[i + 1] = (MR_TypeInfo)
@@ -208,12 +201,11 @@ MR_materialize_answer_block_type_params(const
MR_TypeParamLocns *tvar_locns,
MR_TypeInfoParams type_params;
MR_bool succeeded;
MR_Integer count;
- int i;
count = tvar_locns->MR_tp_param_count;
type_params = (MR_TypeInfoParams) MR_NEW_ARRAY(MR_Word, count + 1);
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
if (tvar_locns->MR_tp_param_locns[i] != 0) {
type_params[i + 1] = (MR_TypeInfo)
MR_lookup_answer_block_long_lval(
diff --git a/runtime/mercury_memory_handlers.c
b/runtime/mercury_memory_handlers.c
index 3c6adcf33..08d0e5863 100644
--- a/runtime/mercury_memory_handlers.c
+++ b/runtime/mercury_memory_handlers.c
@@ -539,8 +539,7 @@ MR_ExceptionName MR_exception_names[] =
static const char *
MR_find_exception_name(DWORD exception_code)
{
- int i;
- for (i = 0; i < sizeof(MR_exception_names)
+ for (int i = 0; i < sizeof(MR_exception_names)
/ sizeof(MR_ExceptionName); i++)
{
if (MR_exception_names[i].exception_code == exception_code) {
@@ -644,8 +643,6 @@ MR_explain_exception_record(EXCEPTION_RECORD *rec)
static void
MR_dump_exception_record(EXCEPTION_RECORD *rec)
{
- int i;
-
if (rec == NULL) {
return;
}
@@ -664,7 +661,7 @@ MR_dump_exception_record(EXCEPTION_RECORD *rec)
MR_INTEGER_LENGTH_MODIFIER "x",
(MR_Word) rec->ExceptionAddress);
- for (i = 0; i < rec->NumberParameters; i++) {
+ for (int i = 0; i < rec->NumberParameters; i++) {
fprintf(stderr, "\n*** Parameter %d : 0x%08lx", i,
(unsigned long) rec->ExceptionInformation[i]);
}
@@ -889,8 +886,7 @@ leave_signal_handler(int sig)
fprintf(stderr, "exiting from signal handler\n");
#if defined(MR_THREAD_SAFE) && defined(MR_THREADSCOPE)
if (MR_all_engine_bases) {
- int i;
- for (i = 0; i < MR_max_engines; i++) {
+ for (int i = 0; i < MR_max_engines; i++) {
if (MR_all_engine_bases[i] &&
MR_all_engine_bases[i]->MR_eng_ts_buffer)
{
diff --git a/runtime/mercury_memory_zones.c b/runtime/mercury_memory_zones.c
index cef12e675..b31c09e33 100644
--- a/runtime/mercury_memory_zones.c
+++ b/runtime/mercury_memory_zones.c
@@ -361,7 +361,6 @@ MR_init_zones(void)
static void
MR_init_offsets(void)
{
- int i;
size_t fake_reg_offset;
offset_counter = 0;
@@ -371,7 +370,7 @@ MR_init_offsets(void)
fake_reg_offset = (MR_Unsigned) MR_fake_reg % MR_pcache_size;
- for (i = 0; i < CACHE_SLICES - 1; i++) {
+ for (int i = 0; i < CACHE_SLICES - 1; i++) {
offset_vector[i] =
(fake_reg_offset + MR_pcache_size * i / CACHE_SLICES)
% MR_pcache_size;
@@ -958,7 +957,7 @@ static MR_bool
MR_should_stop_gc_memory_zones(void);
static MR_MemoryZonesFree * MR_THREADSAFE_VOLATILE free_memory_zones = NULL;
// This value is used to maintain a position within the list of free zones.
-// If it is null then no position is maintained. Otherwise it points to a
+// If it is null, then no position is maintained. Otherwise it points to a
// position within the list, in this case it represents a sub-list of free
// zones. This sub list always contains the least-recently-used zones.
//
@@ -975,7 +974,7 @@ static MR_MemoryZonesFree * MR_THREADSAFE_VOLATILE
static MR_THREADSAFE_VOLATILE MR_Unsigned free_memory_zones_num = 0;
-// The number pages used bo the cached free zones.
+// The number of pages used by the cached free zones.
static MR_THREADSAFE_VOLATILE MR_Unsigned free_memory_zones_pages = 0;
diff --git a/runtime/mercury_minimal_model.c b/runtime/mercury_minimal_model.c
index c299511b9..8fcebf992 100644
--- a/runtime/mercury_minimal_model.c
+++ b/runtime/mercury_minimal_model.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2003-2006 The University of Melbourne.
-// Copyright (C) 2014, 2016, 2018, 2025 The Mercury team.
+// Copyright (C) 2014, 2016, 2018, 2025-2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This module contains the functions related specifically to the stack copy
@@ -176,9 +176,7 @@ MR_enter_consumer_debug(MR_Consumer *consumer)
MR_ConsumerDebug *
MR_lookup_consumer_debug_addr(MR_Consumer *consumer)
{
- int i;
-
- for (i = 0; i < MR_consumer_debug_info_next; i++) {
+ for (int i = 0; i < MR_consumer_debug_info_next; i++) {
if (MR_consumer_debug_infos[i].MR_cod_consumer == consumer) {
return &MR_consumer_debug_infos[i];
}
@@ -190,9 +188,7 @@ MR_lookup_consumer_debug_addr(MR_Consumer *consumer)
MR_ConsumerDebug *
MR_lookup_consumer_debug_num(MR_Unsigned consumer_index)
{
- MR_Unsigned i;
-
- for (i = 0; i < MR_consumer_debug_info_next; i++) {
+ for (MR_Unsigned i = 0; i < MR_consumer_debug_info_next; i++) {
if (MR_consumer_debug_infos[i].MR_cod_sequence_num == consumer_index) {
return &MR_consumer_debug_infos[i];
}
@@ -277,9 +273,7 @@ MR_enter_subgoal_debug(MR_Subgoal *subgoal)
MR_SubgoalDebug *
MR_lookup_subgoal_debug_addr(MR_Subgoal *subgoal)
{
- int i;
-
- for (i = 0; i < MR_subgoal_debug_info_next; i++) {
+ for (int i = 0; i < MR_subgoal_debug_info_next; i++) {
if (MR_subgoal_debug_infos[i].MR_sgd_subgoal == subgoal) {
return &MR_subgoal_debug_infos[i];
}
@@ -291,9 +285,7 @@ MR_lookup_subgoal_debug_addr(MR_Subgoal *subgoal)
MR_SubgoalDebug *
MR_lookup_subgoal_debug_num(MR_Unsigned subgoal_index)
{
- MR_Unsigned i;
-
- for (i = 0; i < MR_subgoal_debug_info_next; i++) {
+ for (MR_Unsigned i = 0; i < MR_subgoal_debug_info_next; i++) {
if (MR_subgoal_debug_infos[i].MR_sgd_sequence_num == subgoal_index) {
return &MR_subgoal_debug_infos[i];
}
@@ -1355,7 +1347,6 @@ prune_right_branches(MR_SavedState *saved_state,
MR_Integer already_pruned,
#ifdef MR_TABLE_DEBUG
if (MR_tabledebug) {
int num_frame_vars;
- int i;
printf("thrashing non-main-branch frame\n");
@@ -1364,7 +1355,7 @@ prune_right_branches(MR_SavedState *saved_state,
MR_Integer already_pruned,
// restored. The vandalism below is intended to test this.
num_frame_vars = frame_size - MR_NONDET_FIXED_SIZE;
- for (i = 1; i <= num_frame_vars; i++) {
+ for (int i = 1; i <= num_frame_vars; i++) {
*MR_based_framevar_addr(saved_fr, i) = -1;
}
}
@@ -1613,9 +1604,7 @@ print_saved_state(FILE *fp, MR_SavedState *saved_state)
static void
print_stack_segment(FILE *fp, MR_Word *segment, MR_Integer size)
{
- int i;
-
- for (i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
fprintf(fp, "%2d %p: %ld (%lx)\n", i, &segment[i],
(long) segment[i], (long) segment[i]);
}
diff --git a/runtime/mercury_misc.c b/runtime/mercury_misc.c
index 605be85c8..ba54dc870 100644
--- a/runtime/mercury_misc.c
+++ b/runtime/mercury_misc.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1996-2000,2002, 2006, 2010-2011 The University of Melbourne.
-// Copyright (C) 2014, 2016, 2018 The Mercury team.
+// Copyright (C) 2014, 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
#include "mercury_conf.h"
@@ -145,9 +145,7 @@ MR_register_exception_cleanup(void (*func)(void
*), void *data)
void
MR_perform_registered_exception_cleanups(void)
{
- int i;
-
- for (i = 0; i < MR_cleanup_record_next; i++) {
+ for (int i = 0; i < MR_cleanup_record_next; i++) {
MR_cleanup_records[i].func(MR_cleanup_records[i].data);
}
}
diff --git a/runtime/mercury_mm_own_stacks.c b/runtime/mercury_mm_own_stacks.c
index ef64113c1..b08a0e342 100644
--- a/runtime/mercury_mm_own_stacks.c
+++ b/runtime/mercury_mm_own_stacks.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2004-2007, 2011 The University of Melbourne.
-// Copyright (C) 2013-2014, 2016, 2018 The Mercury team.
+// Copyright (C) 2013-2014, 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This module contains the functions related specifically to the own stack
@@ -110,9 +110,7 @@ MR_enter_cons_debug(MR_Consumer *consumer)
MR_ConsDebug *
MR_lookup_cons_debug_addr(MR_Consumer *consumer)
{
- int i;
-
- for (i = 0; i < MR_cons_debug_info_next; i++) {
+ for (int i = 0; i < MR_cons_debug_info_next; i++) {
if (MR_cons_debug_infos[i].MR_cod_consumer == consumer) {
return &MR_cons_debug_infos[i];
}
@@ -124,9 +122,7 @@ MR_lookup_cons_debug_addr(MR_Consumer *consumer)
MR_ConsDebug *
MR_lookup_cons_debug_num(int cons_index)
{
- int i;
-
- for (i = 0; i < MR_cons_debug_info_next; i++) {
+ for (int i = 0; i < MR_cons_debug_info_next; i++) {
if (MR_cons_debug_infos[i].MR_cod_sequence_num == cons_index) {
return &MR_cons_debug_infos[i];
}
@@ -232,9 +228,7 @@ MR_enter_gen_debug(MR_Generator *generator)
MR_GenDebug *
MR_lookup_gen_debug_addr(MR_Generator *generator)
{
- int i;
-
- for (i = 0; i < MR_gen_debug_info_next; i++) {
+ for (int i = 0; i < MR_gen_debug_info_next; i++) {
if (MR_gen_debug_infos[i].MR_gd_generator == generator) {
return &MR_gen_debug_infos[i];
}
@@ -246,9 +240,7 @@ MR_lookup_gen_debug_addr(MR_Generator *generator)
MR_GenDebug *
MR_lookup_gen_debug_num(int gen_index)
{
- int i;
-
- for (i = 0; i < MR_gen_debug_info_next; i++) {
+ for (int i = 0; i < MR_gen_debug_info_next; i++) {
if (MR_gen_debug_infos[i].MR_gd_sequence_num == gen_index) {
return &MR_gen_debug_infos[i];
}
@@ -613,7 +605,6 @@ MR_table_mmos_setup_generator(MR_TrieNode
trie_node, MR_Integer num_input_args,
{
MR_GeneratorPtr generator;
MR_Context *context;
- int i;
generator = MR_TABLE_NEW(MR_Generator);
context = MR_get_context_for_gen(generator);
@@ -636,7 +627,7 @@ MR_table_mmos_setup_generator(MR_TrieNode
trie_node, MR_Integer num_input_args,
generator->MR_gen_num_input_args = num_input_args;
generator->MR_gen_input_args = MR_TABLE_NEW_ARRAY(MR_Word, num_input_args);
- for (i = 0; i < num_input_args; i++) {
+ for (int i = 0; i < num_input_args; i++) {
generator->MR_gen_input_args[i] = MR_mmos_arg_regs[i];
}
diff --git a/runtime/mercury_par_builtin.c b/runtime/mercury_par_builtin.c
index 6bd8e8ec9..5dd0a3d5f 100644
--- a/runtime/mercury_par_builtin.c
+++ b/runtime/mercury_par_builtin.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2009, 2011 The University of Melbourne.
-// Copyright (C) 2015-2016, 2018 The Mercury team.
+// Copyright (C) 2015-2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
#include "mercury_types.h"
@@ -41,12 +41,11 @@ MR_LoopControl *
MR_lc_create(unsigned num_workers)
{
MR_LoopControl *lc;
- unsigned i;
lc = MR_GC_malloc(sizeof(MR_LoopControl) +
(num_workers-1) * sizeof(MR_LoopControlSlot));
lc->MR_lc_num_slots = num_workers;
- for (i = 0; i < num_workers; i++) {
+ for (unsigned i = 0; i < num_workers; i++) {
// We allocate contexts as necessary, so that we never allocate a
// context we don't use. Also, by allocating the contexts in
// MR_lc_spawn_off, already spawned off computations can run in
@@ -77,7 +76,7 @@ MR_lc_try_get_free_slot(MR_LoopControl *lc,
MR_Unsigned *lcs_idx)
if (lc->MR_lc_outstanding_workers == lc->MR_lc_num_slots) {
return MR_FALSE;
} else {
- unsigned hint, offset, i;
+ unsigned hint, i;
// We start indexing into the array starting at this hint, it is either
// set to a known free slot or the next unchecked slot after finding a
@@ -85,7 +84,7 @@ MR_lc_try_get_free_slot(MR_LoopControl *lc,
MR_Unsigned *lcs_idx)
hint = lc->MR_lc_free_slot_hint;
- for (offset = 0; offset < lc->MR_lc_num_slots; offset++) {
+ for (unsigned offset = 0; offset < lc->MR_lc_num_slots; offset++) {
i = (hint + offset) % lc->MR_lc_num_slots;
if (lc->MR_lc_slots[i].MR_lcs_is_free) {
lc->MR_lc_slots[i].MR_lcs_is_free = MR_FALSE;
diff --git a/runtime/mercury_prof.c b/runtime/mercury_prof.c
index dda0f9d72..98583b761 100644
--- a/runtime/mercury_prof.c
+++ b/runtime/mercury_prof.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1995-1998, 2000-2002, 2006 The University of Melbourne.
-// Copyright (C) 2013-2016, 2018 The Mercury team.
+// Copyright (C) 2013-2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// Profiling module
@@ -234,11 +234,10 @@ static void
prof_output_addr_pair_table(void)
{
FILE *fptr;
- int i;
fptr = MR_checked_fopen("Prof.CallPair", "create", "w");
- for (i = 0; i < CALL_TABLE_SIZE ; i++) {
+ for (int i = 0; i < CALL_TABLE_SIZE ; i++) {
print_addr_pair_node(fptr, addr_pair_table[i]);
}
@@ -293,7 +292,6 @@ static void
prof_output_addr_table(void)
{
FILE *fptr;
- int i;
double scale;
double rate;
@@ -314,7 +312,7 @@ prof_output_addr_table(void)
// Write out the time profiling data: one one-line entry per node.
- for (i = 0; i < TIME_TABLE_SIZE ; i++) {
+ for (int i = 0; i < TIME_TABLE_SIZE ; i++) {
print_time_node(fptr, addr_table[i]);
}
diff --git a/runtime/mercury_region.c b/runtime/mercury_region.c
index 7df8e2195..147105ba0 100644
--- a/runtime/mercury_region.c
+++ b/runtime/mercury_region.c
@@ -103,7 +103,6 @@ MR_region_request_pages(void)
{
MR_RegionPage *pages;
int bytes_to_request;
- int i;
bytes_to_request = MR_REGION_NUM_PAGES_TO_REQUEST * sizeof(MR_RegionPage);
pages = (MR_RegionPage *) MR_malloc(bytes_to_request);
@@ -112,7 +111,7 @@ MR_region_request_pages(void)
}
pages[0].MR_regionpage_next = NULL;
- for (i = 1; i < MR_REGION_NUM_PAGES_TO_REQUEST; i++) {
+ for (int i = 1; i < MR_REGION_NUM_PAGES_TO_REQUEST; i++) {
pages[i].MR_regionpage_next = &pages[i - 1];
}
@@ -210,7 +209,6 @@
MR_region_nullify_in_commit_frame(MR_RegionCommitFixedFrame
*commit_frame,
MR_RegionHeader *region)
{
MR_RegionCommitSave *commit_save;
- int i;
commit_save = ( MR_RegionCommitSave *) (
(MR_Word *) commit_frame + MR_REGION_COMMIT_FRAME_FIXED_SIZE);
@@ -218,7 +216,7 @@
MR_region_nullify_in_commit_frame(MR_RegionCommitFixedFrame
*commit_frame,
// Loop through the saved regions and nullify the entry of the input
// region if found.
- for (i = 0; i < commit_frame->MR_rcff_num_saved_regions; i++) {
+ for (int i = 0; i < commit_frame->MR_rcff_num_saved_regions; i++) {
if (commit_save != NULL &&
commit_save->MR_commit_save_region == region)
{
@@ -237,7 +235,6 @@ MR_region_nullify_in_ite_frame(MR_RegionHeader *region)
MR_RegionIteProtect *ite_prot;
MR_Word *protected_region;
int num_protected_regions;
- int i;
ite_frame = region->MR_region_ite_protected;
ite_prot = (MR_RegionIteProtect *) ( (MR_Word *) ite_frame +
@@ -247,7 +244,7 @@ MR_region_nullify_in_ite_frame(MR_RegionHeader *region)
// region if found.
num_protected_regions = ite_frame->MR_riff_num_prot_regions;
- for (i = 0; i < num_protected_regions; i++) {
+ for (int i = 0; i < num_protected_regions; i++) {
if (ite_prot != NULL && ite_prot->MR_ite_prot_region == region) {
ite_prot->MR_ite_prot_region = NULL;
break;
@@ -420,10 +417,9 @@
MR_commit_success_destroy_marked_saved_regions(MR_Word
num_saved_regions,
{
MR_RegionCommitSave *commit_save;
MR_RegionHeader *region;
- int i;
commit_save = first_commit_save;
- for (i = 0; i < num_saved_regions; i++, commit_save++) {
+ for (int i = 0; i < num_saved_regions; i++, commit_save++) {
region = commit_save->MR_commit_save_region;
if (region != NULL) {
// The region is saved here and has not been destroyed.
@@ -645,13 +641,12 @@
MR_region_fill_commit_func(MR_RegionCommitFixedFrame
*top_commit_frame,
void
MR_use_region_ite_then_semidet_proc(MR_RegionIteFixedFrame *top_ite_frame)
{
- int i;
MR_RegionIteProtect *ite_prot;
MR_region_debug_start("use_region_ite_then_semidet");
ite_prot = (MR_RegionIteProtect *) ( ( (MR_Word *) top_ite_frame ) +
MR_REGION_ITE_FRAME_FIXED_SIZE);
- for (i = 0; i < top_ite_frame->MR_riff_num_prot_regions;
+ for (int i = 0; i < top_ite_frame->MR_riff_num_prot_regions;
i++, ite_prot++) {
MR_remove_undisjprotected_region_ite_then_semidet(
ite_prot->MR_ite_prot_region);
@@ -663,13 +658,12 @@
MR_use_region_ite_then_semidet_proc(MR_RegionIteFixedFrame
*top_ite_frame)
void
MR_use_region_ite_then_nondet_proc(MR_RegionIteFixedFrame *top_ite_frame)
{
- int i;
MR_RegionIteProtect *ite_prot;
MR_region_debug_start("use_region_ite_then_nondet");
ite_prot = (MR_RegionIteProtect *) ( ( (MR_Word *) top_ite_frame ) +
MR_REGION_ITE_FRAME_FIXED_SIZE);
- for (i = 0; i < top_ite_frame->MR_riff_num_prot_regions;
+ for (int i = 0; i < top_ite_frame->MR_riff_num_prot_regions;
i++, ite_prot++) {
if (ite_prot->MR_ite_prot_region != NULL) {
MR_remove_undisjprotected_region_ite_then_nondet(
@@ -717,17 +711,16 @@ void
MR_use_region_disj_nonlast_semi_commit_proc(
MR_RegionDisjFixedFrame *top_disj_frame)
{
- int i;
MR_RegionSemiDisjProtect *semi_disj_prot;
MR_region_debug_start("use_region_disj_nonlast_semi_commit");
// Destroy any regions protected by the disj frame.
semi_disj_prot = (MR_RegionSemiDisjProtect *) (
( (MR_Word *) top_disj_frame ) + MR_REGION_DISJ_FRAME_FIXED_SIZE);
- for (i = 0; i < top_disj_frame->MR_rdff_num_prot_regions;
+ for (int i = 0; i < top_disj_frame->MR_rdff_num_prot_regions;
i++, semi_disj_prot++) {
- MR_region_destroy_region(
- semi_disj_prot->MR_semi_disj_prot_region);
+ MR_region_destroy_region(
+ semi_disj_prot->MR_semi_disj_prot_region);
}
MR_pop_region_disj_frame(top_disj_frame);
MR_region_debug_end("use_region_disj_nonlast_semi_commit");
@@ -766,14 +759,13 @@ MR_use_region_commit_success_proc(
void
MR_use_region_commit_failure_proc(MR_RegionCommitFixedFrame *top_commit_frame)
{
- int i;
MR_RegionCommitSave *commit_save;
MR_RegionHeader *region;
MR_region_debug_start("use_region_commit_failure");
commit_save = (MR_RegionCommitSave *) (
( (MR_Word *) top_commit_frame ) + MR_REGION_COMMIT_FRAME_FIXED_SIZE);
- for (i = 0; i < top_commit_frame->MR_rcff_num_saved_regions;
+ for (int i = 0; i < top_commit_frame->MR_rcff_num_saved_regions;
i++, commit_save++) {
region = commit_save->MR_commit_save_region;
if (region != NULL) {
@@ -801,12 +793,11 @@
MR_region_ite_unprotect_proc(MR_RegionIteFixedFrame *top_ite_frame)
{
MR_RegionIteProtect *ite_prot;
MR_RegionHeader *protected_region;
- int i;
MR_region_debug_start("ite_unprotect");
ite_prot = (MR_RegionIteProtect *) (
( (MR_Word *) top_ite_frame ) + MR_REGION_ITE_FRAME_FIXED_SIZE);
- for (i = 0; i < top_ite_frame->MR_riff_num_prot_regions;
+ for (int i = 0; i < top_ite_frame->MR_riff_num_prot_regions;
i++, ite_prot++) {
protected_region = ite_prot->MR_ite_prot_region;
MR_region_debug_ite_unprotect(protected_region);
@@ -893,10 +884,9 @@ MR_restore_snapshots_proc(int num_snapshots,
MR_RegionHeader *restoring_region;
MR_RegionPage *saved_last_page;
MR_RegionPage *first_new_page;
- int i;
snapshot = first_snapshot;
- for (i = 0; i < (num_snapshots); i++, snapshot++) {
+ for (int i = 0; i < (num_snapshots); i++, snapshot++) {
restoring_region = snapshot->MR_snapshot_region;
saved_last_page = snapshot->MR_snapshot_saved_last_page;
first_new_page = saved_last_page->MR_regionpage_next;
@@ -1034,7 +1024,6 @@ void
MR_region_ite_frame_protected_regions_msg(MR_RegionIteFixedFrame *ite_frame)
{
MR_RegionIteProtect *ite_prot;
- int i;
// This check is for development, when it becomes more stable,
// the check can be removed. Normally we expect not many regions.
@@ -1047,7 +1036,7 @@
MR_region_ite_frame_protected_regions_msg(MR_RegionIteFixedFrame
*ite_frame)
ite_prot = (MR_RegionIteProtect *) (
(MR_Word *) ite_frame + MR_REGION_ITE_FRAME_FIXED_SIZE);
- for (i = 0; i < ite_frame->MR_riff_num_prot_regions; i++, ite_prot++) {
+ for (int i = 0; i < ite_frame->MR_riff_num_prot_regions; i++, ite_prot++) {
printf("\tAt slot: %d, ite-protect region: %d\n",
ite_prot, ite_prot->MR_ite_prot_region->MR_region_sequence_number);
}
@@ -1058,7 +1047,6 @@
MR_region_ite_frame_snapshots_msg(MR_RegionIteFixedFrame *ite_frame)
{
MR_RegionSnapshot *snapshot;
int protection_size;
- int i;
if (ite_frame->MR_riff_num_snapshots > 10) {
printf("Number of snapshots: %d\n", ite_frame->MR_riff_num_snapshots);
@@ -1069,7 +1057,7 @@
MR_region_ite_frame_snapshots_msg(MR_RegionIteFixedFrame *ite_frame)
MR_REGION_ITE_PROT_SIZE;
snapshot = (MR_RegionSnapshot *) ((MR_Word *) ite_frame +
MR_REGION_ITE_FRAME_FIXED_SIZE + protection_size);
- for (i = 0; i < ite_frame->MR_riff_num_snapshots; i++, snapshot++) {
+ for (int i = 0; i < ite_frame->MR_riff_num_snapshots; i++, snapshot++) {
printf("\tAt slot: %d, snapshot of region: #%d\n", snapshot,
snapshot->MR_snapshot_region->MR_region_sequence_number);
}
@@ -1105,7 +1093,6 @@ void
MR_region_disj_frame_snapshots_msg(MR_RegionDisjFixedFrame *disj_frame)
{
MR_RegionSnapshot *snapshot;
- int i;
if (disj_frame->MR_rdff_num_snapshots > 10) {
printf("Number of snapshots: %d\n", disj_frame->MR_rdff_num_snapshots);
@@ -1114,7 +1101,7 @@
MR_region_disj_frame_snapshots_msg(MR_RegionDisjFixedFrame
*disj_frame)
snapshot = (MR_RegionSnapshot *) (
(MR_Word *) disj_frame + MR_REGION_DISJ_FRAME_FIXED_SIZE);
- for (i = 0; i < disj_frame->MR_rdff_num_snapshots; i++, snapshot++) {
+ for (int i = 0; i < disj_frame->MR_rdff_num_snapshots; i++, snapshot++) {
printf("\tAt slot: %d, snapshot of region: %d\n", snapshot,
snapshot->MR_snapshot_region);
}
@@ -1143,7 +1130,6 @@ void
MR_region_commit_frame_msg(MR_RegionCommitFixedFrame *commit_frame)
{
MR_RegionCommitSave *commit_save;
- int i;
printf("Commit frame #%d: %d\n",
MR_region_get_frame_number((MR_Word *)commit_frame), commit_frame);
@@ -1166,7 +1152,7 @@
MR_region_commit_frame_msg(MR_RegionCommitFixedFrame *commit_frame)
printf("\tNumber of saved regions: %d\n",
commit_frame->MR_rcff_num_saved_regions);
- for (i = 0; i < commit_frame->MR_rcff_num_saved_regions;
+ for (int i = 0; i < commit_frame->MR_rcff_num_saved_regions;
i++, commit_save++)
{
printf("Slot: %d, region: %d\n", commit_save,
@@ -1179,7 +1165,6 @@ MR_region_commit_frame_saved_regions_msg(
MR_RegionCommitFixedFrame *commit_frame)
{
MR_RegionCommitSave *commit_save;
- int i;
// This check is for development, when it becomes more stable,
// the check can be removed.
@@ -1192,7 +1177,7 @@ MR_region_commit_frame_saved_regions_msg(
commit_save = (MR_RegionCommitSave *)
((MR_Word *) commit_frame + MR_REGION_COMMIT_FRAME_FIXED_SIZE);
- for (i = 0; i < commit_frame->MR_rcff_num_saved_regions;
+ for (int i = 0; i < commit_frame->MR_rcff_num_saved_regions;
i++, commit_save++)
{
printf("\tAt slot: %d, saved region: %d\n", commit_save,
diff --git a/runtime/mercury_regs.c b/runtime/mercury_regs.c
index ed7c89511..512ede183 100644
--- a/runtime/mercury_regs.c
+++ b/runtime/mercury_regs.c
@@ -25,10 +25,8 @@ unsigned long MR_num_uses[MR_MAX_REAL_R_REG +
MR_NUM_SPECIAL_REG];
void
MR_print_register_usage_counts(void)
{
- int i;
-
printf("register usage counts:\n");
- for (i = 1; i <= MR_MAX_REAL_R_REG; i++) {
+ for(int i = 1; i <= MR_MAX_REAL_R_REG; i++) {
printf("r%d", i);
printf(MR_COUNT_FORMAT, MR_num_uses[MR_R_SLOT(i)]);
}
@@ -81,10 +79,8 @@ MR_print_register_usage_counts(void)
void
MR_verify_fake_registers(void)
{
- int i;
-
printf("register slots:\n");
- for (i = 1; i <= MR_MAX_REAL_R_REG; i++) {
+ for (int i = 1; i <= MR_MAX_REAL_R_REG; i++) {
printf("r%d", i);
printf(MR_VERIFY_FORMAT, MR_R_SLOT(i));
}
diff --git a/runtime/mercury_report_stats.c b/runtime/mercury_report_stats.c
index 0c05fa341..52f716557 100644
--- a/runtime/mercury_report_stats.c
+++ b/runtime/mercury_report_stats.c
@@ -1,6 +1,6 @@
// vim: ts=4 sw=4 expandtab ft=c
-// Copyright (C) 2021, 2024 The Mercury team.
+// Copyright (C) 2021, 2024, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This file contains code for implementing the predicates in the
@@ -515,7 +515,6 @@ static int
MR_memory_profile_report(FILE *fp, int *line_number,
const MR_memprof_report_entry *table, int num_entries, MR_bool complete)
{
- int i;
const char *name;
int result;
@@ -547,7 +546,7 @@ MR_memory_profile_report(FILE *fp, int *line_number,
num_entries = MAX_REPORT_LINES;
}
- for (i = 0; i < num_entries; i++) {
+ for (int i = 0; i < num_entries; i++) {
if (complete) {
result = fprintf(fp, "%8.8g/%4.1f%% %8.8g/%4.1f%% %s\n",
table[i].counter.cells_at_period_end,
diff --git a/runtime/mercury_stack_trace.c b/runtime/mercury_stack_trace.c
index 2a35caedd..c6e4fa924 100644
--- a/runtime/mercury_stack_trace.c
+++ b/runtime/mercury_stack_trace.c
@@ -772,7 +772,6 @@ MR_find_clique_entry(const MR_LabelLayout *label_layout,
int ancestor_level;
MR_bool in_clique;
int last_filled;
- int i;
MR_do_init_modules();
@@ -835,7 +834,7 @@ MR_find_clique_entry(const MR_LabelLayout *label_layout,
// linear search is likely to be faster for searching small arrays.
in_clique = MR_FALSE;
- for (i = 0; i < num_procs_in_clique; i++) {
+ for (int i = 0; i < num_procs_in_clique; i++) {
if (cur_proc_layout == procs_table[i]) {
in_clique = MR_TRUE;
break;
@@ -875,7 +874,7 @@ MR_find_clique_entry(const MR_LabelLayout *label_layout,
#ifdef MR_DEBUG_FIND_CLIQUE_ENTRY
printf("\n");
- for (i = 0; i < procs_table_next; i++) {
+ for (int i = 0; i < procs_table_next; i++) {
printf("SORTED %d %x\n", i, procs_table[i]);
}
#endif
@@ -883,7 +882,7 @@ MR_find_clique_entry(const MR_LabelLayout *label_layout,
// guaranteed to be consecutive.
last_filled = 0;
- for (i = 1; i < procs_table_next; i++) {
+ for (int i = 1; i < procs_table_next; i++) {
if (procs_table[i] != procs_table[last_filled]) {
last_filled++;
procs_table[last_filled] = procs_table[i];
@@ -895,7 +894,7 @@ MR_find_clique_entry(const MR_LabelLayout *label_layout,
#ifdef MR_DEBUG_FIND_CLIQUE_ENTRY
printf("\n");
- for (i = 0; i < procs_table_next; i++) {
+ for (int i = 0; i < procs_table_next; i++) {
printf("UNIQ %d %x\n", i, procs_table[i]);
}
printf("\n");
@@ -1638,9 +1637,7 @@
MR_step_over_nondet_frame(MR_DumpOrTraverseNondetFrameFunc *func,
static MR_bool
MR_find_matching_branch(MR_Word *fr, int *branch_ptr)
{
- int branch;
-
- for (branch = 0; branch < MR_nondet_branch_info_next; branch++) {
+ for (int branch = 0; branch < MR_nondet_branch_info_next; branch++) {
if (MR_nondet_branch_infos[branch].branch_curfr == fr) {
*branch_ptr = branch;
return MR_TRUE;
@@ -1720,9 +1717,7 @@ MR_nofail_ip(MR_Code *ip)
static MR_Code *
MR_find_nofail_temp_redoip(MR_Word *fr)
{
- int slot;
-
- for (slot = 0; slot < MR_temp_frame_info_next; slot++) {
+ for (int slot = 0; slot < MR_temp_frame_info_next; slot++) {
if (fr == MR_temp_frame_infos[slot].temp_redofr &&
MR_nofail_ip(MR_temp_frame_infos[slot].temp_redoip))
{
@@ -1913,7 +1908,6 @@ MR_find_context(const MR_LabelLayout *label,
const char **fileptr,
const MR_ProcLayout *proc;
const MR_ModuleLayout *module;
const MR_ModuleFileLayout *file_layout;
- int i, j;
proc = label->MR_sll_entry;
if (! MR_PROC_LAYOUT_HAS_EXEC_TRACE(proc)) {
@@ -1921,9 +1915,9 @@ MR_find_context(const MR_LabelLayout *label,
const char **fileptr,
}
module = proc->MR_sle_module_layout;
- for (i = 0; i < module->MR_ml_filename_count; i++) {
+ for (int i = 0; i < module->MR_ml_filename_count; i++) {
file_layout = module->MR_ml_module_file_layout[i];
- for (j = 0; j < file_layout->MR_mfl_label_count; j++) {
+ for (int j = 0; j < file_layout->MR_mfl_label_count; j++) {
if (file_layout->MR_mfl_label_layout[j] == label) {
*fileptr = file_layout->MR_mfl_filename;
*lineptr = file_layout->MR_mfl_label_lineno[j];
diff --git a/runtime/mercury_tabling.c b/runtime/mercury_tabling.c
index b79f761bf..564378086 100644
--- a/runtime/mercury_tabling.c
+++ b/runtime/mercury_tabling.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1997-2007, 2011 The University of Melbourne.
-// Copyright (C) 2014, 2016-2018 The Mercury team.
+// Copyright (C) 2014, 2016-2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This module contains the functions related to tabling that are not
@@ -1398,7 +1398,6 @@ MR_print_answerblock(FILE *fp, const MR_ProcLayout *proc,
MR_TypeCtorInfo tci;
int num_inputs;
int num_outputs;
- int i;
num_inputs = proc->MR_sle_table_info.MR_table_proc->MR_pt_num_inputs;
num_outputs = proc->MR_sle_table_info.MR_table_proc->MR_pt_num_outputs;
@@ -1406,7 +1405,7 @@ MR_print_answerblock(FILE *fp, const MR_ProcLayout *proc,
ptis = proc->MR_sle_table_info.MR_table_proc->MR_pt_ptis;
ptis += num_inputs;
- for (i = 0; i < num_outputs; i++) {
+ for (int i = 0; i < num_outputs; i++) {
if (i > 0) {
fprintf(fp, ", ");
}
diff --git a/runtime/mercury_thread.c b/runtime/mercury_thread.c
index f333263cd..29eee919d 100644
--- a/runtime/mercury_thread.c
+++ b/runtime/mercury_thread.c
@@ -546,12 +546,11 @@ MR_ThreadLocalMuts *
MR_clone_thread_local_mutables(const MR_ThreadLocalMuts *old_muts)
{
MR_ThreadLocalMuts *new_muts;
- MR_Unsigned i;
new_muts = MR_create_thread_local_mutables(MR_num_thread_local_mutables);
MR_LOCK(&new_muts->MR_tlm_lock, "MR_clone_thread_local_mutables");
- for (i = 0; i < MR_num_thread_local_mutables; i++) {
+ for (MR_Unsigned i = 0; i < MR_num_thread_local_mutables; i++) {
new_muts->MR_tlm_values[i] = old_muts->MR_tlm_values[i];
}
MR_UNLOCK(&new_muts->MR_tlm_lock, "MR_clone_thread_local_mutables");
@@ -563,8 +562,6 @@ MR_clone_thread_local_mutables(const
MR_ThreadLocalMuts *old_muts)
void
MR_init_thread_stuff(void)
{
- int i;
-
pthread_mutex_init(&MR_global_lock, MR_MUTEX_ATTR);
#ifndef MR_THREAD_LOCAL_STORAGE
MR_KEY_CREATE(&MR_engine_base_key, NULL);
@@ -579,7 +576,7 @@ MR_init_thread_stuff(void)
pthread_mutex_init(&MR_all_engine_bases_lock, MR_MUTEX_ATTR);
MR_all_engine_bases =
MR_GC_malloc(sizeof(MercuryEngine *) * MR_max_engines);
- for (i = 0; i < MR_max_engines; i++) {
+ for (int i = 0; i < MR_max_engines; i++) {
MR_all_engine_bases[i] = NULL;
}
#endif
diff --git a/runtime/mercury_trace_base.c b/runtime/mercury_trace_base.c
index 7decf270c..7f9747433 100644
--- a/runtime/mercury_trace_base.c
+++ b/runtime/mercury_trace_base.c
@@ -279,7 +279,6 @@ MR_trace_record_label_exec_counts(void *dummy)
keep = MR_FALSE;
if (MR_trace_count_summary_file != NULL) {
if (MR_FILE_EXISTS(MR_trace_count_summary_file)) {
- int i;
// 30 bytes must be enough for the dot, the value of i, and '\0'.
name_len = strlen(MR_trace_count_summary_file) + 30;
@@ -287,7 +286,7 @@ MR_trace_record_label_exec_counts(void *dummy)
fp = NULL;
// Search for a suffix that doesn't exist yet.
- for (i = 1; i <= MR_trace_count_summary_max; i++) {
+ for (int i = 1; i <= MR_trace_count_summary_max; i++) {
MR_snprintf(name, name_len, "%s.%d",
MR_trace_count_summary_file, i);
if (! MR_FILE_EXISTS(name)) {
@@ -364,7 +363,6 @@ MR_trace_record_label_exec_counts(void *dummy)
int summary_status;
int mv_status;
int unlink_status;
- int i;
const char *old_options;
// 30 bytes must be enough for the dot, the value of i, and space.
@@ -386,7 +384,7 @@ MR_trace_record_label_exec_counts(void *dummy)
strcat(cmd, " ");
strcat(cmd, MR_trace_count_summary_file);
- for (i = 1; i <= MR_trace_count_summary_max; i++) {
+ for (int i = 1; i <= MR_trace_count_summary_max; i++) {
MR_snprintf(name, name_len, "%s.%d",
MR_trace_count_summary_file, i);
strcat(cmd, " ");
@@ -414,7 +412,7 @@ MR_trace_record_label_exec_counts(void *dummy)
if (mv_status == 0) {
// Delete all files whose data is now in the summary file.
- for (i = 1; i <= MR_trace_count_summary_max; i++) {
+ for (int i = 1; i <= MR_trace_count_summary_max; i++) {
MR_snprintf(name, name_len, "%s.%d",
MR_trace_count_summary_file, i);
unlink_status = unlink(name);
@@ -443,8 +441,6 @@ MR_trace_write_label_exec_counts(FILE *fp, const
char *progname,
const MR_ModuleFileLayout *file;
int num_modules;
int num_files;
- int module_num;
- int file_num;
unsigned num_written;
MR_trace_name_count_port_ensure_init();
@@ -461,7 +457,7 @@ MR_trace_write_label_exec_counts(FILE *fp, const
char *progname,
num_modules = MR_module_info_next;
num_written = 0;
- for (module_num = 0; module_num < num_modules; module_num++) {
+ for (int module_num = 0; module_num < num_modules; module_num++) {
module = MR_module_infos[module_num];
num_files = module->MR_ml_filename_count;
@@ -469,7 +465,7 @@ MR_trace_write_label_exec_counts(FILE *fp, const
char *progname,
MR_trace_write_quoted_atom(fp, module->MR_ml_name);
fputc('\n', fp);
- for (file_num = 0; file_num < num_files; file_num++) {
+ for (int file_num = 0; file_num < num_files; file_num++) {
file = module->MR_ml_module_file_layout[file_num];
num_written += MR_trace_write_label_exec_counts_for_file(fp,
module, file, module->MR_ml_name, coverage_test);
@@ -1076,15 +1072,13 @@ void
MR_turn_off_debug(MR_SavedDebugState *saved_state,
MR_bool include_counter_vars)
{
- int i;
-
saved_state->MR_sds_debug_enabled = MR_debug_enabled;
saved_state->MR_sds_io_tabling_enabled = MR_io_tabling_enabled;
MR_debug_enabled = MR_FALSE;
MR_update_trace_func_enabled();
MR_io_tabling_enabled = MR_FALSE;
- for (i = 0; i < MR_MAXFLAG ; i++) {
+ for (int i = 0; i < MR_MAXFLAG ; i++) {
saved_state->MR_sds_debugflags[i] = MR_debugflag[i];
MR_debugflag[i] = MR_FALSE;
}
@@ -1102,13 +1096,11 @@ MR_turn_off_debug(MR_SavedDebugState *saved_state,
void
MR_turn_debug_back_on(const MR_SavedDebugState *saved_state)
{
- int i;
-
MR_debug_enabled = saved_state->MR_sds_debug_enabled;
MR_update_trace_func_enabled();
MR_io_tabling_enabled = saved_state->MR_sds_io_tabling_enabled;
- for (i = 0; i < MR_MAXFLAG; i++) {
+ for (int i = 0; i < MR_MAXFLAG; i++) {
MR_debugflag[i] = saved_state->MR_sds_debugflags[i];
}
@@ -1149,10 +1141,8 @@ MR_trace_get_exception_value(void)
void
MR_trace_print_histogram(FILE *fp, const char *which, int *histogram, int max)
{
- int i;
-
fprintf(fp, "%s histogram\n", which);
- for (i = 1; i <= max; i++) {
+ for (int i = 1; i <= max; i++) {
fprintf(fp, "depth %4d: %10d", i, histogram[i]);
if (i + 1 <= max && histogram[i] != 0) {
fprintf(fp, ", branching factor %7.2f\n",
@@ -1248,7 +1238,6 @@ MR_io_tabling_stats(FILE *fp)
MR_IO_Table_Stats_Hash_Record *record;
int num_entries;
int count;
- int i;
// Create a fresh new hash table, separate from the table created by
// any previous call to this function. We can't use structure assignment,
@@ -1262,7 +1251,7 @@ MR_io_tabling_stats(FILE *fp)
MR_init_hash_table(hash_table);
num_entries = 0;
- for (i = MR_io_tabling_start; i < MR_io_tabling_counter_hwm; i++) {
+ for (int i = MR_io_tabling_start; i < MR_io_tabling_counter_hwm; i++) {
MR_TABLE_START_INT(NULL, MR_FALSE, MR_FALSE, answer_block_trie,
(MR_TrieNode) &MR_io_tabling_pointer, MR_io_tabling_start, i);
answer_block = answer_block_trie->MR_answerblock;
@@ -1298,7 +1287,7 @@ MR_io_tabling_stats(FILE *fp)
qsort(MR_io_tabling_stats_sort_arena, num_entries,
sizeof(MR_IO_Table_Stats_Hash_Record), MR_compare_in_sort_arena);
- for (i = 0; i < num_entries; i++) {
+ for (int i = 0; i < num_entries; i++) {
record = &MR_io_tabling_stats_sort_arena[i];
proc_layout = record->MR_io_tabling_stats_proc;
count = record->MR_io_tabling_stats_count;
diff --git a/runtime/mercury_type_desc.c b/runtime/mercury_type_desc.c
index 3dcabfddb..67af1d086 100644
--- a/runtime/mercury_type_desc.c
+++ b/runtime/mercury_type_desc.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2002-2004, 2006 The University of Melbourne.
-// Copyright (C) 2016, 2018 The Mercury team.
+// Copyright (C) 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// This module exists to handle user-visible descriptions of types and type
@@ -150,7 +150,6 @@ MR_make_type(int arity, MR_TypeCtorDesc
type_ctor_desc, MR_Word arg_types_list)
MR_Word *new_type_info_arena;
MR_Word new_type_info_arena_word;
MR_TypeInfo *new_type_info_args;
- int i;
// We need to treat variable-arity types as a special case here.
@@ -184,7 +183,7 @@ MR_make_type(int arity, MR_TypeCtorDesc
type_ctor_desc, MR_Word arg_types_list)
new_type_info_args);
}
- for (i = 1; i <= arity; i++) {
+ for (int i = 1; i <= arity; i++) {
new_type_info_args[i] = (MR_TypeInfo) MR_list_head(arg_types_list);
arg_types_list = MR_list_tail(arg_types_list);
}
diff --git a/runtime/mercury_type_info.c b/runtime/mercury_type_info.c
index 426a31988..7d03258bd 100644
--- a/runtime/mercury_type_info.c
+++ b/runtime/mercury_type_info.c
@@ -232,7 +232,6 @@ MR_compare_pseudo_type_info(MR_PseudoTypeInfo
pti1, MR_PseudoTypeInfo pti2)
MR_PseudoTypeInfo *arg_vector_2;
int num_arg_types_1;
int num_arg_types_2;
- int i;
int comp;
// Try to optimize a common case:
@@ -312,7 +311,7 @@ MR_compare_pseudo_type_info(MR_PseudoTypeInfo
pti1, MR_PseudoTypeInfo pti2)
}
// Compare the argument types.
- for (i = 1; i <= num_arg_types_1; i++) {
+ for (int i = 1; i <= num_arg_types_1; i++) {
comp = MR_compare_pseudo_type_info(arg_vector_1[i], arg_vector_2[i]);
if (comp != MR_COMPARE_EQUAL) {
return comp;
@@ -331,7 +330,6 @@ MR_unify_pseudo_type_info(MR_PseudoTypeInfo pti1,
MR_PseudoTypeInfo pti2)
MR_PseudoTypeInfo *arg_vector_2;
int num_arg_types_1;
int num_arg_types_2;
- int i;
// Try to optimize a common case:
// If type_info addresses are equal, they must represent the same type.
@@ -405,7 +403,7 @@ MR_unify_pseudo_type_info(MR_PseudoTypeInfo pti1,
MR_PseudoTypeInfo pti2)
}
// Compare the argument types.
- for (i = 1; i <= num_arg_types_1; i++) {
+ for (int i = 1; i <= num_arg_types_1; i++) {
if (! MR_unify_pseudo_type_info(arg_vector_1[i], arg_vector_2[i])) {
return MR_FALSE;
}
@@ -438,7 +436,6 @@ MR_compare_type_info(MR_TypeInfo ti1, MR_TypeInfo ti2)
MR_TypeInfo *arg_vector_2;
int num_arg_types_1;
int num_arg_types_2;
- int i;
int comp;
// Try to optimize a common case:
@@ -495,7 +492,7 @@ MR_compare_type_info(MR_TypeInfo ti1, MR_TypeInfo ti2)
}
// Compare the argument types.
- for (i = 1; i <= num_arg_types_1; i++) {
+ for (int i = 1; i <= num_arg_types_1; i++) {
comp = MR_compare_type_info(arg_vector_1[i], arg_vector_2[i]);
if (comp != MR_COMPARE_EQUAL) {
return comp;
@@ -514,7 +511,6 @@ MR_unify_type_info(MR_TypeInfo ti1, MR_TypeInfo ti2)
MR_TypeInfo *arg_vector_2;
int num_arg_types_1;
int num_arg_types_2;
- int i;
// Try to optimize a common case:
// If type_info addresses are equal, they must represent the same type.
@@ -567,7 +563,7 @@ MR_unify_type_info(MR_TypeInfo ti1, MR_TypeInfo ti2)
}
// Compare the argument types.
- for (i = 1; i <= num_arg_types_1; i++) {
+ for (int i = 1; i <= num_arg_types_1; i++) {
if (! MR_unify_type_info(arg_vector_1[i], arg_vector_2[i])) {
return MR_FALSE;
}
@@ -920,7 +916,6 @@ MR_print_type(FILE *fp, MR_TypeInfo type_info)
MR_TypeCtorInfo tci;
MR_TypeInfo *arg_vector;
int arity;
- int i;
tci = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
if (MR_type_ctor_has_variable_arity(tci)) {
@@ -936,7 +931,7 @@ MR_print_type(FILE *fp, MR_TypeInfo type_info)
if (arity > 0) {
fprintf(fp, "(");
- for (i = 1; i <= arity; i++) {
+ for (int i = 1; i <= arity; i++) {
MR_print_type(fp, arg_vector[i]);
if (i < arity) {
fprintf(fp, ", ");
diff --git a/runtime/mercury_wrapper.c b/runtime/mercury_wrapper.c
index b4ddf3a91..628698276 100644
--- a/runtime/mercury_wrapper.c
+++ b/runtime/mercury_wrapper.c
@@ -644,19 +644,17 @@ mercury_runtime_init(int argc, char **argv)
// The current thread will be running the first engine.
#ifdef MR_LL_PARALLEL_CONJ
{
- int i;
-
MR_ws_engine_threads = MR_GC_NEW_ARRAY(MercuryThread,
MR_num_ws_engines - 1);
- for (i = 0; i < MR_num_ws_engines - 1; i++) {
+ for (int i = 0; i < MR_num_ws_engines - 1; i++) {
MR_ws_engine_threads[i] = MR_create_worksteal_thread();
}
#ifdef MR_THREADSCOPE
// TSC Synchronization is not used, support is commented out.
// See runtime/mercury_threadscope.h for an explanation.
- for (i = 1; i < MR_num_threads; i++) {
+ for (int i = 1; i < MR_num_threads; i++) {
MR_threadscope_sync_tsc_master();
}
#endif
@@ -828,7 +826,6 @@ MR_init_conservative_GC(void)
// to the second MR_Word.
{
- int i;
int limit;
limit = (1 << MR_LOW_TAG_BITS);
@@ -838,7 +835,7 @@ MR_init_conservative_GC(void)
limit += sizeof(MR_Word);
#endif
- for (i = 1; i < limit; i++) {
+ for (int i = 1; i < limit; i++) {
GC_REGISTER_DISPLACEMENT(i);
}
}
@@ -932,7 +929,6 @@ MR_make_argv(const char *string,
char *d;
int args_len = 0;
int argc = 0;
- int i;
// First do a pass over the string to count how much space we need to
// allocate.
@@ -989,7 +985,7 @@ MR_make_argv(const char *string,
s = string;
d = args;
- for (i = 0; i < argc; i++) {
+ for (int i = 0; i < argc; i++) {
// Skip leading whitespace.
while (MR_isspace(*s)) {
s++;
@@ -2506,12 +2502,8 @@ mercury_runtime_main(void)
#endif
#if defined(MR_USE_GCC_NONLOCAL_GOTOS) && defined(MR_DEBUG_THE_RUNTIME)
- {
- int i;
-
- for (i = 0; i < SAFETY_BUFFER_SIZE; i++) {
- MR_assert(safety_buffer[i] == MAGIC_MARKER_2);
- }
+ for (int i = 0; i < SAFETY_BUFFER_SIZE; i++) {
+ MR_assert(safety_buffer[i] == MAGIC_MARKER_2);
}
#endif
@@ -2650,16 +2642,14 @@ MR_print_type_ctor_stats(void)
static void
MR_print_one_type_ctor_stat(FILE *fp, const char *op, MR_TypeStat *type_stat)
{
- int i;
-
- for (i = 0; i < (int) MR_TYPECTOR_REP_UNKNOWN; i++) {
+ for (int i = 0; i < (int) MR_TYPECTOR_REP_UNKNOWN; i++) {
if (type_stat->type_ctor_reps[i] > 0) {
fprintf(fp, "%s %s %ld\n", op,
MR_ctor_rep_name[i], type_stat->type_ctor_reps[i]);
}
}
- for (i = 0; i < type_stat->type_ctor_name_next; i++) {
+ for (int i = 0; i < type_stat->type_ctor_name_next; i++) {
fprintf(fp, "%s %s %s %s %ld\n", op,
type_stat->type_ctor_names[i].type_stat_module,
type_stat->type_ctor_names[i].type_stat_name,
@@ -3009,13 +2999,9 @@ mercury_runtime_terminate(void)
// Each work-stealing engine has been notified to shut down.
// Wait for the threads that they are running on to terminate before
// continuing.
- {
- int i;
-
- for (i = 0; i < MR_num_ws_engines - 1; i++) {
- pthread_join(MR_ws_engine_threads[i], NULL);
- MR_ws_engine_threads[i] = MR_null_thread();
- }
+ for (int i = 0; i < MR_num_ws_engines - 1; i++) {
+ pthread_join(MR_ws_engine_threads[i], NULL);
+ MR_ws_engine_threads[i] = MR_null_thread();
}
#ifdef MR_THREADSCOPE
@@ -3036,9 +3022,8 @@ mercury_runtime_terminate(void)
struct stat statbuf;
char *filename;
char *cmd;
- int i;
- for (i = 1; i < MAX_MEM_USAGE_REPORT_ATTEMPTS; i++) {
+ for (int i = 1; i < MAX_MEM_USAGE_REPORT_ATTEMPTS; i++) {
filename = MR_make_string(MR_ALLOC_SITE_RUNTIME,
"%s%02d", MR_mem_usage_report_prefix, i);
if (stat(filename, &statbuf) == 0) {
diff --git a/runtime/mercury_wsdeque.c b/runtime/mercury_wsdeque.c
index df0a3654b..7c4d4838c 100644
--- a/runtime/mercury_wsdeque.c
+++ b/runtime/mercury_wsdeque.c
@@ -1,7 +1,7 @@
// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 2007, 2010-2011 The University of Melbourne.
-// Copyright (C) 2016, 2018 The Mercury team.
+// Copyright (C) 2016, 2018, 2026 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// mercury_wsdeque.c
@@ -119,12 +119,11 @@ MR_grow_spark_array(const MR_SparkArray
*old_arr, MR_Integer bot,
{
MR_Integer new_size;
MR_SparkArray *new_arr;
- MR_Integer i;
new_size = 2 * (old_arr->MR_sa_max + 1);
new_arr = MR_alloc_spark_array(new_size);
- for (i = top; i < bot; i++) {
+ for (MR_Integer i = top; i < bot; i++) {
MR_sa_element(new_arr, i) = MR_sa_element(old_arr, i);
}
More information about the reviews
mailing list