Skip to content

Commit c1dd35c

Browse files
nyaxtjustincase
authored andcommitted
no gvl mysql_stmt_fetch
1 parent b12be74 commit c1dd35c

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

ext/mysql2/result.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ static void *nogvl_fetch_row(void *ptr) {
120120
return mysql_fetch_row(result);
121121
}
122122

123+
static void *nogvl_stmt_fetch(void *ptr) {
124+
MYSQL_STMT *stmt = ptr;
125+
uintptr_t r = mysql_stmt_fetch(stmt);
126+
127+
return (void *)r;
128+
}
129+
130+
123131
static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int symbolize_keys) {
124132
mysql2_result_wrapper * wrapper;
125133
VALUE rb_field;
@@ -324,8 +332,28 @@ static VALUE rb_mysql_result_stmt_fetch_row(VALUE self, ID db_timezone, ID app_t
324332
);
325333
}
326334

327-
if(mysql_stmt_fetch(wrapper->stmt)) {
328-
return Qnil;
335+
{
336+
int r = (int)rb_thread_call_without_gvl(nogvl_stmt_fetch, wrapper->stmt, RUBY_UBF_IO, 0);
337+
switch(r) {
338+
case 0:
339+
/* success */
340+
break;
341+
342+
case 1:
343+
/* error */
344+
rb_raise_mysql2_stmt_error2(wrapper->stmt
345+
#ifdef HAVE_RUBY_ENCODING_H
346+
, conn_enc
347+
#endif
348+
);
349+
350+
case MYSQL_NO_DATA:
351+
/* no more row */
352+
return Qnil;
353+
354+
case MYSQL_DATA_TRUNCATED:
355+
rb_raise(cMysql2Error, "IMPLBUG: caught MYSQL_DATA_TRUNCATED. should not come here as buffer_length is set to fields[i].max_length.");
356+
}
329357
}
330358

331359
for (i = 0; i < wrapper->numberOfFields; i++) {

0 commit comments

Comments
 (0)