Skip to content

Commit

Permalink
Revert "Change type of hb_sz field (of hblkhdr) from size_t to word"
Browse files Browse the repository at this point in the history
This reverts commit e794f1e.

Reason: AO_t is defined as size_t on most platforms.
  • Loading branch information
ivmai committed Jul 1, 2024
1 parent 16e6996 commit 0354e65
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 59 deletions.
6 changes: 3 additions & 3 deletions allchblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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. */
}
Expand Down
8 changes: 4 additions & 4 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion checksums.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions dbg_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion extra/pcr_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/private/gc_pmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1927,15 +1927,15 @@ 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
/* Spacing between useful mark bits. */
# 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 \
Expand Down
2 changes: 1 addition & 1 deletion malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions mallocx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
14 changes: 7 additions & 7 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0354e65

Please sign in to comment.