Skip to content

Commit

Permalink
Replace assert with RUBY_ASSERT in weakmap.c
Browse files Browse the repository at this point in the history
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
  • Loading branch information
peterzhu2118 committed Feb 12, 2024
1 parent 80700f4 commit 0536b2c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions weakmap.c
Expand Up @@ -39,7 +39,7 @@ wmap_live_p(VALUE obj)
static void
wmap_free_entry(VALUE *key, VALUE *val)
{
assert(key + 1 == val);
RUBY_ASSERT(key + 1 == val);

/* We only need to free key because val is allocated beside key on in the
* same malloc call. */
Expand Down Expand Up @@ -418,7 +418,7 @@ wmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t new_key_ptr, int exi
VALUE new_val = *(((VALUE *)new_key_ptr) + 1);

if (existing) {
assert(*(VALUE *)*key == new_key);
RUBY_ASSERT(*(VALUE *)*key == new_key);
}
else {
VALUE *pair = xmalloc(sizeof(VALUE) * 2);
Expand Down Expand Up @@ -462,7 +462,7 @@ wmap_aset(VALUE self, VALUE key, VALUE val)
static VALUE
wmap_lookup(VALUE self, VALUE key)
{
assert(wmap_live_p(key));
RUBY_ASSERT(wmap_live_p(key));

struct weakmap *w;
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
Expand Down Expand Up @@ -681,7 +681,7 @@ wkmap_compact_table_i(st_data_t key, st_data_t val_obj, st_data_t _data, int _er
static int
wkmap_compact_table_replace(st_data_t *key_ptr, st_data_t *val_ptr, st_data_t _data, int existing)
{
assert(existing);
RUBY_ASSERT(existing);

*(VALUE *)*key_ptr = rb_gc_location(*(VALUE *)*key_ptr);
*val_ptr = (st_data_t)rb_gc_location((VALUE)*val_ptr);
Expand Down Expand Up @@ -729,7 +729,7 @@ static st_index_t
wkmap_hash(st_data_t n)
{
VALUE obj = *(VALUE *)n;
assert(wmap_live_p(obj));
RUBY_ASSERT(wmap_live_p(obj));

return rb_any_hash(obj);
}
Expand Down

0 comments on commit 0536b2c

Please sign in to comment.