Skip to content

Commit

Permalink
Replace assert with RUBY_ASSERT in rational.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 3ed5962 commit 9a2b692
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions rational.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) ||
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9a2b692

Please sign in to comment.