Skip to content

Commit e9b2e83

Browse files
committed
Use rb_funcall if rb_big_cmp doesn't exist
1 parent 53b38d2 commit e9b2e83

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

ext/mysql2/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def asplode(lib)
2424
have_func('rb_wait_for_single_fd')
2525
have_func('rb_hash_dup')
2626
have_func('rb_intern3')
27-
have_func('rb_big_and')
27+
have_func('rb_big_cmp')
2828

2929
# borrowed from mysqlplus
3030
# http://github.com/oldmoe/mysqlplus/blob/master/ext/extconf.rb

ext/mysql2/statement.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ VALUE cMysql2Statement;
44
extern VALUE mMysql2, cMysql2Error, cBigDecimal, cDateTime, cDate;
55
static VALUE sym_stream, intern_new_with_args, intern_each;
66
static VALUE intern_usec, intern_sec, intern_min, intern_hour, intern_day, intern_month, intern_year, intern_to_s;
7+
#ifndef HAVE_RB_BIG_CMP
8+
static ID id_cmp;
9+
#endif
710

811
#define GET_STATEMENT(self) \
912
mysql_stmt_wrapper *stmt_wrapper; \
@@ -209,8 +212,8 @@ static int my_big2ll(VALUE bignum, LONG_LONG *ptr)
209212
{
210213
unsigned LONG_LONG num;
211214
size_t len;
212-
int nlz_bits = 0;
213215
#ifdef HAVE_RB_ABSINT_SIZE
216+
int nlz_bits = 0;
214217
len = rb_absint_size(bignum, &nlz_bits);
215218
#else
216219
len = RBIGNUM_LEN(bignum) * SIZEOF_BDIGITS;
@@ -223,14 +226,17 @@ static int my_big2ll(VALUE bignum, LONG_LONG *ptr)
223226
*ptr = num;
224227
}
225228
else {
226-
if (len == 8 && nlz_bits == 0 &&
229+
if (len == 8 &&
230+
#ifdef HAVE_RB_ABSINT_SIZE
231+
nlz_bits == 0 &&
232+
#endif
233+
#if defined(HAVE_RB_ABSINT_SIZE) && defined(HAVE_RB_ABSINT_SINGLEBIT_P)
227234
/* only -0x8000000000000000 is safe if `len == 8 && nlz_bits == 0` */
228-
#ifdef HAVE_RB_ABSINT_SINGLEBIT_P
229235
!rb_absint_singlebit_p(bignum)
230-
#elif defined(HAVE_RB_BIG_AND)
231-
rb_big_and(bignum, LL2NUM(LLONG_MAX)) != INT2FIX(0)
232-
#else
236+
#elif defined(HAVE_RB_BIG_CMP)
233237
rb_big_cmp(bignum, LL2NUM(LLONG_MIN)) == INT2FIX(-1)
238+
#else
239+
rb_funcall(bignum, intern_cmp, 1, LL2NUM(LLONG_MIN)) == INT2FIX(-1)
234240
#endif
235241
) {
236242
goto overflow;
@@ -553,4 +559,7 @@ void init_mysql2_statement() {
553559
intern_year = rb_intern("year");
554560

555561
intern_to_s = rb_intern("to_s");
562+
#ifndef HAVE_RB_BIG_CMP
563+
id_cmp = rb_intern("cmp");
564+
#endif
556565
}

0 commit comments

Comments
 (0)