From a5a6c86b173327fe912de51b7b6b992b41919d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 18 Jun 2026 14:37:08 +0200 Subject: [PATCH 1/2] util: fix warning about const char* --- src/systemd/util.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/systemd/util.c b/src/systemd/util.c index 4fe41a9..0db9e27 100644 --- a/src/systemd/util.c +++ b/src/systemd/util.c @@ -94,19 +94,16 @@ static int assign_address(const char *s, int parse_sockaddr(const char *s, union sockaddr_union *addr, unsigned *addr_len) { - - char *e, *n; - unsigned u; int r; if (*s == '[') { /* IPv6 in [x:.....:z]:p notation */ - e = strchr(s+1, ']'); + const char *e = strchr(s + 1, ']'); if (!e) return -EINVAL; - n = strndupa(s+1, e-s-1); + char *n = strndupa(s+1, e-s-1); errno = 0; if (inet_pton(AF_INET6, n, &addr->in6.sin6_addr) <= 0) @@ -116,8 +113,9 @@ int parse_sockaddr(const char *s, if (*e) { if (*e != ':') return -EINVAL; - e++; + + unsigned u; r = safe_atou(e, &u); if (r < 0) return r; @@ -132,19 +130,21 @@ int parse_sockaddr(const char *s, *addr_len = sizeof(struct sockaddr_in6); } else { - e = strchr(s, ':'); + const char *e = strchr(s, ':'); if (e) { - r = safe_atou(e+1, &u); + unsigned u; + r = safe_atou(e + 1, &u); if (r < 0) return r; if (u <= 0 || u > 0xFFFF) return -EINVAL; - n = strndupa(s, e-s); + char *n = strndupa(s, e-s); return assign_address(n, u, addr, addr_len); } else { + unsigned u; r = safe_atou(s, &u); if (r < 0) return assign_address(s, 0, addr, addr_len); From e528de6c8942843aafd7288bdaa4b77d48868286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 18 Jun 2026 14:49:45 +0200 Subject: [PATCH 2/2] 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. --- src/systemd/pyutil.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/systemd/pyutil.h b/src/systemd/pyutil.h index 72e44ff..36ff6c0 100644 --- a/src/systemd/pyutil.h +++ b/src/systemd/pyutil.h @@ -3,7 +3,17 @@ #pragma once #define PY_SSIZE_T_CLEAN -#include +/* Work around bug in Python.h: + * it tries to redefine defines already defined by /usr/include/features.h, + * without calling #undef first, causing a warning to be emitted. + * (https://github.com/python/cpython/issues/61322). */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE +# include +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 800 +#define _POSIX_C_SOURCE 202405L void cleanup_Py_DECREFp(PyObject **p); PyObject* absolute_timeout(uint64_t t);