ruby-changes:62793
From: Nobuyoshi <ko1@a...>
Date: Wed, 2 Sep 2020 01:46:32 +0900 (JST)
Subject: [ruby-changes:62793] f6822e4ed0 (master): Format with proper conversion specifiers instead of casts
https://git.ruby-lang.org/ruby.git/commit/?id=f6822e4ed0 From f6822e4ed020600e6556dbaf6e6e3ad837b65592 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 1 Sep 2020 19:43:15 +0900 Subject: Format with proper conversion specifiers instead of casts diff --git a/gc.c b/gc.c index 567fe5d..ef91fa9 100644 --- a/gc.c +++ b/gc.c @@ -1613,7 +1613,8 @@ heap_pages_expand_sorted_to(rb_objspace_t *objspace, size_t next_length) https://github.com/ruby/ruby/blob/trunk/gc.c#L1613 struct heap_page **sorted; size_t size = size_mul_or_raise(next_length, sizeof(struct heap_page *), rb_eRuntimeError); - gc_report(3, objspace, "heap_pages_expand_sorted: next_length: %d, size: %d\n", (int)next_length, (int)size); + gc_report(3, objspace, "heap_pages_expand_sorted: next_length: %"PRIdSIZE", size: %"PRIdSIZE"\n", + next_length, size); if (heap_pages_sorted_length > 0) { sorted = (struct heap_page **)realloc(heap_pages_sorted, size); @@ -1875,8 +1876,11 @@ heap_page_create(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L1876 page = heap_page_allocate(objspace); method = "allocate"; } - if (0) fprintf(stderr, "heap_page_create: %s - %p, heap_allocated_pages: %d, heap_allocated_pages: %d, tomb->total_pages: %d\n", - method, (void *)page, (int)heap_pages_sorted_length, (int)heap_allocated_pages, (int)heap_tomb->total_pages); + if (0) fprintf(stderr, "heap_page_create: %s - %p, " + "heap_allocated_pages: %"PRIdSIZE", " + "heap_allocated_pages: %"PRIdSIZE", " + "tomb->total_pages: %"PRIdSIZE"\n", + method, (void *)page, heap_pages_sorted_length, heap_allocated_pages, heap_tomb->total_pages); return page; } @@ -1960,15 +1964,17 @@ heap_set_increment(rb_objspace_t *objspace, size_t additional_pages) https://github.com/ruby/ruby/blob/trunk/gc.c#L1964 heap_allocatable_pages_set(objspace, next_used_limit - used); - gc_report(1, objspace, "heap_set_increment: heap_allocatable_pages is %d\n", (int)heap_allocatable_pages); + gc_report(1, objspace, "heap_set_increment: heap_allocatable_pages is %"PRIdSIZE"\n", + heap_allocatable_pages); } static int heap_increment(rb_objspace_t *objspace, rb_heap_t *heap) { if (heap_allocatable_pages > 0) { - gc_report(1, objspace, "heap_increment: heap_pages_sorted_length: %d, heap_pages_inc: %d, heap->total_pages: %d\n", - (int)heap_pages_sorted_length, (int)heap_allocatable_pages, (int)heap->total_pages); + gc_report(1, objspace, "heap_increment: heap_pages_sorted_length: %"PRIdSIZE", " + "heap_pages_inc: %"PRIdSIZE", heap->total_pages: %"PRIdSIZE"\n", + heap_pages_sorted_length, heap_allocatable_pages, heap->total_pages); GC_ASSERT(heap_allocatable_pages + heap_eden->total_pages <= heap_pages_sorted_length); GC_ASSERT(heap_allocated_pages <= heap_pages_sorted_length); @@ -4325,9 +4331,9 @@ gc_page_sweep(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *sweep_ https://github.com/ruby/ruby/blob/trunk/gc.c#L4331 record->empty_objects += empty_slots; } #endif - if (0) fprintf(stderr, "gc_page_sweep(%d): total_slots: %d, freed_slots: %d, empty_slots: %d, final_slots: %d\n", - (int)rb_gc_count(), - (int)sweep_page->total_slots, + if (0) fprintf(stderr, "gc_page_sweep(%"PRIdSIZE"): total_slots: %d, freed_slots: %d, empty_slots: %d, final_slots: %d\n", + rb_gc_count(), + sweep_page->total_slots, freed_slots, empty_slots, final_slots); sweep_page->free_slots = freed_slots + empty_slots; @@ -5987,7 +5993,8 @@ allrefs_dump_i(st_data_t k, st_data_t v, st_data_t ptr) https://github.com/ruby/ruby/blob/trunk/gc.c#L5993 static void allrefs_dump(rb_objspace_t *objspace) { - fprintf(stderr, "[all refs] (size: %d)\n", (int)objspace->rgengc.allrefs_table->num_entries); + VALUE size = objspace->rgengc.allrefs_table->num_entries; + fprintf(stderr, "[all refs] (size: %"PRIuVALUE")\n", size); st_foreach(objspace->rgengc.allrefs_table, allrefs_dump_i, 0); } #endif @@ -6213,11 +6220,11 @@ gc_verify_heap_page(rb_objspace_t *objspace, struct heap_page *page, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L6220 if (0) { /* free_slots may not equal to free_objects */ if (page->free_slots != free_objects) { - rb_bug("page %p's free_slots should be %d, but %d\n", (void *)page, (int)page->free_slots, free_objects); + rb_bug("page %p's free_slots should be %d, but %d\n", (void *)page, page->free_slots, free_objects); } } if (page->final_slots != zombie_objects) { - rb_bug("page %p's final_slots should be %d, but %d\n", (void *)page, (int)page->final_slots, zombie_objects); + rb_bug("page %p's final_slots should be %d, but %d\n", (void *)page, page->final_slots, zombie_objects); } return remembered_old_objects; @@ -6307,18 +6314,22 @@ gc_verify_internal_consistency(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L6314 if (!is_lazy_sweeping(heap_eden) && !finalizing) { if (objspace_live_slots(objspace) != data.live_object_count) { - fprintf(stderr, "heap_pages_final_slots: %d, objspace->profile.total_freed_objects: %d\n", - (int)heap_pages_final_slots, (int)objspace->profile.total_freed_objects); - rb_bug("inconsistent live slot number: expect %"PRIuSIZE", but %"PRIuSIZE".", objspace_live_slots(objspace), data.live_object_count); + fprintf(stderr, "heap_pages_final_slots: %"PRIdSIZE", " + "objspace->profile.total_freed_objects: %"PRIdSIZE"\n", + heap_pages_final_slots, objspace->profile.total_freed_objects); + rb_bug("inconsistent live slot number: expect %"PRIuSIZE", but %"PRIuSIZE".", + objspace_live_slots(objspace), data.live_object_count); } } if (!is_marking(objspace)) { if (objspace->rgengc.old_objects != data.old_object_count) { - rb_bug("inconsistent old slot number: expect %"PRIuSIZE", but %"PRIuSIZE".", objspace->rgengc.old_objects, data.old_object_count); + rb_bug("inconsistent old slot number: expect %"PRIuSIZE", but %"PRIuSIZE".", + objspace->rgengc.old_objects, data.old_object_count); } if (objspace->rgengc.uncollectible_wb_unprotected_objects != data.remembered_shady_count) { - rb_bug("inconsistent old slot number: expect %"PRIuSIZE", but %"PRIuSIZE".", objspace->rgengc.uncollectible_wb_unprotected_objects, data.remembered_shady_count); + rb_bug("inconsistent old slot number: expect %"PRIuSIZE", but %"PRIuSIZE".", + objspace->rgengc.uncollectible_wb_unprotected_objects, data.remembered_shady_count); } } @@ -6375,8 +6386,10 @@ gc_marks_start(rb_objspace_t *objspace, int full_mark) https://github.com/ruby/ruby/blob/trunk/gc.c#L6386 #if GC_ENABLE_INCREMENTAL_MARK objspace->rincgc.step_slots = (objspace->marked_slots * 2) / ((objspace->rincgc.pooled_slots / HEAP_PAGE_OBJ_LIMIT) + 1); - if (0) fprintf(stderr, "objspace->marked_slots: %d, objspace->rincgc.pooled_page_num: %d, objspace->rincgc.step_slots: %d, \n", - (int)objspace->marked_slots, (int)objspace->rincgc.pooled_slots, (int)objspace->rincgc.step_slots); + if (0) fprintf(stderr, "objspace->marked_slots: %"PRIdSIZE", " + "objspace->rincgc.pooled_page_num: %"PRIdSIZE", " + "objspace->rincgc.step_slots: %"PRIdSIZE", \n", + objspace->marked_slots, objspace->rincgc.pooled_slots, objspace->rincgc.step_slots); #endif objspace->flags.during_minor_gc = FALSE; objspace->profile.major_gc_count++; @@ -6396,7 +6409,8 @@ gc_marks_start(rb_objspace_t *objspace, int full_mark) https://github.com/ruby/ruby/blob/trunk/gc.c#L6409 gc_mark_roots(objspace, NULL); - gc_report(1, objspace, "gc_marks_start: (%s) end, stack in %d\n", full_mark ? "full" : "minor", (int)mark_stack_size(&objspace->mark_stack)); + gc_report(1, objspace, "gc_marks_start: (%s) end, stack in %"PRIdSIZE"\n", + full_mark ? "full" : "minor", mark_stack_size(&objspace->mark_stack)); } #if GC_ENABLE_INCREMENTAL_MARK @@ -6462,13 +6476,15 @@ gc_marks_finish(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L6476 } if (RGENGC_CHECK_MODE && is_mark_stack_empty(&objspace->mark_stack) == 0) { - rb_bug("gc_marks_finish: mark stack is not empty (%d).", (int)mark_stack_size(&objspace->mark_stack)); + rb_bug("gc_marks_finish: mark stack is not empty (%"PRIdSIZE").", + mark_stack_size(&objspace->mark_stack)); } gc_mark_roots(objspace, 0); if (is_mark_stack_empty(&objspace->mark_stack) == FALSE) { - gc_report(1, objspace, "gc_marks_finish: not empty (%d). retry.\n", (int)mark_stack_size(&objspace->mark_stack)); + gc_report(1, objspace, "gc_marks_finish: not empty (%"PRIdSIZE"). retry.\n", + mark_stack_size(&objspace->mark_stack)); return FALSE; } @@ -6560,8 +6576,10 @@ gc_marks_finish(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L6576 objspace->rgengc.need_major_gc = GPR_FLAG_MAJOR_BY_FORCE; } - gc_report(1, objspace, "gc_marks_finish (marks %d objects, old %d objects, total %d slots, sweep %d slots, increment: %d, next GC: %s)\n", - (int)objspace->marked_slots, (int)objspace->rgengc.old_objects, (int)heap->total_slots, (int)sweep_slots, (int)heap_allocatable_pages, + gc_report(1, objspace, "gc_marks_finish (marks %"PRIdSIZE" objects, " + "old %"PRIdSIZE" objects, total %"PRIdSIZE" slots, " + "sweep %"PRIdSIZE" slots, increment: %"PRIdSIZE", next GC: %s)\n", + objspace->marked_slots, objspace->rgengc.old_objects, heap->total_slots, sweep_slots, heap_allocatable_pages, objspace->rgengc.need_major_gc ? "major" : "minor"); } @@ -6584,7 +6602,7 @@ gc_marks_step(rb_objspace_t *objspace, int slots) https://github.com/ruby/ruby/blob/trunk/gc.c#L66 (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/