Skip to content

Conversation

@tpetazzoni
Copy link
Contributor

@tpetazzoni tpetazzoni commented Dec 7, 2025

Some termio operations are not actually usable on some architectures. For example, the TCGETA, TCSETA, TCSETAF and TCSETAW are defined with a reference to "struct termio" on alpha, hppa and sparc64, but "struct termio" is no longer defined since glibc 2.42, causing a build failure.

Instead of using those operations as soon as they are defined, this commit checks more carefully that they are actually usable. This is done using a new m4 macro PY_CHECK_IOCTL.

Some termio operations are not actually usable on some
architectures. For example, the TCGETA, TCSETA, TCSETAF and TCSETAW
are defined with a reference to "struct termio" on alpha, hppa and
sparc64, but "struct termio" is no longer defined since glibc 2.42,
causing a build failure.

Instead of using those operations as soon as they are defined, this
commit checks more carefully that they are actually usable. This is
done using a new m4 macro PY_CHECK_IOCTL.

Signed-off-by: Thomas Petazzoni <[email protected]>
{"TCFLSH", TCFLSH},
#endif
#ifdef TCGETA
#if defined(HAVE_TCGETA)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ifdef HAVE_TCGETA

Comment on lines +98 to +116
dnl PY_CHECK_IOCTL(IOCTL_SYMBOL)
AC_DEFUN([PY_CHECK_IOCTL],
[
AC_MSG_CHECKING([for $1])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <sys/ioctl.h>]],
[[
/* Test whether $1 is declared */
long val = $1;
return 0;
]]
)],
[AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_$1], [1],
[Define this if $1 termio operation is usable])],
[AC_MSG_RESULT([no])]
)
])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a generic function instead? it's useful for checking the presence of a macro. Make the includes and the expected macro type parameters of that function, as well as the name of your HAVE_ macro as you did. This could be useful elsewhere.

Ina ddition, there is no need for the return 0; as it's implicit. Also remove `/* Test whether $1 is declared */ because it's trivial what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback @picnixz. Actually such a generic macro already "exists" to some degree, it's AC_CHECK_DECL. However, we can't use it in our specific case because what AC_CHECK_DECL does is:

#ifndef YOUR_DECLARATION
(void) YOUR_DECLARATION;
#endif 

The idea being: the #ifndef test if it is a macro => if it is, then fine, we're good. If it's not a macro, it checks if it's a valid r-value.

In our case, TCGETA is a macro, BUT we need to check that it is actually usable, not just "defined". And that's why AC_CHECK_DECL doesn't do the trick.

If you still think a generic macro would be good, what name should it have? Indeed, PY_CHECK_DECL would be very confusing if it has this subtle difference with AC_CHECK_DECL. Or maybe PY_CHECK_USABLE_DECL ?

And of course, our macro isn't as generic as AC_CHECK_DECL, because if the declaration exists but has no value (like #define FOO), then our test will fail.

Copy link
Member

@picnixz picnixz Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was actually different. What I wanted to test is:

TYPE holder = $1;

where you specify TYPE (in your case it's long). And for the name, it would be PY_CHECK_CONSTANT. I wanted you to actually remove the comment but not the test itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes a lot of sense, will do!

kmk142789
kmk142789 previously approved these changes Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants