Skip to content

Commit 0a9d214

Browse files
author
Erlend E. Aasland
committed
Further normalising:
- all callbacks are now named xxx_callback - normalise callable naming in set_*() functions - normalise context argument naming in callbacks
1 parent 966f0f4 commit 0a9d214

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

Modules/_sqlite/clinic/connection.c.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
321321

322322
static PyObject *
323323
pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
324-
PyObject *authorizer_cb);
324+
PyObject *callable);
325325

326326
static PyObject *
327327
pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -330,14 +330,14 @@ pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyObject *const *a
330330
static const char * const _keywords[] = {"authorizer_callback", NULL};
331331
static _PyArg_Parser _parser = {NULL, _keywords, "set_authorizer", 0};
332332
PyObject *argsbuf[1];
333-
PyObject *authorizer_cb;
333+
PyObject *callable;
334334

335335
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
336336
if (!args) {
337337
goto exit;
338338
}
339-
authorizer_cb = args[0];
340-
return_value = pysqlite_connection_set_authorizer_impl(self, authorizer_cb);
339+
callable = args[0];
340+
return_value = pysqlite_connection_set_authorizer_impl(self, callable);
341341

342342
exit:
343343
return return_value;
@@ -354,8 +354,7 @@ PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
354354

355355
static PyObject *
356356
pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
357-
PyObject *progress_handler,
358-
int n);
357+
PyObject *callable, int n);
359358

360359
static PyObject *
361360
pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -364,19 +363,19 @@ pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyObject *co
364363
static const char * const _keywords[] = {"progress_handler", "n", NULL};
365364
static _PyArg_Parser _parser = {NULL, _keywords, "set_progress_handler", 0};
366365
PyObject *argsbuf[2];
367-
PyObject *progress_handler;
366+
PyObject *callable;
368367
int n;
369368

370369
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
371370
if (!args) {
372371
goto exit;
373372
}
374-
progress_handler = args[0];
373+
callable = args[0];
375374
n = _PyLong_AsInt(args[1]);
376375
if (n == -1 && PyErr_Occurred()) {
377376
goto exit;
378377
}
379-
return_value = pysqlite_connection_set_progress_handler_impl(self, progress_handler, n);
378+
return_value = pysqlite_connection_set_progress_handler_impl(self, callable, n);
380379

381380
exit:
382381
return return_value;
@@ -395,7 +394,7 @@ PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
395394

396395
static PyObject *
397396
pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
398-
PyObject *trace_callback);
397+
PyObject *callable);
399398

400399
static PyObject *
401400
pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -404,14 +403,14 @@ pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyObject *cons
404403
static const char * const _keywords[] = {"trace_callback", NULL};
405404
static _PyArg_Parser _parser = {NULL, _keywords, "set_trace_callback", 0};
406405
PyObject *argsbuf[1];
407-
PyObject *trace_callback;
406+
PyObject *callable;
408407

409408
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
410409
if (!args) {
411410
goto exit;
412411
}
413-
trace_callback = args[0];
414-
return_value = pysqlite_connection_set_trace_callback_impl(self, trace_callback);
412+
callable = args[0];
413+
return_value = pysqlite_connection_set_trace_callback_impl(self, callable);
415414

416415
exit:
417416
return return_value;
@@ -817,4 +816,4 @@ pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ss
817816
#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
818817
#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
819818
#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
820-
/*[clinic end generated code: output=a7a899c4e41381ac input=a9049054013a1b77]*/
819+
/*[clinic end generated code: output=9c0dfc6c1ebf9039 input=a9049054013a1b77]*/

Modules/_sqlite/connection.c

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ _pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv
654654
PyGILState_Release(threadstate);
655655
}
656656

657-
static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
657+
static void
658+
step_callback(sqlite3_context *context, int argc, sqlite3_value **params)
658659
{
659660
PyGILState_STATE threadstate = PyGILState_Ensure();
660661

@@ -702,7 +703,7 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_
702703
}
703704

704705
static void
705-
_pysqlite_final_callback(sqlite3_context *context)
706+
final_callback(sqlite3_context *context)
706707
{
707708
PyGILState_STATE threadstate = PyGILState_Ensure();
708709

@@ -897,8 +898,8 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
897898
}
898899
rc = sqlite3_create_function_v2(self->db, name, n_arg, SQLITE_UTF8, ctx,
899900
0,
900-
&_pysqlite_step_callback,
901-
&_pysqlite_final_callback,
901+
&step_callback,
902+
&final_callback,
902903
&destructor_callback); // will decref func
903904
if (rc != SQLITE_OK) {
904905
/* Workaround for SQLite bug: no error code or string is available here */
@@ -908,14 +909,18 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
908909
Py_RETURN_NONE;
909910
}
910911

911-
static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
912+
static int
913+
authorizer_callback(void *ctx, int action, const char *arg1,
914+
const char *arg2 , const char *dbname,
915+
const char *access_attempt_source)
912916
{
913917
PyGILState_STATE gilstate = PyGILState_Ensure();
914918

915919
PyObject *ret;
916920
int rc;
917921

918-
ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
922+
ret = PyObject_CallFunction((PyObject*)ctx, "issss", action, arg1, arg2,
923+
dbname, access_attempt_source);
919924

920925
if (ret == NULL) {
921926
pysqlite_state *state = pysqlite_get_state(NULL);
@@ -953,13 +958,13 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co
953958
}
954959

955960
static int
956-
progress_callback(void *user_arg)
961+
progress_callback(void *ctx)
957962
{
958963
PyGILState_STATE gilstate = PyGILState_Ensure();
959964

960965
int rc;
961966
PyObject *ret;
962-
ret = _PyObject_CallNoArg((PyObject*)user_arg);
967+
ret = _PyObject_CallNoArg((PyObject*)ctx);
963968

964969
if (!ret) {
965970
/* abort query if error occurred */
@@ -990,9 +995,12 @@ progress_callback(void *user_arg)
990995
* may change in future releases. Callback implementations should return zero
991996
* to ensure future compatibility.
992997
*/
993-
static int _trace_callback(unsigned int type, void* user_arg, void* prepared_statement, void* statement_string)
998+
static int
999+
trace_callback(unsigned int type, void *ctx, void *prepared_statement,
1000+
void *statement_string)
9941001
#else
995-
static void _trace_callback(void* user_arg, const char* statement_string)
1002+
static void
1003+
trace_callback(void *ctx, const char *statement_string)
9961004
#endif
9971005
{
9981006
#ifdef HAVE_TRACE_V2
@@ -1008,7 +1016,7 @@ static void _trace_callback(void* user_arg, const char* statement_string)
10081016
py_statement = PyUnicode_DecodeUTF8(statement_string,
10091017
strlen(statement_string), "replace");
10101018
if (py_statement) {
1011-
ret = PyObject_CallOneArg((PyObject*)user_arg, py_statement);
1019+
ret = PyObject_CallOneArg((PyObject*)ctx, py_statement);
10121020
Py_DECREF(py_statement);
10131021
}
10141022

@@ -1033,29 +1041,29 @@ static void _trace_callback(void* user_arg, const char* statement_string)
10331041
/*[clinic input]
10341042
_sqlite3.Connection.set_authorizer as pysqlite_connection_set_authorizer
10351043
1036-
authorizer_callback as authorizer_cb: object
1044+
authorizer_callback as callable: object
10371045
10381046
Sets authorizer callback. Non-standard.
10391047
[clinic start generated code]*/
10401048

10411049
static PyObject *
10421050
pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
1043-
PyObject *authorizer_cb)
1044-
/*[clinic end generated code: output=f18ba575d788b35c input=df079724c020d2f2]*/
1051+
PyObject *callable)
1052+
/*[clinic end generated code: output=c193601e9e8a5116 input=ec104f130b82050b]*/
10451053
{
10461054
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
10471055
return NULL;
10481056
}
10491057

10501058
int rc;
1051-
if (authorizer_cb == Py_None) {
1059+
if (callable == Py_None) {
10521060
rc = sqlite3_set_authorizer(self->db, NULL, NULL);
10531061
Py_XSETREF(self->function_pinboard_authorizer_cb, NULL);
10541062
}
10551063
else {
1056-
Py_INCREF(authorizer_cb);
1057-
Py_XSETREF(self->function_pinboard_authorizer_cb, authorizer_cb);
1058-
rc = sqlite3_set_authorizer(self->db, _authorizer_callback, authorizer_cb);
1064+
Py_INCREF(callable);
1065+
Py_XSETREF(self->function_pinboard_authorizer_cb, callable);
1066+
rc = sqlite3_set_authorizer(self->db, authorizer_callback, callable);
10591067
}
10601068
if (rc != SQLITE_OK) {
10611069
PyErr_SetString(self->OperationalError,
@@ -1069,38 +1077,37 @@ pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
10691077
/*[clinic input]
10701078
_sqlite3.Connection.set_progress_handler as pysqlite_connection_set_progress_handler
10711079
1072-
progress_handler: object
1080+
progress_handler as callable: object
10731081
n: int
10741082
10751083
Sets progress handler callback. Non-standard.
10761084
[clinic start generated code]*/
10771085

10781086
static PyObject *
10791087
pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
1080-
PyObject *progress_handler,
1081-
int n)
1082-
/*[clinic end generated code: output=35a7c10364cb1b04 input=857696c25f964c64]*/
1088+
PyObject *callable, int n)
1089+
/*[clinic end generated code: output=ba14008a483d7a53 input=3cf56d045f130a84]*/
10831090
{
10841091
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
10851092
return NULL;
10861093
}
10871094

1088-
if (progress_handler == Py_None) {
1095+
if (callable == Py_None) {
10891096
/* None clears the progress handler previously set */
10901097
sqlite3_progress_handler(self->db, 0, 0, (void*)0);
10911098
Py_XSETREF(self->function_pinboard_progress_handler, NULL);
10921099
} else {
1093-
sqlite3_progress_handler(self->db, n, progress_callback, progress_handler);
1094-
Py_INCREF(progress_handler);
1095-
Py_XSETREF(self->function_pinboard_progress_handler, progress_handler);
1100+
sqlite3_progress_handler(self->db, n, progress_callback, callable);
1101+
Py_INCREF(callable);
1102+
Py_XSETREF(self->function_pinboard_progress_handler, callable);
10961103
}
10971104
Py_RETURN_NONE;
10981105
}
10991106

11001107
/*[clinic input]
11011108
_sqlite3.Connection.set_trace_callback as pysqlite_connection_set_trace_callback
11021109
1103-
trace_callback: object
1110+
trace_callback as callable: object
11041111
11051112
Sets a trace callback called for each SQL statement (passed as unicode).
11061113
@@ -1109,14 +1116,14 @@ Non-standard.
11091116

11101117
static PyObject *
11111118
pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
1112-
PyObject *trace_callback)
1113-
/*[clinic end generated code: output=fb0e307b9924d454 input=56d60fd38d763679]*/
1119+
PyObject *callable)
1120+
/*[clinic end generated code: output=c9fd551e359165d3 input=d76eabbb633057bc]*/
11141121
{
11151122
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
11161123
return NULL;
11171124
}
11181125

1119-
if (trace_callback == Py_None) {
1126+
if (callable == Py_None) {
11201127
/*
11211128
* None clears the trace callback previously set
11221129
*
@@ -1132,12 +1139,12 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
11321139
Py_XSETREF(self->function_pinboard_trace_callback, NULL);
11331140
} else {
11341141
#ifdef HAVE_TRACE_V2
1135-
sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, _trace_callback, trace_callback);
1142+
sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, trace_callback, callable);
11361143
#else
1137-
sqlite3_trace(self->db, _trace_callback, trace_callback);
1144+
sqlite3_trace(self->db, trace_callback, callable);
11381145
#endif
1139-
Py_INCREF(trace_callback);
1140-
Py_XSETREF(self->function_pinboard_trace_callback, trace_callback);
1146+
Py_INCREF(callable);
1147+
Py_XSETREF(self->function_pinboard_trace_callback, callable);
11411148
}
11421149

11431150
Py_RETURN_NONE;

0 commit comments

Comments
 (0)