Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/mysql2/mysql2_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ void Init_mysql2(void);
#endif

#include <ruby/encoding.h>
// ruby/thread.h was added in 2.0.0. See:
// https://github.com/ruby/ruby/commit/c51a826
//
// Rubinius doesn't define this, but it ships an empty thread.h (the symbols we
// care about are in ruby.h); this is safe to remove when < 2.0.0 is no longer
// supported.
#ifdef HAVE_RUBY_THREAD_H
#include <ruby/thread.h>
#endif
Expand Down
9 changes: 5 additions & 4 deletions ext/mysql2/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ static int my_big2ll(VALUE bignum, LONG_LONG *ptr)
{
unsigned LONG_LONG num;
size_t len;
// rb_absint_size was added in 2.1.0. See:
// https://github.com/ruby/ruby/commit/9fea875
#ifdef HAVE_RB_ABSINT_SIZE
int nlz_bits = 0;
len = rb_absint_size(bignum, &nlz_bits);
Expand All @@ -220,16 +222,15 @@ static int my_big2ll(VALUE bignum, LONG_LONG *ptr)
#ifdef HAVE_RB_ABSINT_SIZE
nlz_bits == 0 &&
#endif
// rb_absint_singlebit_p was added in 2.1.0. See:
// https://github.com/ruby/ruby/commit/e5ff9d5
#if defined(HAVE_RB_ABSINT_SIZE) && defined(HAVE_RB_ABSINT_SINGLEBIT_P)
/* Optimized to avoid object allocation for Ruby 2.1+
* only -0x8000000000000000 is safe if `len == 8 && nlz_bits == 0`
*/
!rb_absint_singlebit_p(bignum)
#elif defined(HAVE_RB_BIG_CMP)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case should still be needed for Ruby 1.9 and 2.0.

@tamird tamird Nov 26, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misread that elif as ifdef. Derp.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, this is fixed up and green now.

rb_big_cmp(bignum, LL2NUM(LLONG_MIN)) == INT2FIX(-1)
#else
/* Ruby 1.8.7 and REE doesn't have rb_big_cmp */
rb_funcall(bignum, id_cmp, 1, LL2NUM(LLONG_MIN)) == INT2FIX(-1)
rb_big_cmp(bignum, LL2NUM(LLONG_MIN)) == INT2FIX(-1)
#endif
) {
goto overflow;
Expand Down
3 changes: 2 additions & 1 deletion ext/mysql2/wait_for_single_fd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* backwards compatibility for pre-1.9.3 C API
* backwards compatibility for Rubinius. See
* https://github.com/rubinius/rubinius/issues/3771.
*
* Ruby 1.9.3 provides this API which allows the use of ppoll() on Linux
* to minimize select() and malloc() overhead on high-numbered FDs.
Expand Down
1 change: 0 additions & 1 deletion spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ def run_gc
end

it "evented async queries should be supported" do
skip("ruby 1.8 doesn't support IO.for_fd options") if RUBY_VERSION.start_with?("1.8.")
# should immediately return nil
expect(@client.query("SELECT sleep(0.1)", :async => true)).to eql(nil)

Expand Down
16 changes: 4 additions & 12 deletions spec/mysql2/statement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,16 @@ def stmt_count
now = Time.now
statement = @client.prepare('SELECT ? AS a')
result = statement.execute(now)
if RUBY_VERSION =~ /1.8/
expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
else
# microseconds is six digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end
# microseconds is six digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end

it "should prepare DateTime values with microseconds" do
now = DateTime.now
statement = @client.prepare('SELECT ? AS a')
result = statement.execute(now)
if RUBY_VERSION =~ /1.8/
expect(result.first['a'].strftime('%F %T %z')).to eql(now.strftime('%F %T %z'))
else
# microseconds is six digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end
# microseconds is six digits after the decimal, but only test on 5 significant figures
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
end

it "should tell us about the fields" do
Expand Down