summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2021-08-31 12:34:44 (GMT)
committerGitHub <noreply@github.com>2021-08-31 12:34:44 (GMT)
commit01dea5f12b31862999217c091399a318f23b460a (patch)
tree1b806b91599762b791936115b0852a5f17e813dc /Modules/_sqlite
parent001ef4600f5ab2e1d7825ddbc0f253377c234d7e (diff)
downloadcpython-01dea5f12b31862999217c091399a318f23b460a.zip
cpython-01dea5f12b31862999217c091399a318f23b460a.tar.gz
cpython-01dea5f12b31862999217c091399a318f23b460a.tar.bz2
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.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/connection.c19
-rw-r--r--Modules/_sqlite/cursor.c5
2 files changed, 14 insertions, 10 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 9ff5fba..864877c 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -59,19 +59,21 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
static PyObject *
new_statement_cache(pysqlite_Connection *self, int maxsize)
{
- PyObject *args[] = { PyLong_FromLong(maxsize), };
- if (args[0] == NULL) {
+ PyObject *args[] = { NULL, PyLong_FromLong(maxsize), };
+ if (args[1] == NULL) {
return NULL;
}
PyObject *lru_cache = self->state->lru_cache;
- PyObject *inner = PyObject_Vectorcall(lru_cache, args, 1, NULL);
- Py_DECREF(args[0]);
+ size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ PyObject *inner = PyObject_Vectorcall(lru_cache, args + 1, nargsf, NULL);
+ Py_DECREF(args[1]);
if (inner == NULL) {
return NULL;
}
- args[0] = (PyObject *)self; // Borrowed ref.
- PyObject *res = PyObject_Vectorcall(inner, args, 1, NULL);
+ args[1] = (PyObject *)self; // Borrowed ref.
+ nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ PyObject *res = PyObject_Vectorcall(inner, args + 1, nargsf, NULL);
Py_DECREF(inner);
return res;
}
@@ -1474,8 +1476,9 @@ pysqlite_collation_callback(
callback_context *ctx = (callback_context *)context;
assert(ctx != NULL);
- PyObject *args[] = { string1, string2 }; // Borrowed refs.
- retval = PyObject_Vectorcall(ctx->callable, args, 2, NULL);
+ PyObject *args[] = { NULL, string1, string2 }; // Borrowed refs.
+ size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ retval = PyObject_Vectorcall(ctx->callable, args + 1, nargsf, NULL);
if (retval == NULL) {
/* execution failed */
goto finally;
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 8b830ec..06ce385 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -462,9 +462,10 @@ error:
static PyObject *
get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
{
- PyObject *args[] = { operation, };
+ PyObject *args[] = { NULL, operation, }; // Borrowed ref.
PyObject *cache = self->connection->statement_cache;
- return PyObject_Vectorcall(cache, args, 1, NULL);
+ size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ return PyObject_Vectorcall(cache, args + 1, nargsf, NULL);
}
static PyObject *