Skip to content

Commit 01dea5f

Browse files
authored
bpo-42064: Offset arguments for PyObject_Vectorcall in the _sqlite module (GH-27931)
This allows e.g. methods to be called efficiently by providing space for a "self" argument; see PY_VECTORCALL_ARGUMENTS_OFFSET docs.
1 parent 001ef46 commit 01dea5f

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Modules/_sqlite/connection.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,21 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
5959
static PyObject *
6060
new_statement_cache(pysqlite_Connection *self, int maxsize)
6161
{
62-
PyObject *args[] = { PyLong_FromLong(maxsize), };
63-
if (args[0] == NULL) {
62+
PyObject *args[] = { NULL, PyLong_FromLong(maxsize), };
63+
if (args[1] == NULL) {
6464
return NULL;
6565
}
6666
PyObject *lru_cache = self->state->lru_cache;
67-
PyObject *inner = PyObject_Vectorcall(lru_cache, args, 1, NULL);
68-
Py_DECREF(args[0]);
67+
size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
68+
PyObject *inner = PyObject_Vectorcall(lru_cache, args + 1, nargsf, NULL);
69+
Py_DECREF(args[1]);
6970
if (inner == NULL) {
7071
return NULL;
7172
}
7273

73-
args[0] = (PyObject *)self; // Borrowed ref.
74-
PyObject *res = PyObject_Vectorcall(inner, args, 1, NULL);
74+
args[1] = (PyObject *)self; // Borrowed ref.
75+
nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
76+
PyObject *res = PyObject_Vectorcall(inner, args + 1, nargsf, NULL);
7577
Py_DECREF(inner);
7678
return res;
7779
}
@@ -1474,8 +1476,9 @@ pysqlite_collation_callback(
14741476

14751477
callback_context *ctx = (callback_context *)context;
14761478
assert(ctx != NULL);
1477-
PyObject *args[] = { string1, string2 }; // Borrowed refs.
1478-
retval = PyObject_Vectorcall(ctx->callable, args, 2, NULL);
1479+
PyObject *args[] = { NULL, string1, string2 }; // Borrowed refs.
1480+
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
1481+
retval = PyObject_Vectorcall(ctx->callable, args + 1, nargsf, NULL);
14791482
if (retval == NULL) {
14801483
/* execution failed */
14811484
goto finally;

Modules/_sqlite/cursor.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,10 @@ begin_transaction(pysqlite_Connection *self)
462462
static PyObject *
463463
get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
464464
{
465-
PyObject *args[] = { operation, };
465+
PyObject *args[] = { NULL, operation, }; // Borrowed ref.
466466
PyObject *cache = self->connection->statement_cache;
467-
return PyObject_Vectorcall(cache, args, 1, NULL);
467+
size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
468+
return PyObject_Vectorcall(cache, args + 1, nargsf, NULL);
468469
}
469470

470471
static PyObject *

0 commit comments

Comments
 (0)