Skip to content

Use bool instead of my_bool which has been removed since MySQL 8.0.1 #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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) {
my_bool b = ( val == SSL_MODE_REQUIRED );
bool b = ( val == SSL_MODE_REQUIRED );
int result = mysql_options( wrapper->client, MYSQL_OPT_SSL_ENFORCE, &b );
return INT2NUM(result);

Expand Down Expand Up @@ -504,7 +504,7 @@ static VALUE do_send_query(void *args) {
*/
static void *nogvl_read_query_result(void *ptr) {
MYSQL * client = ptr;
my_bool res = mysql_read_query_result(client);
bool res = mysql_read_query_result(client);

return (void *)(res == 0 ? Qtrue : Qfalse);
}
Expand Down Expand Up @@ -827,7 +827,7 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
const void *retval = NULL;
unsigned int intval = 0;
const char * charval = NULL;
my_bool boolval;
bool boolval;

GET_CLIENT(self);

Expand Down
4 changes: 2 additions & 2 deletions ext/mysql2/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,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(my_bool));
wrapper->error = xcalloc(wrapper->numberOfFields, sizeof(my_bool));
wrapper->is_null = xcalloc(wrapper->numberOfFields, sizeof(bool));
wrapper->error = xcalloc(wrapper->numberOfFields, sizeof(bool));
wrapper->length = xcalloc(wrapper->numberOfFields, sizeof(unsigned long));

for (i = 0; i < wrapper->numberOfFields; i++) {
Expand Down
5 changes: 3 additions & 2 deletions ext/mysql2/result.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef MYSQL2_RESULT_H
#define MYSQL2_RESULT_H
#include <stdbool.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there platforms these days that don't have stdbool.h available?

I'll check my Solaris and Windows environments. Off the cuff I think this will be a safe change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Bug #85131 Remove my_bool

  • mysql.h now requires a C++ or C99 header to compile. (All supported platforms have C99 compilers, but some are C89 by default and need mode switches like --std=gnu99 or --std=c99.)

Then as long as it is one of the "supported platforms", C99 should be supported.

I'm not familiar with Windows or Solaris C Compiler but googled and found these links:

Supports these ISO C99 language features:
_Bool

B.2.73 -xc99[=o]
The -xc99 option controls compiler recognition of the implemented features from the C99
standard (ISO/IEC 9899:1999, Programming Language - C).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember reading at one point that Ruby wants extensions to compile with C89? Is that still true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I did not find the information if Ruby requires C extensions compiled with C89.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it! While it looks dated at this point, the assumptions are stated here: https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/Assumptions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also found that result.c is already using uintptr_t which is a C99 type from stdint.h but we've not included stdint.h ourselves, which is probably an error.


void init_mysql2_result(void);
VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_RES *r, VALUE statement);
Expand All @@ -21,8 +22,8 @@ typedef struct {
mysql_client_wrapper *client_wrapper;
/* statement result bind buffers */
MYSQL_BIND *result_buffers;
my_bool *is_null;
my_bool *error;
bool *is_null;
bool *error;
unsigned long *length;
} mysql2_result_wrapper;

Expand Down
2 changes: 1 addition & 1 deletion ext/mysql2/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ VALUE rb_mysql_stmt_new(VALUE rb_client, VALUE sql) {

// set STMT_ATTR_UPDATE_MAX_LENGTH attr
{
my_bool truth = 1;
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");
}
Expand Down