Replace assert with RUBY_ASSERT in weakmap.c

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.
This commit is contained in:
Peter Zhu 2024-02-08 09:45:51 -05:00
Родитель 80700f453e
Коммит 0536b2ce48
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -39,7 +39,7 @@ wmap_live_p(VALUE obj)
static void static void
wmap_free_entry(VALUE *key, VALUE *val) 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 /* We only need to free key because val is allocated beside key on in the
* same malloc call. */ * same malloc call. */
@ -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); VALUE new_val = *(((VALUE *)new_key_ptr) + 1);
if (existing) { if (existing) {
assert(*(VALUE *)*key == new_key); RUBY_ASSERT(*(VALUE *)*key == new_key);
} }
else { else {
VALUE *pair = xmalloc(sizeof(VALUE) * 2); VALUE *pair = xmalloc(sizeof(VALUE) * 2);
@ -462,7 +462,7 @@ wmap_aset(VALUE self, VALUE key, VALUE val)
static VALUE static VALUE
wmap_lookup(VALUE self, VALUE key) wmap_lookup(VALUE self, VALUE key)
{ {
assert(wmap_live_p(key)); RUBY_ASSERT(wmap_live_p(key));
struct weakmap *w; struct weakmap *w;
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
@ -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 static int
wkmap_compact_table_replace(st_data_t *key_ptr, st_data_t *val_ptr, st_data_t _data, int existing) 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); *(VALUE *)*key_ptr = rb_gc_location(*(VALUE *)*key_ptr);
*val_ptr = (st_data_t)rb_gc_location((VALUE)*val_ptr); *val_ptr = (st_data_t)rb_gc_location((VALUE)*val_ptr);
@ -729,7 +729,7 @@ static st_index_t
wkmap_hash(st_data_t n) wkmap_hash(st_data_t n)
{ {
VALUE obj = *(VALUE *)n; VALUE obj = *(VALUE *)n;
assert(wmap_live_p(obj)); RUBY_ASSERT(wmap_live_p(obj));
return rb_any_hash(obj); return rb_any_hash(obj);
} }