[commit: packages/unix] master: Don't assume existence of termios constants beyond `B38400` (33920fe)

git at git.haskell.org git at git.haskell.org
Tue Apr 19 21:37:12 UTC 2016


Repository : ssh://git@git.haskell.org/unix

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/33920fe3e0477cef1beda59d0ea47f4344be8d26/unix

>---------------------------------------------------------------

commit 33920fe3e0477cef1beda59d0ea47f4344be8d26
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Mon Nov 16 19:03:12 2015 +0100

    Don't assume existence of termios constants beyond `B38400`
    
    This patch does not modify the `BaudRate` structure but rather causes
    some functions taking a `BaudRate` to throw exceptions on systems which
    don't provide `B57600` and/or `B115200`. I'm not totally happy with this
    patch yet, but this unbreaks compilation on platforms which don't define
    at least of these constants.
    
    This fixes #51


>---------------------------------------------------------------

33920fe3e0477cef1beda59d0ea47f4344be8d26
 System/Posix/Terminal/Common.hsc | 12 ++++++++++++
 changelog.md                     |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/System/Posix/Terminal/Common.hsc b/System/Posix/Terminal/Common.hsc
index 2f6327a..49418f5 100644
--- a/System/Posix/Terminal/Common.hsc
+++ b/System/Posix/Terminal/Common.hsc
@@ -527,8 +527,16 @@ baud2Word B4800 = (#const B4800)
 baud2Word B9600 = (#const B9600)
 baud2Word B19200 = (#const B19200)
 baud2Word B38400 = (#const B38400)
+#ifdef B57600
 baud2Word B57600 = (#const B57600)
+#else
+baud2Word B57600 = error "B57600 not available on this system"
+#endif
+#ifdef B115200
 baud2Word B115200 = (#const B115200)
+#else
+baud2Word B115200 = error "B115200 not available on this system"
+#endif
 
 -- And convert a word back to a baud rate
 -- We really need some cpp macros here.
@@ -551,8 +559,12 @@ word2Baud x =
     else if x == (#const B9600) then B9600
     else if x == (#const B19200) then B19200
     else if x == (#const B38400) then B38400
+#ifdef B57600
     else if x == (#const B57600) then B57600
+#endif
+#ifdef B115200
     else if x == (#const B115200) then B115200
+#endif
     else error "unknown baud rate"
 
 -- Clear termios i_flag
diff --git a/changelog.md b/changelog.md
index c3d43df..0f69383 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,6 +4,8 @@
 
   * Don't assume non-POSIX `WCOREDUMP(x)` macro exists
 
+  * Don't assume existence of termios constants beyond `B38400`
+
 ## 2.7.1.0  *Dec 2014*
 
   * Bundled with GHC 7.10.1



More information about the ghc-commits mailing list