[pypy-commit] pypy kill_ll_termios: Fix translation, and define all constants directly, without using the host Python.

amauryfa noreply at buildbot.pypy.org
Sat Jan 10 13:36:57 CET 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: kill_ll_termios
Changeset: r75280:63d0ea0e1a2b
Date: 2015-01-10 12:26 +0100
http://bitbucket.org/pypy/pypy/changeset/63d0ea0e1a2b/

Log:	Fix translation, and define all constants directly, without using
	the host Python.

diff --git a/pypy/module/termios/__init__.py b/pypy/module/termios/__init__.py
--- a/pypy/module/termios/__init__.py
+++ b/pypy/module/termios/__init__.py
@@ -1,5 +1,7 @@
 from pypy.interpreter.mixedmodule import MixedModule
 
+from rpython.rlib import rtermios
+
 class Module(MixedModule):
     "This module provides an interface to the Posix calls for tty I/O control.\n\
     For a complete description of these calls, see the Posix or Unix manual\n\
@@ -23,10 +25,6 @@
         'error'       : 'space.fromcache(interp_termios.Cache).w_error',
     }
 
-# XXX this is extremaly not-portable, but how to prevent this?
-
-import termios
-for i in dir(termios):
-    val = getattr(termios, i)
-    if i.isupper() and type(val) is int:
-        Module.interpleveldefs[i] = "space.wrap(%s)" % val
+    for name in rtermios.all_constants:
+        value = getattr(rtermios, name)
+        interpleveldefs[name] = "space.wrap(%s)" % value
diff --git a/pypy/module/termios/interp_termios.py b/pypy/module/termios/interp_termios.py
--- a/pypy/module/termios/interp_termios.py
+++ b/pypy/module/termios/interp_termios.py
@@ -6,7 +6,6 @@
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.error import wrap_oserror, OperationError
 from rpython.rlib import rtermios
-import termios
 
 class Cache:
     def __init__(self, space):
@@ -52,9 +51,9 @@
     l_w = [space.wrap(i) for i in [iflag, oflag, cflag, lflag, ispeed, ospeed]]
     # last one need to be chosen carefully
     cc_w = [space.wrap(i) for i in cc]
-    if lflag & termios.ICANON:
-        cc_w[termios.VMIN] = space.wrap(ord(cc[termios.VMIN][0]))
-        cc_w[termios.VTIME] = space.wrap(ord(cc[termios.VTIME][0]))
+    if lflag & rtermios.ICANON:
+        cc_w[rtermios.VMIN] = space.wrap(ord(cc[rtermios.VMIN][0]))
+        cc_w[rtermios.VTIME] = space.wrap(ord(cc[rtermios.VTIME][0]))
     w_cc = space.newlist(cc_w)
     l_w.append(w_cc)
     return space.newlist(l_w)
@@ -63,14 +62,14 @@
 def tcsendbreak(space, w_fd, duration):
     fd = space.c_filedescriptor_w(w_fd)
     try:
-        termios.tcsendbreak(fd, duration)
+        rtermios.tcsendbreak(fd, duration)
     except OSError, e:
         raise convert_error(space, e)
 
 def tcdrain(space, w_fd):
     fd = space.c_filedescriptor_w(w_fd)
     try:
-        termios.tcdrain(fd)
+        rtermios.tcdrain(fd)
     except OSError, e:
         raise convert_error(space, e)
 
@@ -78,7 +77,7 @@
 def tcflush(space, w_fd, queue):
     fd = space.c_filedescriptor_w(w_fd)
     try:
-        termios.tcflush(fd, queue)
+        rtermios.tcflush(fd, queue)
     except OSError, e:
         raise convert_error(space, e)
 
@@ -86,6 +85,6 @@
 def tcflow(space, w_fd, action):
     fd = space.c_filedescriptor_w(w_fd)
     try:
-        termios.tcflow(fd, action)
+        rtermios.tcflow(fd, action)
     except OSError, e:
         raise convert_error(space, e)
diff --git a/pypy/module/termios/test/test_termios.py b/pypy/module/termios/test/test_termios.py
--- a/pypy/module/termios/test/test_termios.py
+++ b/pypy/module/termios/test/test_termios.py
@@ -136,7 +136,7 @@
             val = getattr(termios, name)
             if name.isupper() and type(val) is int:
                 d[name] = val
-        assert d == self.orig_module_dict
+        assert sorted(d.items()) == sorted(self.orig_module_dict.items())
 
     def test_error(self):
         import termios, errno, os
diff --git a/rpython/rlib/rtermios.py b/rpython/rlib/rtermios.py
--- a/rpython/rlib/rtermios.py
+++ b/rpython/rlib/rtermios.py
@@ -11,30 +11,95 @@
 from rpython.rlib.rarithmetic import intmask
 
 eci = ExternalCompilationInfo(
-    includes = ['termios.h', 'unistd.h']
+    includes = ['termios.h', 'unistd.h', 'sys/ioctl.h']
 )
 
 class CConfig:
     _compilation_info_ = eci
-    NCCS = rffi_platform.DefinedConstantInteger('NCCS')
     _HAVE_STRUCT_TERMIOS_C_ISPEED = rffi_platform.Defined(
             '_HAVE_STRUCT_TERMIOS_C_ISPEED')
     _HAVE_STRUCT_TERMIOS_C_OSPEED = rffi_platform.Defined(
             '_HAVE_STRUCT_TERMIOS_C_OSPEED')
 
-    TCSANOW = rffi_platform.ConstantInteger('TCSANOW')
-    TCIOFLUSH = rffi_platform.ConstantInteger('TCIOFLUSH')
-    TCOON = rffi_platform.ConstantInteger('TCOON')
-
-
+CONSTANT_NAMES = (
+    # cfgetospeed(), cfsetospeed() constants
+    """B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600
+       B19200 B38400 B57600 B115200 B230400 B460800 CBAUDEX
+    """
+    # tcsetattr() constants
+    """TCSANOW TCSADRAIN TCSAFLUSH TCSASOFT
+    """
+    # tcflush() constants
+    """TCIFLUSH TCOFLUSH TCIOFLUSH
+    """
+    # tcflow() constants
+    """TCOOFF TCOON TCIOFF TCION
+    """
+    # struct termios.c_iflag constants
+    """IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC 
+       IXON IXANY IXOFF IMAXBEL
+    """
+    # struct termios.c_oflag constants
+    """OPOST OLCUC ONLCR OCRNL ONOCR ONLRET OFILL OFDEL
+       NLDLY CRDLY TABDLY BSDLY VTDLY FFDLY
+    """
+    # struct termios.c_oflag-related values (delay mask)
+    """NL0 NL1 CR0 CR1 CR2 CR3 TAB0 TAB1 TAB2 TAB3 XTABS
+       BS0 BS1 VT0 VT1 FF0 FF1
+    """
+    # struct termios.c_cflag constants
+    """CSIZE CSTOPB CREAD PARENB PARODD HUPCL CLOCAL CIBAUD CRTSCTS
+    """
+    # struct termios.c_cflag-related values (character size)
+    """CS5 CS6 CS7 CS8
+    """
+    # struct termios.c_lflag constants
+    """ISIG ICANON XCASE ECHO ECHOE ECHOK ECHONL ECHOCTL ECHOPRT ECHOKE
+       FLUSHO NOFLSH TOSTOP PENDIN IEXTEN
+    """
+    # indexes into the control chars array returned by tcgetattr()
+    """VINTR VQUIT VERASE VKILL VEOF VTIME VMIN VSWTC VSWTCH VSTART VSTOP
+       VSUSP VEOL VREPRINT VDISCARD VWERASE VLNEXT VEOL2
+    """
+    # Others?
+    """CBAUD CDEL CDSUSP CEOF CEOL CEOL2 CEOT CERASE CESC CFLUSH CINTR CKILL
+       CLNEXT CNUL COMMON CQUIT CRPRNT CSTART CSTOP CSUSP CSWTCH CWERASE
+       EXTA EXTB
+       FIOASYNC FIOCLEX FIONBIO FIONCLEX FIONREAD
+       IBSHIFT INIT_C_CC IOCSIZE_MASK IOCSIZE_SHIFT
+       NCC NCCS NSWTCH N_MOUSE N_PPP N_SLIP N_STRIP N_TTY
+       TCFLSH TCGETA TCGETS TCSBRK TCSBRKP TCSETA TCSETAF TCSETAW TCSETS
+       TCSETSF TCSETSW TCXONC
+       TIOCCONS TIOCEXCL TIOCGETD TIOCGICOUNT TIOCGLCKTRMIOS TIOCGPGRP
+       TIOCGSERIAL TIOCGSOFTCAR TIOCGWINSZ TIOCINQ TIOCLINUX TIOCMBIC
+       TIOCMBIS TIOCMGET TIOCMIWAIT TIOCMSET TIOCM_CAR TIOCM_CD TIOCM_CTS 
+       TIOCM_DSR TIOCM_DTR TIOCM_LE TIOCM_RI TIOCM_RNG TIOCM_RTS TIOCM_SR
+       TIOCM_ST TIOCNOTTY TIOCNXCL TIOCOUTQ TIOCPKT TIOCPKT_DATA
+       TIOCPKT_DOSTOP TIOCPKT_FLUSHREAD TIOCPKT_FLUSHWRITE TIOCPKT_NOSTOP
+       TIOCPKT_START TIOCPKT_STOP TIOCSCTTY TIOCSERCONFIG TIOCSERGETLSR 
+       TIOCSERGETMULTI TIOCSERGSTRUCT TIOCSERGWILD TIOCSERSETMULTI
+       TIOCSERSWILD TIOCSER_TEMT TIOCSETD TIOCSLCKTRMIOS TIOCSPGRP
+       TIOCSSERIAL TIOCSSOFTCAR TIOCSTI TIOCSWINSZ TIOCTTYGSTRUCT
+    """).split()
+    
+for name in CONSTANT_NAMES:
+    setattr(CConfig, name, rffi_platform.DefinedConstantInteger(name))
 
 c_config = rffi_platform.configure(CConfig)
-NCCS = c_config['NCCS']
 
-TCSANOW = c_config['TCSANOW']
-TCIOFLUSH = c_config['TCIOFLUSH']
-TCOON = c_config['TCOON']
+# Copy VSWTCH to VSWTC and vice-versa
+if c_config['VSWTC'] is None:
+    c_config['VSWTC'] = c_config['VSWTCH']
+if c_config['VSWTCH'] is None:
+    c_config['VSWTCH'] = c_config['VSWTC']
 
+all_constants = {}
+for name in CONSTANT_NAMES:
+    value = c_config[name]
+    if value is not None:
+        globals()[name] = value
+        all_constants[name] = value
+            
 TCFLAG_T = rffi.UINT
 CC_T = rffi.UCHAR
 SPEED_T = rffi.UINT


More information about the pypy-commit mailing list