Skip to content

Commit 3ab8f5b

Browse files
committed
modules: silence warnings about unused params
_unused_ is used for 'self' wherever the function does not use self. assert(!args) is added in the places where METH_NOARGS is used. assert(self) is added in a few places where self _is_ used.
1 parent 628319c commit 3ab8f5b

File tree

6 files changed

+118
-35
lines changed

6 files changed

+118
-35
lines changed

src/systemd/_daemon.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ PyDoc_STRVAR(booted__doc__,
3535
"Wraps sd_booted(3)."
3636
);
3737

38-
static PyObject* booted(PyObject *self, PyObject *args) {
38+
static PyObject* booted(PyObject *self _unused_, PyObject *args) {
3939
int r;
40+
4041
assert(!args);
4142

4243
r = sd_booted();
@@ -55,7 +56,7 @@ PyDoc_STRVAR(notify__doc__,
5556
"Send a message to the init system about a status change.\n"
5657
"Wraps sd_notify(3).");
5758

58-
static PyObject* notify(PyObject *self, PyObject *args, PyObject *keywds) {
59+
static PyObject* notify(PyObject *self _unused_, PyObject *args, PyObject *keywds) {
5960
int r;
6061
const char* msg;
6162
int unset = false, n_fds;
@@ -142,7 +143,7 @@ PyDoc_STRVAR(listen_fds__doc__,
142143
"Wraps sd_listen_fds(3)."
143144
);
144145

145-
static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
146+
static PyObject* listen_fds(PyObject *self _unused_, PyObject *args, PyObject *keywds) {
146147
int r;
147148
int unset = true;
148149

@@ -176,7 +177,8 @@ static void free_names(char **names) {
176177
free(*n);
177178
free(names);
178179
}
179-
static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject *keywds) {
180+
181+
static PyObject* listen_fds_with_names(PyObject *self _unused_, PyObject *args, PyObject *keywds) {
180182
int r;
181183
int unset = false;
182184
char **names = NULL;
@@ -228,7 +230,7 @@ PyDoc_STRVAR(is_fifo__doc__,
228230
);
229231

230232

231-
static PyObject* is_fifo(PyObject *self, PyObject *args) {
233+
static PyObject* is_fifo(PyObject *self _unused_, PyObject *args) {
232234
int r;
233235
int fd;
234236
const char *path = NULL;
@@ -254,7 +256,7 @@ PyDoc_STRVAR(is_mq__doc__,
254256
"Wraps sd_is_mq(3)."
255257
);
256258

257-
static PyObject* is_mq(PyObject *self, PyObject *args) {
259+
static PyObject* is_mq(PyObject *self _unused_, PyObject *args) {
258260
int r;
259261
int fd;
260262
const char *path = NULL;
@@ -282,7 +284,7 @@ PyDoc_STRVAR(is_socket__doc__,
282284
"Constants for `family` are defined in the socket module."
283285
);
284286

285-
static PyObject* is_socket(PyObject *self, PyObject *args) {
287+
static PyObject* is_socket(PyObject *self _unused_, PyObject *args) {
286288
int r;
287289
int fd, family = AF_UNSPEC, type = 0, listening = -1;
288290

@@ -304,7 +306,7 @@ PyDoc_STRVAR(is_socket_inet__doc__,
304306
"Constants for `family` are defined in the socket module."
305307
);
306308

307-
static PyObject* is_socket_inet(PyObject *self, PyObject *args) {
309+
static PyObject* is_socket_inet(PyObject *self _unused_, PyObject *args) {
308310
int r;
309311
int fd, family = AF_UNSPEC, type = 0, listening = -1, port = 0;
310312

@@ -337,7 +339,7 @@ PyDoc_STRVAR(is_socket_sockaddr__doc__,
337339
#endif
338340
);
339341

340-
static PyObject* is_socket_sockaddr(PyObject *self, PyObject *args) {
342+
static PyObject* is_socket_sockaddr(PyObject *self _unused_, PyObject *args) {
341343
int r;
342344
int fd, type = 0, flowinfo = 0, listening = -1;
343345
const char *address;
@@ -384,7 +386,7 @@ PyDoc_STRVAR(is_socket_unix__doc__,
384386
"Wraps sd_is_socket_unix(3)."
385387
);
386388

387-
static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
389+
static PyObject* is_socket_unix(PyObject *self _unused_, PyObject *args) {
388390
int r;
389391
int fd, type = 0, listening = -1;
390392
char* path = NULL;

src/systemd/_journal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PyDoc_STRVAR(journal_sendv__doc__,
1414
"Send an entry to the journal."
1515
);
1616

17-
static PyObject *journal_sendv(PyObject *self, PyObject *args) {
17+
static PyObject* journal_sendv(PyObject *self _unused_, PyObject *args) {
1818
struct iovec *iov = NULL;
1919
int argc;
2020
int i, r;
@@ -71,7 +71,7 @@ PyDoc_STRVAR(journal_stream_fd__doc__,
7171
"Open a stream to journal by calling sd_journal_stream_fd(3)."
7272
);
7373

74-
static PyObject* journal_stream_fd(PyObject *self, PyObject *args) {
74+
static PyObject* journal_stream_fd(PyObject *self _unused_, PyObject *args) {
7575
const char* identifier;
7676
int priority, level_prefix;
7777
int fd;

src/systemd/_reader.c

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ PyDoc_STRVAR(Reader_fileno__doc__,
337337
static PyObject* Reader_fileno(Reader *self, PyObject *args) {
338338
int fd;
339339

340+
assert(self);
341+
assert(!args);
342+
340343
fd = sd_journal_get_fd(self->j);
341344
set_error(fd, NULL, NULL);
342345
if (fd < 0)
@@ -352,6 +355,9 @@ PyDoc_STRVAR(Reader_reliable_fd__doc__,
352355
static PyObject* Reader_reliable_fd(Reader *self, PyObject *args) {
353356
int r;
354357

358+
assert(self);
359+
assert(!args);
360+
355361
r = sd_journal_reliable_fd(self->j);
356362
if (set_error(r, NULL, NULL) < 0)
357363
return NULL;
@@ -366,6 +372,9 @@ PyDoc_STRVAR(Reader_get_events__doc__,
366372
static PyObject* Reader_get_events(Reader *self, PyObject *args) {
367373
int r;
368374

375+
assert(self);
376+
assert(!args);
377+
369378
r = sd_journal_get_events(self->j);
370379
if (set_error(r, NULL, NULL) < 0)
371380
return NULL;
@@ -384,6 +393,9 @@ static PyObject* Reader_get_timeout(Reader *self, PyObject *args) {
384393
int r;
385394
uint64_t t;
386395

396+
assert(self);
397+
assert(!args);
398+
387399
r = sd_journal_get_timeout(self->j, &t);
388400
if (set_error(r, NULL, NULL) < 0)
389401
return NULL;
@@ -404,6 +416,9 @@ static PyObject* Reader_get_timeout_ms(Reader *self, PyObject *args) {
404416
int r;
405417
uint64_t t;
406418

419+
assert(self);
420+
assert(!args);
421+
407422
r = sd_journal_get_timeout(self->j, &t);
408423
if (set_error(r, NULL, NULL) < 0)
409424
return NULL;
@@ -438,6 +453,9 @@ static PyObject* Reader_get_usage(Reader *self, PyObject *args) {
438453
int r;
439454
uint64_t bytes;
440455

456+
assert(self);
457+
assert(!args);
458+
441459
r = sd_journal_get_usage(self->j, &bytes);
442460
if (set_error(r, NULL, NULL) < 0)
443461
return NULL;
@@ -462,7 +480,9 @@ PyDoc_STRVAR(Reader___exit____doc__,
462480
"__exit__(type, value, traceback) -> None\n\n"
463481
"Part of the context manager protocol.\n"
464482
"Closes the journal.\n");
465-
static PyObject* Reader___exit__(Reader *self, PyObject *args) {
483+
static PyObject* Reader___exit__(Reader *self, PyObject *args _unused_) {
484+
assert(self);
485+
466486
return Reader_close(self, NULL);
467487
}
468488

@@ -475,6 +495,8 @@ static PyObject* Reader_next(Reader *self, PyObject *args) {
475495
int64_t skip = 1LL;
476496
int r = -EUCLEAN;
477497

498+
assert(self);
499+
478500
if (!PyArg_ParseTuple(args, "|L:next", &skip))
479501
return NULL;
480502

@@ -590,6 +612,9 @@ static PyObject* Reader_get_all(Reader *self, PyObject *args) {
590612
size_t msg_len;
591613
int r;
592614

615+
assert(self);
616+
assert(!args);
617+
593618
dict = PyDict_New();
594619
if (!dict)
595620
return NULL;
@@ -706,6 +731,7 @@ static PyObject* Reader_add_match(Reader *self, PyObject *args, PyObject *keywds
706731
char *match;
707732
Py_ssize_t match_len;
708733
int r;
734+
709735
if (!PyArg_ParseTuple(args, "s#:add_match", &match, &match_len))
710736
return NULL;
711737

@@ -729,6 +755,10 @@ PyDoc_STRVAR(Reader_add_disjunction__doc__,
729755
"See :manpage:`sd_journal_add_disjunction(3)` for explanation.");
730756
static PyObject* Reader_add_disjunction(Reader *self, PyObject *args) {
731757
int r;
758+
759+
assert(self);
760+
assert(!args);
761+
732762
r = sd_journal_add_disjunction(self->j);
733763
if (set_error(r, NULL, NULL) < 0)
734764
return NULL;
@@ -743,6 +773,10 @@ PyDoc_STRVAR(Reader_add_conjunction__doc__,
743773
"See :manpage:`sd_journal_add_disjunction(3)` for explanation.");
744774
static PyObject* Reader_add_conjunction(Reader *self, PyObject *args) {
745775
int r;
776+
777+
assert(self);
778+
assert(!args);
779+
746780
r = sd_journal_add_conjunction(self->j);
747781
if (set_error(r, NULL, NULL) < 0)
748782
return NULL;
@@ -753,6 +787,9 @@ PyDoc_STRVAR(Reader_flush_matches__doc__,
753787
"flush_matches() -> None\n\n"
754788
"Clear all current match filters.");
755789
static PyObject* Reader_flush_matches(Reader *self, PyObject *args) {
790+
assert(self);
791+
assert(!args);
792+
756793
sd_journal_flush_matches(self->j);
757794
Py_RETURN_NONE;
758795
}
@@ -764,6 +801,10 @@ PyDoc_STRVAR(Reader_seek_head__doc__,
764801
"See :manpage:`sd_journal_seek_head(3)`.");
765802
static PyObject* Reader_seek_head(Reader *self, PyObject *args) {
766803
int r;
804+
805+
assert(self);
806+
assert(!args);
807+
767808
Py_BEGIN_ALLOW_THREADS
768809
r = sd_journal_seek_head(self->j);
769810
Py_END_ALLOW_THREADS
@@ -782,6 +823,9 @@ PyDoc_STRVAR(Reader_seek_tail__doc__,
782823
static PyObject* Reader_seek_tail(Reader *self, PyObject *args) {
783824
int r;
784825

826+
assert(self);
827+
assert(!args);
828+
785829
Py_BEGIN_ALLOW_THREADS
786830
r = sd_journal_seek_tail(self->j);
787831
Py_END_ALLOW_THREADS
@@ -799,6 +843,8 @@ static PyObject* Reader_seek_realtime(Reader *self, PyObject *args) {
799843
uint64_t timestamp;
800844
int r;
801845

846+
assert(self);
847+
802848
if (!PyArg_ParseTuple(args, "K:seek_realtime", &timestamp))
803849
return NULL;
804850

@@ -824,6 +870,8 @@ static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args) {
824870
sd_id128_t id;
825871
int r;
826872

873+
assert(self);
874+
827875
if (!PyArg_ParseTuple(args, "K|z:seek_monotonic", &timestamp, &bootid))
828876
return NULL;
829877

@@ -1061,6 +1109,9 @@ PyDoc_STRVAR(Reader_enumerate_fields__doc__,
10611109
"Return a set of field names appearing in the journal.\n"
10621110
"See sd_journal_enumerate_fields(3).");
10631111
static PyObject* Reader_enumerate_fields(Reader *self, PyObject *args) {
1112+
assert(self);
1113+
assert(!args);
1114+
10641115
#if HAVE_ENUMERATE_FIELDS
10651116
_cleanup_Py_DECREF_ PyObject *_value_set = NULL;
10661117
PyObject *value_set;
@@ -1103,6 +1154,9 @@ PyDoc_STRVAR(Reader_has_runtime_files__doc__,
11031154
"Returns true if runtime journal files have been found.\n\n"
11041155
"See :manpage:`sd_journal_test_cursor(3)`.");
11051156
static PyObject* Reader_has_runtime_files(Reader *self, PyObject *args) {
1157+
assert(self);
1158+
assert(!args);
1159+
11061160
#if HAVE_ENUMERATE_FIELDS
11071161
int r;
11081162

@@ -1124,6 +1178,9 @@ PyDoc_STRVAR(Reader_has_persistent_files__doc__,
11241178
"Returns true if persistent journal files have been found.\n\n"
11251179
"See :manpage:`sd_journal_test_cursor(3)`.");
11261180
static PyObject* Reader_has_persistent_files(Reader *self, PyObject *args) {
1181+
assert(self);
1182+
assert(!args);
1183+
11271184
#if HAVE_ENUMERATE_FIELDS
11281185
int r;
11291186

@@ -1185,7 +1242,7 @@ PyDoc_STRVAR(get_catalog__doc__,
11851242
"get_catalog(id128) -> str\n\n"
11861243
"Retrieve a message catalog entry for the given id.\n"
11871244
"Wraps :manpage:`sd_journal_get_catalog_for_message_id(3)`.");
1188-
static PyObject* get_catalog(PyObject *self, PyObject *args) {
1245+
static PyObject* get_catalog(PyObject *self _unused_, PyObject *args) {
11891246
int r;
11901247
char *id_ = NULL;
11911248
sd_id128_t id;
@@ -1215,20 +1272,24 @@ PyDoc_STRVAR(data_threshold__doc__,
12151272
"Fields longer than this will be truncated to the threshold size.\n"
12161273
"Defaults to 64Kb.");
12171274

1218-
static PyObject* Reader_get_data_threshold(Reader *self, void *closure) {
1275+
static PyObject* Reader_get_data_threshold(Reader *self, void *closure _unused_) {
12191276
size_t cvalue;
12201277
int r;
12211278

1279+
assert(self);
1280+
12221281
r = sd_journal_get_data_threshold(self->j, &cvalue);
12231282
if (set_error(r, NULL, NULL) < 0)
12241283
return NULL;
12251284

12261285
return long_FromSize_t(cvalue);
12271286
}
12281287

1229-
static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closure) {
1288+
static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closure _unused_) {
12301289
int r;
12311290

1291+
assert(self);
1292+
12321293
if (!value) {
12331294
PyErr_SetString(PyExc_AttributeError, "Cannot delete data threshold");
12341295
return -1;
@@ -1245,7 +1306,9 @@ static int Reader_set_data_threshold(Reader *self, PyObject *value, void *closur
12451306

12461307
PyDoc_STRVAR(closed__doc__,
12471308
"True iff journal is closed");
1248-
static PyObject* Reader_get_closed(Reader *self, void *closure) {
1309+
static PyObject* Reader_get_closed(Reader *self, void *closure _unused_) {
1310+
assert(self);
1311+
12491312
return PyBool_FromLong(!self->j);
12501313
}
12511314

src/systemd/id128.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ static PyObject* make_uuid(sd_id128_t id) {
6969
return PyObject_Call(UUID, args, kwargs);
7070
}
7171

72-
#define helper(name) \
73-
static PyObject *name(PyObject *self, PyObject *args) { \
74-
sd_id128_t id; \
75-
int r; \
76-
\
77-
assert(!args); \
78-
\
79-
r = sd_id128_##name(&id); \
80-
if (r < 0) { \
81-
errno = -r; \
82-
return PyErr_SetFromErrno(PyExc_IOError); \
83-
} \
84-
\
85-
return make_uuid(id); \
72+
#define helper(name) \
73+
static PyObject *name(PyObject *self _unused_, PyObject *args) { \
74+
sd_id128_t id; \
75+
int r; \
76+
\
77+
assert(!args); \
78+
\
79+
r = sd_id128_##name(&id); \
80+
if (r < 0) { \
81+
errno = -r; \
82+
return PyErr_SetFromErrno(PyExc_IOError); \
83+
} \
84+
\
85+
return make_uuid(id); \
8686
}
8787

8888
helper(randomize)
8989
helper(get_machine)
9090
helper(get_boot)
9191

92-
static PyObject *get_machine_app_specific(PyObject *self, PyObject *args) {
92+
static PyObject *get_machine_app_specific(PyObject *self _unused_, PyObject *args) {
9393
_cleanup_Py_DECREF_ PyObject *uuid_bytes = NULL;
9494

9595
uuid_bytes = PyObject_GetAttrString(args, "bytes");

0 commit comments

Comments
 (0)