Skip to content

Commit 774e1d0

Browse files
committed
modules: modernize variable declarations
1 parent 28a90e8 commit 774e1d0

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

src/systemd/_journal.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@ PyDoc_STRVAR(journal_sendv__doc__,
1515
);
1616

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

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

2825
/* Allocate sufficient iovector space for the arguments. */
29-
iov = alloca(argc * sizeof(struct iovec));
26+
struct iovec *iov = alloca(argc * sizeof(struct iovec));
3027

3128
/* Iterate through the Python arguments and fill the iovector. */
32-
for (i = 0; i < argc; ++i) {
29+
for (int i = 0; i < argc; ++i) {
3330
PyObject *item = PyTuple_GetItem(args, i);
3431
char *stritem;
3532
Py_ssize_t length;
@@ -60,7 +57,7 @@ static PyObject* journal_sendv(PyObject *self _unused_, PyObject *args) {
6057
ret = Py_None;
6158

6259
out:
63-
for (i = 0; i < argc; ++i)
60+
for (int i = 0; i < argc; i++)
6461
Py_XDECREF(encoded[i]);
6562

6663
return ret;

src/systemd/_reader.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,20 @@ static int null_converter(PyObject* obj, void *_result) {
108108
*/
109109
static int strv_converter(PyObject* obj, void *_result) {
110110
char ***result = _result;
111-
Py_ssize_t i, len;
112111

113112
assert(result);
114113

115114
if (!PySequence_Check(obj))
116115
return 0;
117116

118-
len = PySequence_Length(obj);
117+
Py_ssize_t len = PySequence_Length(obj);
119118
*result = new0(char*, len + 1);
120119
if (!*result) {
121120
set_error(-ENOMEM, NULL, NULL);
122121
return 0;
123122
}
124123

125-
for (i = 0; i < len; i++) {
124+
for (Py_ssize_t i = 0; i < len; i++) {
126125
PyObject *item;
127126
_cleanup_Py_DECREF_ PyObject *bytes = NULL;
128127
char *s;
@@ -168,23 +167,21 @@ static int long_as_fd(PyObject *obj, int *fd) {
168167
* Convert a Python sequence object into an int array.
169168
*/
170169
static int intlist_converter(PyObject* obj, int **_result, size_t *_len) {
171-
_cleanup_free_ int *result = NULL;
172-
Py_ssize_t i, len;
173-
174170
assert(_result);
175171
assert(_len);
176172

177173
if (!PySequence_Check(obj))
178174
return 0;
179175

180-
len = PySequence_Length(obj);
181-
result = new0(int, len);
176+
Py_ssize_t len = PySequence_Length(obj);
177+
_cleanup_free_ int *result = new0(int, len);
178+
182179
if (!result) {
183180
set_error(-ENOMEM, NULL, NULL);
184181
return 0;
185182
}
186183

187-
for (i = 0; i < len; i++) {
184+
for (Py_ssize_t i = 0; i < len; i++) {
188185
PyObject *item;
189186
int fd;
190187

src/systemd/login.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ PyDoc_STRVAR(module__doc__,
1818
static PyObject* name(PyObject *self _unused_, PyObject *args) { \
1919
_cleanup_strv_free_ char **list = NULL; \
2020
int r; \
21-
PyObject *ans; \
2221
\
2322
assert(!args); \
2423
\
@@ -28,7 +27,7 @@ static PyObject* name(PyObject *self _unused_, PyObject *args) { \
2827
return PyErr_SetFromErrno(PyExc_IOError); \
2928
} \
3029
\
31-
ans = PyList_New(r); \
30+
PyObject *ans = PyList_New(r); \
3231
if (!ans) \
3332
return NULL; \
3433
\
@@ -53,7 +52,6 @@ helper(machine_names)
5352
static PyObject* uids(PyObject *self _unused_, PyObject *args) {
5453
_cleanup_free_ uid_t *list = NULL;
5554
int r;
56-
PyObject *ans;
5755

5856
assert(!args);
5957

@@ -63,7 +61,7 @@ static PyObject* uids(PyObject *self _unused_, PyObject *args) {
6361
return PyErr_SetFromErrno(PyExc_IOError);
6462
}
6563

66-
ans = PyList_New(r);
64+
PyObject *ans = PyList_New(r);
6765
if (!ans)
6866
return NULL;
6967

@@ -121,7 +119,7 @@ typedef struct {
121119
static PyTypeObject MonitorType;
122120

123121
static void Monitor_dealloc(Monitor* self) {
124-
sd_login_monitor_unref(self->monitor);
122+
self->monitor = sd_login_monitor_unref(self->monitor);
125123
Py_TYPE(self)->tp_free((PyObject*)self);
126124
}
127125

@@ -241,8 +239,7 @@ static PyObject* Monitor_close(Monitor *self, PyObject *args) {
241239
assert(self);
242240
assert(!args);
243241

244-
sd_login_monitor_unref(self->monitor);
245-
self->monitor = NULL;
242+
self->monitor = sd_login_monitor_unref(self->monitor);
246243
Py_RETURN_NONE;
247244
}
248245

0 commit comments

Comments
 (0)