10000 bpo-44991: Make GIL handling more explicit in `sqlite3` callbacks by erlend-aasland · Pull Request #27934 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44991: Make GIL handling more explicit in sqlite3 callbacks #27934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2021
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
Address review
- since _destructor is a callback, wrap it in GIL lock/unlock
- remove GIL lock/unlock from create_callback_context()
  • Loading branch information
Erlend E. Aasland committed Aug 31, 2021
commit d42eb38fa8935145c3562570acf3481a64b1b616
18 changes: 9 additions & 9 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,34 +781,34 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
static callback_context *
create_callback_context(pysqlite_state *state, PyObject *callable)
{
PyGILState_STATE gstate = PyGILState_Ensure();
callback_context *ctx = PyMem_Malloc(sizeof(callback_context));
if (ctx != NULL) {
ctx->callable = Py_NewRef(callable);
ctx->state = state;
}
PyGILState_Release(gstate);
return ctx;
}

static void
free_callback_context(callback_context *ctx)
{
assert(ctx != NULL);
Py_DECREF(ctx->callable);
PyMem_Free(ctx);
}

static void
_destructor(void *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->callable);
PyMem_Free(ctx);
free_callback_context((callback_context *)ctx);
PyGILState_Release(gstate);
}
}

static void _destructor(void* args)
{
free_callback_context((callback_context *)args);
}

/*[clinic input]
_sqlite3.Connection.create_function as pysqlite_connection_create_function

Expand Down
0