From 6acccf096e72e85c9d1a4c9813044ade7e285ee9 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 20 Nov 2025 20:56:34 +0000 Subject: [PATCH] python: Include first Python is broken and requires that we include before all other headers so it can make inadvisable definitions of _POSIX_C_SOURCE and other things. This wasn't a problem before, but a recent change to glibc makes this necessary now. See also a similar commit in nbdkit: https://gitlab.com/nbdkit/nbdkit/-/commit/f924c3c34be8352070b99c7b02fd200088b2a885 I also removed the -Wcast-align suppression as that is no longer needed. (cherry picked from commit 18d9769dc32fe65867ff904db7636b1255f8d59c) --- generator/python.ml | 19 ++++++++++++------- python/handle.c | 4 ++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/generator/python.ml b/generator/python.ml index 86b70b2de..06728235f 100644 --- a/generator/python.ml +++ b/generator/python.ml @@ -44,13 +44,6 @@ let rec generate_python_actions_h () = #include \"guestfs.h\" #include \"guestfs-stringlists-utils.h\" -#define PY_SSIZE_T_CLEAN 1 - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored \"-Wcast-align\" -#include -#pragma GCC diagnostic pop - static inline guestfs_h * get_handle (PyObject *obj) { @@ -119,6 +112,10 @@ and generate_python_structs () = generate_header CStyle LGPLv2plus; pr "\ +/* This must be included first. */ +#define PY_SSIZE_T_CLEAN 1 +#include + #include #include @@ -255,6 +252,10 @@ and generate_python_actions actions () = generate_header CStyle LGPLv2plus; pr "\ +/* This must be included first. */ +#define PY_SSIZE_T_CLEAN 1 +#include + #include /* It is safe to call deprecated functions from this file. */ @@ -527,6 +528,10 @@ and generate_python_module () = generate_header CStyle LGPLv2plus; pr "\ +/* This must be included first. */ +#define PY_SSIZE_T_CLEAN 1 +#include + #include #include diff --git a/python/handle.c b/python/handle.c index fcfcb5c30..9b1d01f5a 100644 --- a/python/handle.c +++ b/python/handle.c @@ -22,6 +22,10 @@ * F). */ +/* This must be included first. */ +#define PY_SSIZE_T_CLEAN 1 +#include + #include #include