8000 gh-85283: Build termios extension with the limited C API (#116928) · python/cpython@1cf0301 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cf0301

Browse files
authored
gh-85283: Build termios extension with the limited C API (#116928)
1 parent 8e3c953 commit 1cf0301

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,8 @@ Build Changes
14791479
* Building CPython now requires a compiler with support for the C11 atomic
14801480
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.
14811481

1482-
* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``, ``winsound``,
1482+
* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``,
1483+
``termios``, ``winsound``,
14831484
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``,
14841485
``_testimportmultiple`` and ``_uuid`` C extensions are now built with the
14851486
:ref:`limited C API <limited-c-api>`.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
The ``fcntl``, ``grp`` and ``pwd`` C extensions are now built with the :ref:`limited
2-
C API <limited-c-api>`. (Contributed by Victor Stinner in :gh:`85283`.)
1+
The ``fcntl``, ``grp``, ``pwd`` and ``termios`` C extensions are now
2+
built with the :ref:`limited C API <limited-c-api>`. Patch by Victor Stinner.

Modules/clinic/termios.c.h

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

Modules/termios.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
/* termios.c -- POSIX terminal I/O module implementation. */
22

3-
#ifndef Py_BUILD_CORE_BUILTIN
4-
# define Py_BUILD_CORE_MODULE 1
3+
// Need limited C API version 3.13 for PyLong_AsInt()
4+
// in code generated by Argument Clinic.
5+
#include "pyconfig.h" // Py_GIL_DISABLED
6+
#ifndef Py_GIL_DISABLED
7+
# define Py_LIMITED_API 0x030d0000
58
#endif
69

710
#include "Python.h"
811

12+
#include <string.h> // memset()
13+
#include <sys/ioctl.h>
14+
#include <termios.h>
15+
#include <unistd.h> // _POSIX_VDISABLE
16+
917
// On QNX 6, struct termio must be declared by including sys/termio.h
1018
// if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
1119
// be included before termios.h or it will generate an error.
@@ -19,28 +27,26 @@
1927
# define CTRL(c) ((c)&037)
2028
#endif
2129

30+
// We could do better. Check bpo-32660
2231
#if defined(__sun)
23-
/* We could do better. Check issue-32660 */
24-
#include <sys/filio.h>
25-
#include <sys/sockio.h>
32+
# include <sys/filio.h>
33+
# include <sys/sockio.h>
2634
#endif
2735

28-
#include <termios.h>
29-
#include <sys/ioctl.h>
30-
#include <unistd.h> // _POSIX_VDISABLE
31-
3236
/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
3337
* MDTR, MRI, and MRTS (apparently used internally by some things
3438
* defined as macros; these are not used here directly).
3539
*/
3640
#ifdef HAVE_SYS_MODEM_H
37-
#include <sys/modem.h>
41+
# include <sys/modem.h>
3842
#endif
43+
3944
/* HP-UX requires that this be included to pick up TIOCGPGRP and friends */
4045
#ifdef HAVE_SYS_BSDTTY_H
41-
#include <sys/bsdtty.h>
46+
# include <sys/bsdtty.h>
4247
#endif
4348

49+
4450
/*[clinic input]
4551
module termios
4652
[clinic start generated code]*/
@@ -120,7 +126,7 @@ termios_tcgetattr_impl(PyObject *module, int fd)
120126
v = PyBytes_FromStringAndSize(&ch, 1);
121127
if (v == NULL)
122128
goto err;
123-
PyList_SET_ITEM(cc, i, v);
129+
PyList_SetItem(cc, i, v);
124130
}
125131

126132
/* Convert the MIN and TIME slots to integer. On some systems, the
@@ -154,7 +160,7 @@ termios_tcgetattr_impl(PyObject *module, int fd)
154160
Py_DECREF(v); \
155161
goto err; \
156162
} \
157-
PyList_SET_ITEM(v, index, l); \
163+
PyList_SetItem(v, index, l); \
158164
} while (0)
159165

160166
ADD_LONG_ITEM(0, mode.c_iflag);
@@ -165,7 +171,7 @@ termios_tcgetattr_impl(PyObject *module, int fd)
165171
ADD_LONG_ITEM(5, ospeed);
166172
#undef ADD_LONG_ITEM
167173

168-
PyList_SET_ITEM(v, 6, cc);
174+
PyList_SetItem(v, 6, cc);
169175
return v;
170176
err:
171177
Py_DECREF(cc);
@@ -214,7 +220,7 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
214220

215221
speed_t ispeed, ospeed;
216222
#define SET_FROM_LIST(TYPE, VAR, LIST, N) do { \
217-
PyObject *item = PyList_GET_ITEM(LIST, N); \
223+
PyObject *item = PyList_GetItem(LIST, N); \
218224
long num = PyLong_AsLong(item); \
219225
if (num == -1 && PyErr_Occurred()) { \
220226
return NULL; \
@@ -230,7 +236,7 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
230236
SET_FROM_LIST(speed_t, ospeed, term, 5);
231237
#undef SET_FROM_LIST
232238

233-
PyObject *cc = PyList_GET_ITEM(term, 6);
239+
PyObject *cc = PyList_GetItem(term, 6);
234240
if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
235241
PyErr_Format(PyExc_TypeError,
236242
"tcsetattr: attributes[6] must be %d element list",

0 commit comments

Comments
 (0)
0