8000 bpo-42064: Pass module state to trace, progress, and authorizer callbacks by erlend-aasland · Pull Request #27940 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42064: Pass module state to trace, progress, and authorizer callbacks #27940

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 17 commits into from
Sep 7, 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
Next Next commit
Merge branch 'main' into sqlite-callback-state/part2
  • Loading branch information
Erlend E. Aasland committed Sep 7, 2021
commit d0a422b212f432e6d0f155138489c913d1bab163
30 changes: 14 additions & 16 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,10 @@ authorizer_callback(void *ctx, int action, const char *arg1,
PyObject *ret;
int rc = SQLITE_DENY;

callback_context *ctx = (callback_context *)user_arg;
assert(ctx != NULL);
ret = PyObject_CallFunction(ctx->callable, "issss", action, arg1, arg2,
dbname, access_attempt_source);
PyObject *callable = ((callback_context *)ctx)->callable;
ret = PyObject_CallFunction(callable, "issss", action, arg1, arg2, dbname,
access_attempt_source);

if (ret == NULL) {
print_or_clear_traceback(ctx);
Expand Down Expand Up @@ -996,8 +996,8 @@ progress_callback(void *ctx)
int rc;
PyObject *ret;

callback_context *ctx = (callback_context *)user_arg;
assert(ctx != NULL);
PyObject *callable = ((callback_context *)ctx)->callable;
ret = _PyObject_CallNoArg(ctx->callable);
if (!ret) {
/* abort query if error occurred */
Expand Down Expand Up @@ -1045,7 +1045,8 @@ trace_callback(void *ctx, const char *statement_string)
callback_context *ctx = (callback_context *)user_arg;
assert(ctx != NULL);
if (py_statement) {
ret = PyObject_CallOneArg(ctx->callable, py_statement);
PyObject *callable = ((callback_context *)ctx)->callable;
ret = PyObject_CallOneArg(callable, py_statement);
Py_DECREF(py_statement);
}

Expand Down Expand Up @@ -1085,12 +1086,11 @@ pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
SET_CALLBACK_CONTEXT(self->authorizer_ctx, NULL);
}
else {
callback_context *ctx = create_callback_context(self->state,
authorizer_cb);
callback_context *ctx = create_callback_context(self->state, callable);
if (ctx == NULL) {
return NULL;
}
rc = sqlite3_set_authorizer(self->db, _authorizer_callback, ctx);
rc = sqlite3_set_authorizer(self->db, authorizer_callback, ctx);
SET_CALLBACK_CONTEXT(self->authorizer_ctx, ctx);
}
if (rc != SQLITE_OK) {
Expand Down Expand Up @@ -1125,12 +1125,11 @@ pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
sqlite3_progress_handler(self->db, 0, 0, (void*)0);
SET_CALLBACK_CONTEXT(self->progress_ctx, NULL);
} else {
callback_context *ctx = create_callback_context(self->state,
progress_handler);
callback_context *ctx = create_callback_context(self->state, callable);
if (ctx == NULL) {
return NULL;
}
sqlite3_progress_handler(self->db, n, _progress_handler, ctx);
sqlite3_progress_handler(self->db, n, progress_handler, ctx);
SET_CALLBACK_CONTEXT(self->progress_ctx, ctx);
}
Py_RETURN_NONE;
Expand Down Expand Up @@ -1171,17 +1170,16 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
SET_CALLBACK_CONTEXT(self->trace_ctx, NULL);
}
else {
callback_context *ctx = create_callback_context(self->state,
trace_callback);
callback_context *ctx = create_callback_context(self->state, callable);
if (ctx == NULL) {
return NULL;
}
#ifdef HAVE_TRACE_V2
sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, _trace_callback, ctx);
sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, trace_callback, ctx);
#else
sqlite3_trace(self->db, _trace_callback, ctx);
sqlite3_trace(self->db, trace_callback, ctx);
#endif
SET_CALLBACK_CONTEXT(self->trace_ctx, ctx);
SET_CALLBACK_CONTEXT(self->trace_ctx, callable);
}

Py_RETURN_NONE;
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0