Skip to content

Commit

Permalink
[GR-48942] Use the original RB_INT2FIX() and RUBY_FIXNUM_{MIN,MAX}
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4019
  • Loading branch information
eregon committed Sep 28, 2023
2 parents eaf1483 + 81d281e commit d60d4eb
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/cext/ABI_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
3
9 changes: 0 additions & 9 deletions lib/cext/include/ruby/internal/arithmetic/fixnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@
* represent is 4,611,686,018,427,387,904, which is not fixable. The
* seemingly-strange "< FIXNUM_MAX + 1" expression below is due to this.
*/
#ifdef TRUFFLERUBY
#define RB_POSFIXABLE(f) ((f) <= RUBY_FIXNUM_MAX)
#else
#define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1)
#endif

/**
* Checks if the passed value is in range of fixnum, assuming it is a negative
Expand All @@ -55,15 +51,10 @@
/** Checks if the passed value is in range of fixnum */
#define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_))

#ifdef TRUFFLERUBY
#define RUBY_FIXNUM_MAX LONG_MAX
#define RUBY_FIXNUM_MIN LONG_MIN
#else
/** Maximum possible value that a fixnum can represent. */
#define RUBY_FIXNUM_MAX (LONG_MAX / 2)

/** Minimum possible value that a fixnum can represent. */
#define RUBY_FIXNUM_MIN (LONG_MIN / 2)
#endif /* TRUFFLERUBY */

#endif /* RBIMPL_ARITHMETIC_FIXNUM_H */
4 changes: 0 additions & 4 deletions lib/cext/include/ruby/internal/arithmetic/long.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ RBIMPL_ATTR_ARTIFICIAL()
static inline VALUE
RB_INT2FIX(long i)
{
#ifdef TRUFFLERUBY
return rb_tr_longwrap(i);
#else
RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(i));

/* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully
Expand All @@ -135,7 +132,6 @@ RB_INT2FIX(long i)

RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(n));
return n;
#endif
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/c/cext/integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ int rb_absint_singlebit_p(VALUE val) {
}

VALUE rb_int2big(intptr_t n) {
// it cannot overflow Fixnum
return LONG2FIX(n);
// intptr_t is the same as long
return rb_tr_longwrap(n);
}

0 comments on commit d60d4eb

Please sign in to comment.