Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,9 @@ def child(wpipe):
expected = terminal_input.decode(sys.stdin.encoding) # what else?
self.assertEqual(input_result, expected)

# NSKIP023 https://github.com/nanvix/cpython/issues/503
@unittest.skipIf(support.is_nanvix_standalone,
"NSKIP023: os.pipe() ENOSYS in standalone mode")
def test_input_tty(self):
# Test input() functionality when wired to a tty (the code path
# is different and invokes GNU readline if available).
Expand All @@ -2337,16 +2340,25 @@ def skip_if_readline(self):
if 'readline' in sys.modules:
self.skipTest("the readline module is loaded")

# NSKIP023 https://github.com/nanvix/cpython/issues/503
@unittest.skipIf(support.is_nanvix_standalone,
"NSKIP023: os.pipe() ENOSYS in standalone mode")
def test_input_tty_non_ascii(self):
self.skip_if_readline()
# Check stdin/stdout encoding is used when invoking PyOS_Readline()
self.check_input_tty("prompté", b"quux\xe9", "utf-8")

# NSKIP023 https://github.com/nanvix/cpython/issues/503
@unittest.skipIf(support.is_nanvix_standalone,
"NSKIP023: os.pipe() ENOSYS in standalone mode")
def test_input_tty_non_ascii_unicode_errors(self):
self.skip_if_readline()
# Check stdin/stdout error handler is used when invoking PyOS_Readline()
self.check_input_tty("prompté", b"quux\xe9", "ascii")

# NSKIP023 https://github.com/nanvix/cpython/issues/503
@unittest.skipIf(support.is_nanvix_standalone,
"NSKIP023: os.pipe() ENOSYS in standalone mode")
def test_input_no_stdout_fileno(self):
# Issue #24402: If stdin is the original terminal but stdout.fileno()
# fails, do not use the original stdout file descriptor
Expand Down
48 changes: 46 additions & 2 deletions Modules/termios.c
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you file issues for those in nanvix repo?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed in nanvix/nanvix — one per missing or stubbed function:

Missing from libposix (guarded behind HAVE_* in this PR):

No-op stubs in dummy.rs (link, silently lie — separate behavioural bugs):

Each issue includes the POSIX signature, where it's needed, the
current cpython-side workaround, acceptance criteria, and a
revert checklist for when it lands.

Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,17 @@ termios_tcgetattr_impl(PyObject *module, int fd)
return PyErr_SetFromErrno(state->TermiosError);
}

speed_t ispeed = cfgetispeed(&mode);
speed_t ospeed = cfgetospeed(&mode);
speed_t ispeed, ospeed;
#ifdef HAVE_CFGETISPEED
ispeed = cfgetispeed(&mode);
#else
ispeed = 0;
#endif
#ifdef HAVE_CFGETOSPEED
ospeed = cfgetospeed(&mode);
#else
ospeed = 0;
#endif

PyObject *cc = PyList_New(NCCS);
if (cc == NULL) {
Expand Down Expand Up @@ -232,10 +241,18 @@ termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term)
}
}

#ifdef HAVE_CFSETISPEED
if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
return PyErr_SetFromErrno(state->TermiosError);
#else
(void)ispeed;
#endif
#ifdef HAVE_CFSETOSPEED
if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
return PyErr_SetFromErrno(state->TermiosError);
#else
(void)ospeed;
#endif

Py_BEGIN_ALLOW_THREADS
r = tcsetattr(fd, when, &mode);
Expand Down Expand Up @@ -265,6 +282,7 @@ termios_tcsendbreak_impl(PyObject *module, int fd, int duration)
/*[clinic end generated code: output=5945f589b5d3ac66 input=dc2f32417691f8ed]*/
{
termiosmodulestate *state = PyModule_GetState(module);
#ifdef HAVE_TCSENDBREAK
int r;

Py_BEGIN_ALLOW_THREADS
Expand All @@ -276,6 +294,12 @@ termios_tcsendbreak_impl(PyObject *module, int fd, int duration)
}

Py_RETURN_NONE;
#else
(void)fd;
(void)duration;
errno = ENOSYS;
return PyErr_SetFromErrno(state->TermiosError);
#endif
Comment thread
ada-x64 marked this conversation as resolved.
}

/*[clinic input]
Expand All @@ -292,6 +316,7 @@ termios_tcdrain_impl(PyObject *module, int fd)
/*[clinic end generated code: output=5fd86944c6255955 input=c99241b140b32447]*/
{
termiosmodulestate *state = PyModule_GetState(module);
#ifdef HAVE_TCDRAIN
int r;

Py_BEGIN_ALLOW_THREADS
Expand All @@ -303,6 +328,11 @@ termios_tcdrain_impl(PyObject *module, int fd)
}

Py_RETURN_NONE;
#else
(void)fd;
errno = ENOSYS;
return PyErr_SetFromErrno(state->TermiosError);
#endif
}

/*[clinic input]
Expand All @@ -324,6 +354,7 @@ termios_tcflush_impl(PyObject *module, int fd, int queue)
/*[clinic end generated code: output=2424f80312ec2f21 input=0f7d08122ddc07b5]*/
{
termiosmodulestate *state = PyModule_GetState(module);
#ifdef HAVE_TCFLUSH
int r;

Py_BEGIN_ALLOW_THREADS
Expand All @@ -335,6 +366,12 @@ termios_tcflush_impl(PyObject *module, int fd, int queue)
}

Py_RETURN_NONE;
#else
(void)fd;
(void)queue;
errno = ENOSYS;
return PyErr_SetFromErrno(state->TermiosError);
#endif
}

/*[clinic input]
Expand All @@ -356,6 +393,7 @@ termios_tcflow_impl(PyObject *module, int fd, int action)
/*[clinic end generated code: output=afd10928e6ea66eb input=c6aff0640b6efd9c]*/
{
termiosmodulestate *state = PyModule_GetState(module);
#ifdef HAVE_TCFLOW
int r;

Py_BEGIN_ALLOW_THREADS
Expand All @@ -367,6 +405,12 @@ termios_tcflow_impl(PyObject *module, int fd, int action)
}

Py_RETURN_NONE;
#else
(void)fd;
(void)action;
errno = ENOSYS;
return PyErr_SetFromErrno(state->TermiosError);
#endif
}

/*[clinic input]
Expand Down
49 changes: 48 additions & 1 deletion configure

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

7 changes: 4 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4898,7 +4898,9 @@ fi

# checks for library functions
AC_CHECK_FUNCS([ \
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
accept4 alarm bind_textdomain_codeset \
cfgetispeed cfgetospeed cfsetispeed cfsetospeed \
chmod chown clock close_range confstr \
copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
Expand All @@ -4919,7 +4921,7 @@ AC_CHECK_FUNCS([ \
setresuid setreuid setsid setuid setvbuf shutdown sigaction sigaltstack \
sigfillset siginterrupt sigpending sigrelse sigtimedwait sigwait \
sigwaitinfo snprintf splice strftime strlcpy strsignal symlinkat sync \
sysconf system tcgetpgrp tcsetpgrp tempnam timegm times tmpfile \
sysconf system tcdrain tcflow tcflush tcgetpgrp tcsendbreak tcsetpgrp tempnam timegm times tmpfile \
tmpnam tmpnam_r truncate ttyname umask uname unlinkat utimensat utimes vfork \
wait wait3 wait4 waitid waitpid wcscoll wcsftime wcsxfrm wmemcmp writev \
Comment thread
ada-x64 marked this conversation as resolved.
])
Expand Down Expand Up @@ -7277,7 +7279,6 @@ AS_CASE([$ac_sys_system],
[pwd],
[spwd],
[syslog],
[termios],
[_crypt],
[nis],
[_dbm],
Expand Down
24 changes: 24 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@
/* Define to 1 if you have the <bzlib.h> header file. */
#undef HAVE_BZLIB_H

/* Define to 1 if you have the `cfgetispeed' function. */
#undef HAVE_CFGETISPEED

/* Define to 1 if you have the `cfgetospeed' function. */
#undef HAVE_CFGETOSPEED

/* Define to 1 if you have the `cfsetispeed' function. */
#undef HAVE_CFSETISPEED

/* Define to 1 if you have the `cfsetospeed' function. */
#undef HAVE_CFSETOSPEED

/* Define to 1 if you have the 'chflags' function. */
#undef HAVE_CHFLAGS

Expand Down Expand Up @@ -1402,9 +1414,21 @@
/* Define to 1 if you have the <sys/xattr.h> header file. */
#undef HAVE_SYS_XATTR_H

/* Define to 1 if you have the `tcdrain' function. */
#undef HAVE_TCDRAIN

/* Define to 1 if you have the `tcflow' function. */
#undef HAVE_TCFLOW

/* Define to 1 if you have the `tcflush' function. */
#undef HAVE_TCFLUSH

/* Define to 1 if you have the `tcgetpgrp' function. */
#undef HAVE_TCGETPGRP

/* Define to 1 if you have the `tcsendbreak' function. */
#undef HAVE_TCSENDBREAK

/* Define to 1 if you have the `tcsetpgrp' function. */
#undef HAVE_TCSETPGRP

Expand Down
Loading