Skip to content

Enable termios stdlib module#567

Merged
ppenna merged 2 commits into
nanvix/v3.12.3from
feat/302-termios
Apr 30, 2026
Merged

Enable termios stdlib module#567
ppenna merged 2 commits into
nanvix/v3.12.3from
feat/302-termios

Conversation

@ada-x64
Copy link
Copy Markdown

@ada-x64 ada-x64 commented Apr 30, 2026

Closes #302.

Enables the termios stdlib module on the Nanvix port.

What changed

  • Turn termios on — drop it from the "not available" list in
    configure.ac (and mirror in the generated configure).
  • Patch around missing libc functions — Nanvix's libposix only
    exports tcgetattr / tcsetattr (as no-op stubs). The other eight
    POSIX termios functions (tcdrain, tcflush, tcflow,
    tcsendbreak, cf{g,s}et{i,o}speed) are missing and would fail
    to link. Following the HAVE_MSYNC pattern from Enable the mmap stdlib module on Nanvix #561:
    • add each function to AC_CHECK_FUNCS,
    • add matching HAVE_* slots in pyconfig.h.in,
    • guard each call site in Modules/termios.ccf*speed calls
      fall back to zero/no-op so tc{get,set}attr still works
      end-to-end; the four top-level functions raise termios.error with
      errno = ENOSYS, matching the errno-based convention used
      elsewhere in the module.
  • Skip four PtyTests methods on standalone mode — see below.

On any platform with the full termios surface (i.e. every existing
in-tree target other than Nanvix), the HAVE_* macros are defined and
behaviour is unchanged.

Why the test_builtin.py skips

Enabling termios exposes a pre-existing standalone-mode gap. The
chain:

  • Before this PR, import termios failed on Nanvix.
  • That made import tty fail (it does from termios import *),
    which made import pty fail.
  • test_builtin.py does try: import pty / except ImportError: pty = None
    and gates PtyTests on @unittest.skipUnless(pty, ...), so all
    four methods skipped silently.
  • After this PR, termiosttypty all import cleanly, the
    gate opens, and the four methods actually run for the first time.
  • They then fail on standalone because they call os.pipe(), which
    is unimplemented in standalone mode (tracked as NSKIP023 /
    [posix] Support pipe() nanvix#343).

The four methods get @unittest.skipIf(support.is_nanvix_standalone, ...)
matching the existing pattern in test_genericpath.py and
test_posix.py. Single-process and multi-process modes have working
pipe() and run the tests normally.

Verification

./z distclean && ./z clean && ./z --mode=$MODE setup && ./z test
green across all three modes:

mode result
standalone 116/116
single-process 121/121
multi-process 121/121

Smoke import termios; print(termios.B9600) prints 9600 per mode
against the staged ramfs.

Follow-ups (separate PRs)

Copilot AI review requested due to automatic review settings April 30, 2026 14:15
Drop [termios] from the Nanvix arm of PY_STDLIB_MOD_SET_NA in
configure.ac, and the matching py_cv_module_termios=n/a in the
generated configure. The PY_STDLIB_MOD([termios], ...) gate is
header-only and termios.h is present in the toolchain.

Refs #302.

This comment was marked as resolved.

Cycle 2 of the empirical enablement of issue #302. Cycle 1 (commit
77606547e38) flipped termios on in Modules/Setup.stdlib and confirmed
that Modules/termios.c calls cfget/cfset speed helpers, tcsendbreak,
tcdrain, tcflush, tcflow unconditionally, and that nanvix's libposix.a
exports tcgetattr/tcsetattr/tcgetpgrp/tcsetpgrp but not the rest.

This commit:
- adds cfgetispeed, cfgetospeed, cfsetispeed, cfsetospeed, tcdrain,
  tcflow, tcflush, tcsendbreak to the AC_CHECK_FUNCS list in
  configure.ac and mirrors the change in the generated configure
  script (no autoreconf, per port convention).
- adds the matching HAVE_* slots to pyconfig.h.in so the autoconf
  substitution has targets.
- guards the speed helpers with defined(HAVE_CF*SPEED) (zero fallback
  for the getters, no-op for the setters) and wraps tcsendbreak,
  tcdrain, tcflush, tcflow bodies in defined(HAVE_TC*); platforms
  without a given function raise termios.error 'not supported on this
  system' instead of failing to link.
- skips PtyTests in Lib/test/test_builtin.py under standalone mode
  (NSKIP023, issue #503) since termios now imports cleanly there and
  un-skips four pty.fork() tests that hit os.pipe() ENOSYS, mirroring
  the precedent in Lib/test/test_genericpath.py and test_posix.py.

On any platform with the full termios surface (every existing in-tree
target), the HAVE_* macros are defined and behaviour is unchanged. On
nanvix, import termios now succeeds across standalone, single-process,
and multi-process; regrtest is green in all three modes and a smoke
'import termios; print(termios.B9600)' against the staged ramfs prints
9600 in each.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables the termios stdlib extension module for the Nanvix port by removing it from Nanvix’s “not available” module set and adding autoconf-based feature detection/guards so the module links even when Nanvix’s libc lacks parts of the POSIX termios surface.

Changes:

  • Enable termios on Nanvix by removing it from PY_STDLIB_MOD_SET_NA (and mirroring in generated configure).
  • Add AC_CHECK_FUNCS probes + pyconfig.h.in templates for missing termios-related libc functions, and guard the affected call sites in Modules/termios.c.
  • Skip PtyTests input/pty-driven tests on Nanvix standalone mode due to os.pipe() returning ENOSYS.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyconfig.h.in Adds #undef HAVE_* templates for termios-related libc function probes.
configure.ac Adds AC_CHECK_FUNCS entries for termios funcs and enables the termios module for Nanvix.
configure Mirrors configure.ac changes in the checked-in generated script.
Modules/termios.c Guards calls to missing termios APIs; provides fallbacks/errors when unavailable.
Lib/test/test_builtin.py Skips pty-based input() tests on Nanvix standalone where os.pipe() is unimplemented.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread configure.ac
Comment thread Modules/termios.c
Comment thread 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable termios stdlib module (terminal I/O control)

3 participants