From 23106c0af77e0e5bdd8e44e784fb77c36d75f9b6 Mon Sep 17 00:00:00 2001 From: Jean byroot Boussier Date: Mon, 17 Jan 2022 22:15:14 +0100 Subject: [PATCH 1/3] Undefine T_DATA allocators for Ruby 3.2 compatibility (#1236) Ref: https://bugs.ruby-lang.org/issues/18007 Co-authored-by: Jean Boussier --- ext/mysql2/result.c | 1 + ext/mysql2/statement.c | 1 + spec/mysql2/result_spec.rb | 13 ++----------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ext/mysql2/result.c b/ext/mysql2/result.c index 5e03c90b..314cecda 100644 --- a/ext/mysql2/result.c +++ b/ext/mysql2/result.c @@ -1174,6 +1174,7 @@ void init_mysql2_result() { rb_global_variable(&cDateTime); cMysql2Result = rb_define_class_under(mMysql2, "Result", rb_cObject); + rb_undef_alloc_func(cMysql2Result); rb_global_variable(&cMysql2Result); rb_define_method(cMysql2Result, "each", rb_mysql_result_each, -1); diff --git a/ext/mysql2/statement.c b/ext/mysql2/statement.c index 137268af..b31efeb2 100644 --- a/ext/mysql2/statement.c +++ b/ext/mysql2/statement.c @@ -581,6 +581,7 @@ void init_mysql2_statement() { rb_global_variable(&cBigDecimal); cMysql2Statement = rb_define_class_under(mMysql2, "Statement", rb_cObject); + rb_undef_alloc_func(cMysql2Statement); rb_global_variable(&cMysql2Statement); rb_define_method(cMysql2Statement, "param_count", rb_mysql_stmt_param_count, 0); diff --git a/spec/mysql2/result_spec.rb b/spec/mysql2/result_spec.rb index 73fd6996..614cafc1 100644 --- a/spec/mysql2/result_spec.rb +++ b/spec/mysql2/result_spec.rb @@ -6,17 +6,8 @@ end it "should raise a TypeError exception when it doesn't wrap a result set" do - if RUBY_VERSION >= "3.1" - expect { Mysql2::Result.new }.to raise_error(TypeError) - expect { Mysql2::Result.allocate }.to raise_error(TypeError) - else - r = Mysql2::Result.new - expect { r.count }.to raise_error(TypeError) - expect { r.fields }.to raise_error(TypeError) - expect { r.field_types }.to raise_error(TypeError) - expect { r.size }.to raise_error(TypeError) - expect { r.each }.to raise_error(TypeError) - end + expect { Mysql2::Result.new }.to raise_error(TypeError) + expect { Mysql2::Result.allocate }.to raise_error(TypeError) end it "should have included Enumerable" do From 33ee746f5af293a58c060a057a6bf94e4deb2051 Mon Sep 17 00:00:00 2001 From: Jean byroot Boussier Date: Mon, 17 Jan 2022 22:15:33 +0100 Subject: [PATCH 2/3] Add Ruby 3.1 to the CI matrix (#1235) Co-authored-by: Jean Boussier --- .github/workflows/build.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f01c3f8..4c6d7514 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,35 +17,36 @@ jobs: - ubuntu-18.04 # bionic # - ubuntu-16.04 # xenial ruby: + - '3.1' - '3.0' - - 2.7 - - 2.6 - - 2.5 - - 2.4 - - 2.3 - - 2.2 - - 2.1 + - '2.7' + - '2.6' + - '2.5' + - '2.4' + - '2.3' + - '2.2' + - '2.1' db: [''] include: # Allow failure due to Mysql2::Error: Unknown system variable 'session_track_system_variables'. - - {os: ubuntu-16.04, ruby: 2.4, db: mariadb10.0, allow-failure: true} + - {os: ubuntu-16.04, ruby: '2.4', db: mariadb10.0, allow-failure: true} # Comment out due to ci/setup.sh stucking. # - {os: ubuntu-18.04, ruby: 2.4, db: mariadb10.1} # Allow failure due to the issue #965, #1165. - - {os: ubuntu-20.04, ruby: 2.4, db: mariadb10.3, allow-failure: true} - - {os: ubuntu-18.04, ruby: 2.4, db: mysql57} + - {os: ubuntu-20.04, ruby: '2.4', db: mariadb10.3, allow-failure: true} + - {os: ubuntu-18.04, ruby: '2.4', db: mysql57} # Allow failure due to the issue #1165. - - {os: ubuntu-20.04, ruby: 2.4, db: mysql80, allow-failure: true} + - {os: ubuntu-20.04, ruby: '2.4', db: mysql80, allow-failure: true} - {os: ubuntu-18.04, ruby: 'head', db: '', allow-failure: true} # db: A DB's brew package name in macOS case. # Set a name "db: 'name@X.Y'" when using an old version. # MariaDB lastet version # Allow failure due to the following test failures that rarely happens. # https://github.com/brianmario/mysql2/issues/1194 - - {os: macos-latest, ruby: 2.4, db: mariadb, allow-failure: true} + - {os: macos-latest, ruby: '2.4', db: mariadb, allow-failure: true} # MySQL latest version # Allow failure due to the issue #1165. - - {os: macos-latest, ruby: 2.4, db: mysql, allow-failure: true} + - {os: macos-latest, ruby: '2.4', db: mysql, allow-failure: true} # On the fail-fast: true, it cancels all in-progress jobs # if any matrix job fails unlike Travis fast_finish. fail-fast: false From 8193dc412c6a266045b9d13a9da36c16750939a4 Mon Sep 17 00:00:00 2001 From: akira yamada Date: Tue, 18 Jan 2022 06:49:36 +0900 Subject: [PATCH 3/3] Fix to build with MySQL 5.1 (#1197) --- ext/mysql2/client.c | 6 ++++++ ext/mysql2/extconf.rb | 1 + 2 files changed, 7 insertions(+) diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 04bf2cc8..5b699e92 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -935,10 +935,12 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) { retval = charval; break; +#ifdef HAVE_MYSQL_DEFAULT_AUTH case MYSQL_DEFAULT_AUTH: charval = (const char *)StringValueCStr(value); retval = charval; break; +#endif #ifdef HAVE_CONST_MYSQL_ENABLE_CLEARTEXT_PLUGIN case MYSQL_ENABLE_CLEARTEXT_PLUGIN: @@ -1404,7 +1406,11 @@ static VALUE set_init_command(VALUE self, VALUE value) { } static VALUE set_default_auth(VALUE self, VALUE value) { +#ifdef HAVE_MYSQL_DEFAULT_AUTH return _mysql_client_options(self, MYSQL_DEFAULT_AUTH, value); +#else + rb_raise(cMysql2Error, "pluggable authentication is not available, you may need a newer MySQL client library"); +#endif } static VALUE set_enable_cleartext_plugin(VALUE self, VALUE value) { diff --git a/ext/mysql2/extconf.rb b/ext/mysql2/extconf.rb index 2818a934..75fc8c0a 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -124,6 +124,7 @@ def add_ssl_defines(header) have_struct_member('MYSQL', 'net.pvio', mysql_h) # These constants are actually enums, so they cannot be detected by #ifdef in C code. +have_const('MYSQL_DEFAULT_AUTH', mysql_h) have_const('MYSQL_ENABLE_CLEARTEXT_PLUGIN', mysql_h) have_const('SERVER_QUERY_NO_GOOD_INDEX_USED', mysql_h) have_const('SERVER_QUERY_NO_INDEX_USED', mysql_h)