Visitar URL original
bpo-42064: Pass module state to `sqlite3` UDF callbacks by erlend-aasland · Pull Request #27456 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hold GIL when allocating/freeing context
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Jul 30, 2021
commit c5da5abb74e39cfd29438f3304e7441625cd209f
11 changes: 6 additions & 5 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,9 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
static callback_context *
create_callback_context(pysqlite_state *state, PyObject *obj)
{
PyGILState_STATE gstate = PyGILState_Ensure();
callback_context *ctx = PyMem_Malloc(sizeof(callback_context));
PyGILState_Release(gstate);
if (ctx != NULL) {
ctx->obj = Py_NewRef(obj);
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
ctx->state = state;
Expand All @@ -848,19 +850,18 @@ static void
free_callback_context(callback_context *ctx)
{
if (ctx != NULL) {
// This function may be called without the GIL held, so we need to
// ensure that we destroy 'ctx' with the GIL held.
PyGILState_STATE gstate = PyGILState_Ensure();
Py_DECREF(ctx->obj);
PyMem_Free(ctx);
PyGILState_Release(gstate);
}
}

static void _destructor(void* args)
{
// This function may be called without the GIL held, so we need to ensure
// that we destroy 'args' with the GIL
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
free_callback_context((callback_context *)args);
PyGILState_Release(gstate);
}

/*[clinic input]
Expand Down