diff --git a/allchblk.c b/allchblk.c index 542df3162..159c06aee 100644 --- a/allchblk.c +++ b/allchblk.c @@ -523,7 +523,7 @@ GC_INNER void GC_unmap_old(unsigned threshold) } GC_num_unmapped_regions = regions; # endif - GC_unmap((ptr_t)h, (size_t)(hhdr -> hb_sz)); + GC_unmap((ptr_t)h, hhdr -> hb_sz); hhdr -> hb_flags |= WAS_UNMAPPED; } } @@ -956,7 +956,7 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k, # ifdef USE_MUNMAP if (!IS_MAPPED(hhdr)) { GC_adjust_num_unmapped(hbp, hhdr); - GC_remap((ptr_t)hbp, (size_t)(hhdr -> hb_sz)); + GC_remap((ptr_t)hbp, hhdr -> hb_sz); hhdr -> hb_flags &= (unsigned char)~WAS_UNMAPPED; } # endif @@ -972,7 +972,7 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k, # ifdef USE_MUNMAP if (!IS_MAPPED(hhdr)) { GC_adjust_num_unmapped(hbp, hhdr); - GC_remap((ptr_t)hbp, (size_t)(hhdr -> hb_sz)); + GC_remap((ptr_t)hbp, hhdr -> hb_sz); hhdr -> hb_flags &= (unsigned char)~WAS_UNMAPPED; /* Note: This may leave adjacent, mapped free blocks. */ } diff --git a/alloc.c b/alloc.c index d0ce3e246..14ed09c44 100644 --- a/alloc.c +++ b/alloc.c @@ -991,7 +991,7 @@ GC_INNER void GC_set_fl_marks(ptr_t q) const struct hblk *last_h = h; hdr *hhdr; # ifdef MARK_BIT_PER_OBJ - word sz; + size_t sz; # endif GC_ASSERT(q != NULL); @@ -1003,7 +1003,7 @@ GC_INNER void GC_set_fl_marks(ptr_t q) q2 = (ptr_t)obj_link(q); # endif for (;;) { - word bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); + unsigned bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); if (!mark_bit_from_hdr(hhdr, bit_no)) { set_mark_bit_from_hdr(hhdr, bit_no); @@ -1090,10 +1090,10 @@ STATIC void GC_clear_fl_marks(ptr_t q) struct hblk *h = HBLKPTR(q); const struct hblk *last_h = h; hdr *hhdr = HDR(h); - word sz = hhdr -> hb_sz; /* Normally set only once. */ + size_t sz = hhdr -> hb_sz; /* Normally set only once. */ for (;;) { - word bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); + unsigned bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); if (mark_bit_from_hdr(hhdr, bit_no)) { size_t n_marks = hhdr -> hb_n_marks; diff --git a/backgraph.c b/backgraph.c index 0ae2285ba..18024fe15 100644 --- a/backgraph.c +++ b/backgraph.c @@ -295,7 +295,7 @@ typedef void (*per_object_func)(ptr_t p, size_t n_bytes, word gc_descr); static GC_CALLBACK void per_object_helper(struct hblk *h, void *fn_ptr) { const hdr *hhdr = HDR(h); - size_t sz = (size_t)(hhdr -> hb_sz); + size_t sz = hhdr -> hb_sz; word descr = hhdr -> hb_descr; per_object_func fn = *(per_object_func *)fn_ptr; size_t i = 0; diff --git a/checksums.c b/checksums.c index ac2c11a9b..9c728fc15 100644 --- a/checksums.c +++ b/checksums.c @@ -115,7 +115,7 @@ STATIC void GC_CALLBACK GC_add_block(struct hblk *h, void *dummy) const hdr *hhdr = HDR(h); UNUSED_ARG(dummy); - GC_bytes_in_used_blocks += (hhdr->hb_sz + HBLKSIZE-1) & ~(word)(HBLKSIZE-1); + GC_bytes_in_used_blocks += (hhdr -> hb_sz + HBLKSIZE-1) & ~(HBLKSIZE-1); } STATIC void GC_check_blocks(void) diff --git a/dbg_mlc.c b/dbg_mlc.c index 8cc885411..2aeecc0d6 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -780,9 +780,9 @@ GC_API void GC_CALL GC_debug_free(void * p) ) { GC_free(base); } else { - word i; - word sz = hhdr -> hb_sz; - word obj_sz = BYTES_TO_WORDS(sz - sizeof(oh)); + size_t i; + size_t sz = hhdr -> hb_sz; + size_t obj_sz = BYTES_TO_WORDS(sz - sizeof(oh)); for (i = 0; i < obj_sz; ++i) ((GC_uintptr_t *)p)[i] = GC_FREED_MEM_MARKER; @@ -935,8 +935,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL const hdr *hhdr = HDR(hbp); ptr_t p = hbp -> hb_body; ptr_t plim; - word sz = hhdr -> hb_sz; - word bit_no; + size_t sz = hhdr -> hb_sz; + size_t bit_no; UNUSED_ARG(dummy); plim = sz > MAXOBJBYTES ? p : p + HBLKSIZE - sz; @@ -963,8 +963,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_INNER GC_bool GC_check_leaked(ptr_t base) { - word i; - word obj_sz; + size_t i; + size_t obj_sz; word *p; if ( diff --git a/extra/pcr_interface.c b/extra/pcr_interface.c index 9ce455f50..8c31be6fb 100644 --- a/extra/pcr_interface.c +++ b/extra/pcr_interface.c @@ -77,7 +77,7 @@ void GC_enumerate_block(struct hblk *h, enumerate_data * ed) # endif hhdr = HDR(h); descr = hhdr -> hb_descr; - sz = (size_t)hhdr->hb_sz; + sz = hhdr -> hb_sz; if (descr != 0 && ed -> ed_pointerfree || descr == 0 && !(ed -> ed_pointerfree)) return; lim = (ptr_t)(h+1) - sz; diff --git a/include/private/gc_pmark.h b/include/private/gc_pmark.h index 7be3406f3..99d005129 100644 --- a/include/private/gc_pmark.h +++ b/include/private/gc_pmark.h @@ -281,7 +281,7 @@ GC_INLINE mse * GC_push_contents_hdr(ptr_t current, mse * mark_stack_top, /* Accurate enough if HBLKSIZE <= 2**15. */ GC_STATIC_ASSERT(HBLKSIZE <= (1 << 15)); - obj_displ = (((low_prod >> 16) + 1) * (size_t)hhdr->hb_sz) >> 16; + obj_displ = (((low_prod >> 16) + 1) * hhdr -> hb_sz) >> 16; # endif if (do_offset_check && !GC_valid_offsets[obj_displ]) { GC_ADD_TO_BLACK_LIST_NORMAL(current, source); diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 387dac983..c0b256d21 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1160,11 +1160,11 @@ struct hblkhdr { /* LARGE_INV_SZ. */ # define LARGE_INV_SZ ((unsigned32)1 << 16) # endif - word hb_sz; /* If in use, size in bytes, of objects in the block. */ - /* if free, the size in bytes of the whole block. */ - /* We assume that this is convertible to signed_word */ - /* without generating a negative result. We avoid */ - /* generating free blocks larger than that. */ + size_t hb_sz; /* If in use, size in bytes, of objects in the block. */ + /* if free, the size in bytes of the whole block */ + /* We assume that this is convertible to signed_word */ + /* without generating a negative result. We avoid */ + /* generating free blocks larger than that. */ word hb_descr; /* object descriptor for marking. See */ /* gc_mark.h. */ # ifndef MARK_BIT_PER_OBJ @@ -1927,7 +1927,7 @@ struct GC_traced_stack_sect_s { #endif /* !USE_MARK_BYTES */ #ifdef MARK_BIT_PER_OBJ -# define MARK_BIT_NO(offset, sz) (((word)(offset))/(sz)) +# define MARK_BIT_NO(offset, sz) (((unsigned)(offset))/(sz)) /* Get the mark bit index corresponding to the given byte */ /* offset and size (in bytes). */ # define MARK_BIT_OFFSET(sz) 1 @@ -1935,7 +1935,7 @@ struct GC_traced_stack_sect_s { # define FINAL_MARK_BIT(sz) ((sz) > MAXOBJBYTES ? 1 : HBLK_OBJS(sz)) /* Position of final, always set, mark bit. */ #else -# define MARK_BIT_NO(offset, sz) BYTES_TO_GRANULES((word)(offset)) +# define MARK_BIT_NO(offset, sz) BYTES_TO_GRANULES((unsigned)(offset)) # define MARK_BIT_OFFSET(sz) BYTES_TO_GRANULES(sz) # define FINAL_MARK_BIT(sz) \ ((sz) > MAXOBJBYTES ? MARK_BITS_PER_HBLK \ diff --git a/malloc.c b/malloc.c index 853189b76..a2934069a 100644 --- a/malloc.c +++ b/malloc.c @@ -610,7 +610,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_uncollectable(size_t lb) /* Explicitly deallocate the object. hhdr should correspond to p. */ static void free_internal(void *p, const hdr *hhdr) { - size_t lb = (size_t)(hhdr -> hb_sz); /* size in bytes */ + size_t lb = hhdr -> hb_sz; /* size in bytes */ size_t lg = BYTES_TO_GRANULES(lb); /* size in granules */ int k = hhdr -> hb_obj_kind; diff --git a/mallocx.c b/mallocx.c index 36d325633..eb5bff4d5 100644 --- a/mallocx.c +++ b/mallocx.c @@ -46,7 +46,7 @@ GC_API int GC_CALL GC_get_kind_and_size(const void * p, size_t * psize) const hdr *hhdr = HDR(p); if (psize != NULL) { - *psize = (size_t)(hhdr -> hb_sz); + *psize = hhdr -> hb_sz; } return hhdr -> hb_obj_kind; } @@ -96,7 +96,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) return NULL; } hhdr = HDR(HBLKPTR(p)); - sz = (size_t)hhdr->hb_sz; + sz = hhdr -> hb_sz; obj_kind = hhdr -> hb_obj_kind; orig_sz = sz; diff --git a/mark.c b/mark.c index 5b165596e..b0ab2b7f9 100644 --- a/mark.c +++ b/mark.c @@ -176,10 +176,10 @@ GC_INNER void GC_clear_hdr_marks(hdr *hhdr) # ifdef AO_HAVE_load /* Atomic access is used to avoid racing with GC_realloc. */ - last_bit = FINAL_MARK_BIT((size_t)AO_load((volatile AO_t *)&hhdr->hb_sz)); + last_bit = FINAL_MARK_BIT(AO_load((volatile AO_t *)&hhdr->hb_sz)); # else /* No race as GC_realloc holds the allocator lock while updating hb_sz. */ - last_bit = FINAL_MARK_BIT((size_t)hhdr->hb_sz); + last_bit = FINAL_MARK_BIT(hhdr -> hb_sz); # endif BZERO(hhdr -> hb_marks, sizeof(hhdr->hb_marks)); @@ -191,7 +191,7 @@ GC_INNER void GC_clear_hdr_marks(hdr *hhdr) GC_INNER void GC_set_hdr_marks(hdr *hhdr) { unsigned i; - size_t sz = (size_t)hhdr->hb_sz; + size_t sz = hhdr -> hb_sz; unsigned n_marks = (unsigned)FINAL_MARK_BIT(sz); # ifdef USE_MARK_BYTES @@ -1903,7 +1903,7 @@ GC_INNER void GC_push_all_stack(ptr_t bottom, ptr_t top) /* Push all objects reachable from marked objects in the given block. */ STATIC void GC_push_marked(struct hblk *h, const hdr *hhdr) { - word sz = hhdr -> hb_sz; + size_t sz = hhdr -> hb_sz; word descr = hhdr -> hb_descr; ptr_t p; word bit_no; @@ -1965,7 +1965,7 @@ STATIC void GC_push_marked(struct hblk *h, const hdr *hhdr) GC_ATTR_NO_SANITIZE_THREAD STATIC void GC_push_unconditionally(struct hblk *h, const hdr *hhdr) { - word sz = hhdr -> hb_sz; + size_t sz = hhdr -> hb_sz; word descr = hhdr -> hb_descr; ptr_t p; ptr_t lim; @@ -1995,12 +1995,12 @@ STATIC void GC_push_marked(struct hblk *h, const hdr *hhdr) /* Test whether any page in the given block is dirty. */ STATIC GC_bool GC_block_was_dirty(struct hblk *h, const hdr *hhdr) { - word sz; + size_t sz; ptr_t p; # ifdef AO_HAVE_load /* Atomic access is used to avoid racing with GC_realloc. */ - sz = (word)AO_load((volatile AO_t *)&(hhdr -> hb_sz)); + sz = AO_load((volatile AO_t *)&(hhdr -> hb_sz)); # else sz = hhdr -> hb_sz; # endif diff --git a/misc.c b/misc.c index 60d08fbc1..74b1d0c3c 100644 --- a/misc.c +++ b/misc.c @@ -477,7 +477,7 @@ GC_API size_t GC_CALL GC_size(const void * p) if (EXPECT(NULL == p, FALSE)) return 0; hhdr = HDR(p); - return (size_t)(hhdr -> hb_sz); + return hhdr -> hb_sz; } /* These getters remain unsynchronized for compatibility (since some */ @@ -2477,7 +2477,7 @@ static void GC_CALLBACK block_add_size(struct hblk *h, void *pbytes) { const hdr *hhdr = HDR(h); - *(word *)pbytes += (hhdr -> hb_sz + HBLKSIZE-1) & ~(word)(HBLKSIZE-1); + *(word *)pbytes += ((word)hhdr->hb_sz + HBLKSIZE-1) & ~(word)(HBLKSIZE-1); # if defined(CPPCHECK) GC_noop1_ptr(h); # endif diff --git a/reclaim.c b/reclaim.c index 510275f22..1df4d8430 100644 --- a/reclaim.c +++ b/reclaim.c @@ -138,7 +138,7 @@ GC_INNER GC_bool GC_block_empty(const hdr *hhdr) return 0 == hhdr -> hb_n_marks; } -STATIC GC_bool GC_block_nearly_full(const hdr *hhdr, word sz) +STATIC GC_bool GC_block_nearly_full(const hdr *hhdr, size_t sz) { return hhdr -> hb_n_marks > HBLK_OBJS(sz) * 7 / 8; } @@ -175,7 +175,7 @@ GC_INLINE word *GC_clear_block(word *p, word sz, word *pcount) * free list. Returns the new list. * Clears unmarked objects. Sz is in bytes. */ -STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, const hdr *hhdr, word sz, +STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, const hdr *hhdr, size_t sz, ptr_t list, word *pcount) { word bit_no; @@ -207,7 +207,7 @@ STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, const hdr *hhdr, word sz, } /* The same thing, but don't clear objects: */ -STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, const hdr *hhdr, word sz, +STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, const hdr *hhdr, size_t sz, ptr_t list, word *pcount) { word bit_no; @@ -238,7 +238,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, const hdr *hhdr, word sz, #ifdef ENABLE_DISCLAIM /* Call reclaim notifier for block's kind on each unmarked object in */ /* block, all within a pair of corresponding enter/leave callbacks. */ - STATIC ptr_t GC_disclaim_and_reclaim(struct hblk *hbp, hdr *hhdr, word sz, + STATIC ptr_t GC_disclaim_and_reclaim(struct hblk *hbp, hdr *hhdr, size_t sz, ptr_t list, word *pcount) { word bit_no; @@ -272,7 +272,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, const hdr *hhdr, word sz, #endif /* ENABLE_DISCLAIM */ /* Don't really reclaim objects, just check for unmarked ones: */ -STATIC void GC_reclaim_check(struct hblk *hbp, const hdr *hhdr, word sz) +STATIC void GC_reclaim_check(struct hblk *hbp, const hdr *hhdr, size_t sz) { word bit_no; ptr_t p, plim; @@ -337,7 +337,7 @@ GC_INNER ptr_t GC_reclaim_generic(struct hblk *hbp, hdr *hhdr, size_t sz, * If entirely empty blocks are to be completely deallocated, then * caller should perform that check. */ -STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, word sz, +STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, size_t sz, GC_bool report_if_found) { hdr *hhdr; @@ -360,7 +360,7 @@ STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, word sz, STATIC void GC_disclaim_and_reclaim_or_free_small_block(struct hblk *hbp) { hdr *hhdr; - word sz; + size_t sz; struct obj_kind *ok; void **flh; void *flh_next; @@ -392,7 +392,7 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp, void *report_if_found) { hdr *hhdr; - word sz; /* size of objects in current block */ + size_t sz; /* size of objects in current block */ struct obj_kind *ok; GC_ASSERT(I_HOLD_LOCK()); @@ -403,7 +403,7 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp, ok = &GC_obj_kinds[hhdr -> hb_obj_kind]; # ifdef AO_HAVE_load /* Atomic access is used to avoid racing with GC_realloc. */ - sz = (word)AO_load((volatile AO_t *)&(hhdr -> hb_sz)); + sz = AO_load((volatile AO_t *)&(hhdr -> hb_sz)); # else /* No race as GC_realloc holds the allocator lock while */ /* updating hb_sz. */ @@ -531,9 +531,9 @@ GC_ATTR_NO_SANITIZE_THREAD unsigned GC_n_set_marks(const hdr *hhdr) { unsigned result = 0; - word i; - word offset = MARK_BIT_OFFSET(hhdr -> hb_sz); - word limit = FINAL_MARK_BIT(hhdr -> hb_sz); + size_t i; + size_t offset = MARK_BIT_OFFSET(hhdr -> hb_sz); + size_t limit = FINAL_MARK_BIT(hhdr -> hb_sz); for (i = 0; i < limit; i += offset) { result += hhdr -> hb_marks[i]; @@ -558,11 +558,12 @@ static unsigned count_ones(word n) unsigned GC_n_set_marks(const hdr *hhdr) { unsigned result = 0; - word sz = hhdr -> hb_sz; - word i; + size_t sz = hhdr -> hb_sz; + size_t i; # ifdef MARK_BIT_PER_OBJ - word n_objs = HBLK_OBJS(sz); - word n_mark_words = divWORDSZ(n_objs > 0 ? n_objs : 1); /* round down */ + size_t n_objs = HBLK_OBJS(sz); + size_t n_mark_words = divWORDSZ(n_objs > 0 + ? n_objs : 1); /* round down */ for (i = 0; i <= n_mark_words; i++) { result += count_ones(hhdr -> hb_marks[i]); @@ -577,7 +578,7 @@ unsigned GC_n_set_marks(const hdr *hhdr) result--; /* exclude the one bit set past the end */ # ifndef MARK_BIT_PER_OBJ if (IS_UNCOLLECTABLE(hhdr -> hb_obj_kind)) { - size_t lg = (size_t)BYTES_TO_GRANULES(sz); + size_t lg = BYTES_TO_GRANULES(sz); /* As mentioned in GC_set_hdr_marks(), all the bits are set */ /* instead of every n-th, thus the result should be adjusted. */ @@ -597,7 +598,7 @@ GC_API unsigned GC_CALL GC_count_set_marks_in_hblk(const void *p) { STATIC void GC_CALLBACK GC_print_block_descr(struct hblk *h, void *raw_ps) { const hdr *hhdr = HDR(h); - word sz = hhdr -> hb_sz; + size_t sz = hhdr -> hb_sz; struct Print_stats *ps = (struct Print_stats *)raw_ps; unsigned n_marks = GC_n_set_marks(hhdr); unsigned n_objs = (unsigned)HBLK_OBJS(sz); @@ -613,7 +614,7 @@ GC_API unsigned GC_CALL GC_count_set_marks_in_hblk(const void *p) { hhdr -> hb_obj_kind, (unsigned)sz, n_marks, n_objs); ps -> number_of_blocks++; ps -> total_bytes += - (sz + HBLKSIZE-1) & ~(word)(HBLKSIZE-1); /* round up */ + (word)(sz + HBLKSIZE-1) & ~(word)(HBLKSIZE-1); /* round up */ } void GC_print_block_list(void) @@ -849,7 +850,7 @@ STATIC void GC_CALLBACK GC_do_enumerate_reachable_objects(struct hblk *hbp, ptr_t p, plim; const struct enumerate_reachable_s *ped = (struct enumerate_reachable_s *)ed_ptr; - size_t sz = (size_t)(hhdr -> hb_sz); + size_t sz = hhdr -> hb_sz; size_t bit_no; if (GC_block_empty(hhdr)) return; diff --git a/typd_mlc.c b/typd_mlc.c index 23066007f..95beb6916 100644 --- a/typd_mlc.c +++ b/typd_mlc.c @@ -676,8 +676,8 @@ static complex_descriptor *get_complex_descr(word *addr, size_t nwords) STATIC mse *GC_CALLBACK GC_array_mark_proc(word *addr, mse *mark_stack_top, mse *mark_stack_limit, word env) { - word sz = HDR(addr) -> hb_sz; - size_t nwords = (size_t)BYTES_TO_WORDS(sz); + size_t sz = HDR(addr) -> hb_sz; + size_t nwords = BYTES_TO_WORDS(sz); complex_descriptor *complex_d = get_complex_descr(addr, nwords); mse *orig_mark_stack_top = mark_stack_top; mse *new_mark_stack_top;