Skip to content

Commit 7ba29d0

Browse files
committed
configure.ac: detect unusable termio operations
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. Such a check cannot be done with the standard AC_CHECK_DECL() m4 macro, as this macro only checks that the #define exists, not that it is actually usable (i.e builds properly). Therefore, we introduce a PY_CHECK_CONSTANT() m4 macro, that verifies that the constant is actually usable. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
1 parent 58e1c7a commit 7ba29d0

File tree

5 files changed

+182
-4
lines changed

5 files changed

+182
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Some termio operations are not actually usable on some architectures. For
2+
example, the TCGETA, TCSETA, TCSETAF and TCSETAW are defined with a
3+
reference to "struct termio" on alpha, hppa and sparc64, but "struct termio"
4+
is no longer defined since glibc 2.42, causing a build failure.
5+
6+
Instead of using those operations as soon as they are defined, this commit
7+
checks more carefully that they are actually usable. This is done using a
8+
new m4 macro PY_CHECK_CONSTANT.

Modules/termios.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ static struct constant {
11161116
#ifdef TCFLSH
11171117
{"TCFLSH", TCFLSH},
11181118
#endif
1119-
#ifdef TCGETA
1119+
#if defined(HAVE_TCGETA)
11201120
{"TCGETA", TCGETA},
11211121
#endif
11221122
#ifdef TCGETS
@@ -1128,13 +1128,13 @@ static struct constant {
11281128
#ifdef TCSBRKP
11291129
{"TCSBRKP", TCSBRKP},
11301130
#endif
1131-
#ifdef TCSETA
1131+
#if defined(HAVE_TCSETA)
11321132
{"TCSETA", TCSETA},
11331133
#endif
1134-
#ifdef TCSETAF
1134+
#if defined(HAVE_TCSETAF)
11351135
{"TCSETAF", TCSETAF},
11361136
#endif
1137-
#ifdef TCSETAW
1137+
#if defined(HAVE_TCSETAW)
11381138
{"TCSETAW", TCSETAW},
11391139
#endif
11401140
#ifdef TCSETS

configure

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ AC_DEFUN([PY_CHECK_EMSCRIPTEN_PORT], [
9595
AS_VAR_POPDEF([py_libs])
9696
])
9797

98+
dnl PY_CHECK_CONSTANT(TYPE, CONSTANT, [INCLUDES])
99+
dnl Checks whether the constant exists and is actually usable (unlike
100+
dnl AC_CHECK_DECL that only checks if the constant exists)
101+
AC_DEFUN([PY_CHECK_CONSTANT],
102+
[
103+
AC_MSG_CHECKING([for $2])
104+
AC_COMPILE_IFELSE(
105+
[AC_LANG_PROGRAM(
106+
[$3],
107+
[[
108+
$1 val = $2;
109+
]]
110+
)],
111+
[AC_MSG_RESULT([yes])
112+
AC_DEFINE([HAVE_$2], [1],
113+
[Define this if $2 is usable])],
114+
[AC_MSG_RESULT([no])]
115+
)
116+
])
117+
98118
AC_SUBST([BASECPPFLAGS])
99119
if test "$srcdir" != . -a "$srcdir" != "$(pwd)"; then
100120
# If we're building out-of-tree, we need to make sure the following
@@ -8245,6 +8265,12 @@ AC_SUBST([JIT_STENCILS_H])
82458265
# substitute multiline block, must come after last PY_STDLIB_MOD()
82468266
AC_SUBST([MODULE_BLOCK])
82478267

8268+
# ioctls used by Modules/termios.c but not usable on all platforms
8269+
PY_CHECK_CONSTANT([long], [TCGETA], [#include <sys/ioctl.h>])
8270+
PY_CHECK_CONSTANT([long], [TCSETA], [#include <sys/ioctl.h>])
8271+
PY_CHECK_CONSTANT([long], [TCSETAF], [#include <sys/ioctl.h>])
8272+
PY_CHECK_CONSTANT([long], [TCSETAW], [#include <sys/ioctl.h>])
8273+
82488274
# generate output files
82498275
AC_CONFIG_FILES(m4_normalize([
82508276
Makefile.pre

pyconfig.h.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,9 +1524,21 @@
15241524
/* Define to 1 if you have the <sys/xattr.h> header file. */
15251525
#undef HAVE_SYS_XATTR_H
15261526

1527+
/* Define this if TCGETA is usable */
1528+
#undef HAVE_TCGETA
1529+
15271530
/* Define to 1 if you have the 'tcgetpgrp' function. */
15281531
#undef HAVE_TCGETPGRP
15291532

1533+
/* Define this if TCSETA is usable */
1534+
#undef HAVE_TCSETA
1535+
1536+
/* Define this if TCSETAF is usable */
1537+
#undef HAVE_TCSETAF
1538+
1539+
/* Define this if TCSETAW is usable */
1540+
#undef HAVE_TCSETAW
1541+
15301542
/* Define to 1 if you have the 'tcsetpgrp' function. */
15311543
#undef HAVE_TCSETPGRP
15321544

0 commit comments

Comments
 (0)