Skip to content

gh-92206: Improve scoping of sqlite3 statement step helper #92207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 14 additions & 2 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,18 @@ get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
return PyObject_Vectorcall(cache, args + 1, nargsf, NULL);
}

static inline int
stmt_step(sqlite3_stmt *statement)
{
int rc;

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_step(statement);
Py_END_ALLOW_THREADS

return rc;
}

PyObject *
_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
{
Expand Down Expand Up @@ -570,7 +582,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
goto error;
}

rc = pysqlite_step(self->statement->st);
rc = stmt_step(self->statement->st);
if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
if (PyErr_Occurred()) {
/* there was an error that occurred in a user-defined callback */
Expand Down Expand Up @@ -799,7 +811,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
if (row == NULL) {
return NULL;
}
int rc = pysqlite_step(stmt);
int rc = stmt_step(stmt);
if (rc == SQLITE_DONE) {
(void)pysqlite_statement_reset(self->statement);
}
Expand Down
12 changes: 0 additions & 12 deletions Modules/_sqlite/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@
#include "module.h"
#include "connection.h"

int
pysqlite_step(sqlite3_stmt *statement)
{
int rc;

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_step(statement);
Py_END_ALLOW_THREADS

return rc;
}

// Returns non-NULL if a new exception should be raised
static PyObject *
get_exception_class(pysqlite_state *state, int errorcode)
Expand Down
2 changes: 0 additions & 2 deletions Modules/_sqlite/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include "sqlite3.h"
#include "connection.h"

int pysqlite_step(sqlite3_stmt *statement);

/**
* Checks the SQLite error code and sets the appropriate DB-API exception.
* Returns the error code (0 means no error occurred).
Expand Down