From 81edfda1f59704ed8b910a2dc387a13e51a86ed9 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 11 Jan 2021 21:53:51 +0100 Subject: [PATCH 1/8] Fix scope and normalise argument spec --- Modules/_sqlite/cache.c | 21 ++++--- Modules/_sqlite/connection.c | 89 ++++++++++++++++++++---------- Modules/_sqlite/cursor.c | 21 ++++--- Modules/_sqlite/microprotocols.c | 6 +- Modules/_sqlite/module.c | 13 +++-- Modules/_sqlite/prepare_protocol.c | 10 +++- Modules/_sqlite/row.c | 20 ++++--- Modules/_sqlite/statement.c | 33 +++++++---- Modules/_sqlite/util.c | 10 ++-- 9 files changed, 146 insertions(+), 77 deletions(-) diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c index 078a484b86cee6..e9e04f5eca1710 100644 --- a/Modules/_sqlite/cache.c +++ b/Modules/_sqlite/cache.c @@ -25,7 +25,8 @@ #include /* only used internally */ -pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data) +static pysqlite_Node * +pysqlite_new_node(PyObject *key, PyObject *data) { pysqlite_Node* node; @@ -43,7 +44,8 @@ pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data) return node; } -void pysqlite_node_dealloc(pysqlite_Node* self) +static void +pysqlite_node_dealloc(pysqlite_Node *self) { PyTypeObject *tp = Py_TYPE(self); @@ -54,7 +56,8 @@ void pysqlite_node_dealloc(pysqlite_Node* self) Py_DECREF(tp); } -int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs) +static int +pysqlite_cache_init(pysqlite_Cache *self, PyObject *args, PyObject *kwargs) { PyObject* factory; int size = 10; @@ -85,7 +88,8 @@ int pysqlite_cache_init(pysqlite_Cache* self, PyObject* args, PyObject* kwargs) return 0; } -void pysqlite_cache_dealloc(pysqlite_Cache* self) +static void +pysqlite_cache_dealloc(pysqlite_Cache *self) { PyTypeObject *tp = Py_TYPE(self); pysqlite_Node* node; @@ -113,7 +117,8 @@ void pysqlite_cache_dealloc(pysqlite_Cache* self) Py_DECREF(tp); } -PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key) +extern PyObject * +pysqlite_cache_get(pysqlite_Cache *self, PyObject *key) { pysqlite_Node* node; pysqlite_Node* ptr; @@ -217,7 +222,8 @@ PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key) return Py_NewRef(node->data); } -PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args) +static PyObject * +pysqlite_cache_display(pysqlite_Cache *self, PyObject *args) { pysqlite_Node* ptr; PyObject* prevkey; @@ -291,7 +297,8 @@ static PyType_Spec cache_spec = { }; PyTypeObject *pysqlite_CacheType = NULL; -extern int pysqlite_cache_setup_types(PyObject *mod) +extern int +pysqlite_cache_setup_types(PyObject *mod) { pysqlite_NodeType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &node_spec, NULL); if (pysqlite_NodeType == NULL) { diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 81f12e83c2fe11..1ce9d85f526467 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -57,8 +57,9 @@ static const char * const begin_statements[] = { static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored)); static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self); - -int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) +static int +pysqlite_connection_init(pysqlite_Connection *self, PyObject *args, + PyObject *kwargs) { static char *kwlist[] = { "database", "timeout", "detect_types", "isolation_level", @@ -193,7 +194,9 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject } /* action in (ACTION_RESET, ACTION_FINALIZE) */ -void pysqlite_do_all_statements(pysqlite_Connection* self, int action, int reset_cursors) +static void +pysqlite_do_all_statements(pysqlite_Connection *self, int action, + int reset_cursors) { int i; PyObject* weakref; @@ -225,7 +228,8 @@ void pysqlite_do_all_statements(pysqlite_Connection* self, int action, int reset } } -void pysqlite_connection_dealloc(pysqlite_Connection* self) +static void +pysqlite_connection_dealloc(pysqlite_Connection *self) { PyTypeObject *tp = Py_TYPE(self); @@ -255,7 +259,9 @@ void pysqlite_connection_dealloc(pysqlite_Connection* self) * * 0 => error; 1 => ok */ -int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor) +extern int +pysqlite_connection_register_cursor(pysqlite_Connection *connection, + PyObject *cursor) { PyObject* weakref; @@ -356,7 +362,8 @@ pysqlite_connection_close_impl(pysqlite_Connection *self) * * 0 => error; 1 => ok */ -int pysqlite_check_connection(pysqlite_Connection* con) +extern int +pysqlite_check_connection(pysqlite_Connection *con) { if (!con->initialized) { PyErr_SetString(pysqlite_ProgrammingError, "Base Connection.__init__ not called."); @@ -371,7 +378,8 @@ int pysqlite_check_connection(pysqlite_Connection* con) } } -PyObject* _pysqlite_connection_begin(pysqlite_Connection* self) +extern PyObject * +_pysqlite_connection_begin(pysqlite_Connection *self) { int rc; const char* tail; @@ -509,7 +517,7 @@ pysqlite_connection_rollback_impl(pysqlite_Connection *self) } static int -_pysqlite_set_result(sqlite3_context* context, PyObject* py_val) +_pysqlite_set_result(sqlite3_context *context, PyObject *py_val) { if (py_val == Py_None) { sqlite3_result_null(context); @@ -546,7 +554,9 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) return 0; } -PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_value** argv) +static PyObject * +_pysqlite_build_py_params(sqlite3_context *context, int argc, + sqlite3_value **argv) { PyObject* args; int i; @@ -601,7 +611,8 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_ } static void -_pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv) +_pysqlite_func_callback(sqlite3_context *context, int argc, + sqlite3_value **argv) { PyObject* args; PyObject* py_func; @@ -637,7 +648,9 @@ _pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv PyGILState_Release(threadstate); } -static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params) +static void +_pysqlite_step_callback(sqlite3_context *context, int argc, + sqlite3_value **params) { PyObject* args; PyObject* function_result = NULL; @@ -751,7 +764,8 @@ _pysqlite_final_callback(sqlite3_context *context) PyGILState_Release(threadstate); } -static void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self) +static void +_pysqlite_drop_unused_statement_references(pysqlite_Connection *self) { PyObject* new_list; PyObject* weakref; @@ -782,7 +796,8 @@ static void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self Py_SETREF(self->statements, new_list); } -static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) +static void +_pysqlite_drop_unused_cursor_references(pysqlite_Connection *self) { PyObject* new_list; PyObject* weakref; @@ -813,7 +828,8 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) Py_SETREF(self->cursors, new_list); } -static void _destructor(void* args) +static void +_destructor(void *args) { Py_DECREF((PyObject*)args); } @@ -914,7 +930,10 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self, 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) +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; @@ -953,7 +972,8 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co return rc; } -static int _progress_handler(void* user_arg) +static int +_progress_handler(void *user_arg) { int rc; PyObject *ret; @@ -987,9 +1007,12 @@ static int _progress_handler(void* user_arg) * may change in future releases. Callback implementations should return zero * to ensure future compatibility. */ -static int _trace_callback(unsigned int type, void* user_arg, void* prepared_statement, void* statement_string) +static int +_trace_callback(unsigned int type, void *user_arg, void *prepared_statement, + void *statement_string) #else -static void _trace_callback(void* user_arg, const char* statement_string) +static void +_trace_callback(void *user_arg, const char *statement_string) #endif { PyObject *py_statement = NULL; @@ -1197,7 +1220,8 @@ pysqlite_connection_load_extension_impl(pysqlite_Connection *self, } #endif -int pysqlite_check_thread(pysqlite_Connection* self) +extern int +pysqlite_check_thread(pysqlite_Connection *self) { if (self->check_same_thread) { if (PyThread_get_thread_ident() != self->thread_ident) { @@ -1212,12 +1236,14 @@ int pysqlite_check_thread(pysqlite_Connection* self) return 1; } -static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused) +static PyObject * +pysqlite_connection_get_isolation_level(pysqlite_Connection *self, void *unused) { return Py_NewRef(self->isolation_level); } -static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused) +static PyObject * +pysqlite_connection_get_total_changes(pysqlite_Connection *self, void *unused) { if (!pysqlite_check_connection(self)) { return NULL; @@ -1226,7 +1252,8 @@ static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self } } -static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused) +static PyObject * +pysqlite_connection_get_in_transaction(pysqlite_Connection *self, void *unused) { if (!pysqlite_check_connection(self)) { return NULL; @@ -1238,7 +1265,9 @@ static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* sel } static int -pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored)) +pysqlite_connection_set_isolation_level(pysqlite_Connection *self, + PyObject *isolation_level, + void *Py_UNUSED(ignored)) { if (isolation_level == NULL) { PyErr_SetString(PyExc_AttributeError, "cannot delete attribute"); @@ -1288,7 +1317,9 @@ pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* iso return 0; } -PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) +static PyObject * +pysqlite_connection_call(pysqlite_Connection *self, PyObject *args, + PyObject *kwargs) { PyObject* sql; pysqlite_Statement* statement; @@ -1457,10 +1488,9 @@ pysqlite_connection_executescript(pysqlite_Connection *self, /* ------------------------- COLLATION CODE ------------------------ */ static int -pysqlite_collation_callback( - void* context, - int text1_length, const void* text1_data, - int text2_length, const void* text2_data) +pysqlite_collation_callback(void *context, int text1_length, + const void *text1_data, int text2_length, + const void *text2_data) { PyObject* callback = (PyObject*)context; PyObject* string1 = 0; @@ -1919,7 +1949,8 @@ static PyType_Spec connection_spec = { PyTypeObject *pysqlite_ConnectionType = NULL; -extern int pysqlite_connection_setup_types(PyObject *module) +extern int +pysqlite_connection_setup_types(PyObject *module) { pysqlite_ConnectionType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &connection_spec, NULL); if (pysqlite_ConnectionType == NULL) { diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index d1578ad6aafb81..8d2db82a80ccb0 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -32,8 +32,6 @@ class _sqlite3.Cursor "pysqlite_Cursor *" "pysqlite_CursorType" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b2072d8db95411d5]*/ -PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self); - static const char errmsg_fetch_across_rollback[] = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from."; /*[clinic input] @@ -83,7 +81,8 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self, return 0; } -static void pysqlite_cursor_dealloc(pysqlite_Cursor* self) +static void +pysqlite_cursor_dealloc(pysqlite_Cursor *self) { PyTypeObject *tp = Py_TYPE(self); @@ -133,7 +132,7 @@ _pysqlite_get_converter(const char *keystr, Py_ssize_t keylen) } static int -pysqlite_build_row_cast_map(pysqlite_Cursor* self) +pysqlite_build_row_cast_map(pysqlite_Cursor *self) { int i; const char* pos; @@ -240,7 +239,7 @@ _pysqlite_build_column_name(pysqlite_Cursor *self, const char *colname) * - sqlite3_step() has been called before and it returned SQLITE_ROW. */ static PyObject * -_pysqlite_fetch_one_row(pysqlite_Cursor* self) +_pysqlite_fetch_one_row(pysqlite_Cursor *self) { int i, numcols; PyObject* row; @@ -366,7 +365,8 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) * * 0 => error; 1 => ok */ -static int check_cursor(pysqlite_Cursor* cur) +static int +check_cursor(pysqlite_Cursor *cur) { if (!cur->initialized) { PyErr_SetString(pysqlite_ProgrammingError, "Base Cursor.__init__ not called."); @@ -387,7 +387,8 @@ static int check_cursor(pysqlite_Cursor* cur) } static PyObject * -_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument) +_pysqlite_query_execute(pysqlite_Cursor *self, int multiple, + PyObject *operation, PyObject *second_argument) { PyObject* parameters_list = NULL; PyObject* parameters_iter = NULL; @@ -746,7 +747,8 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj) } } -PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self) +static PyObject * +pysqlite_cursor_iternext(pysqlite_Cursor *self) { PyObject* next_row_tuple; PyObject* next_row; @@ -1018,7 +1020,8 @@ static PyType_Spec cursor_spec = { PyTypeObject *pysqlite_CursorType = NULL; -extern int pysqlite_cursor_setup_types(PyObject *module) +extern int +pysqlite_cursor_setup_types(PyObject *module) { pysqlite_CursorType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &cursor_spec, NULL); if (pysqlite_CursorType == NULL) { diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c index e219a7239f8a7d..b1ae901049b580 100644 --- a/Modules/_sqlite/microprotocols.c +++ b/Modules/_sqlite/microprotocols.c @@ -35,7 +35,7 @@ static PyObject *psyco_adapters = NULL; /* pysqlite_microprotocols_init - initialize the adapters dictionary */ -int +extern int pysqlite_microprotocols_init(PyObject *module) { /* create adapters dictionary and put it in module namespace */ @@ -52,7 +52,7 @@ pysqlite_microprotocols_init(PyObject *module) /* pysqlite_microprotocols_add - add a reverse type-caster to the dictionary */ -int +extern int pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast) { PyObject* key; @@ -73,7 +73,7 @@ pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast) /* pysqlite_microprotocols_adapt - adapt an object to the built-in protocol */ -PyObject * +extern PyObject * pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) { _Py_IDENTIFIER(__adapt__); diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 6bfb1b73f82391..719265a7adedb3 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -56,8 +56,8 @@ PyObject* _pysqlite_converters = NULL; int _pysqlite_enable_callback_tracebacks = 0; int pysqlite_BaseTypeAdapted = 0; -static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* - kwargs) +static PyObject * +module_connect(PyObject *self, PyObject *args, PyObject *kwargs) { /* Python seems to have no way of extracting a single keyword-arg at * C-level, so this code is redundant with the one in connection_init in @@ -256,7 +256,8 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto, return pysqlite_microprotocols_adapt(obj, proto, alt); } -static int converters_init(PyObject* module) +static int +converters_init(PyObject *module) { _pysqlite_converters = PyDict_New(); if (!_pysqlite_converters) { @@ -281,7 +282,8 @@ static PyMethodDef module_methods[] = { {NULL, NULL} }; -static int add_integer_constants(PyObject *module) { +static int +add_integer_constants(PyObject *module) { int ret = 0; ret += PyModule_AddIntMacro(module, PARSE_DECLTYPES); @@ -361,7 +363,8 @@ do { \ } \ } while (0) -PyMODINIT_FUNC PyInit__sqlite3(void) +PyMODINIT_FUNC +PyInit__sqlite3(void) { PyObject *module; diff --git a/Modules/_sqlite/prepare_protocol.c b/Modules/_sqlite/prepare_protocol.c index 089d66b9810857..501b039c6aa380 100644 --- a/Modules/_sqlite/prepare_protocol.c +++ b/Modules/_sqlite/prepare_protocol.c @@ -23,12 +23,15 @@ #include "prepare_protocol.h" -int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs) +static int +pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol *self, PyObject *args, + PyObject *kwargs) { return 0; } -void pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol* self) +static void +pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol *self) { PyTypeObject *tp = Py_TYPE(self); @@ -52,7 +55,8 @@ static PyType_Spec type_spec = { PyTypeObject *pysqlite_PrepareProtocolType = NULL; -extern int pysqlite_prepare_protocol_setup_types(PyObject *module) +extern int +pysqlite_prepare_protocol_setup_types(PyObject *module) { pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &type_spec, NULL); if (pysqlite_PrepareProtocolType == NULL) { diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index 04e308fa1c350c..4d3359ea64159b 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -31,7 +31,8 @@ class _sqlite3.Row "pysqlite_Row *" "pysqlite_RowType" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=384227da65f250fd]*/ -void pysqlite_row_dealloc(pysqlite_Row* self) +static void +pysqlite_row_dealloc(pysqlite_Row *self) { PyTypeObject *tp = Py_TYPE(self); @@ -105,7 +106,8 @@ equal_ignore_case(PyObject *left, PyObject *right) return 1; } -PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) +static PyObject * +pysqlite_row_subscript(pysqlite_Row *self, PyObject *idx) { Py_ssize_t _idx; Py_ssize_t nitems, i; @@ -150,7 +152,7 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) } static Py_ssize_t -pysqlite_row_length(pysqlite_Row* self) +pysqlite_row_length(pysqlite_Row *self) { return PyTuple_GET_SIZE(self->data); } @@ -184,17 +186,20 @@ pysqlite_row_keys_impl(pysqlite_Row *self) return list; } -static PyObject* pysqlite_iter(pysqlite_Row* self) +static PyObject * +pysqlite_iter(pysqlite_Row *self) { return PyObject_GetIter(self->data); } -static Py_hash_t pysqlite_row_hash(pysqlite_Row *self) +static Py_hash_t +pysqlite_row_hash(pysqlite_Row *self) { return PyObject_Hash(self->description) ^ PyObject_Hash(self->data); } -static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid) +static PyObject * +pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid) { if (opid != Py_EQ && opid != Py_NE) Py_RETURN_NOTIMPLEMENTED; @@ -241,7 +246,8 @@ static PyType_Spec row_spec = { PyTypeObject *pysqlite_RowType = NULL; -extern int pysqlite_row_setup_types(PyObject *module) +extern int +pysqlite_row_setup_types(PyObject *module) { pysqlite_RowType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &row_spec, NULL); if (pysqlite_RowType == NULL) { diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index b62de58109eddc..cba1406bbbc0c7 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -48,7 +48,9 @@ typedef enum { TYPE_UNKNOWN } parameter_type; -int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql) +extern int +pysqlite_statement_create(pysqlite_Statement *self, + pysqlite_Connection *connection, PyObject *sql) { const char* tail; int rc; @@ -112,7 +114,9 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con return rc; } -int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter) +extern int +pysqlite_statement_bind_parameter(pysqlite_Statement *self, int pos, + PyObject *parameter) { int rc = SQLITE_OK; const char *string; @@ -190,7 +194,8 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec } /* returns 0 if the object is one of Python's internal ones that don't need to be adapted */ -static int _need_adapt(PyObject* obj) +static int +_need_adapt(PyObject *obj) { if (pysqlite_BaseTypeAdapted) { return 1; @@ -204,7 +209,9 @@ static int _need_adapt(PyObject* obj) } } -void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters) +extern void +pysqlite_statement_bind_parameters(pysqlite_Statement *self, + PyObject *parameters) { PyObject* current_param; PyObject* adapted; @@ -327,7 +334,8 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para } } -int pysqlite_statement_finalize(pysqlite_Statement* self) +extern int +pysqlite_statement_finalize(pysqlite_Statement *self) { int rc; @@ -344,7 +352,8 @@ int pysqlite_statement_finalize(pysqlite_Statement* self) return rc; } -int pysqlite_statement_reset(pysqlite_Statement* self) +extern int +pysqlite_statement_reset(pysqlite_Statement *self) { int rc; @@ -363,12 +372,14 @@ int pysqlite_statement_reset(pysqlite_Statement* self) return rc; } -void pysqlite_statement_mark_dirty(pysqlite_Statement* self) +extern void +pysqlite_statement_mark_dirty(pysqlite_Statement *self) { self->in_use = 1; } -void pysqlite_statement_dealloc(pysqlite_Statement* self) +static void +pysqlite_statement_dealloc(pysqlite_Statement *self) { PyTypeObject *tp = Py_TYPE(self); @@ -398,7 +409,8 @@ void pysqlite_statement_dealloc(pysqlite_Statement* self) * * Returns 1 if there is more left than should be. 0 if ok. */ -static int pysqlite_check_remaining_sql(const char* tail) +static int +pysqlite_check_remaining_sql(const char *tail) { const char* pos = tail; @@ -479,7 +491,8 @@ static PyType_Spec stmt_spec = { }; PyTypeObject *pysqlite_StatementType = NULL; -extern int pysqlite_statement_setup_types(PyObject *module) +extern int +pysqlite_statement_setup_types(PyObject *module) { pysqlite_StatementType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &stmt_spec, NULL); if (pysqlite_StatementType == NULL) { diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c index 1dbabcdd94a811..d1c7a7416bf92a 100644 --- a/Modules/_sqlite/util.c +++ b/Modules/_sqlite/util.c @@ -24,7 +24,8 @@ #include "module.h" #include "connection.h" -int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection) +extern int +pysqlite_step(sqlite3_stmt *statement, pysqlite_Connection *connection) { int rc; @@ -45,7 +46,8 @@ int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection) * Checks the SQLite error code and sets the appropriate DB-API exception. * Returns the error code (0 means no error occurred). */ -int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st) +extern int +_pysqlite_seterror(sqlite3 *db, sqlite3_stmt *st) { int errorcode = sqlite3_errcode(db); @@ -103,8 +105,8 @@ int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st) # define IS_LITTLE_ENDIAN 1 #endif -sqlite_int64 -_pysqlite_long_as_int64(PyObject * py_val) +extern sqlite_int64 +_pysqlite_long_as_int64(PyObject *py_val) { int overflow; long long value = PyLong_AsLongLongAndOverflow(py_val, &overflow); From 23b108f9c92f8a1075f1fd7501b13a594a186e92 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 19 Feb 2021 12:57:53 +0100 Subject: [PATCH 2/8] Add Py_UNUSED --- Modules/_sqlite/connection.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 1ce9d85f526467..5ae4890fbdba69 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1237,13 +1237,15 @@ pysqlite_check_thread(pysqlite_Connection *self) } static PyObject * -pysqlite_connection_get_isolation_level(pysqlite_Connection *self, void *unused) +pysqlite_connection_get_isolation_level(pysqlite_Connection *self, + void *Py_UNUSED(unused)) { return Py_NewRef(self->isolation_level); } static PyObject * -pysqlite_connection_get_total_changes(pysqlite_Connection *self, void *unused) +pysqlite_connection_get_total_changes(pysqlite_Connection *self, + void *Py_UNUSED(unused)) { if (!pysqlite_check_connection(self)) { return NULL; @@ -1253,7 +1255,8 @@ pysqlite_connection_get_total_changes(pysqlite_Connection *self, void *unused) } static PyObject * -pysqlite_connection_get_in_transaction(pysqlite_Connection *self, void *unused) +pysqlite_connection_get_in_transaction(pysqlite_Connection *self, + void *Py_UNUSED(unused)) { if (!pysqlite_check_connection(self)) { return NULL; From bd5c34559f7b85328e0f90a67888d8dc1e740b1a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 20 Feb 2021 07:36:21 +0100 Subject: [PATCH 3/8] Address review: Remove 'extern' keyword --- Modules/_sqlite/cache.c | 4 ++-- Modules/_sqlite/connection.c | 10 +++++----- Modules/_sqlite/cursor.c | 2 +- Modules/_sqlite/microprotocols.c | 6 +++--- Modules/_sqlite/prepare_protocol.c | 2 +- Modules/_sqlite/row.c | 2 +- Modules/_sqlite/statement.c | 14 +++++++------- Modules/_sqlite/util.c | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c index e9e04f5eca1710..91561d88b2eaa9 100644 --- a/Modules/_sqlite/cache.c +++ b/Modules/_sqlite/cache.c @@ -117,7 +117,7 @@ pysqlite_cache_dealloc(pysqlite_Cache *self) Py_DECREF(tp); } -extern PyObject * +PyObject * pysqlite_cache_get(pysqlite_Cache *self, PyObject *key) { pysqlite_Node* node; @@ -297,7 +297,7 @@ static PyType_Spec cache_spec = { }; PyTypeObject *pysqlite_CacheType = NULL; -extern int +int pysqlite_cache_setup_types(PyObject *mod) { pysqlite_NodeType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &node_spec, NULL); diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 5ae4890fbdba69..9064ac5f563ad3 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -259,7 +259,7 @@ pysqlite_connection_dealloc(pysqlite_Connection *self) * * 0 => error; 1 => ok */ -extern int +int pysqlite_connection_register_cursor(pysqlite_Connection *connection, PyObject *cursor) { @@ -362,7 +362,7 @@ pysqlite_connection_close_impl(pysqlite_Connection *self) * * 0 => error; 1 => ok */ -extern int +int pysqlite_check_connection(pysqlite_Connection *con) { if (!con->initialized) { @@ -378,7 +378,7 @@ pysqlite_check_connection(pysqlite_Connection *con) } } -extern PyObject * +PyObject * _pysqlite_connection_begin(pysqlite_Connection *self) { int rc; @@ -1220,7 +1220,7 @@ pysqlite_connection_load_extension_impl(pysqlite_Connection *self, } #endif -extern int +int pysqlite_check_thread(pysqlite_Connection *self) { if (self->check_same_thread) { @@ -1952,7 +1952,7 @@ static PyType_Spec connection_spec = { PyTypeObject *pysqlite_ConnectionType = NULL; -extern int +int pysqlite_connection_setup_types(PyObject *module) { pysqlite_ConnectionType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &connection_spec, NULL); diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 8d2db82a80ccb0..bf9a62127ceffc 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -1020,7 +1020,7 @@ static PyType_Spec cursor_spec = { PyTypeObject *pysqlite_CursorType = NULL; -extern int +int pysqlite_cursor_setup_types(PyObject *module) { pysqlite_CursorType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &cursor_spec, NULL); diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c index b1ae901049b580..e219a7239f8a7d 100644 --- a/Modules/_sqlite/microprotocols.c +++ b/Modules/_sqlite/microprotocols.c @@ -35,7 +35,7 @@ static PyObject *psyco_adapters = NULL; /* pysqlite_microprotocols_init - initialize the adapters dictionary */ -extern int +int pysqlite_microprotocols_init(PyObject *module) { /* create adapters dictionary and put it in module namespace */ @@ -52,7 +52,7 @@ pysqlite_microprotocols_init(PyObject *module) /* pysqlite_microprotocols_add - add a reverse type-caster to the dictionary */ -extern int +int pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast) { PyObject* key; @@ -73,7 +73,7 @@ pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast) /* pysqlite_microprotocols_adapt - adapt an object to the built-in protocol */ -extern PyObject * +PyObject * pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) { _Py_IDENTIFIER(__adapt__); diff --git a/Modules/_sqlite/prepare_protocol.c b/Modules/_sqlite/prepare_protocol.c index 501b039c6aa380..7d2d7ade591467 100644 --- a/Modules/_sqlite/prepare_protocol.c +++ b/Modules/_sqlite/prepare_protocol.c @@ -55,7 +55,7 @@ static PyType_Spec type_spec = { PyTypeObject *pysqlite_PrepareProtocolType = NULL; -extern int +int pysqlite_prepare_protocol_setup_types(PyObject *module) { pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &type_spec, NULL); diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index 4d3359ea64159b..f079d73dafd1e5 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -246,7 +246,7 @@ static PyType_Spec row_spec = { PyTypeObject *pysqlite_RowType = NULL; -extern int +int pysqlite_row_setup_types(PyObject *module) { pysqlite_RowType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &row_spec, NULL); diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index cba1406bbbc0c7..cb36c0b27675bb 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -48,7 +48,7 @@ typedef enum { TYPE_UNKNOWN } parameter_type; -extern int +int pysqlite_statement_create(pysqlite_Statement *self, pysqlite_Connection *connection, PyObject *sql) { @@ -114,7 +114,7 @@ pysqlite_statement_create(pysqlite_Statement *self, return rc; } -extern int +int pysqlite_statement_bind_parameter(pysqlite_Statement *self, int pos, PyObject *parameter) { @@ -209,7 +209,7 @@ _need_adapt(PyObject *obj) } } -extern void +void pysqlite_statement_bind_parameters(pysqlite_Statement *self, PyObject *parameters) { @@ -334,7 +334,7 @@ pysqlite_statement_bind_parameters(pysqlite_Statement *self, } } -extern int +int pysqlite_statement_finalize(pysqlite_Statement *self) { int rc; @@ -352,7 +352,7 @@ pysqlite_statement_finalize(pysqlite_Statement *self) return rc; } -extern int +int pysqlite_statement_reset(pysqlite_Statement *self) { int rc; @@ -372,7 +372,7 @@ pysqlite_statement_reset(pysqlite_Statement *self) return rc; } -extern void +void pysqlite_statement_mark_dirty(pysqlite_Statement *self) { self->in_use = 1; @@ -491,7 +491,7 @@ static PyType_Spec stmt_spec = { }; PyTypeObject *pysqlite_StatementType = NULL; -extern int +int pysqlite_statement_setup_types(PyObject *module) { pysqlite_StatementType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &stmt_spec, NULL); diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c index d1c7a7416bf92a..2ffba443e56557 100644 --- a/Modules/_sqlite/util.c +++ b/Modules/_sqlite/util.c @@ -24,7 +24,7 @@ #include "module.h" #include "connection.h" -extern int +int pysqlite_step(sqlite3_stmt *statement, pysqlite_Connection *connection) { int rc; @@ -46,7 +46,7 @@ pysqlite_step(sqlite3_stmt *statement, pysqlite_Connection *connection) * Checks the SQLite error code and sets the appropriate DB-API exception. * Returns the error code (0 means no error occurred). */ -extern int +int _pysqlite_seterror(sqlite3 *db, sqlite3_stmt *st) { int errorcode = sqlite3_errcode(db); @@ -105,7 +105,7 @@ _pysqlite_seterror(sqlite3 *db, sqlite3_stmt *st) # define IS_LITTLE_ENDIAN 1 #endif -extern sqlite_int64 +sqlite_int64 _pysqlite_long_as_int64(PyObject *py_val) { int overflow; From 5a159fb6fdde0d854b0cc1580042b65aaad0a514 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 20 Feb 2021 23:33:50 +0100 Subject: [PATCH 4/8] Address review: revert OoS style changes --- Modules/_sqlite/cache.c | 6 +-- Modules/_sqlite/connection.c | 73 ++++++++++-------------------- Modules/_sqlite/cursor.c | 16 +++---- Modules/_sqlite/module.c | 13 ++---- Modules/_sqlite/prepare_protocol.c | 3 +- Modules/_sqlite/row.c | 14 ++---- Modules/_sqlite/statement.c | 30 ++++-------- Modules/_sqlite/util.c | 8 ++-- 8 files changed, 54 insertions(+), 109 deletions(-) diff --git a/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c index 91561d88b2eaa9..ec4a22fb7a2d80 100644 --- a/Modules/_sqlite/cache.c +++ b/Modules/_sqlite/cache.c @@ -117,8 +117,7 @@ pysqlite_cache_dealloc(pysqlite_Cache *self) Py_DECREF(tp); } -PyObject * -pysqlite_cache_get(pysqlite_Cache *self, PyObject *key) +PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key) { pysqlite_Node* node; pysqlite_Node* ptr; @@ -297,8 +296,7 @@ static PyType_Spec cache_spec = { }; PyTypeObject *pysqlite_CacheType = NULL; -int -pysqlite_cache_setup_types(PyObject *mod) +extern int pysqlite_cache_setup_types(PyObject *mod) { pysqlite_NodeType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &node_spec, NULL); if (pysqlite_NodeType == NULL) { diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 9064ac5f563ad3..ac4f6f0901af75 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -259,9 +259,7 @@ pysqlite_connection_dealloc(pysqlite_Connection *self) * * 0 => error; 1 => ok */ -int -pysqlite_connection_register_cursor(pysqlite_Connection *connection, - PyObject *cursor) +int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor) { PyObject* weakref; @@ -362,8 +360,7 @@ pysqlite_connection_close_impl(pysqlite_Connection *self) * * 0 => error; 1 => ok */ -int -pysqlite_check_connection(pysqlite_Connection *con) +int pysqlite_check_connection(pysqlite_Connection* con) { if (!con->initialized) { PyErr_SetString(pysqlite_ProgrammingError, "Base Connection.__init__ not called."); @@ -378,8 +375,7 @@ pysqlite_check_connection(pysqlite_Connection *con) } } -PyObject * -_pysqlite_connection_begin(pysqlite_Connection *self) +PyObject* _pysqlite_connection_begin(pysqlite_Connection* self) { int rc; const char* tail; @@ -517,7 +513,7 @@ pysqlite_connection_rollback_impl(pysqlite_Connection *self) } static int -_pysqlite_set_result(sqlite3_context *context, PyObject *py_val) +_pysqlite_set_result(sqlite3_context* context, PyObject* py_val) { if (py_val == Py_None) { sqlite3_result_null(context); @@ -611,8 +607,7 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, } static void -_pysqlite_func_callback(sqlite3_context *context, int argc, - sqlite3_value **argv) +_pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv) { PyObject* args; PyObject* py_func; @@ -648,9 +643,7 @@ _pysqlite_func_callback(sqlite3_context *context, int argc, PyGILState_Release(threadstate); } -static void -_pysqlite_step_callback(sqlite3_context *context, int argc, - sqlite3_value **params) +static void _pysqlite_step_callback(sqlite3_context* context, int argc, sqlite3_value** params) { PyObject* args; PyObject* function_result = NULL; @@ -764,8 +757,7 @@ _pysqlite_final_callback(sqlite3_context *context) PyGILState_Release(threadstate); } -static void -_pysqlite_drop_unused_statement_references(pysqlite_Connection *self) +static void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self) { PyObject* new_list; PyObject* weakref; @@ -796,8 +788,7 @@ _pysqlite_drop_unused_statement_references(pysqlite_Connection *self) Py_SETREF(self->statements, new_list); } -static void -_pysqlite_drop_unused_cursor_references(pysqlite_Connection *self) +static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) { PyObject* new_list; PyObject* weakref; @@ -828,8 +819,7 @@ _pysqlite_drop_unused_cursor_references(pysqlite_Connection *self) Py_SETREF(self->cursors, new_list); } -static void -_destructor(void *args) +static void _destructor(void* args) { Py_DECREF((PyObject*)args); } @@ -930,10 +920,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self, 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) +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; @@ -972,8 +959,7 @@ _authorizer_callback(void *user_arg, int action, const char *arg1, return rc; } -static int -_progress_handler(void *user_arg) +static int _progress_handler(void* user_arg) { int rc; PyObject *ret; @@ -1007,12 +993,9 @@ _progress_handler(void *user_arg) * may change in future releases. Callback implementations should return zero * to ensure future compatibility. */ -static int -_trace_callback(unsigned int type, void *user_arg, void *prepared_statement, - void *statement_string) +static int _trace_callback(unsigned int type, void* user_arg, void* prepared_statement, void* statement_string) #else -static void -_trace_callback(void *user_arg, const char *statement_string) +static void _trace_callback(void* user_arg, const char* statement_string) #endif { PyObject *py_statement = NULL; @@ -1220,8 +1203,7 @@ pysqlite_connection_load_extension_impl(pysqlite_Connection *self, } #endif -int -pysqlite_check_thread(pysqlite_Connection *self) +int pysqlite_check_thread(pysqlite_Connection* self) { if (self->check_same_thread) { if (PyThread_get_thread_ident() != self->thread_ident) { @@ -1236,16 +1218,12 @@ pysqlite_check_thread(pysqlite_Connection *self) return 1; } -static PyObject * -pysqlite_connection_get_isolation_level(pysqlite_Connection *self, - void *Py_UNUSED(unused)) +static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused) { return Py_NewRef(self->isolation_level); } -static PyObject * -pysqlite_connection_get_total_changes(pysqlite_Connection *self, - void *Py_UNUSED(unused)) +static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused) { if (!pysqlite_check_connection(self)) { return NULL; @@ -1254,9 +1232,7 @@ pysqlite_connection_get_total_changes(pysqlite_Connection *self, } } -static PyObject * -pysqlite_connection_get_in_transaction(pysqlite_Connection *self, - void *Py_UNUSED(unused)) +static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused) { if (!pysqlite_check_connection(self)) { return NULL; @@ -1267,10 +1243,7 @@ pysqlite_connection_get_in_transaction(pysqlite_Connection *self, Py_RETURN_FALSE; } -static int -pysqlite_connection_set_isolation_level(pysqlite_Connection *self, - PyObject *isolation_level, - void *Py_UNUSED(ignored)) +static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored)) { if (isolation_level == NULL) { PyErr_SetString(PyExc_AttributeError, "cannot delete attribute"); @@ -1491,9 +1464,10 @@ pysqlite_connection_executescript(pysqlite_Connection *self, /* ------------------------- COLLATION CODE ------------------------ */ static int -pysqlite_collation_callback(void *context, int text1_length, - const void *text1_data, int text2_length, - const void *text2_data) +pysqlite_collation_callback( + void* context, + int text1_length, const void* text1_data, + int text2_length, const void* text2_data) { PyObject* callback = (PyObject*)context; PyObject* string1 = 0; @@ -1952,8 +1926,7 @@ static PyType_Spec connection_spec = { PyTypeObject *pysqlite_ConnectionType = NULL; -int -pysqlite_connection_setup_types(PyObject *module) +extern int pysqlite_connection_setup_types(PyObject *module) { pysqlite_ConnectionType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &connection_spec, NULL); if (pysqlite_ConnectionType == NULL) { diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index bf9a62127ceffc..4f982c94404d4b 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -81,8 +81,7 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self, return 0; } -static void -pysqlite_cursor_dealloc(pysqlite_Cursor *self) +static void pysqlite_cursor_dealloc(pysqlite_Cursor* self) { PyTypeObject *tp = Py_TYPE(self); @@ -132,7 +131,7 @@ _pysqlite_get_converter(const char *keystr, Py_ssize_t keylen) } static int -pysqlite_build_row_cast_map(pysqlite_Cursor *self) +pysqlite_build_row_cast_map(pysqlite_Cursor* self) { int i; const char* pos; @@ -239,7 +238,7 @@ _pysqlite_build_column_name(pysqlite_Cursor *self, const char *colname) * - sqlite3_step() has been called before and it returned SQLITE_ROW. */ static PyObject * -_pysqlite_fetch_one_row(pysqlite_Cursor *self) +_pysqlite_fetch_one_row(pysqlite_Cursor* self) { int i, numcols; PyObject* row; @@ -365,8 +364,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor *self) * * 0 => error; 1 => ok */ -static int -check_cursor(pysqlite_Cursor *cur) +static int check_cursor(pysqlite_Cursor* cur) { if (!cur->initialized) { PyErr_SetString(pysqlite_ProgrammingError, "Base Cursor.__init__ not called."); @@ -387,8 +385,7 @@ check_cursor(pysqlite_Cursor *cur) } static PyObject * -_pysqlite_query_execute(pysqlite_Cursor *self, int multiple, - PyObject *operation, PyObject *second_argument) +_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument) { PyObject* parameters_list = NULL; PyObject* parameters_iter = NULL; @@ -1020,8 +1017,7 @@ static PyType_Spec cursor_spec = { PyTypeObject *pysqlite_CursorType = NULL; -int -pysqlite_cursor_setup_types(PyObject *module) +extern int pysqlite_cursor_setup_types(PyObject* module) { pysqlite_CursorType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &cursor_spec, NULL); if (pysqlite_CursorType == NULL) { diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 719265a7adedb3..6bfb1b73f82391 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -56,8 +56,8 @@ PyObject* _pysqlite_converters = NULL; int _pysqlite_enable_callback_tracebacks = 0; int pysqlite_BaseTypeAdapted = 0; -static PyObject * -module_connect(PyObject *self, PyObject *args, PyObject *kwargs) +static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* + kwargs) { /* Python seems to have no way of extracting a single keyword-arg at * C-level, so this code is redundant with the one in connection_init in @@ -256,8 +256,7 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto, return pysqlite_microprotocols_adapt(obj, proto, alt); } -static int -converters_init(PyObject *module) +static int converters_init(PyObject* module) { _pysqlite_converters = PyDict_New(); if (!_pysqlite_converters) { @@ -282,8 +281,7 @@ static PyMethodDef module_methods[] = { {NULL, NULL} }; -static int -add_integer_constants(PyObject *module) { +static int add_integer_constants(PyObject *module) { int ret = 0; ret += PyModule_AddIntMacro(module, PARSE_DECLTYPES); @@ -363,8 +361,7 @@ do { \ } \ } while (0) -PyMODINIT_FUNC -PyInit__sqlite3(void) +PyMODINIT_FUNC PyInit__sqlite3(void) { PyObject *module; diff --git a/Modules/_sqlite/prepare_protocol.c b/Modules/_sqlite/prepare_protocol.c index 7d2d7ade591467..ad793324b94b5b 100644 --- a/Modules/_sqlite/prepare_protocol.c +++ b/Modules/_sqlite/prepare_protocol.c @@ -55,8 +55,7 @@ static PyType_Spec type_spec = { PyTypeObject *pysqlite_PrepareProtocolType = NULL; -int -pysqlite_prepare_protocol_setup_types(PyObject *module) +extern int pysqlite_prepare_protocol_setup_types(PyObject *module) { pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &type_spec, NULL); if (pysqlite_PrepareProtocolType == NULL) { diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c index f079d73dafd1e5..97a5a17ada9d0b 100644 --- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -152,7 +152,7 @@ pysqlite_row_subscript(pysqlite_Row *self, PyObject *idx) } static Py_ssize_t -pysqlite_row_length(pysqlite_Row *self) +pysqlite_row_length(pysqlite_Row* self) { return PyTuple_GET_SIZE(self->data); } @@ -186,20 +186,17 @@ pysqlite_row_keys_impl(pysqlite_Row *self) return list; } -static PyObject * -pysqlite_iter(pysqlite_Row *self) +static PyObject* pysqlite_iter(pysqlite_Row* self) { return PyObject_GetIter(self->data); } -static Py_hash_t -pysqlite_row_hash(pysqlite_Row *self) +static Py_hash_t pysqlite_row_hash(pysqlite_Row *self) { return PyObject_Hash(self->description) ^ PyObject_Hash(self->data); } -static PyObject * -pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid) +static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid) { if (opid != Py_EQ && opid != Py_NE) Py_RETURN_NOTIMPLEMENTED; @@ -246,8 +243,7 @@ static PyType_Spec row_spec = { PyTypeObject *pysqlite_RowType = NULL; -int -pysqlite_row_setup_types(PyObject *module) +extern int pysqlite_row_setup_types(PyObject *module) { pysqlite_RowType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &row_spec, NULL); if (pysqlite_RowType == NULL) { diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index cb36c0b27675bb..f179eee16f4d40 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -48,9 +48,7 @@ typedef enum { TYPE_UNKNOWN } parameter_type; -int -pysqlite_statement_create(pysqlite_Statement *self, - pysqlite_Connection *connection, PyObject *sql) +int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql) { const char* tail; int rc; @@ -114,9 +112,7 @@ pysqlite_statement_create(pysqlite_Statement *self, return rc; } -int -pysqlite_statement_bind_parameter(pysqlite_Statement *self, int pos, - PyObject *parameter) +int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter) { int rc = SQLITE_OK; const char *string; @@ -194,8 +190,7 @@ pysqlite_statement_bind_parameter(pysqlite_Statement *self, int pos, } /* returns 0 if the object is one of Python's internal ones that don't need to be adapted */ -static int -_need_adapt(PyObject *obj) +static int _need_adapt(PyObject* obj) { if (pysqlite_BaseTypeAdapted) { return 1; @@ -209,9 +204,7 @@ _need_adapt(PyObject *obj) } } -void -pysqlite_statement_bind_parameters(pysqlite_Statement *self, - PyObject *parameters) +void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters) { PyObject* current_param; PyObject* adapted; @@ -334,8 +327,7 @@ pysqlite_statement_bind_parameters(pysqlite_Statement *self, } } -int -pysqlite_statement_finalize(pysqlite_Statement *self) +int pysqlite_statement_finalize(pysqlite_Statement* self) { int rc; @@ -352,8 +344,7 @@ pysqlite_statement_finalize(pysqlite_Statement *self) return rc; } -int -pysqlite_statement_reset(pysqlite_Statement *self) +int pysqlite_statement_reset(pysqlite_Statement* self) { int rc; @@ -372,8 +363,7 @@ pysqlite_statement_reset(pysqlite_Statement *self) return rc; } -void -pysqlite_statement_mark_dirty(pysqlite_Statement *self) +void pysqlite_statement_mark_dirty(pysqlite_Statement* self) { self->in_use = 1; } @@ -409,8 +399,7 @@ pysqlite_statement_dealloc(pysqlite_Statement *self) * * Returns 1 if there is more left than should be. 0 if ok. */ -static int -pysqlite_check_remaining_sql(const char *tail) +static int pysqlite_check_remaining_sql(const char* tail) { const char* pos = tail; @@ -491,8 +480,7 @@ static PyType_Spec stmt_spec = { }; PyTypeObject *pysqlite_StatementType = NULL; -int -pysqlite_statement_setup_types(PyObject *module) +extern int pysqlite_statement_setup_types(PyObject *module) { pysqlite_StatementType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &stmt_spec, NULL); if (pysqlite_StatementType == NULL) { diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c index 2ffba443e56557..1dbabcdd94a811 100644 --- a/Modules/_sqlite/util.c +++ b/Modules/_sqlite/util.c @@ -24,8 +24,7 @@ #include "module.h" #include "connection.h" -int -pysqlite_step(sqlite3_stmt *statement, pysqlite_Connection *connection) +int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection) { int rc; @@ -46,8 +45,7 @@ pysqlite_step(sqlite3_stmt *statement, pysqlite_Connection *connection) * Checks the SQLite error code and sets the appropriate DB-API exception. * Returns the error code (0 means no error occurred). */ -int -_pysqlite_seterror(sqlite3 *db, sqlite3_stmt *st) +int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st) { int errorcode = sqlite3_errcode(db); @@ -106,7 +104,7 @@ _pysqlite_seterror(sqlite3 *db, sqlite3_stmt *st) #endif sqlite_int64 -_pysqlite_long_as_int64(PyObject *py_val) +_pysqlite_long_as_int64(PyObject * py_val) { int overflow; long long value = PyLong_AsLongLongAndOverflow(py_val, &overflow); From 1c63733743099dd6781b963843cc84c7f28a5ee7 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 20 Feb 2021 23:38:32 +0100 Subject: [PATCH 5/8] Revert _pysqlite_step_callback --- Modules/_sqlite/connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index ac4f6f0901af75..075dae793b6c93 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -643,7 +643,7 @@ _pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv PyGILState_Release(threadstate); } -static void _pysqlite_step_callback(sqlite3_context* context, int argc, sqlite3_value** params) +static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params) { PyObject* args; PyObject* function_result = NULL; From 8487b88f07c4f2201ec5a5dd38a1de3952b38df9 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 20 Feb 2021 23:39:28 +0100 Subject: [PATCH 6/8] Really revert _authorizer_callback --- Modules/_sqlite/connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 075dae793b6c93..aedd80e51d46c7 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -920,7 +920,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self, 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) +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; From e97517faefff6216804c5e14102a854605131c67 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 20 Feb 2021 23:40:12 +0100 Subject: [PATCH 7/8] Revert pysqlite_connection_set_isolation_level --- Modules/_sqlite/connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index aedd80e51d46c7..34ba29be3497f0 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1243,7 +1243,8 @@ static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* sel Py_RETURN_FALSE; } -static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored)) +static int +pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored)) { if (isolation_level == NULL) { PyErr_SetString(PyExc_AttributeError, "cannot delete attribute"); From 03ca40ab20c32a881396762c415017f2f711723f Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 20 Feb 2021 23:42:42 +0100 Subject: [PATCH 8/8] Restore pysqlite_cursor_setup_types --- Modules/_sqlite/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 4f982c94404d4b..9058aabb5fc067 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -1017,7 +1017,7 @@ static PyType_Spec cursor_spec = { PyTypeObject *pysqlite_CursorType = NULL; -extern int pysqlite_cursor_setup_types(PyObject* module) +extern int pysqlite_cursor_setup_types(PyObject *module) { pysqlite_CursorType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &cursor_spec, NULL); if (pysqlite_CursorType == NULL) {