Replace assert with RUBY_ASSERT in rational.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:03 -05:00
Родитель 3ed5962755
Коммит 9a2b692249
1 изменённых файлов: 16 добавлений и 16 удалений

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

@ -389,8 +389,8 @@ f_gcd(VALUE x, VALUE y)
{
VALUE r = f_gcd_orig(x, y);
if (f_nonzero_p(r)) {
assert(f_zero_p(f_mod(x, r)));
assert(f_zero_p(f_mod(y, r)));
RUBY_ASSERT(f_zero_p(f_mod(x, r)));
RUBY_ASSERT(f_zero_p(f_mod(y, r)));
}
return r;
}
@ -456,8 +456,8 @@ nurat_int_value(VALUE num)
static void
nurat_canonicalize(VALUE *num, VALUE *den)
{
assert(num); assert(RB_INTEGER_TYPE_P(*num));
assert(den); assert(RB_INTEGER_TYPE_P(*den));
RUBY_ASSERT(num); RUBY_ASSERT(RB_INTEGER_TYPE_P(*num));
RUBY_ASSERT(den); RUBY_ASSERT(RB_INTEGER_TYPE_P(*den));
if (INT_NEGATIVE_P(*den)) {
*num = rb_int_uminus(*num);
*den = rb_int_uminus(*den);
@ -497,16 +497,16 @@ nurat_s_canonicalize_internal_no_reduce(VALUE klass, VALUE num, VALUE den)
inline static VALUE
f_rational_new2(VALUE klass, VALUE x, VALUE y)
{
assert(!k_rational_p(x));
assert(!k_rational_p(y));
RUBY_ASSERT(!k_rational_p(x));
RUBY_ASSERT(!k_rational_p(y));
return nurat_s_canonicalize_internal(klass, x, y);
}
inline static VALUE
f_rational_new_no_reduce2(VALUE klass, VALUE x, VALUE y)
{
assert(!k_rational_p(x));
assert(!k_rational_p(y));
RUBY_ASSERT(!k_rational_p(x));
RUBY_ASSERT(!k_rational_p(y));
return nurat_s_canonicalize_internal_no_reduce(klass, x, y);
}
@ -610,7 +610,7 @@ nurat_denominator(VALUE self)
VALUE
rb_rational_uminus(VALUE self)
{
const int unused = (assert(RB_TYPE_P(self, T_RATIONAL)), 0);
const int unused = (RUBY_ASSERT(RB_TYPE_P(self, T_RATIONAL)), 0);
get_dat1(self);
(void)unused;
return f_rational_new2(CLASS_OF(self), rb_int_uminus(dat->num), dat->den);
@ -646,7 +646,7 @@ inline static VALUE
f_imul(long x, long y)
{
VALUE r = f_imul_orig(x, y);
assert(f_eqeq_p(r, f_mul(LONG2NUM(x), LONG2NUM(y))));
RUBY_ASSERT(f_eqeq_p(r, f_mul(LONG2NUM(x), LONG2NUM(y))));
return r;
}
#endif
@ -795,7 +795,7 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
{
VALUE num, den;
assert(RB_TYPE_P(self, T_RATIONAL));
RUBY_ASSERT(RB_TYPE_P(self, T_RATIONAL));
/* Integer#** can return Rational with Float right now */
if (RB_FLOAT_TYPE_P(anum) || RB_FLOAT_TYPE_P(aden) ||
@ -806,10 +806,10 @@ f_muldiv(VALUE self, VALUE anum, VALUE aden, VALUE bnum, VALUE bden, int k)
return DBL2NUM(x);
}
assert(RB_INTEGER_TYPE_P(anum));
assert(RB_INTEGER_TYPE_P(aden));
assert(RB_INTEGER_TYPE_P(bnum));
assert(RB_INTEGER_TYPE_P(bden));
RUBY_ASSERT(RB_INTEGER_TYPE_P(anum));
RUBY_ASSERT(RB_INTEGER_TYPE_P(aden));
RUBY_ASSERT(RB_INTEGER_TYPE_P(bnum));
RUBY_ASSERT(RB_INTEGER_TYPE_P(bden));
if (k == '/') {
VALUE t;
@ -2559,7 +2559,7 @@ nurat_convert(VALUE klass, VALUE numv, VALUE denv, int raise)
VALUE a1 = numv, a2 = denv;
int state;
assert(!UNDEF_P(a1));
RUBY_ASSERT(!UNDEF_P(a1));
if (NIL_P(a1) || NIL_P(a2)) {
if (!raise) return Qnil;