diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 47fbe8dc0..00b50fd46 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -114,7 +114,7 @@ static VALUE rb_set_ssl_mode_option(VALUE self, VALUE setting) { int val = NUM2INT( setting ); if (version >= 50703 && version < 50711) { if (val == SSL_MODE_DISABLED || val == SSL_MODE_REQUIRED) { - bool b = ( val == SSL_MODE_REQUIRED ); + my_bool b = ( val == SSL_MODE_REQUIRED ); int result = mysql_options( wrapper->client, MYSQL_OPT_SSL_ENFORCE, &b ); return INT2NUM(result); } else { @@ -526,7 +526,7 @@ static VALUE do_send_query(void *args) { */ static void *nogvl_read_query_result(void *ptr) { MYSQL * client = ptr; - bool res = mysql_read_query_result(client); + my_bool res = mysql_read_query_result(client); return (void *)(res == 0 ? Qtrue : Qfalse); } @@ -846,7 +846,7 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) { const void *retval = NULL; unsigned int intval = 0; const char * charval = NULL; - bool boolval; + my_bool boolval; GET_CLIENT(self); diff --git a/ext/mysql2/extconf.rb b/ext/mysql2/extconf.rb index 8755cb091..05535a449 100644 --- a/ext/mysql2/extconf.rb +++ b/ext/mysql2/extconf.rb @@ -105,12 +105,17 @@ def add_ssl_defines(header) add_ssl_defines(mysql_h) have_struct_member('MYSQL', 'net.vio', mysql_h) 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_ENABLE_CLEARTEXT_PLUGIN', mysql_h) have_const('SERVER_QUERY_NO_GOOD_INDEX_USED', mysql_h) have_const('SERVER_QUERY_NO_INDEX_USED', mysql_h) have_const('SERVER_QUERY_WAS_SLOW', mysql_h) +# my_bool is replaced by C99 bool in MySQL 8.0, but we want +# to retain compatibility with the typedef in earlier MySQLs. +have_type('my_bool', mysql_h) + # This is our wishlist. We use whichever flags work on the host. # -Wall and -Wextra are included by default. wishlist = [ diff --git a/ext/mysql2/mysql2_ext.h b/ext/mysql2/mysql2_ext.h index f76ea45ec..e1ce0e943 100644 --- a/ext/mysql2/mysql2_ext.h +++ b/ext/mysql2/mysql2_ext.h @@ -28,6 +28,14 @@ void Init_mysql2(void); #define RB_MYSQL_UNUSED #endif +/* MySQL 8.0 replaces my_bool with C99 bool. Earlier versions of MySQL had + * a typedef to char. Gem users reported failures on big endian systems when + * using C99 bool types with older MySQLs due to mismatched behavior. */ +#ifndef HAVE_TYPE_MY_BOOL +#include +typedef bool my_bool; +#endif + #include #include #include diff --git a/ext/mysql2/result.c b/ext/mysql2/result.c index 857de908e..a4957ee42 100644 --- a/ext/mysql2/result.c +++ b/ext/mysql2/result.c @@ -218,8 +218,8 @@ static void rb_mysql_result_alloc_result_buffers(VALUE self, MYSQL_FIELD *fields if (wrapper->result_buffers != NULL) return; wrapper->result_buffers = xcalloc(wrapper->numberOfFields, sizeof(MYSQL_BIND)); - wrapper->is_null = xcalloc(wrapper->numberOfFields, sizeof(bool)); - wrapper->error = xcalloc(wrapper->numberOfFields, sizeof(bool)); + wrapper->is_null = xcalloc(wrapper->numberOfFields, sizeof(my_bool)); + wrapper->error = xcalloc(wrapper->numberOfFields, sizeof(my_bool)); wrapper->length = xcalloc(wrapper->numberOfFields, sizeof(unsigned long)); for (i = 0; i < wrapper->numberOfFields; i++) { diff --git a/ext/mysql2/result.h b/ext/mysql2/result.h index 525a2188b..0c25b24b6 100644 --- a/ext/mysql2/result.h +++ b/ext/mysql2/result.h @@ -1,6 +1,5 @@ #ifndef MYSQL2_RESULT_H #define MYSQL2_RESULT_H -#include void init_mysql2_result(void); VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_RES *r, VALUE statement); @@ -22,8 +21,8 @@ typedef struct { mysql_client_wrapper *client_wrapper; /* statement result bind buffers */ MYSQL_BIND *result_buffers; - bool *is_null; - bool *error; + my_bool *is_null; + my_bool *error; unsigned long *length; } mysql2_result_wrapper; diff --git a/ext/mysql2/statement.c b/ext/mysql2/statement.c index 3bfba62d5..fdd3699cd 100644 --- a/ext/mysql2/statement.c +++ b/ext/mysql2/statement.c @@ -115,7 +115,7 @@ VALUE rb_mysql_stmt_new(VALUE rb_client, VALUE sql) { // set STMT_ATTR_UPDATE_MAX_LENGTH attr { - bool truth = 1; + my_bool truth = 1; if (mysql_stmt_attr_set(stmt_wrapper->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &truth)) { rb_raise(cMysql2Error, "Unable to initialize prepared statement: set STMT_ATTR_UPDATE_MAX_LENGTH"); }