Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move _pysqlite_enable_callback_tracebacks to global state
  • Loading branch information
Erlend E. Aasland committed Jul 14, 2021
commit 8a3a681ca9f680fe01bd629fd0ffb2bd6c9ff21f
51 changes: 35 additions & 16 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,11 @@ _pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv
Py_DECREF(py_retval);
}
if (!ok) {
if (_pysqlite_enable_callback_tracebacks) {
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
}
else {
PyErr_Clear();
}
sqlite3_result_error(context, "user-defined function raised exception", -1);
Expand Down Expand Up @@ -669,9 +671,12 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_

if (PyErr_Occurred()) {
*aggregate_instance = 0;
if (_pysqlite_enable_callback_tracebacks) {

pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
}
else {
PyErr_Clear();
}
sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1);
Expand All @@ -693,9 +698,11 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_
Py_DECREF(args);

if (!function_result) {
if (_pysqlite_enable_callback_tracebacks) {
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
}
else {
PyErr_Clear();
}
sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1);
Expand Down Expand Up @@ -746,9 +753,11 @@ _pysqlite_final_callback(sqlite3_context *context)
Py_DECREF(function_result);
}
if (!ok) {
if (_pysqlite_enable_callback_tracebacks) {
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
}
else {
PyErr_Clear();
}
sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
Expand Down Expand Up @@ -941,21 +950,27 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);

if (ret == NULL) {
if (_pysqlite_enable_callback_tracebacks)
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
else
}
else {
PyErr_Clear();
}

rc = SQLITE_DENY;
}
else {
if (PyLong_Check(ret)) {
rc = _PyLong_AsInt(ret);
if (rc == -1 && PyErr_Occurred()) {
if (_pysqlite_enable_callback_tracebacks)
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
else
}
else {
PyErr_Clear();
}
rc = SQLITE_DENY;
}
}
Expand All @@ -979,9 +994,11 @@ static int _progress_handler(void* user_arg)
ret = _PyObject_CallNoArg((PyObject*)user_arg);

if (!ret) {
if (_pysqlite_enable_callback_tracebacks) {
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
}
else {
PyErr_Clear();
}

Expand Down Expand Up @@ -1030,9 +1047,11 @@ static void _trace_callback(void* user_arg, const char* statement_string)
if (ret) {
Py_DECREF(ret);
} else {
if (_pysqlite_enable_callback_tracebacks) {
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
}
else {
PyErr_Clear();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
static PyObject *
_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
{
pysqlite_state *state = pysqlite_get_state(NULL);
PyObject* parameters_list = NULL;
PyObject* parameters_iter = NULL;
PyObject* parameters = NULL;
Expand Down Expand Up @@ -584,7 +585,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
if (PyErr_Occurred()) {
/* there was an error that occurred in a user-defined callback */
if (_pysqlite_enable_callback_tracebacks) {
if (state->enable_callback_tracebacks) {
PyErr_Print();
} else {
PyErr_Clear();
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module _sqlite3
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/

/* static objects at module-level */
int _pysqlite_enable_callback_tracebacks = 0;
int pysqlite_BaseTypeAdapted = 0;

pysqlite_state pysqlite_global_state;
Expand Down Expand Up @@ -220,7 +219,8 @@ static PyObject *
pysqlite_enable_callback_trace_impl(PyObject *module, int enable)
/*[clinic end generated code: output=4ff1d051c698f194 input=cb79d3581eb77c40]*/
{
_pysqlite_enable_callback_tracebacks = enable;
pysqlite_state *state = pysqlite_get_state(module);
state->enable_callback_tracebacks = enable;

Py_RETURN_NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct {
*/
PyObject *converters;

int enable_callback_tracebacks;
PyObject *lru_cache;

PyTypeObject *ConnectionType;
Expand All @@ -64,7 +65,6 @@ pysqlite_get_state(PyObject *Py_UNUSED(module))
return &pysqlite_global_state;
}

extern int _pysqlite_enable_callback_tracebacks;
extern int pysqlite_BaseTypeAdapted;

#define PARSE_DECLTYPES 1
Expand Down