Skip to content

Commit e528de6

Browse files
committed
pyutil: silence a warning caused by Python.h
There is no great solution. Python.h expects to be included first and to be allowed to pollute the define namespace. We don't want to do that, because in other places we want to include sd-messages.h early, and also we want to use a higher standard than the obsolete version that Python.h declares. Unfortunately, there is no nice solution to this problem. So call #undef enough times to silence warnings and after including the header, define the standard for our code to a recent version.
1 parent a5a6c86 commit e528de6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/systemd/pyutil.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
#pragma once
44

55
#define PY_SSIZE_T_CLEAN
6-
#include <Python.h>
6+
/* Work around bug in Python.h:
7+
* it tries to redefine defines already defined by /usr/include/features.h,
8+
* without calling #undef first, causing a warning to be emitted.
9+
* (https://github.com/python/cpython/issues/61322). */
10+
#undef _POSIX_C_SOURCE
11+
#undef _XOPEN_SOURCE
12+
# include <Python.h>
13+
#undef _POSIX_C_SOURCE
14+
#undef _XOPEN_SOURCE
15+
#define _XOPEN_SOURCE 800
16+
#define _POSIX_C_SOURCE 202405L
717

818
void cleanup_Py_DECREFp(PyObject **p);
919
PyObject* absolute_timeout(uint64_t t);

0 commit comments

Comments
 (0)