Skip to content

Commit d42eb38

Browse files
author
Erlend E. Aasland
committed
Address review
- since _destructor is a callback, wrap it in GIL lock/unlock - remove GIL lock/unlock from create_callback_context()
1 parent 2a2152d commit d42eb38

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Modules/_sqlite/connection.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -781,34 +781,34 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
781781
static callback_context *
782782
create_callback_context(pysqlite_state *state, PyObject *callable)
783783
{
784-
PyGILState_STATE gstate = PyGILState_Ensure();
785784
callback_context *ctx = PyMem_Malloc(sizeof(callback_context));
786785
if (ctx != NULL) {
787786
ctx->callable = Py_NewRef(callable);
788787
ctx->state = state;
789788
}
790-
PyGILState_Release(gstate);
791789
return ctx;
792790
}
793791

794792
static void
795793
free_callback_context(callback_context *ctx)
794+
{
795+
assert(ctx != NULL);
796+
Py_DECREF(ctx->callable);
797+
PyMem_Free(ctx);
798+
}
799+
800+
static void
801+
_destructor(void *ctx)
796802
{
797803
if (ctx != NULL) {
798804
// This function may be called without the GIL held, so we need to
799805
// ensure that we destroy 'ctx' with the GIL held.
800806
PyGILState_STATE gstate = PyGILState_Ensure();
801-
Py_DECREF(ctx->callable);
802-
PyMem_Free(ctx);
807+
free_callback_context((callback_context *)ctx);
803808
PyGILState_Release(gstate);
804809
}
805810
}
806811

807-
static void _destructor(void* args)
808-
{
809-
free_callback_context((callback_context *)args);
810-
}
811-
812812
/*[clinic input]
813813
_sqlite3.Connection.create_function as pysqlite_connection_create_function
814814

0 commit comments

Comments
 (0)