Skip to content

Commit d766640

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. This is done using a new m4 macro PY_CHECK_IOCTL. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
1 parent 58e1c7a commit d766640

File tree

5 files changed

+190
-4
lines changed

5 files changed

+190
-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_IOCTL.

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: 140 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_IOCTL(IOCTL_SYMBOL)
99+
AC_DEFUN([PY_CHECK_IOCTL],
100+
[
101+
AC_MSG_CHECKING([for $1])
102+
AC_COMPILE_IFELSE(
103+
[AC_LANG_PROGRAM(
104+
[[#include <sys/ioctl.h>]],
105+
[[
106+
/* Test whether $1 is declared */
107+
long val = $1;
108+
return 0;
109+
]]
110+
)],
111+
[AC_MSG_RESULT([yes])
112+
AC_DEFINE([HAVE_$1], [1],
113+
[Define this if $1 termio operation 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_IOCTL([TCGETA])
8270+
PY_CHECK_IOCTL([TCSETA])
8271+
PY_CHECK_IOCTL([TCSETAF])
8272+
PY_CHECK_IOCTL([TCSETAW])
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 termio operation 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 termio operation is usable */
1534+
#undef HAVE_TCSETA
1535+
1536+
/* Define this if TCSETAF termio operation is usable */
1537+
#undef HAVE_TCSETAF
1538+
1539+
/* Define this if TCSETAW termio operation 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)