summaryrefslogtreecommitdiff
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-02-24 21:43:03 +0000
committerGitHub <noreply@github.com>2023-02-24 21:43:03 +0000
commit2db23d10bf64bf7c061fd95c6a8079ddc5c9aa4b (patch)
treeaa29d63d7151d976ea301f5fadff1821333690c9 /Modules/_sqlite
parent568fc0dee42a353f327b059a48f97c911de904b3 (diff)
downloadcpython-git-2db23d10bf64bf7c061fd95c6a8079ddc5c9aa4b.tar.gz
gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (in Modules/) (#102196)
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/connection.c14
-rw-r--r--Modules/_sqlite/cursor.c10
2 files changed, 10 insertions, 14 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 4c07d5e0b6..fb61ef82ef 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -908,7 +908,6 @@ final_callback(sqlite3_context *context)
PyObject* function_result;
PyObject** aggregate_instance;
int ok;
- PyObject *exception, *value, *tb;
aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, 0);
if (aggregate_instance == NULL) {
@@ -923,7 +922,7 @@ final_callback(sqlite3_context *context)
}
// Keep the exception (if any) of the last call to step, value, or inverse
- PyErr_Fetch(&exception, &value, &tb);
+ PyObject *exc = PyErr_GetRaisedException();
callback_context *ctx = (callback_context *)sqlite3_user_data(context);
assert(ctx != NULL);
@@ -938,7 +937,7 @@ final_callback(sqlite3_context *context)
}
if (!ok) {
int attr_err = PyErr_ExceptionMatches(PyExc_AttributeError);
- _PyErr_ChainExceptions(exception, value, tb);
+ _PyErr_ChainExceptions1(exc);
/* Note: contrary to the step, value, and inverse callbacks, SQLite
* does _not_, as of SQLite 3.38.0, propagate errors to sqlite3_step()
@@ -949,7 +948,7 @@ final_callback(sqlite3_context *context)
: "user-defined aggregate's 'finalize' method raised error");
}
else {
- PyErr_Restore(exception, value, tb);
+ PyErr_SetRaisedException(exc);
}
error:
@@ -2274,15 +2273,14 @@ pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
if (commit) {
/* Commit failed; try to rollback in order to unlock the database.
* If rollback also fails, chain the exceptions. */
- PyObject *exc, *val, *tb;
- PyErr_Fetch(&exc, &val, &tb);
+ PyObject *exc = PyErr_GetRaisedException();
result = pysqlite_connection_rollback_impl(self);
if (result == NULL) {
- _PyErr_ChainExceptions(exc, val, tb);
+ _PyErr_ChainExceptions1(exc);
}
else {
Py_DECREF(result);
- PyErr_Restore(exc, val, tb);
+ PyErr_SetRaisedException(exc);
}
}
return NULL;
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 6f7970cf81..caeedbddb8 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -705,11 +705,10 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
Py_DECREF(adapted);
if (rc != SQLITE_OK) {
- PyObject *exc, *val, *tb;
- PyErr_Fetch(&exc, &val, &tb);
+ PyObject *exc = PyErr_GetRaisedException();
sqlite3 *db = sqlite3_db_handle(self->st);
_pysqlite_seterror(state, db);
- _PyErr_ChainExceptions(exc, val, tb);
+ _PyErr_ChainExceptions1(exc);
return;
}
}
@@ -765,11 +764,10 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
Py_DECREF(adapted);
if (rc != SQLITE_OK) {
- PyObject *exc, *val, *tb;
- PyErr_Fetch(&exc, &val, &tb);
+ PyObject *exc = PyErr_GetRaisedException();
sqlite3 *db = sqlite3_db_handle(self->st);
_pysqlite_seterror(state, db);
- _PyErr_ChainExceptions(exc, val, tb);
+ _PyErr_ChainExceptions1(exc);
return;
}
}