From 608c5c6d656aa4853bcecdb2a4771a7b5b769a0e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 28 Dec 2019 01:34:48 +0900 Subject: [PATCH] Made argument types strict for ruby 2.7 (#1096) As function pointer arguments are declared strictly in Ruby 2.7, `do_send_query` and `do_query` cause warnings. ``` cd tmp/x86_64-darwin19/mysql2/2.7.0 /opt/local/bin/gmake compiling ../../../../ext/mysql2/client.c ../../../../ext/mysql2/client.c:787:14: warning: incompatible pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-pointer-types] rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0); ^~~~~~~~~~~~~ /opt/local/include/ruby-2.7.0/ruby/ruby.h:1988:25: note: passing argument to parameter here VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...); ^ ../../../../ext/mysql2/client.c:795:16: warning: incompatible pointer types passing 'VALUE (void *)' (aka 'unsigned long (void *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-pointer-types] rb_rescue2(do_query, (VALUE)&async_args, disconnect_and_raise, self, rb_eException, (VALUE)0); ^~~~~~~~ /opt/local/include/ruby-2.7.0/ruby/ruby.h:1988:25: note: passing argument to parameter here VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...); ^ 2 warnings generated. ``` --- ext/mysql2/client.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 292657199..e97fb4f1d 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -509,10 +509,10 @@ static void *nogvl_send_query(void *ptr) { return (void*)(rv == 0 ? Qtrue : Qfalse); } -static VALUE do_send_query(void *args) { - struct nogvl_send_query_args *query_args = args; +static VALUE do_send_query(VALUE args) { + struct nogvl_send_query_args *query_args = (void *)args; mysql_client_wrapper *wrapper = query_args->wrapper; - if ((VALUE)rb_thread_call_without_gvl(nogvl_send_query, args, RUBY_UBF_IO, 0) == Qfalse) { + if ((VALUE)rb_thread_call_without_gvl(nogvl_send_query, query_args, RUBY_UBF_IO, 0) == Qfalse) { /* an error occurred, we're not active anymore */ wrapper->active_thread = Qnil; rb_raise_mysql2_error(wrapper); @@ -632,8 +632,8 @@ static VALUE disconnect_and_raise(VALUE self, VALUE error) { rb_exc_raise(error); } -static VALUE do_query(void *args) { - struct async_query_args *async_args = args; +static VALUE do_query(VALUE args) { + struct async_query_args *async_args = (void *)args; struct timeval tv; struct timeval *tvp; long int sec; @@ -793,7 +793,7 @@ static VALUE rb_mysql_query(VALUE self, VALUE sql, VALUE current) { return rb_ensure(rb_mysql_client_async_result, self, disconnect_and_mark_inactive, self); } #else - do_send_query(&args); + do_send_query((VALUE)&args); /* this will just block until the result is ready */ return rb_ensure(rb_mysql_client_async_result, self, disconnect_and_mark_inactive, self);