@@ -187,10 +187,9 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
187
187
}
188
188
self -> check_same_thread = check_same_thread ;
189
189
190
- Py_XSETREF (self -> function_pinboard , PyDict_New ());
191
- if (!self -> function_pinboard ) {
192
- return -1 ;
193
- }
190
+ self -> function_pinboard_trace_callback = NULL ;
191
+ self -> function_pinboard_progress_handler = NULL ;
192
+ self -> function_pinboard_authorizer_cb = NULL ;
194
193
195
194
Py_XSETREF (self -> collations , PyDict_New ());
196
195
if (!self -> collations ) {
@@ -250,13 +249,13 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self)
250
249
251
250
/* Clean up if user has not called .close() explicitly. */
252
251
if (self -> db ) {
253
- Py_BEGIN_ALLOW_THREADS
254
252
SQLITE3_CLOSE (self -> db );
255
- Py_END_ALLOW_THREADS
256
253
}
257
254
258
255
Py_XDECREF (self -> isolation_level );
259
- Py_XDECREF (self -> function_pinboard );
256
+ Py_XDECREF (self -> function_pinboard_trace_callback );
257
+ Py_XDECREF (self -> function_pinboard_progress_handler );
258
+ Py_XDECREF (self -> function_pinboard_authorizer_cb );
260
259
Py_XDECREF (self -> row_factory );
261
260
Py_XDECREF (self -> text_factory );
262
261
Py_XDECREF (self -> collations );
@@ -343,9 +342,7 @@ PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
343
342
pysqlite_do_all_statements (self , ACTION_FINALIZE , 1 );
344
343
345
344
if (self -> db ) {
346
- Py_BEGIN_ALLOW_THREADS
347
345
rc = SQLITE3_CLOSE (self -> db );
348
- Py_END_ALLOW_THREADS
349
346
350
347
if (rc != SQLITE_OK ) {
351
348
_pysqlite_seterror (self -> db , NULL );
@@ -906,6 +903,12 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
906
903
Py_SETREF (self -> cursors , new_list );
907
904
}
908
905
906
+ static void _destructor (void * args )
907
+ {
908
+ Py_DECREF ((PyObject * )args );
909
+ }
910
+
911
+
909
912
PyObject * pysqlite_connection_create_function (pysqlite_Connection * self , PyObject * args , PyObject * kwargs )
910
913
{
911
914
static char * kwlist [] = {"name" , "narg" , "func" , "deterministic" , NULL };
@@ -941,17 +944,16 @@ PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObjec
941
944
flags |= SQLITE_DETERMINISTIC ;
942
945
#endif
943
946
}
944
- if (PyDict_SetItem (self -> function_pinboard , func , Py_None ) == -1 ) {
945
- return NULL ;
946
- }
947
- rc = sqlite3_create_function (self -> db ,
948
- name ,
949
- narg ,
950
- flags ,
951
- (void * )func ,
952
- _pysqlite_func_callback ,
953
- NULL ,
954
- NULL );
947
+ Py_INCREF (func );
948
+ rc = sqlite3_create_function_v2 (self -> db ,
949
+ name ,
950
+ narg ,
951
+ flags ,
952
+ (void * )func ,
953
+ _pysqlite_func_callback ,
954
+ NULL ,
955
+ NULL ,
956
+ & _destructor );
955
957
956
958
if (rc != SQLITE_OK ) {
957
959
/* Workaround for SQLite bug: no error code or string is available here */
@@ -979,10 +981,17 @@ PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObje
979
981
return NULL ;
980
982
}
981
983
982
- if (PyDict_SetItem (self -> function_pinboard , aggregate_class , Py_None ) == -1 ) {
983
- return NULL ;
984
- }
985
- rc = sqlite3_create_function (self -> db , name , n_arg , SQLITE_UTF8 , (void * )aggregate_class , 0 , & _pysqlite_step_callback , & _pysqlite_final_callback );
984
+ Py_INCREF (aggregate_class );
985
+ rc = sqlite3_create_function_v2 (self -> db ,
986
+ name ,
987
+ n_arg ,
988
+ SQLITE_UTF8 ,
989
+ (void * )aggregate_class ,
990
+ 0 ,
991
+ & _pysqlite_step_callback ,
992
+ & _pysqlite_final_callback ,
993
+ & _destructor );
994
+
986
995
if (rc != SQLITE_OK ) {
987
996
/* Workaround for SQLite bug: no error code or string is available here */
988
997
PyErr_SetString (pysqlite_OperationalError , "Error creating aggregate" );
@@ -1011,10 +1020,7 @@ PyObject* pysqlite_connection_create_window_function(pysqlite_Connection* self,
1011
1020
return NULL ;
1012
1021
}
1013
1022
1014
- if (PyDict_SetItem (self -> function_pinboard , window_function_class , Py_None ) == -1 ) {
1015
- return NULL ;
1016
- }
1017
-
1023
+ Py_INCREF (window_function_class );
1018
1024
rc = sqlite3_create_window_function (
1019
1025
self -> db ,
1020
1026
name ,
@@ -1025,7 +1031,7 @@ PyObject* pysqlite_connection_create_window_function(pysqlite_Connection* self,
1025
1031
& _pysqlite_final_callback ,
1026
1032
& _pysqlite_value_callback ,
1027
1033
& _pysqlite_inverse_callback ,
1028
- NULL );
1034
+ & _destructor );
1029
1035
1030
1036
if (rc != SQLITE_OK ) {
1031
1037
/* Workaround for SQLite bug: no error code or string is available here */
@@ -1147,13 +1153,14 @@ static PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, P
1147
1153
return NULL ;
1148
1154
}
1149
1155
1150
- if (PyDict_SetItem (self -> function_pinboard , authorizer_cb , Py_None ) == -1 ) {
1151
- return NULL ;
1152
- }
1153
1156
rc = sqlite3_set_authorizer (self -> db , _authorizer_callback , (void * )authorizer_cb );
1154
1157
if (rc != SQLITE_OK ) {
1155
1158
PyErr_SetString (pysqlite_OperationalError , "Error setting authorizer callback" );
1159
+ Py_XSETREF (self -> function_pinboard_authorizer_cb , NULL );
1156
1160
return NULL ;
1161
+ } else {
1162
+ Py_INCREF (authorizer_cb );
1163
+ Py_XSETREF (self -> function_pinboard_authorizer_cb , authorizer_cb );
1157
1164
}
1158
1165
Py_RETURN_NONE ;
1159
1166
}
@@ -1177,10 +1184,11 @@ static PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* s
1177
1184
if (progress_handler == Py_None ) {
1178
1185
/* None clears the progress handler previously set */
1179
1186
sqlite3_progress_handler (self -> db , 0 , 0 , (void * )0 );
1187
+ Py_XSETREF (self -> function_pinboard_progress_handler , NULL );
1180
1188
} else {
1181
- if (PyDict_SetItem (self -> function_pinboard , progress_handler , Py_None ) == -1 )
1182
- return NULL ;
1183
1189
sqlite3_progress_handler (self -> db , n , _progress_handler , progress_handler );
1190
+ Py_INCREF (progress_handler );
1191
+ Py_XSETREF (self -> function_pinboard_progress_handler , progress_handler );
1184
1192
}
1185
1193
1186
1194
Py_RETURN_NONE ;
@@ -1204,10 +1212,11 @@ static PyObject* pysqlite_connection_set_trace_callback(pysqlite_Connection* sel
1204
1212
if (trace_callback == Py_None ) {
1205
1213
/* None clears the trace callback previously set */
1206
1214
sqlite3_trace (self -> db , 0 , (void * )0 );
1215
+ Py_XSETREF (self -> function_pinboard_trace_callback , NULL );
1207
1216
} else {
1208
- if (PyDict_SetItem (self -> function_pinboard , trace_callback , Py_None ) == -1 )
1209
- return NULL ;
1210
1217
sqlite3_trace (self -> db , _trace_callback , trace_callback );
1218
+ Py_INCREF (trace_callback );
1219
+ Py_XSETREF (self -> function_pinboard_trace_callback , trace_callback );
1211
1220
}
1212
1221
1213
1222
Py_RETURN_NONE ;
0 commit comments