Skip to content

Commit a799b0b

Browse files
committed
Use a typedef my_bool to improve compatibility across MySQL versions
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.
1 parent 62b57ea commit a799b0b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ext/mysql2/extconf.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,17 @@ def add_ssl_defines(header)
105105
add_ssl_defines(mysql_h)
106106
have_struct_member('MYSQL', 'net.vio', mysql_h)
107107
have_struct_member('MYSQL', 'net.pvio', mysql_h)
108+
108109
# These constants are actually enums, so they cannot be detected by #ifdef in C code.
109110
have_const('MYSQL_ENABLE_CLEARTEXT_PLUGIN', mysql_h)
110111
have_const('SERVER_QUERY_NO_GOOD_INDEX_USED', mysql_h)
111112
have_const('SERVER_QUERY_NO_INDEX_USED', mysql_h)
112113
have_const('SERVER_QUERY_WAS_SLOW', mysql_h)
113114

115+
# my_bool is replaced by C99 bool in MySQL 8.0, but we want
116+
# to retain compatibility with the typedef in earlier MySQLs.
117+
have_type('my_bool', mysql_h)
118+
114119
# This is our wishlist. We use whichever flags work on the host.
115120
# -Wall and -Wextra are included by default.
116121
wishlist = [

ext/mysql2/mysql2_ext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ void Init_mysql2(void);
2828
#define RB_MYSQL_UNUSED
2929
#endif
3030

31+
/* MySQL 8.0 replaces my_bool with C99 bool. Earlier versions of MySQL had
32+
* a typedef to char. Gem users reported failures on big endian systems when
33+
* using C99 bool types with older MySQLs due to mismatched behavior. */
34+
#ifndef HAVE_TYPE_MY_BOOL
35+
#include <stdbool.h>
36+
typedef bool my_bool;
37+
#endif
38+
3139
#include <client.h>
3240
#include <statement.h>
3341
#include <result.h>

0 commit comments

Comments
 (0)