Skip to content

Commit a3f5500

Browse files
committed
Support Ruby 1.8.7 with rb_big_minus
1 parent c75617a commit a3f5500

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/mysql2/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def asplode(lib)
2323
have_func('rb_wait_for_single_fd')
2424
have_func('rb_hash_dup')
2525
have_func('rb_intern3')
26+
have_func('rb_big_cmp')
2627

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

ext/mysql2/statement.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,22 @@ static void set_buffer_for_string(MYSQL_BIND* bind_buffer, unsigned long *length
204204
xfree(length_buffers); \
205205
}
206206

207+
#ifndef HAVE_RB_BIG_CMP
208+
/* both x and y must be Bignum though MRI's rb_big_cmp support more types */
209+
static VALUE rb_big_cmp(VALUE x, VALUE y)
210+
{
211+
/* Ruby 1.8.7 has rb_big_minus */
212+
VALUE r = rb_big_minus(x, y);
213+
if (FIXNUM_P(r)) {
214+
long l = FIX2LONG(r);
215+
return l < 0 ? -1 : l == 0 ? 0 : 1;
216+
}
217+
else { /* must be normalized Bignum */
218+
return RBIGNUM_POSITIVE_P(r) ? 1 : -1;
219+
}
220+
}
221+
#endif
222+
207223
/* return 0 if the given bignum can cast as LONG_LONG, otherwise 1 */
208224
static int my_big2ll(VALUE bignum, LONG_LONG *ptr)
209225
{

0 commit comments

Comments
 (0)