1919#include <stdarg.h>
2020#include <ctype.h>
2121#include "ruby.h"
22+ #include "ruby/thread.h"
2223#ifdef HAVE_VERSION_H
2324#include "version.h"
2425#endif
@@ -175,6 +176,14 @@ SQLExecute_wrapper(void *data)
175176 return SQLExecute (args -> StatementHandle );
176177}
177178
179+ void *
180+ SQLExecute_wrapper_with_gvl (void * data ) {
181+ // Call the original function
182+ VALUE result = SQLExecute_wrapper (data );
183+ // Cast the result to void* and return
184+ return (void * )result ;
185+ }
186+
178187void
179188SQLExecute_unblock (void * data )
180189{
@@ -189,6 +198,14 @@ SQLExecDirect_wrapper(void *data)
189198 return SQLExecDirect (args -> StatementHandle , args -> StatementText , args -> TextLength );
190199}
191200
201+ void *
202+ SQLExecDirect_wrapper_with_gvl (void * data ) {
203+ // Call the original function
204+ VALUE result = SQLExecDirect_wrapper (data );
205+ // Cast the result to void* and return
206+ return (void * )result ;
207+ }
208+
192209void
193210SQLExecDirect_unblock (void * data )
194211{
@@ -979,7 +996,7 @@ free_stmt(STMT *q)
979996static void
980997start_gc ()
981998{
982- rb_funcall (rb_mGC , IDstart , 0 , NULL );
999+ rb_funcall (rb_mGC , IDstart , 0 , 0 );
9831000}
9841001
9851002static void
@@ -1246,7 +1263,7 @@ tracesql(SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, SQLRETURN ret,
12461263 (long ) henv , (long ) hdbc , (long ) hstmt );
12471264 trace_sql_ret (ret );
12481265 }
1249-
1266+
12501267 return ret ;
12511268}
12521269#endif
@@ -1669,7 +1686,7 @@ conf_dsn(int argc, VALUE *argv, VALUE self, int op)
16691686 if (rb_obj_is_kind_of (attr , rb_cHash ) == Qtrue ) {
16701687 VALUE a , x ;
16711688
1672- a = rb_funcall (attr , IDkeys , 0 , NULL );
1689+ a = rb_funcall (attr , IDkeys , 0 , 0 );
16731690 while ((x = rb_ary_shift (a )) != Qnil ) {
16741691 VALUE v = rb_hash_aref (attr , x );
16751692
@@ -2131,7 +2148,7 @@ dbc_connect(int argc, VALUE *argv, VALUE self)
21312148#endif
21322149 rb_raise (Cerror , "%s" , msg );
21332150 }
2134-
2151+
21352152 {
21362153 SQLRETURN nRet ;
21372154
@@ -2144,7 +2161,7 @@ dbc_connect(int argc, VALUE *argv, VALUE self)
21442161 nRet = SQLSetConnectAttr (dbc , SQL_ATTR_LOGIN_TIMEOUT , (SQLPOINTER )nTimeout , SQL_IS_INTEGER );
21452162 if (!SQL_SUCCEEDED (nRet )) fprintf (stderr , "Failed to set timeout to %d: error %d\n" , nTimeout , nRet );
21462163 }
2147-
2164+
21482165 if (!succeeded (SQL_NULL_HENV , dbc , SQL_NULL_HSTMT ,
21492166 SQLConnect (dbc , (SQLTCHAR * ) sdsn , SQL_NTS ,
21502167 (SQLTCHAR * ) suser ,
@@ -2188,7 +2205,7 @@ dbc_drvconnect(VALUE self, VALUE drv)
21882205 VALUE d , a , x ;
21892206
21902207 d = rb_str_new2 ("" );
2191- a = rb_funcall (rb_iv_get (drv , "@attrs" ), IDkeys , 0 , NULL );
2208+ a = rb_funcall (rb_iv_get (drv , "@attrs" ), IDkeys , 0 , 0 );
21922209 while ((x = rb_ary_shift (a )) != Qnil ) {
21932210 VALUE v = rb_hash_aref (rb_iv_get (drv , "@attrs" ), x );
21942211
@@ -4798,16 +4815,16 @@ date_init(int argc, VALUE *argv, VALUE self)
47984815 if (argc > 1 ) {
47994816 rb_raise (rb_eArgError , "wrong # arguments" );
48004817 }
4801- d = rb_funcall (y , IDday , 0 , NULL );
4802- m = rb_funcall (y , IDmonth , 0 , NULL );
4803- y = rb_funcall (y , IDyear , 0 , NULL );
4818+ d = rb_funcall (y , IDday , 0 , 0 );
4819+ m = rb_funcall (y , IDmonth , 0 , 0 );
4820+ y = rb_funcall (y , IDyear , 0 , 0 );
48044821 } else if (rb_obj_is_kind_of (y , rb_cDate ) == Qtrue ) {
48054822 if (argc > 1 ) {
48064823 rb_raise (rb_eArgError , "wrong # arguments" );
48074824 }
4808- d = rb_funcall (y , IDmday , 0 , NULL );
4809- m = rb_funcall (y , IDmonth , 0 , NULL );
4810- y = rb_funcall (y , IDyear , 0 , NULL );
4825+ d = rb_funcall (y , IDmday , 0 , 0 );
4826+ m = rb_funcall (y , IDmonth , 0 , 0 );
4827+ y = rb_funcall (y , IDyear , 0 , 0 );
48114828 } else if ((argc == 1 ) && (rb_obj_is_kind_of (y , rb_cString ) == Qtrue )) {
48124829 if (date_load1 (self , y , 0 ) != Qnil ) {
48134830 return self ;
@@ -5033,9 +5050,9 @@ time_init(int argc, VALUE *argv, VALUE self)
50335050 if (argc > 1 ) {
50345051 rb_raise (rb_eArgError , "wrong # arguments" );
50355052 }
5036- s = rb_funcall (h , IDsec , 0 , NULL );
5037- m = rb_funcall (h , IDmin , 0 , NULL );
5038- h = rb_funcall (h , IDhour , 0 , NULL );
5053+ s = rb_funcall (h , IDsec , 0 , 0 );
5054+ m = rb_funcall (h , IDmin , 0 , 0 );
5055+ h = rb_funcall (h , IDhour , 0 , 0 );
50395056 } else if ((argc == 1 ) && (rb_obj_is_kind_of (h , rb_cString ) == Qtrue )) {
50405057 if (time_load1 (self , h , 0 ) != Qnil ) {
50415058 return self ;
@@ -5273,13 +5290,13 @@ timestamp_init(int argc, VALUE *argv, VALUE self)
52735290 if (argc > 1 ) {
52745291 rb_raise (rb_eArgError , "wrong # arguments" );
52755292 }
5276- f = rb_funcall (y , IDusec , 0 , NULL );
5277- ss = rb_funcall (y , IDsec , 0 , NULL );
5278- mm = rb_funcall (y , IDmin , 0 , NULL );
5279- hh = rb_funcall (y , IDhour , 0 , NULL );
5280- d = rb_funcall (y , IDday , 0 , NULL );
5281- m = rb_funcall (y , IDmonth , 0 , NULL );
5282- y = rb_funcall (y , IDyear , 0 , NULL );
5293+ f = rb_funcall (y , IDusec , 0 , 0 );
5294+ ss = rb_funcall (y , IDsec , 0 , 0 );
5295+ mm = rb_funcall (y , IDmin , 0 , 0 );
5296+ hh = rb_funcall (y , IDhour , 0 , 0 );
5297+ d = rb_funcall (y , IDday , 0 , 0 );
5298+ m = rb_funcall (y , IDmonth , 0 , 0 );
5299+ y = rb_funcall (y , IDyear , 0 , 0 );
52835300 f = INT2NUM (NUM2INT (f ) * 1000 );
52845301 } else if (rb_obj_is_kind_of (y , rb_cDate ) == Qtrue ) {
52855302 if (argc > 1 ) {
@@ -5289,9 +5306,9 @@ timestamp_init(int argc, VALUE *argv, VALUE self)
52895306 ss = INT2FIX (0 );
52905307 mm = INT2FIX (0 );
52915308 hh = INT2FIX (0 );
5292- d = rb_funcall (y , IDmday , 0 , NULL );
5293- m = rb_funcall (y , IDmonth , 0 , NULL );
5294- y = rb_funcall (y , IDyear , 0 , NULL );
5309+ d = rb_funcall (y , IDmday , 0 , 0 );
5310+ m = rb_funcall (y , IDmonth , 0 , 0 );
5311+ y = rb_funcall (y , IDyear , 0 , 0 );
52955312 } else if ((argc == 1 ) && (rb_obj_is_kind_of (y , rb_cString ) == Qtrue )) {
52965313 if (timestamp_load1 (self , y , 0 ) != Qnil ) {
52975314 return self ;
@@ -5766,13 +5783,13 @@ stmt_param_output_value(int argc, VALUE *argv, VALUE self)
57665783
57675784 time = (TIME_STRUCT * ) q -> paraminfo [vnum ].outbuf ;
57685785 frac = rb_float_new (0.0 );
5769- now = rb_funcall (rb_cTime , IDnow , 0 , NULL );
5786+ now = rb_funcall (rb_cTime , IDnow , 0 , 0 );
57705787 v = rb_funcall (rb_cTime ,
57715788 (q -> dbcp -> gmtime == Qtrue ) ? IDutc : IDlocal ,
57725789 7 ,
5773- rb_funcall (now , IDyear , 0 , NULL ),
5774- rb_funcall (now , IDmonth , 0 , NULL ),
5775- rb_funcall (now , IDday , 0 , NULL ),
5790+ rb_funcall (now , IDyear , 0 , 0 ),
5791+ rb_funcall (now , IDmonth , 0 , 0 ),
5792+ rb_funcall (now , IDday , 0 , 0 ),
57765793 INT2NUM (time -> hour ),
57775794 INT2NUM (time -> minute ),
57785795 INT2NUM (time -> second ),
@@ -6423,14 +6440,14 @@ do_fetch(STMT *q, int mode)
64236440
64246441 time = (TIME_STRUCT * ) valp ;
64256442 frac = rb_float_new (0.0 );
6426- now = rb_funcall (rb_cTime , IDnow , 0 , NULL );
6443+ now = rb_funcall (rb_cTime , IDnow , 0 , 0 );
64276444 v = rb_funcall (rb_cTime ,
64286445 (q -> dbcp -> gmtime == Qtrue ) ?
64296446 IDutc : IDlocal ,
64306447 7 ,
6431- rb_funcall (now , IDyear , 0 , NULL ),
6432- rb_funcall (now , IDmonth , 0 , NULL ),
6433- rb_funcall (now , IDday , 0 , NULL ),
6448+ rb_funcall (now , IDyear , 0 , 0 ),
6449+ rb_funcall (now , IDmonth , 0 , 0 ),
6450+ rb_funcall (now , IDday , 0 , 0 ),
64346451 INT2NUM (time -> hour ),
64356452 INT2NUM (time -> minute ),
64366453 INT2NUM (time -> second ),
@@ -7097,7 +7114,7 @@ stmt_prep_int(int argc, VALUE *argv, VALUE self, int mode)
70977114 args .StatementHandle = hstmt ;
70987115 args .StatementText = ssql ;
70997116 args .TextLength = SQL_NTS ;
7100- ret = (SQLRETURN )rb_thread_call_without_gvl (SQLExecDirect_wrapper , & args , SQLExecDirect_unblock , & args );
7117+ ret = (SQLRETURN )rb_thread_call_without_gvl (SQLExecDirect_wrapper_with_gvl , & args , SQLExecDirect_unblock , & args );
71017118
71027119 if (!succeeded_nodata (SQL_NULL_HENV , SQL_NULL_HDBC , hstmt , ret , & msg , "SQLExecDirect('%s')" , csql )) {
71037120 goto sqlerr ;
@@ -7289,9 +7306,9 @@ bind_one_param(int pnum, VALUE arg, STMT *q, char **msgp, int *outpp)
72897306 ctype = SQL_C_TIME ;
72907307 time = (TIME_STRUCT * ) valp ;
72917308 memset (time , 0 , sizeof (TIME_STRUCT ));
7292- time -> hour = rb_funcall (arg , IDhour , 0 , NULL );
7293- time -> minute = rb_funcall (arg , IDmin , 0 , NULL );
7294- time -> second = rb_funcall (arg , IDsec , 0 , NULL );
7309+ time -> hour = rb_funcall (arg , IDhour , 0 , 0 );
7310+ time -> minute = rb_funcall (arg , IDmin , 0 , 0 );
7311+ time -> second = rb_funcall (arg , IDsec , 0 , 0 );
72957312 rlen = 1 ;
72967313 vlen = sizeof (TIME_STRUCT );
72977314 } else if (q -> paraminfo [pnum ].type == SQL_DATE ) {
@@ -7300,9 +7317,9 @@ bind_one_param(int pnum, VALUE arg, STMT *q, char **msgp, int *outpp)
73007317 ctype = SQL_C_DATE ;
73017318 date = (DATE_STRUCT * ) valp ;
73027319 memset (date , 0 , sizeof (DATE_STRUCT ));
7303- date -> year = rb_funcall (arg , IDyear , 0 , NULL );
7304- date -> month = rb_funcall (arg , IDmonth , 0 , NULL );
7305- date -> day = rb_funcall (arg , IDday , 0 , NULL );
7320+ date -> year = rb_funcall (arg , IDyear , 0 , 0 );
7321+ date -> month = rb_funcall (arg , IDmonth , 0 , 0 );
7322+ date -> day = rb_funcall (arg , IDday , 0 , 0 );
73067323 rlen = 1 ;
73077324 vlen = sizeof (TIMESTAMP_STRUCT );
73087325 } else {
@@ -7311,16 +7328,16 @@ bind_one_param(int pnum, VALUE arg, STMT *q, char **msgp, int *outpp)
73117328 ctype = SQL_C_TIMESTAMP ;
73127329 ts = (TIMESTAMP_STRUCT * ) valp ;
73137330 memset (ts , 0 , sizeof (TIMESTAMP_STRUCT ));
7314- ts -> year = rb_funcall (arg , IDyear , 0 , NULL );
7315- ts -> month = rb_funcall (arg , IDmonth , 0 , NULL );
7316- ts -> day = rb_funcall (arg , IDday , 0 , NULL );
7317- ts -> hour = rb_funcall (arg , IDhour , 0 , NULL );
7318- ts -> minute = rb_funcall (arg , IDmin , 0 , NULL );
7319- ts -> second = rb_funcall (arg , IDsec , 0 , NULL );
7331+ ts -> year = rb_funcall (arg , IDyear , 0 , 0 );
7332+ ts -> month = rb_funcall (arg , IDmonth , 0 , 0 );
7333+ ts -> day = rb_funcall (arg , IDday , 0 , 0 );
7334+ ts -> hour = rb_funcall (arg , IDhour , 0 , 0 );
7335+ ts -> minute = rb_funcall (arg , IDmin , 0 , 0 );
7336+ ts -> second = rb_funcall (arg , IDsec , 0 , 0 );
73207337#ifdef TIME_USE_USEC
7321- ts -> fraction = rb_funcall (arg , IDusec , 0 , NULL ) * 1000 ;
7338+ ts -> fraction = rb_funcall (arg , IDusec , 0 , 0 ) * 1000 ;
73227339#else
7323- ts -> fraction = rb_funcall (arg , IDnsec , 0 , NULL );
7340+ ts -> fraction = rb_funcall (arg , IDnsec , 0 , 0 );
73247341#endif
73257342 rlen = 1 ;
73267343 vlen = sizeof (TIMESTAMP_STRUCT );
@@ -7333,9 +7350,9 @@ bind_one_param(int pnum, VALUE arg, STMT *q, char **msgp, int *outpp)
73337350 ctype = SQL_C_DATE ;
73347351 date = (DATE_STRUCT * ) valp ;
73357352 memset (date , 0 , sizeof (DATE_STRUCT ));
7336- date -> year = rb_funcall (arg , IDyear , 0 , NULL );
7337- date -> month = rb_funcall (arg , IDmonth , 0 , NULL );
7338- date -> day = rb_funcall (arg , IDmday , 0 , NULL );
7353+ date -> year = rb_funcall (arg , IDyear , 0 , 0 );
7354+ date -> month = rb_funcall (arg , IDmonth , 0 , 0 );
7355+ date -> day = rb_funcall (arg , IDmday , 0 , 0 );
73397356 rlen = 1 ;
73407357 vlen = sizeof (DATE_STRUCT );
73417358 break ;
@@ -7546,7 +7563,7 @@ stmt_exec_int(int argc, VALUE *argv, VALUE self, int mode)
75467563 }
75477564
75487565 args .StatementHandle = q -> hstmt ;
7549- ret = (SQLRETURN )rb_thread_call_without_gvl (SQLExecute_wrapper , & args , SQLExecute_unblock , & args );
7566+ ret = (SQLRETURN )rb_thread_call_without_gvl (SQLExecute_wrapper_with_gvl , & args , SQLExecute_unblock , & args );
75507567
75517568 if (!succeeded_nodata (SQL_NULL_HENV , SQL_NULL_HDBC , q -> hstmt , ret , & msg , "SQLExecute" )) {
75527569error :
@@ -7862,7 +7879,7 @@ mod_2time(int argc, VALUE *argv, VALUE self)
78627879 rb_raise (rb_eTypeError , "expecting ODBC::Date" );
78637880 }
78647881 } else {
7865- VALUE now = rb_funcall (rb_cTime , IDnow , 0 , NULL );
7882+ VALUE now = rb_funcall (rb_cTime , IDnow , 0 , 0 );
78667883
78677884 y = rb_funcall (rb_cTime , IDyear , 1 , now );
78687885 m = rb_funcall (rb_cTime , IDmonth , 1 , now );
0 commit comments