Skip to content

Commit 1afbdab

Browse files
authored
Merge pull request #160 from keszybz/modernize-code-and-silence-all-warnings
Modernize code and silence all warnings
2 parents 6396126 + 163a99a commit 1afbdab

File tree

13 files changed

+311
-254
lines changed

13 files changed

+311
-254
lines changed

meson.build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ python_dep = python.dependency()
1515

1616
libsystemd_dep = dependency('libsystemd')
1717

18-
common_c_args = [
18+
add_project_arguments(
19+
'-D_GNU_SOURCE=1',
1920
'-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
2021
'-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()),
21-
]
22+
language : 'c',
23+
)
2224

2325
update_constants_py = files('update-constants.py')
2426

src/systemd/_daemon.c

Lines changed: 27 additions & 23 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

@@ -155,7 +156,7 @@ static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
155156
if (set_error(r, NULL, NULL) < 0)
156157
return NULL;
157158

158-
return long_FromLong(r);
159+
return PyLong_FromLong(r);
159160
}
160161

161162
PyDoc_STRVAR(listen_fds_with_names__doc__,
@@ -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;
@@ -196,7 +198,7 @@ static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject
196198
if (tpl == NULL)
197199
return NULL;
198200

199-
item = long_FromLong(r);
201+
item = PyLong_FromLong(r);
200202
if (item == NULL) {
201203
Py_DECREF(tpl);
202204
return NULL;
@@ -206,7 +208,7 @@ static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject
206208
return NULL;
207209
}
208210
for (int i = 0; i < r && names[i] != NULL; i++) {
209-
item = unicode_FromString(names[i]);
211+
item = PyUnicode_FromString(names[i]);
210212
if (PyTuple_SetItem(tpl, 1+i, item) < 0) {
211213
Py_DECREF(tpl);
212214
free_names(names);
@@ -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;
@@ -408,20 +410,22 @@ static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
408410
}
409411

410412

413+
DISABLE_WARNING_CAST_FUNCTION_TYPE;
411414
static PyMethodDef methods[] = {
412-
{ "booted", booted, METH_NOARGS, booted__doc__},
413-
{ "notify", (PyCFunction) notify, METH_VARARGS | METH_KEYWORDS, notify__doc__},
414-
{ "_listen_fds", (PyCFunction) listen_fds, METH_VARARGS | METH_KEYWORDS, listen_fds__doc__},
415+
{ "booted", booted, METH_NOARGS, booted__doc__ },
416+
{ "notify", (PyCFunction) notify, METH_VARARGS | METH_KEYWORDS, notify__doc__ },
417+
{ "_listen_fds", (PyCFunction) listen_fds, METH_VARARGS | METH_KEYWORDS, listen_fds__doc__ },
415418
{ "_listen_fds_with_names", (PyCFunction) listen_fds_with_names,
416-
METH_VARARGS | METH_KEYWORDS, listen_fds_with_names__doc__},
417-
{ "_is_fifo", is_fifo, METH_VARARGS, is_fifo__doc__},
418-
{ "_is_mq", is_mq, METH_VARARGS, is_mq__doc__},
419-
{ "_is_socket", is_socket, METH_VARARGS, is_socket__doc__},
420-
{ "_is_socket_inet", is_socket_inet, METH_VARARGS, is_socket_inet__doc__},
421-
{ "_is_socket_sockaddr", is_socket_sockaddr, METH_VARARGS, is_socket_sockaddr__doc__},
422-
{ "_is_socket_unix", is_socket_unix, METH_VARARGS, is_socket_unix__doc__},
419+
METH_VARARGS | METH_KEYWORDS, listen_fds_with_names__doc__ },
420+
{ "_is_fifo", is_fifo, METH_VARARGS, is_fifo__doc__ },
421+
{ "_is_mq", is_mq, METH_VARARGS, is_mq__doc__ },
422+
{ "_is_socket", is_socket, METH_VARARGS, is_socket__doc__ },
423+
{ "_is_socket_inet", is_socket_inet, METH_VARARGS, is_socket_inet__doc__ },
424+
{ "_is_socket_sockaddr", is_socket_sockaddr, METH_VARARGS, is_socket_sockaddr__doc__ },
425+
{ "_is_socket_unix", is_socket_unix, METH_VARARGS, is_socket_unix__doc__ },
423426
{} /* Sentinel */
424427
};
428+
REENABLE_WARNING;
425429

426430
static struct PyModuleDef module = {
427431
PyModuleDef_HEAD_INIT,

src/systemd/_journal.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3-
#include <Python.h>
4-
53
#include <alloca.h>
64

75
#define SD_JOURNAL_SUPPRESS_LOCATION
86
#include "systemd/sd-journal.h"
97

108
#include "macro.h"
9+
#include "pyutil.h"
1110

1211
PyDoc_STRVAR(journal_sendv__doc__,
1312
"sendv('FIELD=value', 'FIELD=value', ...) -> None\n\n"
1413
"Send an entry to the journal."
1514
);
1615

17-
static PyObject *journal_sendv(PyObject *self, PyObject *args) {
18-
struct iovec *iov = NULL;
19-
int argc;
20-
int i, r;
16+
static PyObject* journal_sendv(PyObject *self _unused_, PyObject *args) {
2117
PyObject *ret = NULL;
22-
PyObject **encoded;
18+
int r;
2319

2420
/* Allocate an array for the argument strings */
25-
argc = PyTuple_Size(args);
26-
encoded = alloca0(argc * sizeof(PyObject*));
21+
int argc = PyTuple_Size(args);
22+
PyObject **encoded = alloca0(argc * sizeof(PyObject*));
2723

2824
/* Allocate sufficient iovector space for the arguments. */
29-
iov = alloca(argc * sizeof(struct iovec));
25+
struct iovec *iov = alloca(argc * sizeof(struct iovec));
3026

3127
/* Iterate through the Python arguments and fill the iovector. */
32-
for (i = 0; i < argc; ++i) {
28+
for (int i = 0; i < argc; ++i) {
3329
PyObject *item = PyTuple_GetItem(args, i);
3430
char *stritem;
3531
Py_ssize_t length;
@@ -51,7 +47,7 @@ static PyObject *journal_sendv(PyObject *self, PyObject *args) {
5147
r = sd_journal_sendv(iov, argc);
5248
if (r < 0) {
5349
errno = -r;
54-
PyErr_SetFromErrno(PyExc_IOError);
50+
PyErr_SetFromErrno(PyExc_OSError);
5551
goto out;
5652
}
5753

@@ -60,7 +56,7 @@ static PyObject *journal_sendv(PyObject *self, PyObject *args) {
6056
ret = Py_None;
6157

6258
out:
63-
for (i = 0; i < argc; ++i)
59+
for (int i = 0; i < argc; i++)
6460
Py_XDECREF(encoded[i]);
6561

6662
return ret;
@@ -71,7 +67,7 @@ PyDoc_STRVAR(journal_stream_fd__doc__,
7167
"Open a stream to journal by calling sd_journal_stream_fd(3)."
7268
);
7369

74-
static PyObject* journal_stream_fd(PyObject *self, PyObject *args) {
70+
static PyObject* journal_stream_fd(PyObject *self _unused_, PyObject *args) {
7571
const char* identifier;
7672
int priority, level_prefix;
7773
int fd;
@@ -83,14 +79,14 @@ static PyObject* journal_stream_fd(PyObject *self, PyObject *args) {
8379
fd = sd_journal_stream_fd(identifier, priority, level_prefix);
8480
if (fd < 0) {
8581
errno = -fd;
86-
return PyErr_SetFromErrno(PyExc_IOError);
82+
return PyErr_SetFromErrno(PyExc_OSError);
8783
}
8884

8985
return PyLong_FromLong(fd);
9086
}
9187

9288
static PyMethodDef methods[] = {
93-
{ "sendv", journal_sendv, METH_VARARGS, journal_sendv__doc__ },
89+
{ "sendv", journal_sendv, METH_VARARGS, journal_sendv__doc__ },
9490
{ "stream_fd", journal_stream_fd, METH_VARARGS, journal_stream_fd__doc__ },
9591
{} /* Sentinel */
9692
};

0 commit comments

Comments
 (0)