Enable termios stdlib module#567
Conversation
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.
352311d to
93263d6
Compare
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.
93263d6 to
f21fd9b
Compare
There was a problem hiding this comment.
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
termioson Nanvix by removing it fromPY_STDLIB_MOD_SET_NA(and mirroring in generatedconfigure). - Add
AC_CHECK_FUNCSprobes +pyconfig.h.intemplates for missing termios-related libc functions, and guard the affected call sites inModules/termios.c. - Skip
PtyTestsinput/pty-driven tests on Nanvix standalone mode due toos.pipe()returningENOSYS.
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.
There was a problem hiding this comment.
Could you file issues for those in nanvix repo?
There was a problem hiding this comment.
Filed in nanvix/nanvix — one per missing or stubbed function:
Missing from libposix (guarded behind HAVE_* in this PR):
- nanvix/2220 — tcdrain
- nanvix/2221 — tcflush
- nanvix/2222 — tcflow
- nanvix/2223 — tcsendbreak
- nanvix/2224 — cfgetispeed
- nanvix/2225 — cfgetospeed
- nanvix/2226 — cfsetispeed
- nanvix/2227 — cfsetospeed
No-op stubs in dummy.rs (link, silently lie — separate behavioural bugs):
- nanvix/2228 — tcgetattr
- nanvix/2229 — tcsetattr
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.
Closes #302.
Enables the
termiosstdlib module on the Nanvix port.What changed
termioson — drop it from the "not available" list inconfigure.ac(and mirror in the generatedconfigure).libposixonlyexports
tcgetattr/tcsetattr(as no-op stubs). The other eightPOSIX termios functions (
tcdrain,tcflush,tcflow,tcsendbreak,cf{g,s}et{i,o}speed) are missing and would failto link. Following the
HAVE_MSYNCpattern from Enable the mmap stdlib module on Nanvix #561:AC_CHECK_FUNCS,HAVE_*slots inpyconfig.h.in,Modules/termios.c—cf*speedcallsfall back to zero/no-op so
tc{get,set}attrstill worksend-to-end; the four top-level functions raise
termios.errorwitherrno = ENOSYS, matching the errno-based convention usedelsewhere in the module.
PtyTestsmethods 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 andbehaviour is unchanged.
Why the test_builtin.py skips
Enabling
termiosexposes a pre-existing standalone-mode gap. Thechain:
import termiosfailed on Nanvix.import ttyfail (it doesfrom termios import *),which made
import ptyfail.test_builtin.pydoestry: import pty / except ImportError: pty = Noneand gates
PtyTestson@unittest.skipUnless(pty, ...), so allfour methods skipped silently.
termios→tty→ptyall import cleanly, thegate opens, and the four methods actually run for the first time.
os.pipe(), whichis 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.pyandtest_posix.py. Single-process and multi-process modes have workingpipe()and run the tests normally.Verification
./z distclean && ./z clean && ./z --mode=$MODE setup && ./z testgreen across all three modes:
Smoke
import termios; print(termios.B9600)prints9600per modeagainst the staged ramfs.
Follow-ups (separate PRs)
nanvix/nanvixumbrella for the eight missing termios functions.nanvix/cpythoncleanup ticket to drop theHAVE_*guards oncelibposix grows the symbols (analogue of [build] Remove HAVE_MSYNC guard in mmapmodule.c once nanvix/nanvix#2212 lands #562).
tc{get,set}attrruntime semantics — they linkbut do nothing.