Skip to content

Commit

Permalink
Use a typedef my_bool to improve compatibility across MySQL versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sodabrew committed Mar 19, 2018
1 parent 62b57ea commit a799b0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/mysql2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
8 changes: 8 additions & 0 deletions ext/mysql2/mysql2_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdbool.h>
typedef bool my_bool;
#endif

#include <client.h>
#include <statement.h>
#include <result.h>
Expand Down

0 comments on commit a799b0b

Please sign in to comment.