diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -343,18 +343,17 @@ PyObject* pysqlite_connection_close(pysq if (rc != SQLITE_OK) { _pysqlite_seterror(self->db, NULL); return NULL; } else { self->db = NULL; } } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* * Checks if a connection object is usable (i. e. not closed). * * 0 => error; 1 => ok */ int pysqlite_check_connection(pysqlite_Connection* con) @@ -852,18 +851,17 @@ PyObject* pysqlite_connection_create_fun if (rc != SQLITE_OK) { /* Workaround for SQLite bug: no error code or string is available here */ PyErr_SetString(pysqlite_OperationalError, "Error creating function"); return NULL; } else { if (PyDict_SetItem(self->function_pinboard, func, Py_None) == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) { PyObject* aggregate_class; int n_arg; @@ -884,18 +882,17 @@ PyObject* pysqlite_connection_create_agg if (rc != SQLITE_OK) { /* Workaround for SQLite bug: no error code or string is available here */ PyErr_SetString(pysqlite_OperationalError, "Error creating aggregate"); return NULL; } else { if (PyDict_SetItem(self->function_pinboard, aggregate_class, Py_None) == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source) { PyObject *ret; int rc; #ifdef WITH_THREAD @@ -1020,18 +1017,17 @@ static PyObject* pysqlite_connection_set if (rc != SQLITE_OK) { PyErr_SetString(pysqlite_OperationalError, "Error setting authorizer callback"); return NULL; } else { if (PyDict_SetItem(self->function_pinboard, authorizer_cb, Py_None) == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } static PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) { PyObject* progress_handler; int n; @@ -1050,18 +1046,17 @@ static PyObject* pysqlite_connection_set /* None clears the progress handler previously set */ sqlite3_progress_handler(self->db, 0, 0, (void*)0); } else { sqlite3_progress_handler(self->db, n, _progress_handler, progress_handler); if (PyDict_SetItem(self->function_pinboard, progress_handler, Py_None) == -1) return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject* pysqlite_connection_set_trace_callback(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) { PyObject* trace_callback; static char *kwlist[] = { "trace_callback", NULL }; @@ -1078,18 +1073,17 @@ static PyObject* pysqlite_connection_set /* None clears the trace callback previously set */ sqlite3_trace(self->db, 0, (void*)0); } else { if (PyDict_SetItem(self->function_pinboard, trace_callback, Py_None) == -1) return NULL; sqlite3_trace(self->db, _trace_callback, trace_callback); } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #ifdef HAVE_LOAD_EXTENSION static PyObject* pysqlite_enable_load_extension(pysqlite_Connection* self, PyObject* args) { int rc; int onoff; @@ -1102,18 +1096,17 @@ static PyObject* pysqlite_enable_load_ex } rc = sqlite3_enable_load_extension(self->db, onoff); if (rc != SQLITE_OK) { PyErr_SetString(pysqlite_OperationalError, "Error enabling load extension"); return NULL; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } static PyObject* pysqlite_load_extension(pysqlite_Connection* self, PyObject* args) { int rc; char* extension_name; char* errmsg; @@ -1126,18 +1119,17 @@ static PyObject* pysqlite_load_extension return NULL; } rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg); if (rc != 0) { PyErr_SetString(pysqlite_OperationalError, errmsg); return NULL; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } #endif int pysqlite_check_thread(pysqlite_Connection* self) { #ifdef WITH_THREAD if (self->check_same_thread) { diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -237,18 +237,17 @@ int pysqlite_build_row_cast_map(pysqlite return 0; } PyObject* _pysqlite_build_column_name(const char* colname) { const char* pos; if (!colname) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } for (pos = colname;; pos++) { if (*pos == 0 || *pos == '[') { if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) { pos--; } return PyUnicode_FromStringAndSize(colname, pos - colname); @@ -909,18 +908,17 @@ PyObject* pysqlite_cursor_iternext(pysql } PyObject* pysqlite_cursor_fetchone(pysqlite_Cursor* self, PyObject* args) { PyObject* row; row = pysqlite_cursor_iternext(self); if (!row && !PyErr_Occurred()) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return row; } PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args, PyObject* kwargs) { static char *kwlist[] = {"size", NULL, NULL}; @@ -991,35 +989,33 @@ PyObject* pysqlite_cursor_fetchall(pysql } else { return list; } } PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args) { /* don't care, return None */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args) { if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) { return NULL; } if (self->statement) { (void)pysqlite_statement_reset(self->statement); Py_CLEAR(self->statement); } self->closed = 1; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyMethodDef cursor_methods[] = { {"execute", (PyCFunction)pysqlite_cursor_execute, METH_VARARGS, PyDoc_STR("Executes a SQL statement.")}, {"executemany", (PyCFunction)pysqlite_cursor_executemany, METH_VARARGS, PyDoc_STR("Repeatedly executes a SQL statement.")}, {"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_VARARGS, diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -134,18 +134,17 @@ static PyObject* module_enable_shared_ca } rc = sqlite3_enable_shared_cache(do_enable); if (rc != SQLITE_OK) { PyErr_SetString(pysqlite_OperationalError, "Changing the shared_cache flag failed"); return NULL; } else { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } } PyDoc_STRVAR(module_enable_shared_cache_doc, "enable_shared_cache(do_enable)\n\ \n\ Enable or disable shared cache mode for the calling thread.\n\ Experimental/Non-standard."); @@ -167,18 +166,17 @@ static PyObject* module_register_adapter || type == &PyUnicode_Type || type == &PyByteArray_Type) { pysqlite_BaseTypeAdapted = 1; } rc = pysqlite_microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster); if (rc == -1) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(module_register_adapter_doc, "register_adapter(type, callable)\n\ \n\ Registers an adapter with pysqlite's adapter registry. Non-standard."); static PyObject* module_register_converter(PyObject* self, PyObject* args) @@ -216,18 +214,17 @@ PyDoc_STRVAR(module_register_converter_d Registers a converter with pysqlite. Non-standard."); static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args) { if (!PyArg_ParseTuple(args, "i", &_enable_callback_tracebacks)) { return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } PyDoc_STRVAR(enable_callback_tracebacks_doc, "enable_callback_tracebacks(flag)\n\ \n\ Enable or disable callback functions throwing errors to stderr."); static void converters_init(PyObject* dict)