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
Merge branch 'main' into sqlite-callback-state/part2
  • Loading branch information
Erlend E. Aasland committed Aug 31, 2021
commit 943ad790180e0ed5a9cf27ab93853bb5195dacfc
21 changes: 8 additions & 13 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ new_statement_cache(pysqlite_Connection *self, int maxsize)
do { \
callback_context *tmp = ctx_ptr; \
ctx_ptr = ctx; \
free_callback_context(tmp); \
if (tmp) { \
free_callback_context(tmp); \
} \
} while (0)

/*[clinic input]
Expand Down Expand Up @@ -281,9 +283,9 @@ connection_close(pysqlite_Connection *self)
static void
free_callback_contexts(pysqlite_Connection *self)
{
free_callback_context(self->trace_ctx);
free_callback_context(self->progress_ctx);
free_callback_context(self->authorizer_ctx);
SET_CALLBACK_CONTEXT(self->trace_ctx, NULL);
SET_CALLBACK_CONTEXT(self->progress_ctx, NULL);
SET_CALLBACK_CONTEXT(self->authorizer_ctx, NULL);
}

static void
Expand Down Expand Up @@ -833,7 +835,7 @@ static void
free_callback_context(callback_context *ctx)
{
assert(ctx != NULL);
Py_DECREF(ctx->callable);
Py_XDECREF(ctx->callable);
PyMem_Free(ctx);
}

Expand All @@ -844,8 +846,7 @@ _destructor(void *ctx)
// 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_XDECREF(ctx->callable);
PyMem_Free(ctx);
free_callback_context((callback_context *)ctx);
PyGILState_Release(gstate);
}
}
Expand Down Expand Up @@ -987,14 +988,10 @@ static int _progress_handler(void* user_arg)

int rc;
PyObject *ret;
PyGILState_STATE gilstate;

gilstate = PyGILState_Ensure();

callback_context *ctx = (callback_context *)user_arg;
assert(ctx != NULL);
ret = _PyObject_CallNoArg(ctx->callable);

if (!ret) {
/* abort query if error occurred */
rc = -1;
Expand Down Expand Up @@ -1180,8 +1177,6 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
Py_RETURN_NONE;
}

#undef SET_CALLBACK_CONTEXT

#ifndef SQLITE_OMIT_LOAD_EXTENSION
/*[clinic input]
_sqlite3.Connection.enable_load_extension as pysqlite_connection_enable_load_extension
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.