]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93829: In sqlite3, replace Py_BuildValue with faster APIs (#93830)
authorErlend Egeberg Aasland <erlend.aasland@protonmail.com>
Wed, 15 Jun 2022 08:42:49 +0000 (10:42 +0200)
committerGitHub <noreply@github.com>
Wed, 15 Jun 2022 08:42:49 +0000 (10:42 +0200)
- In Modules/_sqlite/connection.c, use PyLong_FromLong
- In Modules/_sqlite/microprotocols.c, use PyTuple_Pack

Modules/_sqlite/connection.c
Modules/_sqlite/microprotocols.c

index 484af7a1771b06716360a5437b49e81112d54df3..f0e6a56b43a609a50299827ca6f80d07dcebc5ef 100644 (file)
@@ -1582,9 +1582,8 @@ static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self
 {
     if (!pysqlite_check_connection(self)) {
         return NULL;
-    } else {
-        return Py_BuildValue("i", sqlite3_total_changes(self->db));
     }
+    return PyLong_FromLong(sqlite3_total_changes(self->db));
 }
 
 static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused)
index a79f0067b17e8c3b8fb432f7bb0f8baeac075d5c..148220d0f91f96f7cb73b8aeeb8f12ae48eab7d9 100644 (file)
@@ -57,7 +57,7 @@ pysqlite_microprotocols_add(pysqlite_state *state, PyTypeObject *type,
 
     assert(type != NULL);
     assert(proto != NULL);
-    key = Py_BuildValue("(OO)", (PyObject*)type, proto);
+    key = PyTuple_Pack(2, (PyObject *)type, proto);
     if (!key) {
         return -1;
     }
@@ -81,7 +81,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
        way to get a quotable object to be its instance */
 
     /* look for an adapter in the registry */
-    key = Py_BuildValue("(OO)", (PyObject*)Py_TYPE(obj), proto);
+    key = PyTuple_Pack(2, (PyObject *)Py_TYPE(obj), proto);
     if (!key) {
         return NULL;
     }