diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-04-23 11:21:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 11:21:08 (GMT) |
commit | e9194ea6eaa18299d6ccbd3555ce150fab0c6184 (patch) | |
tree | ec024c749bd04630e19c2bfc421e6ca000862be8 /Modules | |
parent | 927b841c215a1ca36c9b3203eadc67ce05b1ed07 (diff) | |
download | cpython-e9194ea6eaa18299d6ccbd3555ce150fab0c6184.zip cpython-e9194ea6eaa18299d6ccbd3555ce150fab0c6184.tar.gz cpython-e9194ea6eaa18299d6ccbd3555ce150fab0c6184.tar.bz2 |
bpo-43852: Improve tuple creation in sqlite3 (GH-25421)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/connection.c | 3 | ||||
-rw-r--r-- | Modules/_sqlite/cursor.c | 25 |
2 files changed, 10 insertions, 18 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 9336549..150291c 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -592,8 +592,7 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, goto error; } - PyTuple_SetItem(args, i, cur_py_value); - + PyTuple_SET_ITEM(args, i, cur_py_value); } return args; diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 09c9a8c..60dfc7d 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -357,7 +357,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) if (!converted) { goto error; } - PyTuple_SetItem(row, i, converted); + PyTuple_SET_ITEM(row, i, converted); } if (PyErr_Occurred()) @@ -406,7 +406,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation PyObject* func_args; PyObject* result; int numcols; - PyObject* descriptor; PyObject* column_name; sqlite_int64 lastrowid; @@ -557,30 +556,24 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation goto error; } for (i = 0; i < numcols; i++) { - descriptor = PyTuple_New(7); - if (!descriptor) { - goto error; - } const char *colname; colname = sqlite3_column_name(self->statement->st, i); if (colname == NULL) { PyErr_NoMemory(); - Py_DECREF(descriptor); goto error; } column_name = _pysqlite_build_column_name(self, colname); if (column_name == NULL) { - Py_DECREF(descriptor); goto error; } - PyTuple_SetItem(descriptor, 0, column_name); - PyTuple_SetItem(descriptor, 1, Py_NewRef(Py_None)); - PyTuple_SetItem(descriptor, 2, Py_NewRef(Py_None)); - PyTuple_SetItem(descriptor, 3, Py_NewRef(Py_None)); - PyTuple_SetItem(descriptor, 4, Py_NewRef(Py_None)); - PyTuple_SetItem(descriptor, 5, Py_NewRef(Py_None)); - PyTuple_SetItem(descriptor, 6, Py_NewRef(Py_None)); - PyTuple_SetItem(self->description, i, descriptor); + PyObject *descriptor = PyTuple_Pack(7, column_name, + Py_None, Py_None, Py_None, + Py_None, Py_None, Py_None); + Py_DECREF(column_name); + if (descriptor == NULL) { + goto error; + } + PyTuple_SET_ITEM(self->description, i, descriptor); } } |