Skip to content

Commit 9bd1a0a

Browse files
committed
modules: include Python.h from one place only, clean up includes
systemd headers should be included using <>. And use a single include of Python.h and define PY_SSIZE_T_CLEAN before it, so that we're using a consistent API everywhere.
1 parent 1cce39b commit 9bd1a0a

File tree

8 files changed

+15
-28
lines changed

8 files changed

+15
-28
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ python_dep = python.dependency()
1616
libsystemd_dep = dependency('libsystemd')
1717

1818
add_project_arguments(
19+
'-D_GNU_SOURCE=1',
1920
'-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
2021
'-DLIBSYSTEMD_VERSION=@0@'.format(libsystemd_dep.version()),
2122
language : 'c',

src/systemd/_journal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
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"

src/systemd/_reader.c

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

3-
#define PY_SSIZE_T_CLEAN
4-
#pragma GCC diagnostic push
5-
#pragma GCC diagnostic ignored "-Wredundant-decls"
6-
#include <Python.h>
7-
#pragma GCC diagnostic pop
8-
9-
#include <structmember.h>
10-
#include <datetime.h>
11-
#include <time.h>
12-
#include <stdio.h>
133
#include <stdbool.h>
14-
15-
#include "systemd/sd-journal.h"
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <time.h>
7+
#include <systemd/sd-journal.h>
168

179
#include "pyutil.h"
1810
#include "macro.h"
1911
#include "strv.h"
2012

13+
/* This needs to be below Python.h include for some reason */
14+
#include <datetime.h>
15+
2116
#if defined(LIBSYSTEMD_VERSION) || LIBSYSTEMD_JOURNAL_VERSION > 204
2217
# define HAVE_JOURNAL_OPEN_FILES 1
2318
#else

src/systemd/id128.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3-
#include <Python.h>
4-
53
/* Our include is first, so that our defines are replaced by the ones
64
* from the system header. If the system header has the same definitions
75
* (or does not have them at all), this replacement is silent. If the
@@ -12,8 +10,8 @@
1210
#include "id128-defines.h"
1311
#include <systemd/sd-messages.h>
1412

15-
#include "pyutil.h"
1613
#include "macro.h"
14+
#include "pyutil.h"
1715

1816
#define HAVE_SD_ID128_GET_MACHINE_APP_SPECIFIC (LIBSYSTEMD_VERSION >= 240)
1917

src/systemd/login.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3-
#define PY_SSIZE_T_CLEAN
4-
#pragma GCC diagnostic push
5-
#pragma GCC diagnostic ignored "-Wredundant-decls"
6-
#include <Python.h>
7-
#pragma GCC diagnostic pop
3+
#include <systemd/sd-login.h>
84

9-
#include "systemd/sd-login.h"
105
#include "pyutil.h"
116
#include "strv.h"
127

src/systemd/macro.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#pragma once
44

5+
#include <stdlib.h>
6+
57
#define DISABLE_WARNING_MISSING_PROTOTYPES \
68
_Pragma("GCC diagnostic push"); \
79
_Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"")

src/systemd/pyutil.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3-
#include <Python.h>
43
#include "pyutil.h"
54

65
void cleanup_Py_DECREFp(PyObject **p) {

src/systemd/pyutil.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
#pragma once
44

5-
#ifndef Py_TYPE
6-
/* avoid duplication warnings from errors in Python 2.7 headers */
7-
# include <Python.h>
8-
#endif
5+
#define PY_SSIZE_T_CLEAN
6+
#include <Python.h>
97

108
void cleanup_Py_DECREFp(PyObject **p);
119
PyObject* absolute_timeout(uint64_t t);

0 commit comments

Comments
 (0)