get rid of double-pointer casting

This commit is contained in:
Brian Lopez 2010-10-13 15:17:35 -07:00
parent a17ba07c75
commit 0d1e9916bf

View File

@ -83,11 +83,11 @@ static VALUE rb_raise_mysql2_error(MYSQL *client) {
} }
static VALUE nogvl_init(void *ptr) { static VALUE nogvl_init(void *ptr) {
MYSQL **client = (MYSQL **)ptr; MYSQL *client;
/* may initialize embedded server and read /etc/services off disk */ /* may initialize embedded server and read /etc/services off disk */
*client = mysql_init(NULL); client = mysql_init((MYSQL *)ptr);
return *client ? Qtrue : Qfalse; return client ? Qtrue : Qfalse;
} }
static VALUE nogvl_connect(void *ptr) { static VALUE nogvl_connect(void *ptr) {
@ -132,6 +132,7 @@ static void rb_mysql_client_free(void * ptr) {
/* It's safe to call mysql_close() on an already closed connection. */ /* It's safe to call mysql_close() on an already closed connection. */
if (!wrapper->closed) { if (!wrapper->closed) {
mysql_close(wrapper->client); mysql_close(wrapper->client);
free(wrapper->client);
} }
xfree(ptr); xfree(ptr);
} }
@ -140,8 +141,8 @@ static VALUE nogvl_close(void * ptr) {
mysql_client_wrapper *wrapper = ptr; mysql_client_wrapper *wrapper = ptr;
if (!wrapper->closed) { if (!wrapper->closed) {
mysql_close(wrapper->client); mysql_close(wrapper->client);
wrapper->client->net.fd = -1;
wrapper->closed = 1; wrapper->closed = 1;
free(wrapper->client);
} }
return Qnil; return Qnil;
} }
@ -153,6 +154,7 @@ static VALUE allocate(VALUE klass) {
wrapper->encoding = Qnil; wrapper->encoding = Qnil;
wrapper->active = 0; wrapper->active = 0;
wrapper->closed = 0; wrapper->closed = 0;
wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
return obj; return obj;
} }
@ -510,7 +512,7 @@ static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE
static VALUE init_connection(VALUE self) { static VALUE init_connection(VALUE self) {
GET_CLIENT(self); GET_CLIENT(self);
if (rb_thread_blocking_region(nogvl_init, ((void *) &wrapper->client), RUBY_UBF_IO, 0) == Qfalse) { if (rb_thread_blocking_region(nogvl_init, wrapper->client, RUBY_UBF_IO, 0) == Qfalse) {
/* TODO: warning - not enough memory? */ /* TODO: warning - not enough memory? */
return rb_raise_mysql2_error(wrapper->client); return rb_raise_mysql2_error(wrapper->client);
} }