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
Show file tree
Hide file tree
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
Next Next commit
Add stubs for managing callback context
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Jul 29, 2021
commit bebc47ac07ac6e5798e2a648b2f0bcc1ae676710
20 changes: 20 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,26 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
Py_SETREF(self->cursors, new_list);
}

static callback_context *
create_callback_context(pysqlite_state *state, PyObject *obj)
{
callback_context *ctx = PyMem_Malloc(sizeof(callback_context));
if (ctx != NULL) {
ctx->obj = Py_NewRef(obj);
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
ctx->state = state;
}
return ctx;
}

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

static void _destructor(void* args)
{
// This function may be called without the GIL held, so we need to ensure
Expand Down
6 changes: 6 additions & 0 deletions Modules/_sqlite/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@

#include "sqlite3.h"

typedef struct _callback_context
{
PyObject *obj;
pysqlite_state *state;
} callback_context;

typedef struct
{
PyObject_HEAD
Expand Down