@@ -124,8 +124,9 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
124124 self -> detect_types = detect_types ;
125125 self -> timeout = timeout ;
126126 (void )sqlite3_busy_timeout (self -> db , (int )(timeout * 1000 ));
127-
127+ #ifdef WITH_THREAD
128128 self -> thread_ident = PyThread_get_thread_ident ();
129+ #endif
129130 self -> check_same_thread = check_same_thread ;
130131
131132 self -> function_pinboard = PyDict_New ();
@@ -510,9 +511,11 @@ void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value**
510511 PyObject * py_func ;
511512 PyObject * py_retval = NULL ;
512513
514+ #ifdef WITH_THREAD
513515 PyGILState_STATE threadstate ;
514516
515517 threadstate = PyGILState_Ensure ();
518+ #endif
516519
517520 py_func = (PyObject * )sqlite3_user_data (context );
518521
@@ -534,7 +537,9 @@ void _pysqlite_func_callback(sqlite3_context* context, int argc, sqlite3_value**
534537 _sqlite3_result_error (context , "user-defined function raised exception" , -1 );
535538 }
536539
540+ #ifdef WITH_THREAD
537541 PyGILState_Release (threadstate );
542+ #endif
538543}
539544
540545static void _pysqlite_step_callback (sqlite3_context * context , int argc , sqlite3_value * * params )
@@ -545,9 +550,11 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_
545550 PyObject * * aggregate_instance ;
546551 PyObject * stepmethod = NULL ;
547552
553+ #ifdef WITH_THREAD
548554 PyGILState_STATE threadstate ;
549555
550556 threadstate = PyGILState_Ensure ();
557+ #endif
551558
552559 aggregate_class = (PyObject * )sqlite3_user_data (context );
553560
@@ -594,7 +601,9 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_
594601 Py_XDECREF (stepmethod );
595602 Py_XDECREF (function_result );
596603
604+ #ifdef WITH_THREAD
597605 PyGILState_Release (threadstate );
606+ #endif
598607}
599608
600609void _pysqlite_final_callback (sqlite3_context * context )
@@ -603,9 +612,11 @@ void _pysqlite_final_callback(sqlite3_context* context)
603612 PyObject * * aggregate_instance ;
604613 PyObject * aggregate_class ;
605614
615+ #ifdef WITH_THREAD
606616 PyGILState_STATE threadstate ;
607617
608618 threadstate = PyGILState_Ensure ();
619+ #endif
609620
610621 aggregate_class = (PyObject * )sqlite3_user_data (context );
611622
@@ -633,7 +644,9 @@ void _pysqlite_final_callback(sqlite3_context* context)
633644 Py_XDECREF (* aggregate_instance );
634645 Py_XDECREF (function_result );
635646
647+ #ifdef WITH_THREAD
636648 PyGILState_Release (threadstate );
649+ #endif
637650}
638651
639652void _pysqlite_drop_unused_statement_references (pysqlite_Connection * self )
@@ -728,9 +741,11 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
728741{
729742 PyObject * ret ;
730743 int rc ;
744+ #ifdef WITH_THREAD
731745 PyGILState_STATE gilstate ;
732746
733747 gilstate = PyGILState_Ensure ();
748+ #endif
734749 ret = PyObject_CallFunction ((PyObject * )user_arg , "issss" , action , arg1 , arg2 , dbname , access_attempt_source );
735750
736751 if (!ret ) {
@@ -750,17 +765,21 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
750765 Py_DECREF (ret );
751766 }
752767
768+ #ifdef WITH_THREAD
753769 PyGILState_Release (gilstate );
770+ #endif
754771 return rc ;
755772}
756773
757774static int _progress_handler (void * user_arg )
758775{
759776 int rc ;
760777 PyObject * ret ;
778+ #ifdef WITH_THREAD
761779 PyGILState_STATE gilstate ;
762780
763781 gilstate = PyGILState_Ensure ();
782+ #endif
764783 ret = PyObject_CallFunction ((PyObject * )user_arg , "" );
765784
766785 if (!ret ) {
@@ -777,7 +796,9 @@ static int _progress_handler(void* user_arg)
777796 Py_DECREF (ret );
778797 }
779798
799+ #ifdef WITH_THREAD
780800 PyGILState_Release (gilstate );
801+ #endif
781802 return rc ;
782803}
783804
@@ -832,6 +853,7 @@ PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, Py
832853
833854int pysqlite_check_thread (pysqlite_Connection * self )
834855{
856+ #ifdef WITH_THREAD
835857 if (self -> check_same_thread ) {
836858 if (PyThread_get_thread_ident () != self -> thread_ident ) {
837859 PyErr_Format (pysqlite_ProgrammingError ,
@@ -842,7 +864,7 @@ int pysqlite_check_thread(pysqlite_Connection* self)
842864 }
843865
844866 }
845-
867+ #endif
846868 return 1 ;
847869}
848870
@@ -1067,12 +1089,14 @@ pysqlite_collation_callback(
10671089 PyObject * callback = (PyObject * )context ;
10681090 PyObject * string1 = 0 ;
10691091 PyObject * string2 = 0 ;
1092+ #ifdef WITH_THREAD
10701093 PyGILState_STATE gilstate ;
1071-
1094+ #endif
10721095 PyObject * retval = NULL ;
10731096 int result = 0 ;
1074-
1097+ #ifdef WITH_THREAD
10751098 gilstate = PyGILState_Ensure ();
1099+ #endif
10761100
10771101 if (PyErr_Occurred ()) {
10781102 goto finally ;
@@ -1101,9 +1125,9 @@ pysqlite_collation_callback(
11011125 Py_XDECREF (string1 );
11021126 Py_XDECREF (string2 );
11031127 Py_XDECREF (retval );
1104-
1128+ #ifdef WITH_THREAD
11051129 PyGILState_Release (gilstate );
1106-
1130+ #endif
11071131 return result ;
11081132}
11091133
0 commit comments