Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-85283: Build termios extension with the limited C API#116928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:limited_termios
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletionDoc/whatsnew/3.13.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1479,7 +1479,8 @@ Build Changes
* Building CPython now requires a compiler with support for the C11 atomic
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.

* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``, ``winsound``,
* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``,
``termios``, ``winsound``,
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``,
``_testimportmultiple`` and ``_uuid`` C extensions are now built with the
:ref:`limited C API <limited-c-api>`.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
The ``fcntl``, ``grp``and ``pwd`` C extensions are now built with the :ref:`limited
C API <limited-c-api>`.(Contributed by Victor Stinner in :gh:`85283`.)
The ``fcntl``, ``grp``, ``pwd``and ``termios`` C extensions are now
built with the :ref:`limitedC API <limited-c-api>`.Patch by Victor Stinner.
29 changes: 16 additions & 13 deletionsModules/clinic/termios.c.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

38 changes: 22 additions & 16 deletionsModules/termios.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
/* termios.c -- POSIX terminal I/O module implementation. */

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
// Need limited C API version 3.13 for PyLong_AsInt()
// in code generated by Argument Clinic.
#include "pyconfig.h" // Py_GIL_DISABLED
#ifndef Py_GIL_DISABLED
# define Py_LIMITED_API 0x030d0000
#endif

#include "Python.h"

#include <string.h> // memset()
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h> // _POSIX_VDISABLE

// On QNX 6, struct termio must be declared by including sys/termio.h
// if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
// be included before termios.h or it will generate an error.
Expand All@@ -19,28 +27,26 @@
# define CTRL(c) ((c)&037)
#endif

// We could do better. Check bpo-32660
#if defined(__sun)
/* We could do better. Check issue-32660 */
#include <sys/filio.h>
#include <sys/sockio.h>
# include <sys/filio.h>
# include <sys/sockio.h>
#endif

#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h> // _POSIX_VDISABLE

/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
* MDTR, MRI, and MRTS (apparently used internally by some things
* defined as macros; these are not used here directly).
*/
#ifdef HAVE_SYS_MODEM_H
#include <sys/modem.h>
#include <sys/modem.h>
#endif

/* HP-UX requires that this be included to pick up TIOCGPGRP and friends */
#ifdef HAVE_SYS_BSDTTY_H
#include <sys/bsdtty.h>
#include <sys/bsdtty.h>
#endif


/*[clinic input]
module termios
[clinic start generated code]*/
Expand DownExpand Up@@ -120,7 +126,7 @@ termios_tcgetattr_impl(PyObject *module, int fd)
v = PyBytes_FromStringAndSize(&ch, 1);
if (v == NULL)
goto err;
PyList_SET_ITEM(cc, i, v);
PyList_SetItem(cc, i, v);
}

/* Convert the MIN and TIME slots to integer. On some systems, the
Expand DownExpand Up@@ -154,7 +160,7 @@ termios_tcgetattr_impl(PyObject *module, int fd)
Py_DECREF(v); \
goto err; \
} \
PyList_SET_ITEM(v, index, l); \
PyList_SetItem(v, index, l); \
} while (0)

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

PyList_SET_ITEM(v, 6, cc);
PyList_SetItem(v, 6, cc);
return v;
err:
Py_DECREF(cc);
Expand DownExpand Up@@ -214,7 +220,7 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)

speed_t ispeed, ospeed;
#define SET_FROM_LIST(TYPE, VAR, LIST, N) do { \
PyObject *item =PyList_GET_ITEM(LIST, N); \
PyObject *item =PyList_GetItem(LIST, N); \
long num = PyLong_AsLong(item); \
if (num == -1 && PyErr_Occurred()) { \
return NULL; \
Expand All@@ -230,7 +236,7 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
SET_FROM_LIST(speed_t, ospeed, term, 5);
#undef SET_FROM_LIST

PyObject *cc =PyList_GET_ITEM(term, 6);
PyObject *cc =PyList_GetItem(term, 6);
if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
PyErr_Format(PyExc_TypeError,
"tcsetattr: attributes[6] must be %d element list",
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp