Skip to content

Commit

Permalink
Define GC_CAST_AWAY_CONST_PVOID() public macro
Browse files Browse the repository at this point in the history
Issue #627 (bdwgc).

* dbg_mlc.c (GC_debug_ptr_store_and_dirty): Use
GC_CAST_AWAY_CONST_PVOID() instead of explicit cast to word and then
to void*.
* include/gc/gc.h (GC_GENERAL_REGISTER_DISAPPEARING_LINK_SAFE,
GC_REGISTER_LONG_LINK_SAFE): Likewise.
* include/private/gc_priv.h (GC_base_C): Likewise.
* specific.c (GC_key_create_inner): Likewise.
* include/gc/gc.h (include/gc/gc.h): New public macro.
  • Loading branch information
ivmai committed Jun 12, 2024
1 parent f68db21 commit b9ad46f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dbg_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ GC_API void GC_CALL GC_debug_end_stubborn_change(const void *p)

GC_API void GC_CALL GC_debug_ptr_store_and_dirty(void *p, const void *q)
{
*(void **)GC_is_visible(p) = GC_is_valid_displacement(
(/* no const */ void *)(word)q);
*(void **)GC_is_visible(p)
= GC_is_valid_displacement(GC_CAST_AWAY_CONST_PVOID(q));
GC_debug_end_stubborn_change(p);
REACHABLE_AFTER_DIRTY(q);
}
Expand Down
7 changes: 4 additions & 3 deletions include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1098,15 +1098,16 @@ GC_API /* 'realloc' attr */ GC_ATTR_ALLOC_SIZE(2) void * GC_CALL
GC_debug_realloc_replacement(void * /* object_addr */,
size_t /* size_in_bytes */);

#define GC_CAST_AWAY_CONST_PVOID(p) ((/* no const */ void *)(GC_uintptr_t)(p))

/* Convenient macros for disappearing links registration working both */
/* for debug and non-debug allocated objects, and accepting interior */
/* pointers to object. */
#define GC_GENERAL_REGISTER_DISAPPEARING_LINK_SAFE(link, obj) \
GC_general_register_disappearing_link(link, \
GC_base((/* no const */ void *)(GC_word)(obj)))
GC_base(GC_CAST_AWAY_CONST_PVOID(obj)))
#define GC_REGISTER_LONG_LINK_SAFE(link, obj) \
GC_register_long_link(link, \
GC_base((/* no const */ void *)(GC_word)(obj)))
GC_register_long_link(link, GC_base(GC_CAST_AWAY_CONST_PVOID(obj)))

#ifdef GC_DEBUG_REPLACEMENT
# define GC_MALLOC(sz) GC_debug_malloc_replacement(sz)
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 @@ -2705,7 +2705,7 @@ GC_EXTERN GC_bool GC_print_back_height;
#endif

/* Same as GC_base but excepts and returns a pointer to const object. */
#define GC_base_C(p) ((const void *)GC_base((/* no const */ void *)(word)(p)))
#define GC_base_C(p) ((const void *)GC_base(GC_CAST_AWAY_CONST_PVOID(p)))

/* Debugging print routines: */
void GC_print_block_list(void);
Expand Down
4 changes: 2 additions & 2 deletions specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ GC_INNER int GC_key_create_inner(tsd ** key_ptr)
GC_ASSERT(ADDR(&invalid_tse.next) % sizeof(tse *) == 0);
result = (tsd *)MALLOC_CLEAR(sizeof(tsd));
if (NULL == result) return ENOMEM;
ret = pthread_mutex_init(&result->lock, NULL);
ret = pthread_mutex_init(&(result -> lock), NULL);
if (ret != 0) return ret;
for (i = 0; i < TS_CACHE_SIZE; ++i) {
result -> cache[i] = (/* no const */ tse *)(word)(&invalid_tse);
result -> cache[i] = (tse *)GC_CAST_AWAY_CONST_PVOID(&invalid_tse);
}
# ifdef GC_ASSERTIONS
for (i = 0; i < TS_HASH_SIZE; ++i) {
Expand Down

0 comments on commit b9ad46f

Please sign in to comment.