@@ -186,10 +186,9 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
186
186
}
187
187
self -> check_same_thread = check_same_thread ;
188
188
189
- Py_XSETREF (self -> function_pinboard , PyDict_New ());
190
- if (!self -> function_pinboard ) {
191
- return -1 ;
192
- }
189
+ self -> function_pinboard_trace_callback = NULL ;
190
+ self -> function_pinboard_progress_handler = NULL ;
191
+ self -> function_pinboard_authorizer_cb = NULL ;
193
192
194
193
Py_XSETREF (self -> collations , PyDict_New ());
195
194
if (!self -> collations ) {
@@ -249,19 +248,18 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
249
248
250
249
/* Clean up if user has not called .close() explicitly. */
251
250
if (self -> db ) {
252
- Py_BEGIN_ALLOW_THREADS
253
251
SQLITE3_CLOSE (self -> db );
254
- Py_END_ALLOW_THREADS
255
252
}
256
253
257
254
Py_XDECREF (self -> isolation_level );
258
- Py_XDECREF (self -> function_pinboard );
255
+ Py_XDECREF (self -> function_pinboard_trace_callback );
256
+ Py_XDECREF (self -> function_pinboard_progress_handler );
257
+ Py_XDECREF (self -> function_pinboard_authorizer_cb );
259
258
Py_XDECREF (self -> row_factory );
260
259
Py_XDECREF (self -> text_factory );
261
260
Py_XDECREF (self -> collations );
262
261
Py_XDECREF (self -> statements );
263
262
Py_XDECREF (self -> cursors );
264
-
265
263
Py_TYPE (self )-> tp_free ((PyObject * )self );
266
264
}
267
265
@@ -342,9 +340,7 @@ PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
342
340
pysqlite_do_all_statements (self , ACTION_FINALIZE , 1 );
343
341
344
342
if (self -> db ) {
345
- Py_BEGIN_ALLOW_THREADS
346
343
rc = SQLITE3_CLOSE (self -> db );
347
- Py_END_ALLOW_THREADS
348
344
349
345
if (rc != SQLITE_OK ) {
350
346
_pysqlite_seterror (self -> db , NULL );
@@ -808,6 +804,11 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
808
804
Py_SETREF (self -> cursors , new_list );
809
805
}
810
806
807
+ static void _destructor (void * args )
808
+ {
809
+ Py_DECREF ((PyObject * )args );
810
+ }
811
+
811
812
PyObject * pysqlite_connection_create_function (pysqlite_Connection * self , PyObject * args , PyObject * kwargs )
812
813
{
813
814
static char * kwlist [] = {"name" , "narg" , "func" , "deterministic" , NULL };
@@ -843,17 +844,16 @@ PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObjec
843
844
flags |= SQLITE_DETERMINISTIC ;
844
845
#endif
845
846
}
846
- if (PyDict_SetItem (self -> function_pinboard , func , Py_None ) == -1 ) {
847
- return NULL ;
848
- }
849
- rc = sqlite3_create_function (self -> db ,
850
- name ,
851
- narg ,
852
- flags ,
853
- (void * )func ,
854
- _pysqlite_func_callback ,
855
- NULL ,
856
- NULL );
847
+ Py_INCREF (func );
848
+ rc = sqlite3_create_function_v2 (self -> db ,
849
+ name ,
850
+ narg ,
851
+ flags ,
852
+ (void * )func ,
853
+ _pysqlite_func_callback ,
854
+ NULL ,
855
+ NULL ,
856
+ & _destructor ); // will decref func
857
857
858
858
if (rc != SQLITE_OK ) {
859
859
/* Workaround for SQLite bug: no error code or string is available here */
@@ -880,11 +880,16 @@ PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObje
880
880
kwlist , & name , & n_arg , & aggregate_class )) {
881
881
return NULL ;
882
882
}
883
-
884
- if (PyDict_SetItem (self -> function_pinboard , aggregate_class , Py_None ) == -1 ) {
885
- return NULL ;
886
- }
887
- rc = sqlite3_create_function (self -> db , name , n_arg , SQLITE_UTF8 , (void * )aggregate_class , 0 , & _pysqlite_step_callback , & _pysqlite_final_callback );
883
+ Py_INCREF (aggregate_class );
884
+ rc = sqlite3_create_function_v2 (self -> db ,
885
+ name ,
886
+ n_arg ,
887
+ SQLITE_UTF8 ,
888
+ (void * )aggregate_class ,
889
+ 0 ,
890
+ & _pysqlite_step_callback ,
891
+ & _pysqlite_final_callback ,
892
+ & _destructor ); // will decref func
888
893
if (rc != SQLITE_OK ) {
889
894
/* Workaround for SQLite bug: no error code or string is available here */
890
895
PyErr_SetString (pysqlite_OperationalError , "Error creating aggregate" );
@@ -1003,13 +1008,14 @@ static PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, P
1003
1008
return NULL ;
1004
1009
}
1005
1010
1006
- if (PyDict_SetItem (self -> function_pinboard , authorizer_cb , Py_None ) == -1 ) {
1007
- return NULL ;
1008
- }
1009
1011
rc = sqlite3_set_authorizer (self -> db , _authorizer_callback , (void * )authorizer_cb );
1010
1012
if (rc != SQLITE_OK ) {
1011
1013
PyErr_SetString (pysqlite_OperationalError , "Error setting authorizer callback" );
1014
+ Py_XSETREF (self -> function_pinboard_authorizer_cb , NULL );
1012
1015
return NULL ;
1016
+ } else {
1017
+ Py_INCREF (authorizer_cb );
1018
+ Py_XSETREF (self -> function_pinboard_authorizer_cb , authorizer_cb );
1013
1019
}
1014
1020
Py_RETURN_NONE ;
1015
1021
}
@@ -1033,12 +1039,12 @@ static PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* s
1033
1039
if (progress_handler == Py_None ) {
1034
1040
/* None clears the progress handler previously set */
1035
1041
sqlite3_progress_handler (self -> db , 0 , 0 , (void * )0 );
1042
+ Py_XSETREF (self -> function_pinboard_progress_handler , NULL );
1036
1043
} else {
1037
- if (PyDict_SetItem (self -> function_pinboard , progress_handler , Py_None ) == -1 )
1038
- return NULL ;
1039
1044
sqlite3_progress_handler (self -> db , n , _progress_handler , progress_handler );
1045
+ Py_INCREF (progress_handler );
1046
+ Py_XSETREF (self -> function_pinboard_progress_handler , progress_handler );
1040
1047
}
1041
-
1042
1048
Py_RETURN_NONE ;
1043
1049
}
1044
1050
@@ -1060,10 +1066,11 @@ static PyObject* pysqlite_connection_set_trace_callback(pysqlite_Connection* sel
1060
1066
if (trace_callback == Py_None ) {
1061
1067
/* None clears the trace callback previously set */
1062
1068
sqlite3_trace (self -> db , 0 , (void * )0 );
1069
+ Py_XSETREF (self -> function_pinboard_trace_callback , NULL );
1063
1070
} else {
1064
- if (PyDict_SetItem (self -> function_pinboard , trace_callback , Py_None ) == -1 )
1065
- return NULL ;
1066
1071
sqlite3_trace (self -> db , _trace_callback , trace_callback );
1072
+ Py_INCREF (trace_callback );
1073
+ Py_XSETREF (self -> function_pinboard_trace_callback , trace_callback );
1067
1074
}
1068
1075
1069
1076
Py_RETURN_NONE ;
0 commit comments