Kaydet (Commit) ffff7631 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #18519: Fix test_sqlite on old versions of libsqlite3

With old SQLite versions, _sqlite3_result_error() sets a new Python exception,
so don't restore the previous exception.
üst 044c5168
...@@ -698,6 +698,7 @@ void _pysqlite_final_callback(sqlite3_context* context) ...@@ -698,6 +698,7 @@ void _pysqlite_final_callback(sqlite3_context* context)
_Py_IDENTIFIER(finalize); _Py_IDENTIFIER(finalize);
int ok; int ok;
PyObject *exception, *value, *tb; PyObject *exception, *value, *tb;
int restore;
#ifdef WITH_THREAD #ifdef WITH_THREAD
PyGILState_STATE threadstate; PyGILState_STATE threadstate;
...@@ -715,6 +716,7 @@ void _pysqlite_final_callback(sqlite3_context* context) ...@@ -715,6 +716,7 @@ void _pysqlite_final_callback(sqlite3_context* context)
/* Keep the exception (if any) of the last call to step() */ /* Keep the exception (if any) of the last call to step() */
PyErr_Fetch(&exception, &value, &tb); PyErr_Fetch(&exception, &value, &tb);
restore = 1;
function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, ""); function_result = _PyObject_CallMethodId(*aggregate_instance, &PyId_finalize, "");
...@@ -732,11 +734,18 @@ void _pysqlite_final_callback(sqlite3_context* context) ...@@ -732,11 +734,18 @@ void _pysqlite_final_callback(sqlite3_context* context)
PyErr_Clear(); PyErr_Clear();
} }
_sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1); _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
#if SQLITE_VERSION_NUMBER < 3003003
/* with old SQLite versions, _sqlite3_result_error() sets a new Python
exception, so don't restore the previous exception */
restore = 0;
#endif
} }
/* Restore the exception (if any) of the last call to step(), if (restore) {
but clear also the current exception if finalize() failed */ /* Restore the exception (if any) of the last call to step(),
PyErr_Restore(exception, value, tb); but clear also the current exception if finalize() failed */
PyErr_Restore(exception, value, tb);
}
error: error:
#ifdef WITH_THREAD #ifdef WITH_THREAD
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment