Skip to content

Commit

Permalink
Adjust formatting of some macros by adding extra parentheses and similar
Browse files Browse the repository at this point in the history
* cord/tests/de_win.h (CHAR_CMD): Add extra parentheses for the proper
auto-formatting.
* dbg_mlc.c (OFN_UNSET): Likewise.
* include/gc/gc_inline.h (GC_MALLOC_WORDS_KIND): Likewise.
* include/private/gc_priv.h [!DONT_ADD_BYTE_AT_END && !LINT2]
(EXTRA_BYTES): Likewise.
* os_dep.c [MPROTECT_VDB && (MSWIN32 || MSWINCE)] (SIG_DFL): Likewise.
* dbg_mlc.c (CROSSES_HBLK): Reorder arithmetic operands for the proper
auto-formatting.
* include/gc/gc_inline.h (GC_FAST_MALLOC_GRANS): Likewise.
* include/gc/cord.h (CORD_nul): Remove redundant parentheses.
* os_dep.c (PAGE_ALIGNED): Rename to `IS_PAGE_ALIGNED`; rename `x`
argument to `p`; define only if `GC_ASSERTIONS`.
  • Loading branch information
ivmai committed Nov 5, 2024
1 parent e42e7e2 commit 0da8a39
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cord/tests/de_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define EDIT_CMD_FLAG 0x200
#define REPEAT_FLAG 0x400

#define CHAR_CMD(i) ((i)&0xff)
#define CHAR_CMD(i) ((i) & (0xff))

/* MENU: DE */
#define IDM_FILESAVE (EDIT_CMD_FLAG + WRITE)
Expand Down
4 changes: 2 additions & 2 deletions dbg_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ GC_generate_random_backtrace(void)
#endif /* KEEP_BACK_PTRS */

#define CROSSES_HBLK(p, sz) \
((ADDR((p) + sizeof(oh) + (sz)-1) ^ ADDR(p)) >= HBLKSIZE)
((ADDR((p) + (sizeof(oh) - 1) + (sz)) ^ ADDR(p)) >= HBLKSIZE)

GC_INNER void *
GC_store_debug_info_inner(void *base, size_t sz, const char *string,
Expand Down Expand Up @@ -1071,7 +1071,7 @@ GC_debug_invoke_finalizer(void *obj, void *data)
}

/* Special finalizer_proc value to detect GC_register_finalizer failure. */
# define OFN_UNSET ((GC_finalization_proc) ~(GC_funcptr_uint)0)
# define OFN_UNSET ((GC_finalization_proc)(~(GC_funcptr_uint)0))

/* Set ofn and ocd to reflect the values we got back. */
static void
Expand Down
2 changes: 1 addition & 1 deletion include/gc/cord.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ CORD_API size_t CORD_str(CORD /* x */, size_t /* start */, CORD /* s */);
/* The resulting representation takes constant space, independent of i. */
CORD_API CORD CORD_chars(char /* c */, size_t /* i */);

#define CORD_nul(i) CORD_chars('\0', (i))
#define CORD_nul(i) CORD_chars('\0', i)

/* Turn a file into cord. The file must be seekable. Its contents */
/* must remain constant. The file may be accessed as an immediate */
Expand Down
18 changes: 9 additions & 9 deletions include/gc/gc_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
GC_end_stubborn_change(my_fl); \
GC_reachable_here(next); \
} \
GC_ASSERT(GC_size(result) >= (lg)*GC_GRANULE_BYTES); \
GC_ASSERT(GC_size(result) >= GC_GRANULE_BYTES * (lg)); \
GC_ASSERT((k) == GC_I_PTRFREE \
|| 0 /* NULL */ == ((void **)result)[1]); \
break; \
Expand All @@ -187,8 +187,8 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
: GC_RAW_BYTES_FROM_INDEX(lg), \
k, my_fl); \
my_entry = *my_fl; \
if (my_entry == 0) { \
result = (*GC_get_oom_fn())((lg)*GC_GRANULE_BYTES); \
if (0 /* NULL */ == my_entry) { \
result = (*GC_get_oom_fn())(GC_GRANULE_BYTES * (lg)); \
break; \
} \
} \
Expand All @@ -203,12 +203,12 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
/* allocator lock. The caller is responsible for supplying a cleared */
/* tiny_fl free-list array. For single-threaded applications, this may */
/* be a global array. */
#define GC_MALLOC_WORDS_KIND(result, n, tiny_fl, k, init) \
do { \
size_t lg = GC_PTRS_TO_WHOLE_GRANULES(n); \
\
GC_FAST_MALLOC_GRANS(result, lg, tiny_fl, 0 /* num_direct */, k, \
GC_malloc_kind(lg *GC_GRANULE_BYTES, k), init); \
#define GC_MALLOC_WORDS_KIND(result, n, tiny_fl, k, init) \
do { \
size_t lg = GC_PTRS_TO_WHOLE_GRANULES(n); \
\
GC_FAST_MALLOC_GRANS(result, lg, tiny_fl, 0 /* num_direct */, k, \
GC_malloc_kind((lg)*GC_GRANULE_BYTES, k), init); \
} while (0)

#define GC_MALLOC_WORDS(result, n, tiny_fl) \
Expand Down
2 changes: 1 addition & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ GC_INNER void GC_print_finalization_stats(void);
/* GC_all_interior_pointers is assumed to have only 0 or 1 value. */
# define EXTRA_BYTES ((size_t)(GC_all_interior_pointers ? 1 : 0))
# else
# define EXTRA_BYTES (size_t) GC_all_interior_pointers
# define EXTRA_BYTES ((size_t)GC_all_interior_pointers)
# endif
# define MAX_EXTRA_BYTES 1
#else
Expand Down
12 changes: 7 additions & 5 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3235,11 +3235,11 @@ static DWORD protect_junk;
# if defined(MSWIN32)
typedef LPTOP_LEVEL_EXCEPTION_FILTER SIG_HNDLR_PTR;
# undef SIG_DFL
# define SIG_DFL ((LPTOP_LEVEL_EXCEPTION_FILTER) ~(GC_funcptr_uint)0)
# define SIG_DFL ((LPTOP_LEVEL_EXCEPTION_FILTER)(~(GC_funcptr_uint)0))
# elif defined(MSWINCE)
typedef LONG(WINAPI *SIG_HNDLR_PTR)(struct _EXCEPTION_POINTERS *);
# undef SIG_DFL
# define SIG_DFL ((SIG_HNDLR_PTR) ~(GC_funcptr_uint)0)
# define SIG_DFL ((SIG_HNDLR_PTR)(~(GC_funcptr_uint)0))
# elif defined(DARWIN)
# ifdef BROKEN_EXCEPTION_HANDLING
typedef void (*SIG_HNDLR_PTR)();
Expand Down Expand Up @@ -3572,7 +3572,9 @@ GC_dirty_init(void)
}
# endif /* !DARWIN */

# define PAGE_ALIGNED(x) ((ADDR(x) & (GC_page_size - 1)) == 0)
# ifdef GC_ASSERTIONS
# define IS_PAGE_ALIGNED(p) ((ADDR(p) & (GC_page_size - 1)) == 0)
# endif

STATIC void
GC_protect_heap(void)
Expand All @@ -3587,8 +3589,8 @@ GC_protect_heap(void)
struct hblk *current_start; /* start of block to be protected */
ptr_t limit;

GC_ASSERT(PAGE_ALIGNED(start));
GC_ASSERT(PAGE_ALIGNED(len));
GC_ASSERT(IS_PAGE_ALIGNED(start));
GC_ASSERT(IS_PAGE_ALIGNED(len));
# ifndef DONT_PROTECT_PTRFREE
/* We avoid protecting pointer-free objects unless the page */
/* size differs from HBLKSIZE. */
Expand Down

0 comments on commit 0da8a39

Please sign in to comment.