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.
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]
4551module 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