Skip to content

Commit

Permalink
Remove USE_RGENGC_LOGGING_WB_UNPROTECT
Browse files Browse the repository at this point in the history
This macro is broken when set to anything other than 0. And has had a
comment saying that it's broken for 3 years.

This commit deletes it and the associated logging code. It's clearly
not being used.

Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
  • Loading branch information
eightbitraptor and peterzhu2118 committed Feb 17, 2023
1 parent a7beb4c commit 81dc3a1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 74 deletions.
43 changes: 0 additions & 43 deletions gc.c
Expand Up @@ -9128,49 +9128,6 @@ rb_gc_writebarrier_remember(VALUE obj)
}
}

static st_table *rgengc_unprotect_logging_table;

static int
rgengc_unprotect_logging_exit_func_i(st_data_t key, st_data_t val, st_data_t arg)
{
fprintf(stderr, "%s\t%"PRIuVALUE"\n", (char *)key, (VALUE)val);
return ST_CONTINUE;
}

static void
rgengc_unprotect_logging_exit_func(void)
{
st_foreach(rgengc_unprotect_logging_table, rgengc_unprotect_logging_exit_func_i, 0);
}

void
rb_gc_unprotect_logging(void *objptr, const char *filename, int line)
{
VALUE obj = (VALUE)objptr;

if (rgengc_unprotect_logging_table == 0) {
rgengc_unprotect_logging_table = st_init_strtable();
atexit(rgengc_unprotect_logging_exit_func);
}

if (RVALUE_WB_UNPROTECTED(obj) == 0) {
char buff[0x100];
st_data_t cnt = 1;
char *ptr = buff;

snprintf(ptr, 0x100 - 1, "%s|%s:%d", obj_info(obj), filename, line);

if (st_lookup(rgengc_unprotect_logging_table, (st_data_t)ptr, &cnt)) {
cnt++;
}
else {
ptr = (strdup)(buff);
if (!ptr) rb_memerror();
}
st_insert(rgengc_unprotect_logging_table, (st_data_t)ptr, cnt);
}
}

void
rb_copy_wb_protected_attribute(VALUE dest, VALUE obj)
{
Expand Down
33 changes: 2 additions & 31 deletions include/ruby/internal/rgengc.h
Expand Up @@ -55,14 +55,6 @@
# define USE_RINCGC 1
#endif

/**
* @deprecated This macro seems broken. Setting this to anything other than
* zero just doesn't compile. We need to KonMari.
*/
#ifndef USE_RGENGC_LOGGING_WB_UNPROTECT
# define USE_RGENGC_LOGGING_WB_UNPROTECT 0
#endif

/**
* @private
*
Expand Down Expand Up @@ -302,22 +294,6 @@ void rb_gc_writebarrier(VALUE old, VALUE young);
*/
void rb_gc_writebarrier_unprotect(VALUE obj);

#if USE_RGENGC_LOGGING_WB_UNPROTECT
/**
* @private
*
* This is the implementation of #RGENGC_LOGGING_WB_UNPROTECT(). People
* don't use it directly.
*
* @param[in] objptr Don't know why this is a pointer to void but in
* reality this is a pointer to an object that is about
* to be un-protected.
* @param[in] filename Pass C's `__FILE__` here.
* @param[in] line Pass C's `__LINE__` here.
*/
void rb_gc_unprotect_logging(void *objptr, const char *filename, int line);
#endif

RBIMPL_SYMBOL_EXPORT_END()

RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Expand Down Expand Up @@ -378,13 +354,12 @@ rb_obj_wb_unprotect(
RBIMPL_ATTR_MAYBE_UNUSED()
int line)
{
#if USE_RGENGC_LOGGING_WB_UNPROTECT
RGENGC_LOGGING_WB_UNPROTECT(RBIMPL_CAST((void *)x), filename, line);
#endif
rb_gc_writebarrier_unprotect(x);
return x;
}

#define RGENGC_LOGGING_OBJ_WRITTEN rb_gc_obj_written_logging

/**
* @private
*
Expand All @@ -409,10 +384,6 @@ rb_obj_written(
RBIMPL_ATTR_MAYBE_UNUSED()
int line)
{
#if USE_RGENGC_LOGGING_WB_UNPROTECT
RGENGC_LOGGING_OBJ_WRITTEN(a, oldv, b, filename, line);
#endif

if (!RB_SPECIAL_CONST_P(b)) {
rb_gc_writebarrier(a, b);
}
Expand Down

0 comments on commit 81dc3a1

Please sign in to comment.